From 127327e0e7ed714ac3c361cf5856e1809548dd54 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Tue, 17 Dec 2024 12:04:19 -0600 Subject: [PATCH] chore: clean up, lint, move write_json to utils, resolve conflicts, update dev deps --- Cargo.lock | 6 +- Cargo.toml | 10 + crates/cli/Cargo.toml | 2 +- crates/cli/src/cli.rs | 19 +- crates/cli/src/main.rs | 55 +--- crates/cli/src/utils.rs | 23 -- crates/core/Cargo.toml | 12 +- crates/core/src/utils.rs | 22 ++ e2e-tests-rust/Cargo.lock | 371 ++++++++----------------- e2e-tests-rust/Cargo.toml | 7 +- e2e-tests-rust/src/provider/testing.rs | 2 +- e2e-tests-rust/tests/lib.rs | 103 ++++--- 12 files changed, 236 insertions(+), 396 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3374b11..b0713d6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,7 +404,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "tempfile", + "tempdir", "tokio", "tower 0.4.13", "tower-http", @@ -1166,9 +1166,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index 8c99cd65..5ecabfc7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,16 @@ tracing-subscriber = { version = "0.3", features = [ "local-time", ] } +######################### +# Test dependencies # +######################### +httptest = "0.15.4" +tempdir = "0.3.7" +maplit = "1.0.2" +zksync-web3-rs = "0.1.1" +ethers = { version = "2.0.4", features = ["rustls"] } +test-case = "3.3.1" + ######################### # Local dependencies # ######################### diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 95d68715..ca38223c 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -36,4 +36,4 @@ tower-http.workspace = true flate2.workspace = true [dev-dependencies] -tempfile = "3" +tempdir.workspace = true diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index ffaf2f47..10fb392a 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -1,4 +1,4 @@ -use crate::utils::{parse_genesis_file, write_json_file}; +use crate::utils::parse_genesis_file; use alloy_signer_local::coins_bip39::{English, Mnemonic}; use anvil_zksync_config::constants::{ DEFAULT_DISK_CACHE_DIR, DEFAULT_MNEMONIC, TEST_NODE_NETWORK_ID, @@ -7,11 +7,13 @@ use anvil_zksync_config::types::{ AccountGenerator, CacheConfig, CacheType, Genesis, SystemContractsOptions, }; use anvil_zksync_config::TestNodeConfig; +use anvil_zksync_core::{ + node::{InMemoryNode, VersionedState}, + utils::write_json_file, +}; use anvil_zksync_types::{ LogLevel, ShowCalls, ShowGasDetails, ShowStorageLogs, ShowVMDetails, TransactionOrder, }; -use anvil_zksync_core::node::state::VersionedState; -use anvil_zksync_core::node::InMemoryNode; use anyhow::Result; use clap::{arg, command, Parser, Subcommand}; use flate2::read::GzDecoder; @@ -433,7 +435,7 @@ impl Cli { .with_no_mining(self.no_mining) .with_allow_origin(self.allow_origin) .with_no_cors(self.no_cors) - .with_transaction_order(self.order); + .with_transaction_order(self.order) .with_state_interval(self.state_interval) .with_dump_state(self.dump_state) .with_preserve_historical_states(self.preserve_historical_states); @@ -615,10 +617,12 @@ mod tests { BlockSealer, BlockSealerMode, ImpersonationManager, InMemoryNode, TimestampManager, TxPool, }; use clap::Parser; + use serde_json::Value; use std::{ env, net::{IpAddr, Ipv4Addr}, }; + use tempdir::TempDir; #[test] fn can_parse_host() { @@ -666,10 +670,7 @@ mod tests { #[tokio::test] async fn test_dump_state() -> anyhow::Result<()> { - use serde_json::Value; - use tempfile::tempdir; - - let temp_dir = tempdir()?; + let temp_dir = TempDir::new("state-test").expect("failed creating temporary dir"); let dump_path = temp_dir.path().join("state.json"); let config = anvil_zksync_config::TestNodeConfig { @@ -685,7 +686,7 @@ mod tests { &config, TimestampManager::default(), ImpersonationManager::default(), - TxPool::new(ImpersonationManager::default()), + TxPool::new(ImpersonationManager::default(), config.transaction_order), BlockSealer::new(BlockSealerMode::noop()), ); let test_address = zksync_types::H160::random(); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 5ab3abe9..37c3e519 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -22,7 +22,6 @@ use std::fs::File; use std::time::Duration; use std::{env, net::SocketAddr, str::FromStr}; use tower_http::cors::AllowOrigin; -use tokio::signal; use tracing_subscriber::filter::LevelFilter; use zksync_types::fee_model::{FeeModelConfigV2, FeeParams}; use zksync_types::H160; @@ -279,20 +278,6 @@ async fn main() -> anyhow::Result<()> { let any_server_stopped = futures::future::select_all(server_handles.into_iter().map(|h| Box::pin(h.stopped()))); - let mut threads = futures::future::join_all(config.host.iter().map(|host| { - let addr = SocketAddr::new(*host, config.port); - build_json_http( - addr, - log_level_filter, - node.clone(), - config.health_check_endpoint, - config.allow_origin.clone(), - config.no_cors, - ) - })) - .await; - - // Start the state dumper let dump_state = config.dump_state.clone(); let dump_interval = config .state_interval @@ -300,40 +285,21 @@ async fn main() -> anyhow::Result<()> { .unwrap_or(Duration::from_secs(60)); // Default to 60 seconds let preserve_historical_states = config.preserve_historical_states; let node_for_dumper = node.clone(); - let mut state_dumper = PeriodicStateDumper::new( + let state_dumper = tokio::task::spawn(PeriodicStateDumper::new( node_for_dumper, dump_state, dump_interval, preserve_historical_states, - ); - // Start the block producer + )); + let system_contracts = SystemContracts::from_options(&config.system_contracts_options, config.use_evm_emulator); - let block_producer = BlockProducer::new( - node.clone(), - pool.clone(), - block_sealer.clone(), + let block_producer_handle = tokio::task::spawn(BlockProducer::new( + node, + pool, + block_sealer, system_contracts, - ); - - // Spawn a task to handle periodic dumping, block producer, and final dump on shutdown - let handle = tokio::spawn(async move { - tokio::select! { - _ = signal::ctrl_c() => { - tracing::trace!("received shutdown signal, shutting down"); - }, - _ = &mut state_dumper => { - tracing::trace!("State dumper completed"); - }, - _ = block_producer => { - tracing::trace!("Block producer completed"); - } - } - state_dumper.dump().await; - - std::process::exit(0); - }); - threads.push(handle); + )); config.print(fork_print_info.as_ref()); @@ -346,7 +312,10 @@ async fn main() -> anyhow::Result<()> { }, _ = block_producer_handle => { tracing::trace!("block producer was stopped") - } + }, + _ = state_dumper => { + tracing::trace!("state dumper was stopped") + }, } Ok(()) diff --git a/crates/cli/src/utils.rs b/crates/cli/src/utils.rs index 483db276..bc25a507 100644 --- a/crates/cli/src/utils.rs +++ b/crates/cli/src/utils.rs @@ -1,14 +1,7 @@ use anvil_zksync_config::types::Genesis; use anvil_zksync_config::TestNodeConfig; use anvil_zksync_core::fork::ForkDetails; -use anyhow::Context; -use serde::Serialize; use std::fs; -use std::{ - fs::File, - io::{BufWriter, Write}, - path::Path, -}; /// Parses the genesis file from the given path. pub fn parse_genesis_file(path: &str) -> Result { @@ -17,22 +10,6 @@ pub fn parse_genesis_file(path: &str) -> Result { serde_json::from_str(&file_content).map_err(|err| format!("Failed to parse JSON: {err}")) } -/// Writes the given serializable object as JSON to the specified file path using pretty printing. -/// Returns an error if the file cannot be created or if serialization/writing fails. -pub fn write_json_file(path: &Path, obj: &T) -> anyhow::Result<()> { - let file = File::create(path) - .with_context(|| format!("Failed to create file '{}'", path.display()))?; - let mut writer = BufWriter::new(file); - // Note: intentionally using pretty printing for better readability. - serde_json::to_writer_pretty(&mut writer, obj) - .with_context(|| format!("Failed to write JSON to '{}'", path.display()))?; - writer - .flush() - .with_context(|| format!("Failed to flush writer for '{}'", path.display()))?; - - Ok(()) -} - /// Updates the configuration from fork details. pub async fn update_with_fork_details( config: &mut TestNodeConfig, diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 354d8820..118b6092 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -43,9 +43,9 @@ flate2.workspace = true thiserror.workspace = true [dev-dependencies] -httptest = "0.15.4" -tempdir = "0.3.7" -maplit = "1.0.2" -zksync-web3-rs = "0.1.1" -ethers = { version = "2.0.4", features = ["rustls"] } -test-case = "3.3.1" +maplit.workspace = true +ethers.workspace = true +httptest.workspace = true +tempdir.workspace = true +zksync-web3-rs.workspace = true +test-case.workspace = true diff --git a/crates/core/src/utils.rs b/crates/core/src/utils.rs index 08da34cb..57403ca6 100644 --- a/crates/core/src/utils.rs +++ b/crates/core/src/utils.rs @@ -1,6 +1,12 @@ use anyhow::Context; use chrono::{DateTime, Utc}; +use serde::Serialize; use std::{convert::TryInto, fmt}; +use std::{ + fs::File, + io::{BufWriter, Write}, + path::Path, +}; use zksync_multivm::interface::{Call, CallType, ExecutionResult, VmExecutionResultAndLogs}; use zksync_types::{ api::{BlockNumber, DebugCall, DebugCallType}, @@ -188,6 +194,22 @@ pub fn calculate_eth_cost(gas_price_in_wei_per_gas: u64, gas_used: u64) -> f64 { total_cost_in_gwei / 1e9 } +/// Writes the given serializable object as JSON to the specified file path using pretty printing. +/// Returns an error if the file cannot be created or if serialization/writing fails. +pub fn write_json_file(path: &Path, obj: &T) -> anyhow::Result<()> { + let file = File::create(path) + .with_context(|| format!("Failed to create file '{}'", path.display()))?; + let mut writer = BufWriter::new(file); + // Note: intentionally using pretty printing for better readability. + serde_json::to_writer_pretty(&mut writer, obj) + .with_context(|| format!("Failed to write JSON to '{}'", path.display()))?; + writer + .flush() + .with_context(|| format!("Failed to flush writer for '{}'", path.display()))?; + + Ok(()) +} + #[cfg(test)] mod tests { use zksync_types::U256; diff --git a/e2e-tests-rust/Cargo.lock b/e2e-tests-rust/Cargo.lock index 68cc1440..8c72ea42 100644 --- a/e2e-tests-rust/Cargo.lock +++ b/e2e-tests-rust/Cargo.lock @@ -24,7 +24,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom 0.2.15", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -56,8 +56,7 @@ dependencies = [ "alloy-core", "alloy-eips 0.6.4", "alloy-genesis", - "alloy-json-rpc", - "alloy-network", + "alloy-json-rpc 0.6.4", "alloy-network 0.6.4", "alloy-provider", "alloy-pubsub", @@ -95,7 +94,7 @@ dependencies = [ "alloy-serde 0.5.4", "auto_impl", "c-kzg", - "derive_more 1.0.0", + "derive_more", "serde", ] @@ -111,7 +110,7 @@ dependencies = [ "alloy-serde 0.6.4", "auto_impl", "c-kzg", - "derive_more 1.0.0", + "derive_more", "k256 0.13.4", "serde", ] @@ -186,7 +185,7 @@ checksum = "64ffc577390ce50234e02d841214b3dc0bea6aaaae8e04bbf3cb82e9a45da9eb" dependencies = [ "alloy-primitives", "alloy-rlp", - "derive_more 1.0.0", + "derive_more", "serde", ] @@ -198,7 +197,7 @@ checksum = "5f6cee6a35793f3db8a5ffe60e86c695f321d081a567211245f503e8c498fce8" dependencies = [ "alloy-primitives", "alloy-rlp", - "derive_more 1.0.0", + "derive_more", "k256 0.13.4", "serde", ] @@ -215,7 +214,7 @@ dependencies = [ "alloy-rlp", "alloy-serde 0.5.4", "c-kzg", - "derive_more 1.0.0", + "derive_more", "once_cell", "serde", "sha2", @@ -233,7 +232,7 @@ dependencies = [ "alloy-rlp", "alloy-serde 0.6.4", "c-kzg", - "derive_more 1.0.0", + "derive_more", "once_cell", "serde", "sha2", @@ -370,9 +369,9 @@ dependencies = [ "bytes", "cfg-if", "const-hex", - "derive_more 1.0.0", + "derive_more", "foldhash", - "getrandom 0.2.15", + "getrandom", "hashbrown 0.15.2", "hex-literal", "indexmap 2.6.0", @@ -417,7 +416,7 @@ dependencies = [ "futures 0.3.31", "futures-utils-wasm", "lru", - "parking_lot 0.12.3", + "parking_lot", "pin-project", "reqwest 0.12.9", "schnellru", @@ -534,7 +533,7 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "alloy-serde 0.6.4", - "derive_more 1.0.0", + "derive_more", "serde", "strum", ] @@ -552,7 +551,7 @@ dependencies = [ "alloy-rlp", "alloy-serde 0.5.4", "alloy-sol-types", - "derive_more 1.0.0", + "derive_more", "itertools 0.13.0", "serde", "serde_json", @@ -571,7 +570,7 @@ dependencies = [ "alloy-rlp", "alloy-serde 0.6.4", "alloy-sol-types", - "derive_more 1.0.0", + "derive_more", "itertools 0.13.0", "serde", "serde_json", @@ -809,7 +808,7 @@ dependencies = [ [[package]] name = "alloy-zksync" version = "0.6.1" -source = "git+https://github.com/popzxc/alloy-zksync.git?rev=03ce1b31be0622a2d3fdcccdcbbc76212c2bb0da#03ce1b31be0622a2d3fdcccdcbbc76212c2bb0da" +source = "git+https://github.com/popzxc/alloy-zksync.git?rev=6a2e3cfe41cae9f92dc6672dbd0ce56ccc37e9b3#6a2e3cfe41cae9f92dc6672dbd0ce56ccc37e9b3" dependencies = [ "alloy", "async-trait", @@ -898,14 +897,77 @@ dependencies = [ "anyhow", "async-trait", "fs2", - "futures", - "http", + "futures 0.3.31", + "http 1.1.0", "itertools 0.13.0", - "reqwest", + "reqwest 0.12.9", "reqwest-middleware", "serde_json", + "tempdir", "tokio", - "tower", + "tower 0.5.1", +] + +[[package]] +name = "anvil_zksync_config" +version = "0.2.1" +dependencies = [ + "alloy-signer 0.5.4", + "alloy-signer-local 0.5.4", + "anvil_zksync_types", + "clap", + "colored", + "hex", + "rand 0.8.5", + "serde", + "serde_json", + "tracing", + "zksync_types", + "zksync_vm_interface", +] + +[[package]] +name = "anvil_zksync_core" +version = "0.2.1" +dependencies = [ + "anvil_zksync_config", + "anvil_zksync_types", + "anyhow", + "chrono", + "colored", + "ethabi 16.0.0", + "eyre", + "flate2", + "futures 0.3.31", + "hex", + "indexmap 2.6.0", + "itertools 0.13.0", + "lazy_static", + "once_cell", + "reqwest 0.11.27", + "rustc-hash 1.1.0", + "serde", + "serde_json", + "thiserror", + "time", + "tokio", + "tracing", + "tracing-subscriber", + "zksync_contracts", + "zksync_multivm", + "zksync_types", + "zksync_utils", + "zksync_web3_decl", +] + +[[package]] +name = "anvil_zksync_types" +version = "0.2.1" +dependencies = [ + "clap", + "serde", + "tracing", + "zksync_types", ] [[package]] @@ -1256,18 +1318,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bigdecimal" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", - "serde", -] - [[package]] name = "bigdecimal" version = "0.4.7" @@ -1449,7 +1499,7 @@ dependencies = [ "bincode", "blake2", "const_format", - "convert_case 0.6.0", + "convert_case", "crossbeam", "crypto-bigint 0.5.5", "derivative", @@ -1873,12 +1923,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "convert_case" version = "0.6.0" @@ -2074,7 +2118,7 @@ dependencies = [ "hashbrown 0.14.5", "lock_api", "once_cell", - "parking_lot_core 0.9.10", + "parking_lot_core", ] [[package]] @@ -2135,19 +2179,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "convert_case 0.4.0", - "proc-macro2", - "quote", - "rustc_version 0.4.1", - "syn 2.0.89", -] - [[package]] name = "derive_more" version = "1.0.0" @@ -2737,17 +2768,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.15" @@ -2756,7 +2776,7 @@ checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -3406,15 +3426,6 @@ dependencies = [ "serde", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - [[package]] name = "interprocess" version = "2.2.2" @@ -3504,68 +3515,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "jsonrpc-client-transports" -version = "18.0.0" -source = "git+https://github.com/matter-labs/jsonrpc.git?branch=master#12c53e3e20c09c2fb9966a4ef1b0ea63de172540" -dependencies = [ - "derive_more 0.99.18", - "futures 0.3.31", - "jsonrpc-core", - "jsonrpc-pubsub", - "log", - "serde", - "serde_json", -] - -[[package]] -name = "jsonrpc-core" -version = "18.0.0" -source = "git+https://github.com/matter-labs/jsonrpc.git?branch=master#12c53e3e20c09c2fb9966a4ef1b0ea63de172540" -dependencies = [ - "futures 0.3.31", - "futures-executor", - "futures-util", - "log", - "serde", - "serde_derive", - "serde_json", -] - -[[package]] -name = "jsonrpc-core-client" -version = "18.0.0" -source = "git+https://github.com/matter-labs/jsonrpc.git?branch=master#12c53e3e20c09c2fb9966a4ef1b0ea63de172540" -dependencies = [ - "futures 0.3.31", - "jsonrpc-client-transports", -] - -[[package]] -name = "jsonrpc-derive" -version = "18.0.0" -source = "git+https://github.com/matter-labs/jsonrpc.git?branch=master#12c53e3e20c09c2fb9966a4ef1b0ea63de172540" -dependencies = [ - "proc-macro-crate 0.1.5", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "jsonrpc-pubsub" -version = "18.0.0" -source = "git+https://github.com/matter-labs/jsonrpc.git?branch=master#12c53e3e20c09c2fb9966a4ef1b0ea63de172540" -dependencies = [ - "futures 0.3.31", - "jsonrpc-core", - "lazy_static", - "log", - "parking_lot 0.11.2", - "rand 0.7.3", - "serde", -] - [[package]] name = "jsonrpsee" version = "0.23.2" @@ -3625,7 +3574,7 @@ dependencies = [ "http-body 1.0.1", "http-body-util", "jsonrpsee-types", - "parking_lot 0.12.3", + "parking_lot", "pin-project", "rand 0.8.5", "rustc-hash 1.1.0", @@ -3968,7 +3917,7 @@ checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ "hermit-abi", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.52.0", ] @@ -4423,17 +4372,6 @@ dependencies = [ "syn 2.0.89", ] -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -4441,21 +4379,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", - "parking_lot_core 0.9.10", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -4466,7 +4390,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.7", + "redox_syscall", "smallvec", "windows-targets 0.52.6", ] @@ -4661,15 +4585,6 @@ dependencies = [ "uint", ] -[[package]] -name = "proc-macro-crate" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml", -] - [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -4752,7 +4667,7 @@ checksum = "504ee9ff529add891127c4827eb481bd69dc0ebc72e9a682e187db4caa60c3ca" dependencies = [ "dtoa", "itoa", - "parking_lot 0.12.3", + "parking_lot", "prometheus-client-derive-encode", ] @@ -4779,7 +4694,7 @@ dependencies = [ "lazy_static", "num-traits", "rand 0.8.5", - "rand_chacha 0.3.1", + "rand_chacha", "rand_xorshift", "regex-syntax 0.8.5", "rusty-fork", @@ -4955,19 +4870,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", -] - [[package]] name = "rand" version = "0.8.5" @@ -4975,21 +4877,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", + "rand_chacha", "rand_core 0.6.4", "serde", ] -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", -] - [[package]] name = "rand_chacha" version = "0.3.1" @@ -5015,31 +4907,13 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", -] - [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.15", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -5086,15 +4960,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3edd4d5d42c92f0a659926464d4cce56b562761267ecf0f469d85b7de384175" -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.5.7" @@ -5148,6 +5013,15 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + [[package]] name = "reqwest" version = "0.11.27" @@ -5240,8 +5114,8 @@ checksum = "d1ccd3b55e711f91a9885a2fa6fbbb2e39db1776420b062efc058c6410f7e5e3" dependencies = [ "anyhow", "async-trait", - "http", - "reqwest", + "http 1.1.0", + "reqwest 0.12.9", "serde", "thiserror", "tower-service", @@ -5276,7 +5150,7 @@ checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.15", + "getrandom", "libc", "spin", "untrusted", @@ -6212,6 +6086,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tempdir" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +dependencies = [ + "rand 0.4.6", + "remove_dir_all", +] + [[package]] name = "tempfile" version = "3.14.0" @@ -6350,7 +6234,7 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot 0.12.3", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -6433,15 +6317,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - [[package]] name = "toml_datetime" version = "0.6.8" @@ -6893,12 +6768,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -6980,7 +6849,7 @@ checksum = "0048ad49a55b9deb3953841fa1fc5858f0efbcb7a18868c899a360269fac1b23" dependencies = [ "futures 0.3.31", "js-sys", - "parking_lot 0.12.3", + "parking_lot", "pin-utils", "slab", "wasm-bindgen", @@ -7957,10 +7826,10 @@ version = "0.1.0" source = "git+https://github.com/matter-labs/zksync-era.git?rev=6c034f6e180cc92e99766f14c8840c90efa56cec#6c034f6e180cc92e99766f14c8840c90efa56cec" dependencies = [ "anyhow", - "bigdecimal 0.4.7", + "bigdecimal", "blake2", "chrono", - "derive_more 1.0.0", + "derive_more", "hex", "itertools 0.10.5", "num", @@ -7990,7 +7859,7 @@ version = "0.1.0" source = "git+https://github.com/matter-labs/zksync-era.git?rev=6c034f6e180cc92e99766f14c8840c90efa56cec#6c034f6e180cc92e99766f14c8840c90efa56cec" dependencies = [ "anyhow", - "bigdecimal 0.4.7", + "bigdecimal", "futures 0.3.31", "hex", "num", diff --git a/e2e-tests-rust/Cargo.toml b/e2e-tests-rust/Cargo.toml index c2bbb6dc..9f0f5062 100644 --- a/e2e-tests-rust/Cargo.toml +++ b/e2e-tests-rust/Cargo.toml @@ -11,7 +11,7 @@ publish = false [dependencies] alloy-zksync = { git = "https://github.com/popzxc/alloy-zksync.git", rev = "6a2e3cfe41cae9f92dc6672dbd0ce56ccc37e9b3" } -alloy = { version = "0.6", features = ["full", "rlp", "serde", "sol-types", "getrandom", "provider-anvil-api"] } +alloy = { version = "0.6", features = ["full", "rlp", "serde", "sol-types", "getrandom", "provider-anvil-api", "json-rpc"] } anyhow = "1.0" fs2 = "0.4.3" tokio = { version = "1", features = ["time", "rt", "process"] } @@ -23,10 +23,9 @@ reqwest-middleware = { version = "0.4", features = ["json"] } serde_json = "1" tower = "0.5" http = "1.1.0" +anvil_zksync_core = { path = "../crates/core" } +tempdir = "0.3.7" [dev-dependencies] -serde_json = "1.0" -anvil_zksync_core = { path = "../crates/core" } -tempfile = "3" [workspace] # ignore higher-level workspace diff --git a/e2e-tests-rust/src/provider/testing.rs b/e2e-tests-rust/src/provider/testing.rs index 2cbd5ecf..12328e1d 100644 --- a/e2e-tests-rust/src/provider/testing.rs +++ b/e2e-tests-rust/src/provider/testing.rs @@ -20,7 +20,7 @@ use alloy_zksync::network::receipt_response::ReceiptResponse; use alloy_zksync::network::transaction_response::TransactionResponse; use alloy_zksync::network::Zksync; use alloy_zksync::node_bindings::{AnvilZKsync, AnvilZKsyncError::NoKeysAvailable}; -use alloy_zksync::provider::{zksync_provider, ProviderBuilderExt, layers::anvil_zksync::AnvilZKsyncLayer}; +use alloy_zksync::provider::{zksync_provider, layers::anvil_zksync::AnvilZKsyncLayer}; use alloy_zksync::wallet::ZksyncWallet; use anyhow::Context as _; use async_trait::async_trait; diff --git a/e2e-tests-rust/tests/lib.rs b/e2e-tests-rust/tests/lib.rs index f8eeb72f..c0d78b72 100644 --- a/e2e-tests-rust/tests/lib.rs +++ b/e2e-tests-rust/tests/lib.rs @@ -8,19 +8,21 @@ use alloy::{ }; use anvil_zksync_e2e_tests::{ init_testing_provider, init_testing_provider_with_client, AnvilZKsyncApi, ReceiptExt, - ZksyncWalletProviderExt, DEFAULT_TX_VALUE, + ZksyncWalletProviderExt, DEFAULT_TX_VALUE, get_node_binary_path }; use http::header::{ HeaderMap, HeaderValue, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ORIGIN, }; -use std::convert::identity; -use std::time::Duration; const SOME_ORIGIN: HeaderValue = HeaderValue::from_static("http://some.origin"); const OTHER_ORIGIN: HeaderValue = HeaderValue::from_static("http://other.origin"); const ANY_ORIGIN: HeaderValue = HeaderValue::from_static("*"); +use anvil_zksync_core::node::VersionedState; +use std::{ fs, convert::identity, thread::sleep, time::Duration }; +use tempdir::TempDir; + #[tokio::test] async fn interval_sealing_finalization() -> anyhow::Result<()> { // Test that we can submit a transaction and wait for it to finalize when anvil-zksync is @@ -476,10 +478,46 @@ async fn pool_txs_order_fifo() -> anyhow::Result<()> { assert_eq!(&tx_hashes[0], pending_tx0.tx_hash()); assert_eq!(&tx_hashes[1], pending_tx1.tx_hash()); assert_eq!(&tx_hashes[2], pending_tx2.tx_hash()); + Ok(()) } +#[tokio::test] +async fn pool_txs_order_fees() -> anyhow::Result<()> { + let provider_fees = init_testing_provider(|node| node.no_mine().arg("--order=fees")).await?; + + let pending_tx0 = provider_fees.tx().with_rich_from(0).with_max_fee_per_gas(50_000_000).register().await?; + let pending_tx1 = provider_fees.tx().with_rich_from(1).with_max_fee_per_gas(100_000_000).register().await?; + let pending_tx2 = provider_fees.tx().with_rich_from(2).with_max_fee_per_gas(150_000_000).register().await?; + + provider_fees.anvil_mine(Some(U256::from(1)), None).await?; + + let block = provider_fees.get_block(1.into(), BlockTransactionsKind::Hashes).await?.unwrap(); + let tx_hashes = block.transactions.as_hashes().unwrap(); + assert_eq!(&tx_hashes[0], pending_tx2.tx_hash()); + assert_eq!(&tx_hashes[1], pending_tx1.tx_hash()); + assert_eq!(&tx_hashes[2], pending_tx0.tx_hash()); + Ok(()) +} + +#[tokio::test] +async fn transactions_have_index() -> anyhow::Result<()> { + let provider = init_testing_provider(|node| node.no_mine()).await?; + let tx1 = provider.tx().with_rich_from(0).register().await?; + let tx2 = provider.tx().with_rich_from(1).register().await?; + + provider.anvil_mine(Some(U256::from(1)), None).await?; + + let receipt1 = tx1.wait_until_finalized().await?; + let receipt2 = tx2.wait_until_finalized().await?; + + assert_eq!(receipt1.transaction_index(), 0.into()); + assert_eq!(receipt2.transaction_index(), 1.into()); + Ok(()) +} + +#[tokio::test] async fn dump_state_on_run() -> anyhow::Result<()> { - let temp_dir = tempdir()?; + let temp_dir = TempDir::new("state-test").expect("failed creating temporary dir"); let dump_path = temp_dir.path().join("state_dump.json"); let dump_path_clone = dump_path.clone(); @@ -493,13 +531,7 @@ async fn dump_state_on_run() -> anyhow::Result<()> { }) .await?; - let recipient = Address::from_str("0x36615Cf349d7F6344891B1e7CA7C72883F5dc049")?; - let receipt = provider - .tx() - .with_to(recipient) - .with_value(U256::from(100)) - .finalize() - .await?; + provider.tx().finalize().await?; // Allow some time for the state to be dumped sleep(Duration::from_secs(2)); @@ -535,46 +567,13 @@ async fn dump_state_on_run() -> anyhow::Result<()> { Ok(()) } -#[tokio::test] -async fn pool_txs_order_fees() -> anyhow::Result<()> { - let provider_fees = init_testing_provider(|node| node.no_mine().arg("--order=fees")).await?; - - let pending_tx0 = provider_fees.tx().with_rich_from(0).with_max_fee_per_gas(50_000_000).register().await?; - let pending_tx1 = provider_fees.tx().with_rich_from(1).with_max_fee_per_gas(100_000_000).register().await?; - let pending_tx2 = provider_fees.tx().with_rich_from(2).with_max_fee_per_gas(150_000_000).register().await?; - - provider_fees.anvil_mine(Some(U256::from(1)), None).await?; - - let block = provider_fees.get_block(1.into(), BlockTransactionsKind::Hashes).await?.unwrap(); - let tx_hashes = block.transactions.as_hashes().unwrap(); - assert_eq!(&tx_hashes[0], pending_tx2.tx_hash()); - assert_eq!(&tx_hashes[1], pending_tx1.tx_hash()); - assert_eq!(&tx_hashes[2], pending_tx0.tx_hash()); - Ok(()) -} - -#[tokio::test] -async fn transactions_have_index() -> anyhow::Result<()> { - let provider = init_testing_provider(|node| node.no_mine()).await?; - let tx1 = provider.tx().with_rich_from(0).register().await?; - let tx2 = provider.tx().with_rich_from(1).register().await?; - - provider.anvil_mine(Some(U256::from(1)), None).await?; - - let receipt1 = tx1.wait_until_finalized().await?; - let receipt2 = tx2.wait_until_finalized().await?; - - assert_eq!(receipt1.transaction_index(), 0.into()); - assert_eq!(receipt2.transaction_index(), 1.into()); -} - #[tokio::test] async fn dump_state_on_fork() -> anyhow::Result<()> { - let temp_dir = tempdir()?; + let temp_dir = TempDir::new("state-fork-test").expect("failed creating temporary dir"); let dump_path = temp_dir.path().join("state_dump_fork.json"); let dump_path_clone = dump_path.clone(); - let provider = init_testing_provider(move |node| { + let provider = init_testing_provider(move |node| { node .path(get_node_binary_path()) .arg("--state-interval") @@ -585,13 +584,7 @@ async fn dump_state_on_fork() -> anyhow::Result<()> { }) .await?; - let recipient = Address::from_str("0x36615Cf349d7F6344891B1e7CA7C72883F5dc049")?; - let receipt = provider - .tx() - .with_to(recipient) - .with_value(U256::from(100)) - .finalize() - .await?; + provider.tx().finalize().await?; // Allow some time for the state to be dumped sleep(Duration::from_secs(2)); @@ -612,11 +605,11 @@ async fn dump_state_on_fork() -> anyhow::Result<()> { VersionedState::V1 { version: _, state } => { assert!( !state.blocks.is_empty(), - "state_dump.json should contain at least one block" + "state_dump_fork.json should contain at least one block" ); assert!( !state.transactions.is_empty(), - "state_dump.json should contain at least one transaction" + "state_dump_fork.json should contain at least one transaction" ); }, VersionedState::Unknown { version } => {