Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test faucet website #702

Open
wants to merge 10 commits into
base: next
Choose a base branch
from

Conversation

TomasArrachea
Copy link
Collaborator

@TomasArrachea TomasArrachea commented Feb 18, 2025

Closes #673

This PR adds a test for the faucet website. It uses fantoccini as a browser client to test that all components are loading correctly.

To run fantoccini it needs a webdriver running. I'm using chromedriver here, which requires to have Chrome installed.

Also, this PR introduces a stub for the node RPC API. This allows to run the faucet and test it using the stub, instead of having to run the full node.

@TomasArrachea TomasArrachea force-pushed the tomasarrachea-test-faucet-website branch from dad20af to 801aa22 Compare February 20, 2025 17:57
Comment on lines 281 to 284
let mut chromedriver = Command::new("chromedriver")
.arg(format!("--port={chromedriver_port}"))
.spawn()
.expect("failed to start chromedriver");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to install Chromedriver and Chrome to run this locally, but I am not sure on why it's running fine in the CI

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The github CI images have a bunch of pre-installed stuff (I believe the image is like 50GB). This means less cpu wasted installing things etc. And given the amount of webdev, probably almost any semi-popular tooling for it will be pre-installed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create a target in the makefile to install Chromedriver and Chrome?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can unless you assume the OS? Its a pity the dep doesn't have a bundling option, makes this sort of thing much easier.

@TomasArrachea TomasArrachea marked this pull request as ready for review February 20, 2025 17:58
@TomasArrachea TomasArrachea changed the title WIP: test faucet website feat: test faucet website Feb 20, 2025
Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good & interesting (not something I'm familiar with), thank you.

I've left some initial questions and suggestions; I think we may also want to organise the test files a bit somehow but we can address that after everything else.

Right now this tests that the website loads and has the correct title. Would we then extend this with requesting funds from the faucet as well? (separate PR etc maybe).

Comment on lines 238 to 241
.ok_or(anyhow::anyhow!(
"Couldn't get any socket addrs for endpoint: {}",
config.endpoint
))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.ok_or(anyhow::anyhow!(
"Couldn't get any socket addrs for endpoint: {}",
config.endpoint
))?;
.with_context(|| format!("no sockets available on {}, config.endpoint))?;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I'm unsure under what circumstances that would even occur.

Copy link
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I am not too familiar with the setup but it seems great for actually testing the page within a browser context as opposed to something like running a get request through reqwest and then retrieving further resources, etc.

.with_state(faucet_state)
}

async fn serve_faucet(config: FaucetConfig) -> anyhow::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could go above create_router()

// Start the faucet connected to the stub
let config = FaucetConfig {
node_url: stub_node_url,
faucet_account_path: "src/test_data/faucet.mac".into(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be outside /src?

Comment on lines 286 to 287
// Wait for the server to be running
sleep(Duration::from_secs(1)).await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this consistent? I guess 1 second doesn't hurt but otherwise maybe there could be some loop that retries connections a couple of times or something to make it a bit more robust.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this by reading stdout to wait until chromedriver is running: 102b761

// Start the faucet connected to the stub
let config = FaucetConfig {
node_url: stub_node_url,
faucet_account_path: "test_data/faucet.mac".into(),
Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to generate this as part of the test instead?

I mainly ask because I dislike random binary files floating around the codebase.

This does bring up an idea though - if we factor out the match &cli.command from main.rs into a separate function, then we could:

  • Revert the serve_faucet changes (move them back to Command::start. This isn't overly important, just a smaller diff.
  • Run the full faucet init, account creation and start commands in order.

This would also require using tempfs to host the files.

I rather like this idea. Though maybe it would be best to merge this PR and upgrade it in another PR.

@TomasArrachea WDYT? cc @igamigo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downside of this is that the test is now taking a bit longer to run, bit I think it's fine. It was a simple change so I just pushed the changes in this PR

Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, code LGTM. Merging will depend on whether we want to upgrade the test in this PR, or in a follow-up.

Copy link
Collaborator

@tomyrd tomyrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested locally and it worked (after installing Chrome and chromedriver)

Comment on lines +271 to +272
let config_path = temp_dir().join(PathBuf::from("faucet.toml"));
let faucet_account_path = temp_dir().join(PathBuf::from("account.mac"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From memory join takes Into<Path> or no?

Suggested change
let config_path = temp_dir().join(PathBuf::from("faucet.toml"));
let faucet_account_path = temp_dir().join(PathBuf::from("account.mac"));
let config_path = temp_dir().join("faucet.toml");
let faucet_account_path = temp_dir().join("account.mac");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants