Skip to content

Commit

Permalink
refactor(papyrus_base_layer): set port explicitly on anvil spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Feb 27, 2025
1 parent 66b25a2 commit 1517f0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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 @@ -46,7 +46,7 @@ async fn get_proved_block_at_unknown_block_number() {
return;
}

let anvil = anvil();
let anvil = anvil(None);
let config = ethereum_base_layer_config_from_anvil(&anvil);
let contract = EthereumBaseLayerContract::new(config);

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

0 comments on commit 1517f0d

Please sign in to comment.