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

refactor(papyrus_base_layer): set port explicitly on anvil spawn #4489

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/papyrus_base_layer/src/base_layer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn get_proved_block_at_unknown_block_number() {
return;
}

let anvil = anvil();
let anvil = anvil(None);
let config = ethereum_base_layer_config(&anvil);
let contract = ethereum_base_layer_contract(config.node_url, config.starknet_contract_address);

Expand Down
12 changes: 10 additions & 2 deletions crates/papyrus_base_layer/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::ethereum_base_layer_contract::EthereumBaseLayerConfig;
type TestEthereumNodeHandle = (GanacheInstance, TempDir);

const MINIMAL_GANACHE_VERSION: u8 = 7;

// Default funded account, there are more fixed funded accounts,
// see https://github.com/foundry-rs/foundry/tree/master/crates/anvil.
// This address is the sender address of messages sent to L2 by Anvil.
Expand Down Expand Up @@ -74,9 +75,16 @@ pub fn get_test_ethereum_node() -> (TestEthereumNodeHandle, EthereumContractAddr
((ganache, ganache_db), SN_CONTRACT_ADDR.to_string().parse().unwrap())
}

// TODO(Arni): Make port non-optional.
// Spin up Anvil instance, a local Ethereum node, dies when dropped.
pub fn anvil() -> AnvilInstance {
Anvil::new().try_spawn().unwrap_or_else(|error| match error {
pub fn anvil(port: Option<u16>) -> AnvilInstance {
let mut anvil = Anvil::new();
// If the port is not set explicitly, a random value will be used.
if let Some(port) = port {
anvil = anvil.port(port);
}

anvil.try_spawn().unwrap_or_else(|error| match error {
AnvilError::SpawnError(e) if e.to_string().contains("No such file or directory") => {
panic!(
"\n{}\n{}\n",
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_l1_provider/src/l1_scraper_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn txs_happy_flow() {
return;
}

let anvil = anvil();
let anvil = anvil(None);
// Setup.
let (mut scraper, fake_client) = scraper(&anvil).await;

Expand Down
Loading