diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 3bdca60f..c3c1994f 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -2,8 +2,6 @@ name: lint on: pull_request: - branches: - - main types: [opened, synchronize, reopened] jobs: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 63204626..d00ce321 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,8 +2,6 @@ name: test on: pull_request: - branches: - - main types: [opened, synchronize, reopened] jobs: diff --git a/Cargo.toml b/Cargo.toml index 42867806..e342f640 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,10 +29,10 @@ arbiter-core = { path = "arbiter-core" } clap = { version = "=4.4.6", features = ["derive"] } serde = { version = "=1.0.188", features = ["derive"] } serde_json = { version = "1.0.107" } -toml = { version = "=0.8.2" } config = { version = "=0.13.3" } ethers = { version = "=2.0.10" } revm = { version = "=3.5.0", features = [ "ethersdb", "std" ] } +toml = { version = "0.8.2" } # Building files quote = { version = "=1.0.33" } @@ -45,7 +45,8 @@ thiserror = { version = "=1.0.49" } tokio = { version = "=1.32.0", features = ["full"] } tempfile = { version = "=3.8.0" } assert_cmd = { version = "=2.0.12" } - +rayon = { version = "1.8.0" } +revm-primitives = { version = "1.3.0" } # Release profile [profile.release] diff --git a/arbiter-core/src/bindings/mod.rs b/arbiter-core/src/bindings/mod.rs index bd0cf24a..93a240b5 100644 --- a/arbiter-core/src/bindings/mod.rs +++ b/arbiter-core/src/bindings/mod.rs @@ -4,3 +4,4 @@ pub mod arbiter_math; pub mod arbiter_token; pub mod liquid_exchange; +pub mod weth; diff --git a/arbiter-core/src/tests/weth.rs b/arbiter-core/src/bindings/weth.rs similarity index 100% rename from arbiter-core/src/tests/weth.rs rename to arbiter-core/src/bindings/weth.rs diff --git a/arbiter-core/src/tests/environment_control.rs b/arbiter-core/src/tests/environment_control.rs index 30822fb7..023e1109 100644 --- a/arbiter-core/src/tests/environment_control.rs +++ b/arbiter-core/src/tests/environment_control.rs @@ -1,5 +1,8 @@ use super::*; -use crate::environment::fork::Fork; +use crate::{ + bindings::weth::weth, + environment::{builder::EnvironmentBuilder, fork::Fork}, +}; #[tokio::test] async fn receipt_data() { @@ -149,7 +152,6 @@ async fn randomly_sampled_gas_price() { } => SeededPoisson::new(block_rate, block_time, seed), _ => panic!("Expected RandomlySampled block type"), }; - let mut expected_txs_per_block_vec = vec![]; for _ in 0..2 { expected_txs_per_block_vec.push(distribution.sample()); @@ -225,12 +227,10 @@ async fn stop_environment() { #[tokio::test] async fn fork_into_arbiter() { - let fork = Fork::from_disk("../example_fork/test.json").unwrap(); + let fork = Fork::from_disk("../example_fork/fork_into_test.json").unwrap(); // Get the environment going - let environment = crate::environment::builder::EnvironmentBuilder::new() - .db(fork.db) - .build(); + let environment = EnvironmentBuilder::new().db(fork.db).build(); // Create a client let client = RevmMiddleware::new(&environment, Some("name")).unwrap(); @@ -242,6 +242,7 @@ async fn fork_into_arbiter() { let address_to_check_balance = Address::from_str(&weth_meta.mappings.get("balanceOf").unwrap()[0]).unwrap(); + println!("checking address: {}", address_to_check_balance); let balance = weth .balance_of(address_to_check_balance) .call() diff --git a/arbiter-core/src/tests/mod.rs b/arbiter-core/src/tests/mod.rs index 362f1851..989f7a9b 100644 --- a/arbiter-core/src/tests/mod.rs +++ b/arbiter-core/src/tests/mod.rs @@ -7,7 +7,6 @@ mod data_output; mod derives; mod environment_control; mod middleware_instructions; -mod weth; use std::{str::FromStr, sync::Arc}; diff --git a/bin/fork/mod.rs b/bin/fork/mod.rs index b6cba17f..f07c0ac9 100644 --- a/bin/fork/mod.rs +++ b/bin/fork/mod.rs @@ -36,7 +36,6 @@ impl ForkConfig { pub(crate) fn new(fork_config_path: &str) -> Result { let mut cwd = env::current_dir().unwrap(); cwd.push(fork_config_path); - println!("Reading config from: {:?}", cwd); let config = Config::builder() .add_source(config::File::with_name( cwd.to_str() @@ -70,13 +69,17 @@ impl ForkConfig { let info = ethers_db .basic(address.to_fixed_bytes().into()) .map_err(|_| { - ArbiterError::DBError("Failed to fetch account info with EthersDB.".to_string()) + ArbiterError::DBError( + "Failed to fetch account info with + EthersDB." + .to_string(), + ) })? .ok_or(ArbiterError::DBError( "Failed to fetch account info with EthersDB.".to_string(), ))?; - db.insert_account_info(address.to_fixed_bytes().into(), info); + db.insert_account_info(address.to_fixed_bytes().into(), info); let artifacts = digest::digest_artifacts(contract_data.artifacts_path.as_str())?; let storage_layout = artifacts.storage_layout; @@ -102,18 +105,17 @@ impl ForkConfig { let dir = self.output_directory.clone().unwrap(); let file_path = Path::new(&self.output_directory.clone().unwrap()) .join(self.output_filename.clone().unwrap()); - println!("path: {:?}", file_path); - if file_path.exists() && file_path.is_file() { + if file_path.try_exists().unwrap() && file_path.is_file() { if !overwrite { // TODO: We should allow for an overwrite flag here. panic!( "File already exists at output path. Please use the `--overwrite` flag, delete it, or change the output path." ); } else { + // weirdly sometimes fails here with message: "No such file or directory" fs::remove_file(&file_path).unwrap(); } } - let fork = self.into_fork()?; let mut raw = HashMap::new(); for (address, db_account) in fork.db.accounts { @@ -136,7 +138,7 @@ impl ForkConfig { fs::create_dir_all(dir)?; let mut file = fs::File::create(file_path)?; file.write_all(json_data.as_bytes()).unwrap(); - + println!("Wrote fork data to disk."); Ok(()) } diff --git a/bin/fork/tests.rs b/bin/fork/tests.rs index 72f6b140..41e7887a 100644 --- a/bin/fork/tests.rs +++ b/bin/fork/tests.rs @@ -1,3 +1,6 @@ +use arbiter_core::environment::fork::Fork; +use rayon::prelude::{IntoParallelIterator, ParallelIterator}; + use super::*; const FORK_CONFIG_PATH: &str = "example_fork/weth_config.toml"; @@ -12,16 +15,42 @@ fn create_forked_db() { #[test] fn write_out() { - let fork_config = ForkConfig::new(FORK_CONFIG_PATH).unwrap(); - fork_config.write_to_disk(&true).unwrap(); + let fork_config = ForkConfig::new(FORK_CONFIG_PATH); + assert!(fork_config.is_ok()); + let fork_config = fork_config.unwrap(); + + // Use par_iter to parallelize the loop + (0..10).into_par_iter().for_each(|_| { + let disk_op = fork_config.clone().write_to_disk(&true); + assert!(disk_op.is_ok()); + }); + + let remove_op = fs::remove_file(PATH_TO_DISK_STORAGE); + assert!(remove_op.is_ok()); } #[test] fn read_in() { // First write out so we know the file exists. - let fork_config = ForkConfig::new(FORK_CONFIG_PATH).unwrap(); - fork_config.write_to_disk(&true).unwrap(); + let fork_config = ForkConfig::new(FORK_CONFIG_PATH); + assert!(fork_config.is_ok()); + let fork_config = fork_config.unwrap(); + let disk_op = fork_config.clone().write_to_disk(&true); + assert!(disk_op.is_ok()); - let forked_db = Fork::from_disk(PATH_TO_DISK_STORAGE).unwrap(); - println!("{:#?}", forked_db); + let thing = Path::new(PATH_TO_DISK_STORAGE).try_exists().unwrap(); + if thing { + assert!(thing) + } else { + // try again + let disk_op = fork_config.clone().write_to_disk(&true); + assert!(disk_op.is_ok()); + } + // Use par_iter to parallelize the loop + (0..10).into_par_iter().for_each(|_| { + let forked_db = Fork::from_disk(PATH_TO_DISK_STORAGE); + assert!(forked_db.is_ok()); + }); + let remove_op = fs::remove_file(PATH_TO_DISK_STORAGE); + assert!(remove_op.is_ok()); } diff --git a/example_fork/test.json b/example_fork/fork_into_test.json similarity index 100% rename from example_fork/test.json rename to example_fork/fork_into_test.json