Skip to content

Commit

Permalink
chore(papyrus_base_layer): stongly link anvil with starknet_contract_…
Browse files Browse the repository at this point in the history
…address
  • Loading branch information
ArniStarkware committed Mar 2, 2025
1 parent afb296c commit badfd7a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/papyrus_base_layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ url = { workspace = true, features = ["serde"] }
validator.workspace = true

[dev-dependencies]
alloy.workspace = true
alloy = { workspace = true, features = ["node-bindings"] }
colored.workspace = true
ethers-core.workspace = true
mempool_test_utils.workspace = true
Expand Down
7 changes: 3 additions & 4 deletions crates/papyrus_base_layer/src/base_layer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use starknet_api::felt;
use url::Url;

use crate::ethereum_base_layer_contract::{EthereumBaseLayerConfig, EthereumBaseLayerContract};
use crate::test_utils::{anvil, get_test_ethereum_node, DEFAULT_ANVIL_L1_DEPLOYED_ADDRESS};
use crate::test_utils::{anvil, ethereum_base_layer_config_from_anvil, get_test_ethereum_node};
use crate::BaseLayerContract;

fn ethereum_base_layer_contract(
Expand Down Expand Up @@ -56,9 +56,8 @@ async fn get_proved_block_at_unknown_block_number() {
}

let anvil = anvil();
let node_url = anvil.endpoint_url();
let starknet_contract_address = DEFAULT_ANVIL_L1_DEPLOYED_ADDRESS.parse().unwrap();
let contract = ethereum_base_layer_contract(node_url, starknet_contract_address);
let config = ethereum_base_layer_config_from_anvil(&anvil);
let contract = ethereum_base_layer_contract(config.node_url, config.starknet_contract_address);

assert!(
contract
Expand Down
9 changes: 9 additions & 0 deletions crates/papyrus_base_layer/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use starknet_api::hash::StarkHash;
use tar::Archive;
use tempfile::{tempdir, TempDir};

use crate::ethereum_base_layer_contract::EthereumBaseLayerConfig;

type TestEthereumNodeHandle = (GanacheInstance, TempDir);

const MINIMAL_GANACHE_VERSION: u8 = 7;
Expand Down Expand Up @@ -88,3 +90,10 @@ pub fn anvil() -> AnvilInstance {
_ => panic!("Failed to spawn Anvil: {}", error.to_string().red()),
})
}

pub fn ethereum_base_layer_config_from_anvil(anvil: &AnvilInstance) -> EthereumBaseLayerConfig {
EthereumBaseLayerConfig {
node_url: anvil.endpoint_url(),
starknet_contract_address: DEFAULT_ANVIL_L1_DEPLOYED_ADDRESS.parse().unwrap(),
}
}
13 changes: 3 additions & 10 deletions crates/starknet_l1_provider/src/l1_scraper_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ use std::sync::Arc;
use alloy::node_bindings::AnvilInstance;
use alloy::primitives::U256;
use mempool_test_utils::in_ci;
use papyrus_base_layer::ethereum_base_layer_contract::{
EthereumBaseLayerConfig,
EthereumBaseLayerContract,
Starknet,
};
use papyrus_base_layer::ethereum_base_layer_contract::{EthereumBaseLayerContract, Starknet};
use papyrus_base_layer::test_utils::{
anvil,
ethereum_base_layer_config_from_anvil,
DEFAULT_ANVIL_L1_ACCOUNT_ADDRESS,
DEFAULT_ANVIL_L1_DEPLOYED_ADDRESS,
};
use starknet_api::contract_address;
use starknet_api::core::{EntryPointSelector, Nonce};
Expand All @@ -31,10 +27,7 @@ async fn scraper(
anvil: &AnvilInstance,
) -> (L1Scraper<EthereumBaseLayerContract>, Arc<FakeL1ProviderClient>) {
let fake_client = Arc::new(FakeL1ProviderClient::default());
let config = EthereumBaseLayerConfig {
node_url: anvil.endpoint_url(),
starknet_contract_address: DEFAULT_ANVIL_L1_DEPLOYED_ADDRESS.parse().unwrap(),
};
let config = ethereum_base_layer_config_from_anvil(anvil);
let base_layer = EthereumBaseLayerContract::new(config);

// Deploy a fresh Starknet contract on Anvil from the bytecode in the JSON file.
Expand Down

0 comments on commit badfd7a

Please sign in to comment.