From 74c418b3ad7329d7c0978a0aac413ee2823c3265 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Mon, 2 Dec 2024 09:25:43 -0600 Subject: [PATCH 1/5] breaking: updates naming convention to reflect repo rename of era-test-node to anvil-zksync --- .github/workflows/ci.yml | 6 +- README.md | 2 +- examples/deploy.rs | 4 +- examples/showcase.rs | 2 +- .../{era_test_node.rs => anvil_zksync.rs} | 174 +++++++++--------- src/node_bindings/mod.rs | 4 +- .../{era_test_node.rs => anvil_zksync.rs} | 42 ++--- src/provider/layers/mod.rs | 2 +- src/provider/provider_builder_ext.rs | 78 ++++---- 9 files changed, 154 insertions(+), 160 deletions(-) rename src/node_bindings/{era_test_node.rs => anvil_zksync.rs} (69%) rename src/provider/layers/{era_test_node.rs => anvil_zksync.rs} (59%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97c3b1c..8089273 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: Rust on: pull_request: - branches: [ "*" ] + branches: ["*"] push: branches: ["main"] @@ -49,8 +49,8 @@ jobs: - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.4 - - name: Install era-test-node - uses: dutterbutter/era-test-node-action@v1 + - name: Install anvil-zksync + uses: dutterbutter/anvil-zksync-action@v1.0.0 - name: Format run: cargo fmt --all -- --check diff --git a/README.md b/README.md index 0d61129..cad05e8 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ the functionality is added in a way that is aligned with overall `alloy` design, specific to the `Zksync` network, or via extension traits (in case of `Provider`, for example). Similarly to `anvil` bindings, `alloy-zksync` provides bindings for -[era-test-node](https://github.com/matter-labs/era-test-node). +[anvil-zksync](https://github.com/matter-labs/anvil-zksync). For usage, the best reference currently is [examples](./examples/): - [basic usage](./examples/showcase.rs), diff --git a/examples/deploy.rs b/examples/deploy.rs index 574bba7..20a4e52 100644 --- a/examples/deploy.rs +++ b/examples/deploy.rs @@ -1,4 +1,4 @@ -//! Example of deploying a contract at runtime from Solidity bytecode to era-test-node and +//! Example of deploying a contract at runtime from Solidity bytecode to anvil-zksync and //! interacting with it. //! Based on the example from the `alloy` book. @@ -32,7 +32,7 @@ async fn main() -> Result<()> { // to be spawned implicitly and/or you don't want it to be attached to a single provider. let provider = zksync_provider() .with_recommended_fillers() - .on_era_test_node_with_wallet(); + .on_anvil_zksync_with_wallet(); // Manually deploy contract. let bytecode = hex::decode("0000008003000039000000400030043f0000000100200190000000180000c13d00000060021002700000000f02200197000000040020008c000000330000413d000000000301043b000000e003300270000000110030009c000000270000613d000000120030009c000000200000613d000000130030009c000000330000c13d000000240020008c000000330000413d0000000002000416000000000002004b000000330000c13d0000000401100370000000000101043b000000350000013d0000000001000416000000000001004b000000330000c13d0000002001000039000001000010044300000120000004430000001001000041000000390001042e0000000001000416000000000001004b000000330000c13d000000000100041a000000800010043f0000001601000041000000390001042e0000000001000416000000000001004b000000330000c13d000000000100041a000000010110003a000000350000c13d0000001401000041000000000010043f0000001101000039000000040010043f00000015010000410000003a0001043000000000010000190000003a00010430000000000010041b0000000001000019000000390001042e0000003800000432000000390001042e0000003a00010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffff000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000d09de08a000000000000000000000000000000000000000000000000000000008381f58a000000000000000000000000000000000000000000000000000000003fb5c1cb4e487b7100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000200000008000000000000000000000000000000000000000000000000000000000000000000000000000000000907744cfcba9c9276da62757037b7ad91caa65b463857bae5ffcd6ceb985e728").unwrap(); diff --git a/examples/showcase.rs b/examples/showcase.rs index cad7612..da430fe 100644 --- a/examples/showcase.rs +++ b/examples/showcase.rs @@ -15,7 +15,7 @@ async fn main() -> anyhow::Result<()> { // Create a provider with the wallet. let provider = zksync_provider() .with_recommended_fillers() - .on_era_test_node_with_wallet(); + .on_anvil_zksync_with_wallet(); // Build a transaction to send 100 wei from Alice to Vitalik. // The `from` field is automatically filled to the first signer's address (Alice). diff --git a/src/node_bindings/era_test_node.rs b/src/node_bindings/anvil_zksync.rs similarity index 69% rename from src/node_bindings/era_test_node.rs rename to src/node_bindings/anvil_zksync.rs index 19e6f81..d17485e 100644 --- a/src/node_bindings/era_test_node.rs +++ b/src/node_bindings/anvil_zksync.rs @@ -1,7 +1,7 @@ // Adapted from Anvil node bindings in the alloy project: // https://github.com/alloy-rs/alloy/blob/2d26b057c64cbcc77654f4691141c308d63b286f/crates/node-bindings/src/anvil.rs -//! Utilities for launching an `era_test_node` instance. +//! Utilities for launching an `anvil-zksync` instance. use alloy::primitives::{hex, Address, ChainId}; use k256::{ecdsa::SigningKey, SecretKey as K256SecretKey}; @@ -17,14 +17,14 @@ use std::{ use thiserror::Error; use url::Url; -/// How long we will wait for era_test_node to indicate that it is ready. -const ERA_TEST_NODE_STARTUP_TIMEOUT_MILLIS: u64 = 10_000; +/// How long we will wait for anvil-zksync to indicate that it is ready. +const ANVIL_ZKSYNC_STARTUP_TIMEOUT_MILLIS: u64 = 10_000; -/// An era_test_node CLI instance. Will close the instance when dropped. +/// An anvil-zksync CLI instance. Will close the instance when dropped. /// -/// Construct this using [`EraTestNode`]. +/// Construct this using [`AnvilZKsync`]. #[derive(Debug)] -pub struct EraTestNodeInstance { +pub struct AnvilZKsyncInstance { child: Child, private_keys: Vec, addresses: Vec
, @@ -32,7 +32,7 @@ pub struct EraTestNodeInstance { chain_id: Option, } -impl EraTestNodeInstance { +impl AnvilZKsyncInstance { /// Returns a reference to the child process. pub const fn child(&self) -> &Child { &self.child @@ -58,10 +58,10 @@ impl EraTestNodeInstance { self.port } - /// Returns the chain of the era_test_node instance + /// Returns the chain of the anvil-zksync instance pub fn chain_id(&self) -> ChainId { - const ERA_TEST_NODE_CHAIN_ID: ChainId = 260; - self.chain_id.unwrap_or(ERA_TEST_NODE_CHAIN_ID) + const ANVIL_ZKSYNC_CHAIN_ID: ChainId = 260; + self.chain_id.unwrap_or(ANVIL_ZKSYNC_CHAIN_ID) } /// Returns the HTTP endpoint of this instance @@ -77,29 +77,29 @@ impl EraTestNodeInstance { } } -impl Drop for EraTestNodeInstance { +impl Drop for AnvilZKsyncInstance { fn drop(&mut self) { - self.child.kill().expect("could not kill era_test_node"); + self.child.kill().expect("could not kill anvil-zksync"); } } -/// Errors that can occur when working with the [`EraTestNode`]. +/// Errors that can occur when working with the [`AnvilZKsync`]. #[derive(Debug, Error)] -pub enum EraTestNodeError { - /// Spawning the era_test_node process failed. - #[error("could not start era_test_node: {0}")] +pub enum AnvilZKsyncError { + /// Spawning the anvil-zksync process failed. + #[error("could not start anvil-zksync: {0}")] SpawnError(std::io::Error), - /// Timed out waiting for a message from era_test_node's stderr. - #[error("timed out waiting for era_test_node to spawn; is era_test_node installed?")] + /// Timed out waiting for a message from anvil-zksync's stderr. + #[error("timed out waiting for anvil-zksync to spawn; anvil-zksync installed?")] Timeout, - /// A line could not be read from the geth stderr. - #[error("could not read line from era_test_node stderr: {0}")] + /// A line could not be read from the anvil-zksync stderr. + #[error("could not read line from anvil-zksync stderr: {0}")] ReadLineError(std::io::Error), - /// The child era_test_node process's stderr was not captured. - #[error("could not get stderr for era_test_node child process")] + /// The child anvil-zksync process's stderr was not captured. + #[error("could not get stderr for anvil-zksync child process")] NoStderr, /// The private key could not be parsed. @@ -123,29 +123,29 @@ pub enum EraTestNodeError { NoKeysAvailable, } -/// Builder for launching `era_test_node`. +/// Builder for launching `anvil-zksync`. /// /// # Panics /// -/// If `spawn` is called without `era_test_node` being available in the user's $PATH +/// If `spawn` is called without `anvil-zksync` being available in the user's $PATH /// /// # Example /// /// ```no_run -/// use alloy_zksync::node_bindings::EraTestNode; +/// use alloy_zksync::node_bindings::AnvilZKsync; /// /// let port = 8545u16; /// let url = format!("http://localhost:{}", port).to_string(); /// -/// let era_test_node = EraTestNode::new() +/// let anvil_zksync = AnvilZKsync::new() /// .port(port) /// .spawn(); /// -/// drop(era_test_node); // this will kill the instance +/// drop(anvil_zksync); // this will kill the instance /// ``` #[derive(Clone, Debug, Default)] #[must_use = "This Builder struct does nothing unless it is `spawn`ed"] -pub struct EraTestNode { +pub struct AnvilZKsync { program: Option, port: Option, // TODO @@ -161,18 +161,18 @@ pub struct EraTestNode { timeout: Option, } -impl EraTestNode { - /// Creates an empty EraTestNode builder. +impl AnvilZKsync { + /// Creates an empty AnvilZKsync builder. /// The default port is 8545. The mnemonic is chosen randomly. /// /// # Example /// /// ``` - /// # use alloy_zksync::node_bindings::EraTestNode; + /// # use alloy_zksync::node_bindings::AnvilZKsync; /// fn a() { - /// let era_test_node = EraTestNode::default().spawn(); + /// let anvil_zksync = AnvilZKsync::default().spawn(); /// - /// println!("EraTestNode running at `{}`", era_test_node.endpoint()); + /// println!("AnvilZKsync running at `{}`", anvil_zksync.endpoint()); /// # } /// ``` pub fn new() -> Self { @@ -183,50 +183,48 @@ impl EraTestNode { self_ } - /// Creates an EraTestNode builder which will execute `era_test_node` at the given path. + /// Creates an AnvilZKsync builder which will execute `anvil-zksync` at the given path. /// /// # Example /// /// ```no_run - /// # use alloy_zksync::node_bindings::EraTestNode; + /// # use alloy_zksync::node_bindings::AnvilZKsync; /// fn a() { - /// let era_test_node = EraTestNode::at("~/some/location/era_test_node").spawn(); + /// let anvil_zksync = AnvilZKsync::at("~/some/location/anvil-zksync").spawn(); /// - /// println!("EraTestNode running at `{}`", era_test_node.endpoint()); + /// println!("AnvilZKsync running at `{}`", anvil_zksync.endpoint()); /// # } /// ``` pub fn at(path: impl Into) -> Self { Self::new().path(path) } - /// Sets the `path` to the `era_test_node` cli + /// Sets the `path` to the `anvil-zksync` cli /// - /// By default, it's expected that `era_test_node` is in `$PATH`, see also + /// By default, it's expected that `anvil-zksync` is in `$PATH`, see also /// [`std::process::Command::new()`] pub fn path>(mut self, path: T) -> Self { self.program = Some(path.into()); self } - /// Sets the port which will be used when the `era_test_node` instance is launched. + /// Sets the port which will be used when the `anvil-zksync` instance is launched. pub fn port>(mut self, port: T) -> Self { self.port = Some(port.into()); self } - /// Sets the chain_id the `era_test_node` instance will use. + /// Sets the chain_id the `anvil-zksync` instance will use. pub const fn chain_id(mut self, chain_id: u64) -> Self { self.chain_id = Some(chain_id); self } - // TODO - // /// Sets the mnemonic which will be used when the `era_test_node` instance is launched. + /// Sets the mnemonic which will be used when the `anvil-zksync` instance is launched. // pub fn mnemonic>(mut self, mnemonic: T) -> Self { // self.mnemonic = Some(mnemonic.into()); // self // } - // TODO // /// Sets the block-time in seconds which will be used when the `era_test_node` instance is launched. // pub const fn block_time(mut self, block_time: u64) -> Self { @@ -259,13 +257,13 @@ impl EraTestNode { self } - /// Adds an argument to pass to the `era_test_node`. + /// Adds an argument to pass to the `anvil-zksync`. pub fn arg>(mut self, arg: T) -> Self { self.args.push(arg.into()); self } - /// Adds multiple arguments to pass to the `era_test_node`. + /// Adds multiple arguments to pass to the `anvil-zksync`. pub fn args(mut self, args: I) -> Self where I: IntoIterator, @@ -277,28 +275,28 @@ impl EraTestNode { self } - /// Sets the timeout which will be used when the `era_test_node` instance is launched. + /// Sets the timeout which will be used when the `anvil-zksync` instance is launched. pub const fn timeout(mut self, timeout: u64) -> Self { self.timeout = Some(timeout); self } - /// Consumes the builder and spawns `era_test_node`. + /// Consumes the builder and spawns `anvil-zksync`. /// /// # Panics /// /// If spawning the instance fails at any point. #[track_caller] - pub fn spawn(self) -> EraTestNodeInstance { + pub fn spawn(self) -> AnvilZKsyncInstance { self.try_spawn().unwrap() } - /// Consumes the builder and spawns `era_test_node`. If spawning fails, returns an error. - pub fn try_spawn(self) -> Result { + /// Consumes the builder and spawns `anvil-zksync`. If spawning fails, returns an error. + pub fn try_spawn(self) -> Result { let mut cmd = self .program .as_ref() - .map_or_else(|| Command::new("era_test_node"), Command::new); + .map_or_else(|| Command::new("anvil-zksync"), Command::new); cmd.stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::inherit()); // let mut port = self.port.unwrap_or_default(); @@ -332,9 +330,9 @@ impl EraTestNode { cmd.arg("run"); } - let mut child = cmd.spawn().map_err(EraTestNodeError::SpawnError)?; + let mut child = cmd.spawn().map_err(AnvilZKsyncError::SpawnError)?; - let stdout = child.stdout.as_mut().ok_or(EraTestNodeError::NoStderr)?; + let stdout = child.stdout.as_mut().ok_or(AnvilZKsyncError::NoStderr)?; let start = Instant::now(); let mut reader = BufReader::new(stdout); @@ -345,24 +343,22 @@ impl EraTestNode { let port; loop { if start - + Duration::from_millis( - self.timeout.unwrap_or(ERA_TEST_NODE_STARTUP_TIMEOUT_MILLIS), - ) + + Duration::from_millis(self.timeout.unwrap_or(ANVIL_ZKSYNC_STARTUP_TIMEOUT_MILLIS)) <= Instant::now() { - return Err(EraTestNodeError::Timeout); + return Err(AnvilZKsyncError::Timeout); } let mut line = String::new(); reader .read_line(&mut line) - .map_err(EraTestNodeError::ReadLineError)?; - tracing::trace!(target: "era_test_node", line); + .map_err(AnvilZKsyncError::ReadLineError)?; + tracing::trace!(target: "anvil-zksync", line); if let Some(addr) = line.trim().split("Listening on").nth(1) { // // parse the actual port port = SocketAddr::from_str(addr.trim()) - .map_err(|_| EraTestNodeError::ParsePortError)? + .map_err(|_| AnvilZKsyncError::ParsePortError)? .port(); break; } @@ -374,17 +370,17 @@ impl EraTestNode { let mut pk_line = String::new(); reader .read_line(&mut pk_line) - .map_err(EraTestNodeError::ReadLineError)?; - tracing::trace!(target: "era_test_node", pk_line); + .map_err(AnvilZKsyncError::ReadLineError)?; + tracing::trace!(target: "anvil-zksync", pk_line); match pk_line.trim() { "" => break, pk_line => { if pk_line.contains("0x") { let key_str = pk_line.split("0x").nth(1).unwrap(); let key_hex = - hex::decode(key_str).map_err(EraTestNodeError::FromHexError)?; + hex::decode(key_str).map_err(AnvilZKsyncError::FromHexError)?; let key = K256SecretKey::from_bytes((&key_hex[..]).into()) - .map_err(|_| EraTestNodeError::DeserializePrivateKeyError)?; + .map_err(|_| AnvilZKsyncError::DeserializePrivateKeyError)?; addresses.push(Address::from_public_key( SigningKey::from(&key).verifying_key(), )); @@ -407,7 +403,7 @@ impl EraTestNode { } } - Ok(EraTestNodeInstance { + Ok(AnvilZKsyncInstance { child, private_keys, addresses, @@ -423,37 +419,37 @@ mod tests { use alloy::providers::{Provider, ProviderBuilder}; #[test] - fn can_launch_era_test_node() { - let _ = EraTestNode::new().spawn(); + fn can_launch_anvil_zksync() { + let _ = AnvilZKsync::new().spawn(); } #[test] - fn can_launch_era_test_node_with_custom_port() { + fn can_launch_anvil_zksync_with_custom_port() { const PORT: u16 = 7555; - let era = EraTestNode::new().port(PORT).spawn(); - assert_eq!(era.port(), PORT); + let anvil_zksync = AnvilZKsync::new().port(PORT).spawn(); + assert_eq!(anvil_zksync.port(), PORT); } - // TODO: AFAIU era_test_node doesn't support setting block time. + // // TODO: AFAIU anvil-zksync doesn't support setting block time. // #[test] // fn assert_block_time_is_natural_number() { - // //This test is to ensure that older versions of era_test_node are supported + // //This test is to ensure that older versions of anvil-zksync are supported // //even though the block time is a f64, it should be passed as a whole number - // let era_test_node = EraTestNode::new().block_time(12); - // assert_eq!(era_test_node.block_time.unwrap().to_string(), "12"); - // let _ = era_test_node.spawn(); + // let anvil_zksync = AnvilZKsync::new().block_time(12); + // assert_eq!(anvil_zksync.block_time.unwrap().to_string(), "12"); + // let _ = anvil_zksync.spawn(); // } // #[test] - // fn can_launch_era_test_node_with_sub_seconds_block_time() { - // let _ = EraTestNode::new().block_time_f64(0.5).spawn(); + // fn can_launch_anvil_zksync_with_sub_seconds_block_time() { + // let _ = AnvilZKsync::new().block_time_f64(0.5).spawn(); // } #[tokio::test(flavor = "multi_thread")] async fn fork_initializes_correct_chain_id() { let chain_id = 92; - let era_test_node = EraTestNode::new().chain_id(chain_id).spawn(); - let rpc_url = era_test_node.endpoint_url(); + let anvil_zksync = AnvilZKsync::new().chain_id(chain_id).spawn(); + let rpc_url = anvil_zksync.endpoint_url(); let provider = ProviderBuilder::new() .with_recommended_fillers() .on_http(rpc_url); @@ -462,13 +458,13 @@ mod tests { assert_eq!(returned_chain_id, chain_id); - drop(era_test_node); + drop(anvil_zksync); } #[tokio::test(flavor = "multi_thread")] async fn fork_initializes_correct_chain() { - let era_test_node = EraTestNode::new().fork("mainnet").spawn(); - let rpc_url = era_test_node.endpoint_url(); + let anvil_zksync = AnvilZKsync::new().fork("mainnet").spawn(); + let rpc_url = anvil_zksync.endpoint_url(); let provider = ProviderBuilder::new() .with_recommended_fillers() .on_http(rpc_url); @@ -477,19 +473,19 @@ mod tests { assert_eq!(chain_id, 324); - drop(era_test_node); + drop(anvil_zksync); } #[tokio::test(flavor = "multi_thread")] async fn fork_initializes_at_specified_block() { let fork_block_number = 47854817; - let era_test_node = EraTestNode::new() + let anvil_zksync = AnvilZKsync::new() .fork("mainnet") .fork_block_number(fork_block_number) .spawn(); - let rpc_url = era_test_node.endpoint_url(); + let rpc_url = anvil_zksync.endpoint_url(); let provider = ProviderBuilder::new() .with_recommended_fillers() .on_http(rpc_url); @@ -502,12 +498,12 @@ mod tests { "The node did not fork at the expected block number" ); - drop(era_test_node); + drop(anvil_zksync); } #[test] fn assert_chain_id_without_rpc() { - let era_test_node = EraTestNode::new().spawn(); - assert_eq!(era_test_node.chain_id(), 260); + let anvil_zksync = AnvilZKsync::new().spawn(); + assert_eq!(anvil_zksync.chain_id(), 260); } } diff --git a/src/node_bindings/mod.rs b/src/node_bindings/mod.rs index 3f1775c..abc9f6a 100644 --- a/src/node_bindings/mod.rs +++ b/src/node_bindings/mod.rs @@ -1,3 +1,3 @@ -pub use era_test_node::*; +pub use anvil_zksync::*; -mod era_test_node; +mod anvil_zksync; diff --git a/src/provider/layers/era_test_node.rs b/src/provider/layers/anvil_zksync.rs similarity index 59% rename from src/provider/layers/era_test_node.rs rename to src/provider/layers/anvil_zksync.rs index 3e2489d..60a21a1 100644 --- a/src/provider/layers/era_test_node.rs +++ b/src/provider/layers/anvil_zksync.rs @@ -10,23 +10,23 @@ use url::Url; use crate::{ network::Zksync, - node_bindings::{EraTestNode, EraTestNodeInstance}, + node_bindings::{AnvilZKsync, AnvilZKsyncInstance}, }; -/// A layer that wraps an [`EraTestNode`] config. +/// A layer that wraps an [`AnvilZKsync`] config. /// -/// The config will be used to spawn an [`EraTestNodeInstance`] when the layer is applied, or when the -/// user requests any information about the anvil node (e.g. via the [`EraTestNodeLayer::endpoint_url`] +/// The config will be used to spawn an [`AnvilZKsyncInstance`] when the layer is applied, or when the +/// user requests any information about the anvil node (e.g. via the [`AnvilZKsyncLayer::endpoint_url`] /// method). #[derive(Debug, Clone, Default)] -pub struct EraTestNodeLayer { - anvil: EraTestNode, - instance: OnceLock>, +pub struct AnvilZKsyncLayer { + anvil: AnvilZKsync, + instance: OnceLock>, } -impl EraTestNodeLayer { +impl AnvilZKsyncLayer { /// Starts the anvil instance, or gets a reference to the existing instance. - pub fn instance(&self) -> &Arc { + pub fn instance(&self) -> &Arc { self.instance .get_or_init(|| Arc::new(self.anvil.clone().spawn())) } @@ -38,8 +38,8 @@ impl EraTestNodeLayer { } } -impl From for EraTestNodeLayer { - fn from(anvil: EraTestNode) -> Self { +impl From for AnvilZKsyncLayer { + fn from(anvil: AnvilZKsync) -> Self { Self { anvil, instance: OnceLock::new(), @@ -47,36 +47,36 @@ impl From for EraTestNodeLayer { } } -impl ProviderLayer for EraTestNodeLayer +impl ProviderLayer for AnvilZKsyncLayer where P: Provider, T: Transport + Clone, { - type Provider = EraTestNodeProvider; + type Provider = AnvilZKsyncProvider; fn layer(&self, inner: P) -> Self::Provider { let anvil = self.instance(); - EraTestNodeProvider::new(inner, anvil.clone()) + AnvilZKsyncProvider::new(inner, anvil.clone()) } } -/// A provider that wraps an [`EraTestNodeInstance`], preventing the instance from +/// A provider that wraps an [`AnvilZKsyncInstance`], preventing the instance from /// being dropped while the provider is in use. #[derive(Clone, Debug)] -pub struct EraTestNodeProvider { +pub struct AnvilZKsyncProvider { inner: P, - _anvil: Arc, + _anvil: Arc, _pd: PhantomData T>, } -impl EraTestNodeProvider +impl AnvilZKsyncProvider where P: Provider, T: Transport + Clone, { - /// Creates a new `EraTestNodeProvider` with the given inner provider and anvil + /// Creates a new `AnvilZKsyncProvider` with the given inner provider and anvil /// instance. - pub fn new(inner: P, _anvil: Arc) -> Self { + pub fn new(inner: P, _anvil: Arc) -> Self { Self { inner, _anvil, @@ -85,7 +85,7 @@ where } } -impl Provider for EraTestNodeProvider +impl Provider for AnvilZKsyncProvider where P: Provider, T: Transport + Clone, diff --git a/src/provider/layers/mod.rs b/src/provider/layers/mod.rs index c295e90..395d098 100644 --- a/src/provider/layers/mod.rs +++ b/src/provider/layers/mod.rs @@ -1 +1 @@ -pub mod era_test_node; +pub mod anvil_zksync; diff --git a/src/provider/provider_builder_ext.rs b/src/provider/provider_builder_ext.rs index 0ee8789..06677ff 100644 --- a/src/provider/provider_builder_ext.rs +++ b/src/provider/provider_builder_ext.rs @@ -8,12 +8,12 @@ use alloy::{ use crate::{ network::Zksync, - node_bindings::{EraTestNode, EraTestNodeError}, - provider::layers::era_test_node::{EraTestNodeLayer, EraTestNodeProvider}, + node_bindings::{AnvilZKsync, AnvilZKsyncError}, + provider::layers::anvil_zksync::{AnvilZKsyncLayer, AnvilZKsyncProvider}, wallet::ZksyncWallet, }; -type EraTestNodeProviderResult = Result; +type AnvilZKsyncProviderResult = Result; type JoinedZksyncWalletFiller = JoinFill>; type ZksyncHttpTransport = alloy::transports::http::Http; @@ -21,14 +21,14 @@ pub trait ProviderBuilderExt: Sized where F: TxFiller + ProviderLayer, L: ProviderLayer< - EraTestNodeProvider, ZksyncHttpTransport>, + AnvilZKsyncProvider, ZksyncHttpTransport>, ZksyncHttpTransport, Zksync, >, { - fn on_era_test_node(self) -> F::Provider; + fn on_anvil_zksync(self) -> F::Provider; - fn on_era_test_node_with_wallet( + fn on_anvil_zksync_with_wallet( self, ) -> as ProviderLayer< L::Provider, @@ -36,24 +36,22 @@ where Zksync, >>::Provider; - fn on_era_test_node_with_config( - self, - f: impl FnOnce(EraTestNode) -> EraTestNode, - ) -> F::Provider; + fn on_anvil_zksync_with_config(self, f: impl FnOnce(AnvilZKsync) -> AnvilZKsync) + -> F::Provider; - fn on_era_test_node_with_wallet_and_config( + fn on_anvil_zksync_with_wallet_and_config( self, - f: impl FnOnce(EraTestNode) -> EraTestNode, + f: impl FnOnce(AnvilZKsync) -> AnvilZKsync, ) -> as ProviderLayer< L::Provider, ZksyncHttpTransport, Zksync, >>::Provider; - fn try_on_era_test_node_with_wallet_and_config( + fn try_on_anvil_zksync_with_wallet_and_config( self, - f: impl FnOnce(EraTestNode) -> EraTestNode, - ) -> EraTestNodeProviderResult< + f: impl FnOnce(AnvilZKsync) -> AnvilZKsync, + ) -> AnvilZKsyncProviderResult< as ProviderLayer< L::Provider, ZksyncHttpTransport, @@ -66,54 +64,54 @@ impl ProviderBuilderExt for ProviderBuilder where F: TxFiller + ProviderLayer, L: ProviderLayer< - EraTestNodeProvider, ZksyncHttpTransport>, + AnvilZKsyncProvider, ZksyncHttpTransport>, ZksyncHttpTransport, Zksync, >, { - fn on_era_test_node(self) -> F::Provider { - self.on_era_test_node_with_config(std::convert::identity) + fn on_anvil_zksync(self) -> F::Provider { + self.on_anvil_zksync_with_config(std::convert::identity) } - fn on_era_test_node_with_wallet( + fn on_anvil_zksync_with_wallet( self, ) -> as ProviderLayer< L::Provider, ZksyncHttpTransport, Zksync, >>::Provider{ - self.on_era_test_node_with_wallet_and_config(std::convert::identity) + self.on_anvil_zksync_with_wallet_and_config(std::convert::identity) } - fn on_era_test_node_with_config( + fn on_anvil_zksync_with_config( self, - f: impl FnOnce(EraTestNode) -> EraTestNode, + f: impl FnOnce(AnvilZKsync) -> AnvilZKsync, ) -> F::Provider { - let era_test_node_layer = EraTestNodeLayer::from(f(Default::default())); - let url = era_test_node_layer.endpoint_url(); + let anvil_zksync_layer = AnvilZKsyncLayer::from(f(Default::default())); + let url = anvil_zksync_layer.endpoint_url(); - self.layer(era_test_node_layer).on_http(url) + self.layer(anvil_zksync_layer).on_http(url) } - fn on_era_test_node_with_wallet_and_config( + fn on_anvil_zksync_with_wallet_and_config( self, - f: impl FnOnce(EraTestNode) -> EraTestNode, + f: impl FnOnce(AnvilZKsync) -> AnvilZKsync, ) -> as ProviderLayer< L::Provider, ZksyncHttpTransport, Zksync, >>::Provider{ - self.try_on_era_test_node_with_wallet_and_config(f).unwrap() + self.try_on_anvil_zksync_with_wallet_and_config(f).unwrap() } - /// Build this provider with era_test_node, using an Reqwest HTTP transport. The - /// given function is used to configure the era_test_node instance. This - /// function configures a wallet backed by era_test_node keys, and is intended for + /// Build this provider with anvil-zksync, using an Reqwest HTTP transport. The + /// given function is used to configure the anvil-zksync instance. This + /// function configures a wallet backed by anvil-zksync keys, and is intended for /// use in tests. - fn try_on_era_test_node_with_wallet_and_config( + fn try_on_anvil_zksync_with_wallet_and_config( self, - f: impl FnOnce(EraTestNode) -> EraTestNode, - ) -> EraTestNodeProviderResult< + f: impl FnOnce(AnvilZKsync) -> AnvilZKsync, + ) -> AnvilZKsyncProviderResult< as ProviderLayer< L::Provider, ZksyncHttpTransport, @@ -122,16 +120,16 @@ where >{ use alloy::signers::Signer; - let era_test_node_layer = EraTestNodeLayer::from(f(Default::default())); - let url = era_test_node_layer.endpoint_url(); + let anvil_zksync_layer = AnvilZKsyncLayer::from(f(Default::default())); + let url = anvil_zksync_layer.endpoint_url(); - let default_keys = era_test_node_layer.instance().keys().to_vec(); + let default_keys = anvil_zksync_layer.instance().keys().to_vec(); let (default_key, remaining_keys) = default_keys .split_first() - .ok_or(crate::node_bindings::EraTestNodeError::NoKeysAvailable)?; + .ok_or(crate::node_bindings::AnvilZKsyncError::NoKeysAvailable)?; let default_signer = LocalSigner::from(default_key.clone()) - .with_chain_id(Some(era_test_node_layer.instance().chain_id())); + .with_chain_id(Some(anvil_zksync_layer.instance().chain_id())); let mut wallet = ZksyncWallet::from(default_signer); for key in remaining_keys { @@ -139,6 +137,6 @@ where wallet.register_signer(signer) } - Ok(self.wallet(wallet).layer(era_test_node_layer).on_http(url)) + Ok(self.wallet(wallet).layer(anvil_zksync_layer).on_http(url)) } } From 071bc623121da27c89016a6911ce0bb9f1dbca83 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 12 Dec 2024 09:05:17 -0600 Subject: [PATCH 2/5] chore: fix names --- examples/deploy.rs | 4 ++-- src/node_bindings/anvil_zksync.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/deploy.rs b/examples/deploy.rs index 20a4e52..718ab49 100644 --- a/examples/deploy.rs +++ b/examples/deploy.rs @@ -27,8 +27,8 @@ sol! { #[tokio::main] async fn main() -> Result<()> { - // Create provider connected to the `era_test_node`. - // Note that you can manually spawn and configure the `era_test_node`, e.g. if you don't want the instance + // Create provider connected to the `anvil-zksync`. + // Note that you can manually spawn and configure the `anvil-zksync`, e.g. if you don't want the instance // to be spawned implicitly and/or you don't want it to be attached to a single provider. let provider = zksync_provider() .with_recommended_fillers() diff --git a/src/node_bindings/anvil_zksync.rs b/src/node_bindings/anvil_zksync.rs index d17485e..96dff2d 100644 --- a/src/node_bindings/anvil_zksync.rs +++ b/src/node_bindings/anvil_zksync.rs @@ -226,15 +226,15 @@ impl AnvilZKsync { // self // } // TODO - // /// Sets the block-time in seconds which will be used when the `era_test_node` instance is launched. + // /// Sets the block-time in seconds which will be used when the `anvil-zksync` instance is launched. // pub const fn block_time(mut self, block_time: u64) -> Self { // self.block_time = Some(block_time as f64); // self // } // TODO - // /// Sets the block-time in sub-seconds which will be used when the `era_test_node` instance is launched. - // /// Older versions of `era_test_node` do not support sub-second block times. + // /// Sets the block-time in sub-seconds which will be used when the `anvil-zksync` instance is launched. + // /// Older versions of `anvil-zksync` do not support sub-second block times. // pub const fn block_time_f64(mut self, block_time: f64) -> Self { // self.block_time = Some(block_time); // self From 24c83ffb16b62be989ac88475ef87f9d91df4ae9 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 12 Dec 2024 09:08:17 -0600 Subject: [PATCH 3/5] chore: cleanup --- src/node_bindings/anvil_zksync.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node_bindings/anvil_zksync.rs b/src/node_bindings/anvil_zksync.rs index 96dff2d..ee51965 100644 --- a/src/node_bindings/anvil_zksync.rs +++ b/src/node_bindings/anvil_zksync.rs @@ -225,6 +225,7 @@ impl AnvilZKsync { // self.mnemonic = Some(mnemonic.into()); // self // } + // TODO // /// Sets the block-time in seconds which will be used when the `anvil-zksync` instance is launched. // pub const fn block_time(mut self, block_time: u64) -> Self { From 8f14b981bbd2ef461ba2bec7c8c74fa42e89c7e7 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 12 Dec 2024 09:12:08 -0600 Subject: [PATCH 4/5] chore: cleanup --- src/node_bindings/anvil_zksync.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_bindings/anvil_zksync.rs b/src/node_bindings/anvil_zksync.rs index ee51965..d3f2cae 100644 --- a/src/node_bindings/anvil_zksync.rs +++ b/src/node_bindings/anvil_zksync.rs @@ -219,8 +219,9 @@ impl AnvilZKsync { self.chain_id = Some(chain_id); self } + // TODO - /// Sets the mnemonic which will be used when the `anvil-zksync` instance is launched. + // /// Sets the mnemonic which will be used when the `anvil-zksync` instance is launched. // pub fn mnemonic>(mut self, mnemonic: T) -> Self { // self.mnemonic = Some(mnemonic.into()); // self From 273c83a7c73a2c9cb824b71a5ef3df1038f1f31d Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 12 Dec 2024 09:20:11 -0600 Subject: [PATCH 5/5] chore: ignore fork_chain_id test until next anvil-zksync release --- src/node_bindings/anvil_zksync.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node_bindings/anvil_zksync.rs b/src/node_bindings/anvil_zksync.rs index d3f2cae..d4c39f0 100644 --- a/src/node_bindings/anvil_zksync.rs +++ b/src/node_bindings/anvil_zksync.rs @@ -464,6 +464,7 @@ mod tests { } #[tokio::test(flavor = "multi_thread")] + #[ignore] async fn fork_initializes_correct_chain() { let anvil_zksync = AnvilZKsync::new().fork("mainnet").spawn(); let rpc_url = anvil_zksync.endpoint_url();