From 3b90d489a2c3f895901755bd26222f4e6dd780af Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Fri, 19 Jul 2024 08:59:11 +0000 Subject: [PATCH 01/20] should skip serializing block_override if none --- crates/rpc-types-eth/src/call.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/rpc-types-eth/src/call.rs b/crates/rpc-types-eth/src/call.rs index 09f47660e5b..eba019753f0 100644 --- a/crates/rpc-types-eth/src/call.rs +++ b/crates/rpc-types-eth/src/call.rs @@ -9,6 +9,7 @@ pub struct Bundle { /// All transactions to execute pub transactions: Vec, /// Block overrides to apply + #[serde(skip_serializing_if = "Option::is_none")] pub block_override: Option, } From 8c4575192d4de2986bca09a4a6d752e2b3d305f0 Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Mon, 22 Jul 2024 05:04:29 -0700 Subject: [PATCH 02/20] feat: Add call_many (#1085) * Added stages to the sync info rpc type (#1079) * added stages detail * boxed enum * from hashmap to vec with helper type * serde alias and renames and dos * Update crates/rpc-types-eth/src/syncing.rs Co-authored-by: Matthias Seitz * Update crates/rpc-types-eth/src/syncing.rs Co-authored-by: Matthias Seitz * property to pub --------- Co-authored-by: Matthias Seitz * removing async get account (#1080) * fix(node-bindings): backport fix from ethers-rs (#1081) * feat(consensus): add `From` for `Request` (#1083) consensus: add From for Request * fix(eips): make SignedAuthorizationList arbitrary less fallible (#1084) * chore: export rpc account type (#1075) * Update debug.rs * Update debug.rs --------- Co-authored-by: Luca Provini Co-authored-by: Matthias Seitz Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Co-authored-by: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com> --- crates/consensus/src/request.rs | 6 ++++++ crates/eips/Cargo.toml | 2 ++ crates/eips/src/eip7702/auth_list.rs | 21 +++++++++++++++------ crates/eips/src/lib.rs | 5 +++++ crates/node-bindings/src/anvil.rs | 2 +- crates/provider/src/ext/debug.rs | 22 +++++++++++++++++++++- crates/provider/src/provider/trait.rs | 5 +---- crates/rpc-types-eth/src/account.rs | 4 ++++ crates/rpc-types-eth/src/syncing.rs | 24 ++++++++++++++++++++---- 9 files changed, 75 insertions(+), 16 deletions(-) diff --git a/crates/consensus/src/request.rs b/crates/consensus/src/request.rs index 6b6cb3211a9..6087d856f19 100644 --- a/crates/consensus/src/request.rs +++ b/crates/consensus/src/request.rs @@ -41,6 +41,12 @@ impl From for Request { } } +impl From for Request { + fn from(v: ConsolidationRequest) -> Self { + Self::ConsolidationRequest(v) + } +} + impl Request { /// Whether this is a [`DepositRequest`]. pub const fn is_deposit_request(&self) -> bool { diff --git a/crates/eips/Cargo.toml b/crates/eips/Cargo.toml index 4c2a1866ca5..aaff60fa33d 100644 --- a/crates/eips/Cargo.toml +++ b/crates/eips/Cargo.toml @@ -41,6 +41,7 @@ arbitrary = { workspace = true, features = ["derive"], optional = true } # for signed authorization list arbitrary k256 = { workspace = true, optional = true } +rand = { workspace = true, optional = true } [dev-dependencies] alloy-primitives = { workspace = true, features = [ @@ -80,6 +81,7 @@ arbitrary = [ "std", "kzg-sidecar", "dep:arbitrary", + "dep:rand", "alloy-primitives/arbitrary", "alloy-serde?/arbitrary", ] diff --git a/crates/eips/src/eip7702/auth_list.rs b/crates/eips/src/eip7702/auth_list.rs index d7ef4142639..64280012b5b 100644 --- a/crates/eips/src/eip7702/auth_list.rs +++ b/crates/eips/src/eip7702/auth_list.rs @@ -177,10 +177,15 @@ impl Deref for SignedAuthorization { #[cfg(all(any(test, feature = "arbitrary"), feature = "k256"))] impl<'a> arbitrary::Arbitrary<'a> for SignedAuthorization { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - use k256::ecdsa::{signature::hazmat::PrehashSigner, SigningKey}; - let key_bytes = u.arbitrary::<[u8; 32]>()?; - let signing_key = SigningKey::from_bytes(&key_bytes.into()) - .map_err(|_| arbitrary::Error::IncorrectFormat)?; + use k256::{ + ecdsa::{signature::hazmat::PrehashSigner, SigningKey}, + NonZeroScalar, + }; + use rand::{rngs::StdRng, SeedableRng}; + + let rng_seed = u.arbitrary::<[u8; 32]>()?; + let mut rand_gen = StdRng::from_seed(rng_seed); + let signing_key: SigningKey = NonZeroScalar::random(&mut rand_gen).into(); let inner = u.arbitrary::()?; let signature_hash = inner.signature_hash(); @@ -307,7 +312,6 @@ impl Deref for OptionalNonce { mod tests { use super::*; use alloy_primitives::{hex, Signature}; - use arbitrary::Arbitrary; use core::str::FromStr; fn test_encode_decode_roundtrip(auth: Authorization) { @@ -367,10 +371,15 @@ mod tests { assert_eq!(decoded, auth); } - #[cfg(feature = "k256")] + #[cfg(all(feature = "arbitrary", feature = "k256"))] #[test] fn test_arbitrary_auth() { + use arbitrary::Arbitrary; let mut unstructured = arbitrary::Unstructured::new(b"unstructured auth"); + // try this multiple times + let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap(); + let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap(); + let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap(); let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap(); } } diff --git a/crates/eips/src/lib.rs b/crates/eips/src/lib.rs index 393ba4f343e..b1111f8eeb5 100644 --- a/crates/eips/src/lib.rs +++ b/crates/eips/src/lib.rs @@ -11,6 +11,11 @@ #[macro_use] extern crate alloc; +// To ensure no unused imports, since signed auth list requires arbitrary _and_ k256 features, but +// is only enabled using the `arbitrary` feature. +#[cfg(all(not(feature = "k256"), feature = "arbitrary"))] +use rand as _; + pub mod eip1559; pub use eip1559::calc_next_block_base_fee; diff --git a/crates/node-bindings/src/anvil.rs b/crates/node-bindings/src/anvil.rs index 62903e9c2e7..a20cdaaf12a 100644 --- a/crates/node-bindings/src/anvil.rs +++ b/crates/node-bindings/src/anvil.rs @@ -318,7 +318,7 @@ impl Anvil { let mut child = cmd.spawn().map_err(AnvilError::SpawnError)?; - let stdout = child.stdout.as_mut().ok_or(AnvilError::NoStderr)?; + let stdout = child.stdout.take().ok_or(AnvilError::NoStderr)?; let start = Instant::now(); let mut reader = BufReader::new(stdout); diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index f8933bff221..ed1a2ed996f 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -2,7 +2,10 @@ use crate::Provider; use alloy_network::Network; use alloy_primitives::{hex, Bytes, TxHash, B256}; -use alloy_rpc_types_eth::{Block, BlockNumberOrTag, TransactionRequest}; +use alloy_rpc_types_eth::{ + state::StateOverride, Block, BlockNumberOrTag, Bundle, EthCallResponse, StateContext, + TransactionRequest, +}; use alloy_rpc_types_trace::geth::{ BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult, }; @@ -126,6 +129,15 @@ pub trait DebugApi: Send + Sync { block: BlockNumberOrTag, trace_options: GethDebugTracingCallOptions, ) -> TransportResult>; + + /// Simulate arbitrary number of transactions at an arbitrary blockchain index, with the + /// optionality of state overrides + async fn call_many( + &self, + tx: Bundle, + state_context: Option, + state_override: Option, + ) -> TransportResult>; } #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] @@ -136,6 +148,14 @@ where T: Transport + Clone, P: Provider, { + async fn call_many( + &self, + tx: Bundle, + state_context: Option, + state_override: Option, + ) -> TransportResult> { + self.client().request("callMany", (tx, state_context, state_override)).await + } async fn debug_get_raw_header(&self, block: BlockNumberOrTag) -> TransportResult { self.client().request("debug_getRawHeader", (block,)).await } diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 9ccd9c93f27..7d4cc1f889e 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -241,10 +241,7 @@ pub trait Provider: /// Retrieves account information ([Account](alloy_consensus::Account)) for the given [Address] /// at the particular [BlockId]. - async fn get_account( - &self, - address: Address, - ) -> RpcWithBlock { + fn get_account(&self, address: Address) -> RpcWithBlock { RpcWithBlock::new(self.weak_client(), "eth_getAccount", address) } diff --git a/crates/rpc-types-eth/src/account.rs b/crates/rpc-types-eth/src/account.rs index 10d6e9e3b16..439e24dd5a3 100644 --- a/crates/rpc-types-eth/src/account.rs +++ b/crates/rpc-types-eth/src/account.rs @@ -1,6 +1,10 @@ use alloy_primitives::{Address, Bytes, B256, B512, U256}; use alloy_serde::storage::JsonStorageKey; use serde::{Deserialize, Serialize}; + +// re-export account type for `eth_getAccount` +pub use alloy_consensus::Account; + /// Account information. #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct AccountInfo { diff --git a/crates/rpc-types-eth/src/syncing.rs b/crates/rpc-types-eth/src/syncing.rs index 0be858e61cd..68bfd1d0f68 100644 --- a/crates/rpc-types-eth/src/syncing.rs +++ b/crates/rpc-types-eth/src/syncing.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::collections::BTreeMap; /// Syncing info -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SyncInfo { /// Starting block @@ -16,6 +16,22 @@ pub struct SyncInfo { pub warp_chunks_amount: Option, /// Warp sync snapshot chunks processed. pub warp_chunks_processed: Option, + /// The details of the sync stages as an hashmap + /// where the key is the name of the stage and the value is the block number. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub stages: Option>, +} + +/// The detail of the sync stages. +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Stage { + /// The name of the sync stage. + #[serde(alias = "stage_name")] + pub name: String, + /// Indicates the progress of the sync stage. + #[serde(alias = "block_number", with = "alloy_serde::quantity")] + pub block: u64, } /// Peers info @@ -99,10 +115,10 @@ pub struct PipProtocolInfo { } /// Sync status -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum SyncStatus { /// Info when syncing - Info(SyncInfo), + Info(Box), /// Not syncing None, } @@ -117,7 +133,7 @@ impl<'de> Deserialize<'de> for SyncStatus { enum Syncing { /// When client is synced to the highest block, eth_syncing with return "false" None(bool), - IsSyncing(SyncInfo), + IsSyncing(Box), } match Syncing::deserialize(deserializer)? { From b860cbb23cd5bcbd43e193b90078aa18127d7b6f Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 9 Sep 2024 11:41:00 +0000 Subject: [PATCH 03/20] add tempdir utility --- crates/node-bindings/src/lib.rs | 3 +- crates/node-bindings/src/nodes/geth.rs | 31 ++++-------- crates/node-bindings/src/nodes/reth.rs | 31 ++++-------- crates/node-bindings/src/utils.rs | 25 ++++++++++ crates/provider/src/ext/admin.rs | 53 +++++++++++---------- crates/provider/src/ext/anvil.rs | 66 +++++++++++++------------- crates/provider/src/ext/debug.rs | 23 +-------- crates/provider/src/ext/mod.rs | 2 +- crates/provider/src/ext/net.rs | 39 ++++++++------- crates/provider/src/ext/trace.rs | 39 +++++++++------ crates/provider/src/ext/txpool.rs | 58 ++++++++++++---------- 11 files changed, 189 insertions(+), 181 deletions(-) diff --git a/crates/node-bindings/src/lib.rs b/crates/node-bindings/src/lib.rs index 6df8d1e9ff4..2ed26210609 100644 --- a/crates/node-bindings/src/lib.rs +++ b/crates/node-bindings/src/lib.rs @@ -21,8 +21,7 @@ pub use nodes::{ mod node; pub use node::*; -mod utils; -use utils::*; +pub mod utils; /// 1 Ether = 1e18 Wei == 0x0de0b6b3a7640000 Wei pub const WEI_IN_ETHER: U256 = U256::from_limbs([0x0de0b6b3a7640000, 0x0, 0x0, 0x0]); diff --git a/crates/node-bindings/src/nodes/geth.rs b/crates/node-bindings/src/nodes/geth.rs index a87418928e3..6363c5b393d 100644 --- a/crates/node-bindings/src/nodes/geth.rs +++ b/crates/node-bindings/src/nodes/geth.rs @@ -1,8 +1,8 @@ //! Utilities for launching a Geth dev-mode instance. use crate::{ - extract_endpoint, extract_value, unused_port, NodeError, NodeInstanceError, - NODE_DIAL_LOOP_TIMEOUT, NODE_STARTUP_TIMEOUT, + utils::{extract_endpoint, extract_value, unused_port}, + NodeError, NodeInstanceError, NODE_DIAL_LOOP_TIMEOUT, NODE_STARTUP_TIMEOUT, }; use alloy_genesis::{CliqueConfig, Genesis}; use alloy_primitives::Address; @@ -622,33 +622,20 @@ impl Geth { // These tests should use a different datadir for each `geth` spawned. #[cfg(test)] mod tests { + use super::*; - use std::path::Path; + use crate::utils::run_with_tempdir_sync; #[test] fn port_0() { - run_with_tempdir(|_| { + run_with_tempdir_sync("geth-test-", |_| { let _geth = Geth::new().disable_discovery().port(0u16).spawn(); }); } - /// Allows running tests with a temporary directory, which is cleaned up after the function is - /// called. - /// - /// Helps with tests that spawn a helper instance, which has to be dropped before the temporary - /// directory is cleaned up. - #[track_caller] - fn run_with_tempdir(f: impl Fn(&Path)) { - let temp_dir = tempfile::tempdir().unwrap(); - let temp_dir_path = temp_dir.path(); - f(temp_dir_path); - #[cfg(not(windows))] - temp_dir.close().unwrap(); - } - #[test] fn p2p_port() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("geth-test-", |temp_dir_path| { let geth = Geth::new().disable_discovery().data_dir(temp_dir_path).spawn(); let p2p_port = geth.p2p_port(); assert!(p2p_port.is_some()); @@ -657,7 +644,7 @@ mod tests { #[test] fn explicit_p2p_port() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("geth-test-", |temp_dir_path| { // if a p2p port is explicitly set, it should be used let geth = Geth::new().p2p_port(1234).data_dir(temp_dir_path).spawn(); let p2p_port = geth.p2p_port(); @@ -667,7 +654,7 @@ mod tests { #[test] fn dev_mode() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("geth-test-", |temp_dir_path| { // dev mode should not have a p2p port, and dev should be the default let geth = Geth::new().data_dir(temp_dir_path).spawn(); let p2p_port = geth.p2p_port(); @@ -679,7 +666,7 @@ mod tests { #[ignore = "fails on geth >=1.14"] #[allow(deprecated)] fn clique_correctly_configured() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("geth-test-", |temp_dir_path| { let private_key = SigningKey::random(&mut rand::thread_rng()); let geth = Geth::new() .set_clique_private_key(private_key) diff --git a/crates/node-bindings/src/nodes/reth.rs b/crates/node-bindings/src/nodes/reth.rs index 70baa113f7f..c99719c3e3a 100644 --- a/crates/node-bindings/src/nodes/reth.rs +++ b/crates/node-bindings/src/nodes/reth.rs @@ -1,6 +1,6 @@ //! Utilities for launching a Reth dev-mode instance. -use crate::{extract_endpoint, NodeError, NodeInstanceError, NODE_STARTUP_TIMEOUT}; +use crate::{utils::extract_endpoint, NodeError, NodeInstanceError, NODE_STARTUP_TIMEOUT}; use alloy_genesis::Genesis; use std::{ fs::create_dir, @@ -426,12 +426,12 @@ impl Reth { #[cfg(test)] mod tests { use super::*; - use std::path::Path; + use crate::utils::run_with_tempdir_sync; #[test] #[cfg(not(windows))] fn can_launch_reth() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new().data_dir(temp_dir_path).spawn(); assert_ports(&reth, false); @@ -441,7 +441,7 @@ mod tests { #[test] #[cfg(not(windows))] fn can_launch_reth_sepolia() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new().chain_or_path("sepolia").data_dir(temp_dir_path).spawn(); assert_ports(&reth, false); @@ -451,7 +451,7 @@ mod tests { #[test] #[cfg(not(windows))] fn can_launch_reth_dev() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir_path).spawn(); assert_ports(&reth, true); @@ -461,7 +461,7 @@ mod tests { #[test] #[cfg(not(windows))] fn can_launch_reth_dev_custom_genesis() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new() .dev() .disable_discovery() @@ -476,7 +476,7 @@ mod tests { #[test] #[cfg(not(windows))] fn can_launch_reth_dev_custom_blocktime() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new() .dev() .disable_discovery() @@ -491,7 +491,7 @@ mod tests { #[test] #[cfg(not(windows))] fn can_launch_reth_p2p_instance1() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new().instance(1).data_dir(temp_dir_path).spawn(); assert_eq!(reth.http_port(), 8545); @@ -504,7 +504,7 @@ mod tests { #[test] #[cfg(not(windows))] fn can_launch_reth_p2p_instance2() { - run_with_tempdir(|temp_dir_path| { + run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new().instance(2).data_dir(temp_dir_path).spawn(); assert_eq!(reth.http_port(), 8544); @@ -514,19 +514,6 @@ mod tests { }); } - /// Allows running tests with a temporary directory, which is cleaned up after the function is - /// called. - /// - /// Helps with tests that spawn a helper instance, which has to be dropped before the temporary - /// directory is cleaned up. - #[track_caller] - fn run_with_tempdir(f: impl Fn(&Path)) { - let temp_dir = tempfile::tempdir().unwrap(); - let temp_dir_path = temp_dir.path(); - f(temp_dir_path); - temp_dir.close().unwrap(); - } - // Asserts that the ports are set correctly for the given reth instance. fn assert_ports(reth: &RethInstance, dev: bool) { assert_eq!(reth.http_port(), 8545); diff --git a/crates/node-bindings/src/utils.rs b/crates/node-bindings/src/utils.rs index 11c52e1e3f7..a5f4ca9fed5 100644 --- a/crates/node-bindings/src/utils.rs +++ b/crates/node-bindings/src/utils.rs @@ -2,8 +2,11 @@ use std::{ borrow::Cow, + future::Future, net::{SocketAddr, TcpListener}, + path::PathBuf, }; +use tempfile; /// A bit of hack to find an unused TCP port. /// @@ -65,6 +68,28 @@ pub(crate) fn extract_endpoint(key: &str, line: &str) -> Option { val.parse::().ok() } +/// Runs the given closure with a temporary directory. +pub fn run_with_tempdir_sync(prefix: &str, f: impl FnOnce(PathBuf)) { + let temp_dir = tempfile::TempDir::with_prefix(prefix).unwrap(); + let temp_dir_path = temp_dir.path().to_path_buf(); + f(temp_dir_path); + #[cfg(not(windows))] + temp_dir.close().unwrap(); +} + +/// Runs the given async closure with a temporary directory. +pub async fn run_with_tempdir(prefix: &str, f: F) +where + F: FnOnce(PathBuf) -> Fut, + Fut: Future, +{ + let temp_dir = tempfile::TempDir::with_prefix(prefix).unwrap(); + let temp_dir_path = temp_dir.path().to_path_buf(); + f(temp_dir_path).await; + #[cfg(not(windows))] + temp_dir.close().unwrap(); +} + #[test] fn test_extract_http_address() { let line = "INFO [07-01|13:20:42.774] HTTP server started endpoint=127.0.0.1:8545 auth=false prefix= cors= vhosts=localhost"; diff --git a/crates/provider/src/ext/admin.rs b/crates/provider/src/ext/admin.rs index c1872f8e9ec..98cac754989 100644 --- a/crates/provider/src/ext/admin.rs +++ b/crates/provider/src/ext/admin.rs @@ -88,36 +88,41 @@ mod test { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::Geth; - use tempfile::TempDir; + use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn node_info() { - let temp_dir = TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let node_info = provider.node_info().await.unwrap(); - assert!(node_info.enode.starts_with("enode://")); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let node_info = provider.node_info().await.unwrap(); + assert!(node_info.enode.starts_with("enode://")); + }) + .await; } #[tokio::test] async fn admin_peers() { - let temp_dir = TempDir::with_prefix("geth-test-1").unwrap(); - let temp_dir_2 = TempDir::with_prefix("geth-test-2").unwrap(); - let geth1 = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let mut geth2 = - Geth::new().disable_discovery().port(0u16).data_dir(temp_dir_2.path()).spawn(); - - let provider1 = ProviderBuilder::new().on_http(geth1.endpoint_url()); - let provider2 = ProviderBuilder::new().on_http(geth2.endpoint_url()); - let node1_info = provider1.node_info().await.unwrap(); - let node1_id = node1_info.id; - let node1_enode = node1_info.enode; - - let added = provider2.add_peer(&node1_enode).await.unwrap(); - assert!(added); - geth2.wait_to_add_peer(&node1_id).unwrap(); - let peers = provider2.peers().await.unwrap(); - assert_eq!(peers[0].enode, node1_enode); + run_with_tempdir("geth-test-1", |temp_dir_1| async move { + run_with_tempdir("geth-test-2", |temp_dir_2| async move { + let geth1 = Geth::new().disable_discovery().data_dir(&temp_dir_1).spawn(); + let mut geth2 = + Geth::new().disable_discovery().port(0u16).data_dir(&temp_dir_2).spawn(); + + let provider1 = ProviderBuilder::new().on_http(geth1.endpoint_url()); + let provider2 = ProviderBuilder::new().on_http(geth2.endpoint_url()); + let node1_info = provider1.node_info().await.unwrap(); + let node1_id = node1_info.id; + let node1_enode = node1_info.enode; + + let added = provider2.add_peer(&node1_enode).await.unwrap(); + assert!(added); + geth2.wait_to_add_peer(&node1_id).unwrap(); + let peers = provider2.peers().await.unwrap(); + assert_eq!(peers[0].enode, node1_enode); + }) + .await; + }) + .await; } } diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index 9349e1eb8cd..9768c30794e 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -322,7 +322,7 @@ mod tests { // use alloy_node_bindings::Anvil; (to be used in `test_anvil_reset`) #[tokio::test] - async fn test_anvil_impersonate_account_stop_impersonating_account() { + async fn anvil_impersonate_account_stop_impersonating_account() { let provider = ProviderBuilder::new().on_anvil(); let impersonate = Address::random(); @@ -358,7 +358,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_auto_impersonate_account() { + async fn anvil_auto_impersonate_account() { let provider = ProviderBuilder::new().on_anvil(); let impersonate = Address::random(); @@ -396,7 +396,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_get_auto_mine_set_auto_mine() { + async fn anvil_get_auto_mine_set_auto_mine() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -411,7 +411,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_mine() { + async fn anvil_mine() { let provider = ProviderBuilder::new().on_anvil(); let start_num = provider.get_block_number().await.unwrap(); @@ -424,7 +424,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_interval_mining() { + async fn anvil_set_interval_mining() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_interval_mining(1).await.unwrap(); @@ -439,7 +439,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_drop_transaction() { + async fn anvil_drop_transaction() { let provider = ProviderBuilder::new().on_anvil_with_wallet(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -467,7 +467,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_drop_all_transactions() { + async fn anvil_drop_all_transactions() { let provider = ProviderBuilder::new().on_anvil_with_wallet(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -497,7 +497,7 @@ mod tests { // TODO: Fix this test, `chain_id` is not being set correctly. // #[tokio::test] - // async fn test_anvil_reset() { + // async fn anvil_reset() { // let fork1 = Anvil::default().chain_id(777).spawn(); // let fork2 = Anvil::default().chain_id(888).spawn(); @@ -520,7 +520,7 @@ mod tests { // } #[tokio::test] - async fn test_anvil_set_chain_id() { + async fn anvil_set_chain_id() { let provider = ProviderBuilder::new().on_anvil(); let chain_id = 1337; @@ -531,7 +531,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_balance() { + async fn anvil_set_balance() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -543,7 +543,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_code() { + async fn anvil_set_code() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -554,7 +554,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_nonce() { + async fn anvil_set_nonce() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -566,7 +566,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_storage_at() { + async fn anvil_set_storage_at() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -579,14 +579,14 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_logging() { + async fn anvil_set_logging() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_logging(true).await.unwrap(); } #[tokio::test] - async fn test_anvil_set_min_gas_price() { + async fn anvil_set_min_gas_price() { let provider = ProviderBuilder::new().on_anvil(); let gas = U256::from(1337); @@ -600,7 +600,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_next_block_base_fee_per_gas() { + async fn anvil_set_next_block_base_fee_per_gas() { let provider = ProviderBuilder::new().on_anvil(); let basefee = U256::from(1337); @@ -615,7 +615,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_coinbase() { + async fn anvil_set_coinbase() { let provider = ProviderBuilder::new().on_anvil(); let coinbase = Address::random(); @@ -629,7 +629,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_dump_state_load_state() { + async fn anvil_dump_state_load_state() { let provider = ProviderBuilder::new().on_anvil(); let state = provider.anvil_dump_state().await.unwrap(); @@ -642,7 +642,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_node_info() { + async fn anvil_node_info() { let provider = ProviderBuilder::new().on_anvil(); let latest_block = @@ -656,7 +656,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_metadata() { + async fn anvil_metadata() { let provider = ProviderBuilder::new().on_anvil(); let client_version = provider.get_client_version().await.unwrap(); @@ -669,7 +669,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_remove_pool_transactions() { + async fn anvil_remove_pool_transactions() { let provider = ProviderBuilder::new().on_anvil_with_wallet(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -698,7 +698,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_snapshot_revert() { + async fn anvil_snapshot_revert() { let provider = ProviderBuilder::new().on_anvil(); let snapshot_id = provider.anvil_snapshot().await.unwrap(); @@ -734,7 +734,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_increase_time() { + async fn anvil_increase_time() { let provider = ProviderBuilder::new().on_anvil(); let timestamp = provider @@ -751,7 +751,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_next_block_timestamp() { + async fn anvil_set_next_block_timestamp() { let provider = ProviderBuilder::new().on_anvil(); let timestamp = provider @@ -772,7 +772,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_time() { + async fn anvil_set_time() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_time(0).await.unwrap(); @@ -783,7 +783,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_block_gas_limit() { + async fn anvil_set_block_gas_limit() { let provider = ProviderBuilder::new().on_anvil(); let block_gas_limit = U256::from(1337); @@ -797,7 +797,7 @@ mod tests { } #[tokio::test] - async fn test_anvil_set_block_timestamp_interval_anvil_remove_block_timestamp_interval() { + async fn anvil_set_block_timestamp_interval_anvil_remove_block_timestamp_interval() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_block_timestamp_interval(1).await.unwrap(); @@ -840,7 +840,7 @@ mod tests { } #[tokio::test] - async fn test_evm_mine_single_block() { + async fn evm_mine_single_block() { let provider = ProviderBuilder::new().on_anvil(); let start_num = provider.get_block_number().await.unwrap(); @@ -857,7 +857,7 @@ mod tests { // TODO: Fix this test, only a single block is being mined regardless of the `blocks` parameter. // #[tokio::test] - // async fn test_evm_mine_with_configuration() { + // async fn evm_mine_with_configuration() { // let provider = ProviderBuilder::new().on_anvil(); // let start_num = provider.get_block_number().await.unwrap(); @@ -872,7 +872,7 @@ mod tests { // } #[tokio::test] - async fn test_anvil_mine_detailed_single_block() { + async fn anvil_mine_detailed_single_block() { let provider = ProviderBuilder::new().on_anvil(); let start_num = provider.get_block_number().await.unwrap(); @@ -889,7 +889,7 @@ mod tests { // TODO: Fix this test, only a single block is being mined regardless of the `blocks` parameter. // #[tokio::test] - // async fn test_anvil_mine_detailed_with_configuration() { + // async fn anvil_mine_detailed_with_configuration() { // let provider = ProviderBuilder::new().on_anvil(); // let start_num = provider.get_block_number().await.unwrap(); @@ -911,7 +911,7 @@ mod tests { // } #[tokio::test] - async fn test_anvil_set_rpc_url() { + async fn anvil_set_rpc_url() { let provider = ProviderBuilder::new().on_anvil(); let url = "https://example.com".to_string(); @@ -919,7 +919,7 @@ mod tests { } #[tokio::test] - async fn test_eth_send_unsigned_transaction() { + async fn eth_send_unsigned_transaction() { let provider = ProviderBuilder::new().on_anvil(); let alice = Address::random(); diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index b2aa5e819b7..07005ae5a20 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -2,10 +2,7 @@ use crate::Provider; use alloy_network::Network; use alloy_primitives::{hex, Bytes, TxHash, B256}; -use alloy_rpc_types_eth::{ - state::StateOverride, Block, BlockId, BlockNumberOrTag, Bundle, EthCallResponse, StateContext, - TransactionRequest, -}; +use alloy_rpc_types_eth::{Block, BlockId, BlockNumberOrTag, TransactionRequest}; use alloy_rpc_types_trace::geth::{ BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult, }; @@ -129,15 +126,6 @@ pub trait DebugApi: Send + Sync { block: BlockId, trace_options: GethDebugTracingCallOptions, ) -> TransportResult>; - - /// Simulate arbitrary number of transactions at an arbitrary blockchain index, with the - /// optionality of state overrides - async fn call_many( - &self, - tx: Bundle, - state_context: Option, - state_override: Option, - ) -> TransportResult>; } #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] @@ -148,15 +136,6 @@ where T: Transport + Clone, P: Provider, { - async fn call_many( - &self, - tx: Bundle, - state_context: Option, - state_override: Option, - ) -> TransportResult> { - self.client().request("callMany", (tx, state_context, state_override)).await - } - async fn debug_get_raw_header(&self, block: BlockId) -> TransportResult { self.client().request("debug_getRawHeader", (block,)).await } diff --git a/crates/provider/src/ext/mod.rs b/crates/provider/src/ext/mod.rs index a5f5c185a20..edcbac4c15b 100644 --- a/crates/provider/src/ext/mod.rs +++ b/crates/provider/src/ext/mod.rs @@ -28,7 +28,7 @@ pub use net::NetApi; #[cfg(feature = "trace-api")] mod trace; #[cfg(feature = "trace-api")] -pub use trace::{TraceApi, TraceCallList}; +pub use trace::TraceApi; #[cfg(feature = "rpc-api")] mod rpc; diff --git a/crates/provider/src/ext/net.rs b/crates/provider/src/ext/net.rs index f1d962629ae..92ee2e1fb21 100644 --- a/crates/provider/src/ext/net.rs +++ b/crates/provider/src/ext/net.rs @@ -41,35 +41,42 @@ mod test { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::Geth; + use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn call_net_version() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let version = provider.net_version().await.expect("net_version call should succeed"); - assert_eq!(version, 1); + let version = provider.net_version().await.expect("net_version call should succeed"); + assert_eq!(version, 1); + }) + .await } #[tokio::test] async fn call_net_peer_count() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let count = provider.net_peer_count().await.expect("net_peerCount call should succeed"); - assert_eq!(count, 0); + let count = provider.net_peer_count().await.expect("net_peerCount call should succeed"); + assert_eq!(count, 0); + }) + .await } #[tokio::test] async fn call_net_listening() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let listening = provider.net_listening().await.expect("net_listening call should succeed"); - assert!(listening); + let listening = + provider.net_listening().await.expect("net_listening call should succeed"); + assert!(listening); + }) + .await } } diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index b6a81dc2077..0060eb34233 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -10,9 +10,6 @@ use alloy_rpc_types_trace::{ }; use alloy_transport::{Transport, TransportResult}; -/// List of trace calls for use with [`TraceApi::trace_call_many`] -pub type TraceCallList<'a, N> = &'a [(::TransactionRequest, Vec)]; - /// Trace namespace rpc interface that gives access to several non-standard RPC methods. #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] @@ -42,8 +39,8 @@ where /// Not all nodes support this call. fn trace_call_many<'a>( &self, - request: TraceCallList<'a, N>, - ) -> RpcWithBlock, TraceResults>; + request: &'a [(N::TransactionRequest, Vec)], + ) -> RpcWithBlock)], TraceResults>; /// Parity trace transaction. async fn trace_transaction( @@ -117,8 +114,9 @@ where fn trace_call_many<'a>( &self, - request: TraceCallList<'a, N>, - ) -> RpcWithBlock, TraceResults> { + request: &'a [(::TransactionRequest, Vec)], + ) -> RpcWithBlock::TransactionRequest, Vec)], TraceResults> + { RpcWithBlock::new(self.weak_client(), "trace_callMany", request) } @@ -178,18 +176,31 @@ where mod test { use crate::ProviderBuilder; use alloy_eips::BlockNumberOrTag; + use alloy_node_bindings::{utils::run_with_tempdir, Reth}; use super::*; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); + #[tokio::test] + async fn trace_block() { + run_with_tempdir("reth-test-", |temp_dir| async move { + let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); + + let result = provider.trace_block(BlockId::Number(BlockNumberOrTag::Latest)).await; + assert!(result.is_ok()); + + let traces = result.unwrap(); + assert_eq!(traces.len(), 0); + }) + .await } #[tokio::test] - async fn test_trace_block() { - init_tracing(); - let provider = ProviderBuilder::new().on_anvil(); - let traces = provider.trace_block(BlockId::Number(BlockNumberOrTag::Latest)).await.unwrap(); - assert_eq!(traces.len(), 0); + async fn trace_call_many() { + run_with_tempdir("reth-test-", |temp_dir| async move { + let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); + }) + .await } } diff --git a/crates/provider/src/ext/txpool.rs b/crates/provider/src/ext/txpool.rs index 34e497c2190..b97b1a2e4b5 100644 --- a/crates/provider/src/ext/txpool.rs +++ b/crates/provider/src/ext/txpool.rs @@ -78,41 +78,49 @@ mod tests { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::Geth; + use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] - async fn test_txpool_content() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_content().await.unwrap(); - assert_eq!(content, TxpoolContent::default()); + async fn txpool_content() { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_content().await.unwrap(); + assert_eq!(content, TxpoolContent::default()); + }) + .await } #[tokio::test] - async fn test_txpool_content_from() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_content_from(Address::default()).await.unwrap(); - assert_eq!(content, TxpoolContentFrom::default()); + async fn txpool_content_from() { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_content_from(Address::default()).await.unwrap(); + assert_eq!(content, TxpoolContentFrom::default()); + }) + .await } #[tokio::test] - async fn test_txpool_inspect() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_inspect().await.unwrap(); - assert_eq!(content, TxpoolInspect::default()); + async fn txpool_inspect() { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_inspect().await.unwrap(); + assert_eq!(content, TxpoolInspect::default()); + }) + .await } #[tokio::test] - async fn test_txpool_status() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - let content = provider.txpool_status().await.unwrap(); - assert_eq!(content, TxpoolStatus::default()); + async fn txpool_status() { + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + let content = provider.txpool_status().await.unwrap(); + assert_eq!(content, TxpoolStatus::default()); + }) + .await } } From c684b703ef665bb2032cc9663e6a86e5a78170be Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 9 Sep 2024 12:13:31 +0000 Subject: [PATCH 04/20] clean up tests --- crates/provider/src/chain.rs | 8 --- crates/provider/src/ext/debug.rs | 82 ++++++++++++++------------- crates/provider/src/ext/trace.rs | 14 +++-- crates/provider/src/provider/trait.rs | 38 ------------- 4 files changed, 51 insertions(+), 91 deletions(-) diff --git a/crates/provider/src/chain.rs b/crates/provider/src/chain.rs index b69c0f6b700..1734bd73622 100644 --- a/crates/provider/src/chain.rs +++ b/crates/provider/src/chain.rs @@ -134,10 +134,6 @@ mod tests { use super::*; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - async fn with_timeout(fut: T) -> T::Output { tokio::select! { _ = tokio::time::sleep(Duration::from_secs(1)) => panic!("Operation timed out"), @@ -147,8 +143,6 @@ mod tests { #[tokio::test] async fn yield_block() { - init_tracing(); - let anvil = Anvil::new().spawn(); let client = ReqwestClient::new_http(anvil.endpoint_url()); @@ -169,8 +163,6 @@ mod tests { // Make sure that we can process more blocks than fits in the cache. const BLOCKS_TO_MINE: usize = BLOCK_CACHE_SIZE.get() + 1; - init_tracing(); - let anvil = Anvil::new().spawn(); let client = ReqwestClient::new_http(anvil.endpoint_url()); diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index 07005ae5a20..d7c3ca9743e 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -222,16 +222,11 @@ mod test { use super::*; use alloy_network::TransactionBuilder; - use alloy_node_bindings::Geth; + use alloy_node_bindings::{utils::run_with_tempdir, Geth}; use alloy_primitives::{address, U256}; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - #[tokio::test] async fn test_debug_trace_transaction() { - init_tracing(); let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let from = provider.default_signer_address(); @@ -257,7 +252,6 @@ mod test { #[tokio::test] async fn test_debug_trace_call() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil_with_wallet(); let from = provider.default_signer_address(); let gas_price = provider.get_gas_price().await.unwrap(); @@ -283,50 +277,58 @@ mod test { #[tokio::test] async fn call_debug_get_raw_header() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let rlp_header = provider - .debug_get_raw_header(BlockId::Number(BlockNumberOrTag::Latest)) - .await - .expect("debug_getRawHeader call should succeed"); - - assert!(!rlp_header.is_empty()); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let rlp_header = provider + .debug_get_raw_header(BlockId::Number(BlockNumberOrTag::Latest)) + .await + .expect("debug_getRawHeader call should succeed"); + + assert!(!rlp_header.is_empty()); + }) + .await } #[tokio::test] async fn call_debug_get_raw_block() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let rlp_block = provider - .debug_get_raw_block(BlockId::Number(BlockNumberOrTag::Latest)) - .await - .expect("debug_getRawBlock call should succeed"); - - assert!(!rlp_block.is_empty()); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let rlp_block = provider + .debug_get_raw_block(BlockId::Number(BlockNumberOrTag::Latest)) + .await + .expect("debug_getRawBlock call should succeed"); + + assert!(!rlp_block.is_empty()); + }) + .await } #[tokio::test] async fn call_debug_get_raw_receipts() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let result = - provider.debug_get_raw_receipts(BlockId::Number(BlockNumberOrTag::Latest)).await; - assert!(result.is_ok()); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let result = + provider.debug_get_raw_receipts(BlockId::Number(BlockNumberOrTag::Latest)).await; + assert!(result.is_ok()); + }) + .await } #[tokio::test] async fn call_debug_get_bad_blocks() { - let temp_dir = tempfile::TempDir::with_prefix("geth-test-").unwrap(); - let geth = Geth::new().disable_discovery().data_dir(temp_dir.path()).spawn(); - let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); - - let result = provider.debug_get_bad_blocks().await; - assert!(result.is_ok()); + run_with_tempdir("geth-test-", |temp_dir| async move { + let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); + + let result = provider.debug_get_bad_blocks().await; + assert!(result.is_ok()); + }) + .await } } diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 0060eb34233..29bf5baae39 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -10,6 +10,9 @@ use alloy_rpc_types_trace::{ }; use alloy_transport::{Transport, TransportResult}; +/// List of trace calls for use with [`TraceApi::trace_call_many`] +pub type TraceCallList<'a, N> = &'a [(::TransactionRequest, Vec)]; + /// Trace namespace rpc interface that gives access to several non-standard RPC methods. #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] @@ -39,8 +42,8 @@ where /// Not all nodes support this call. fn trace_call_many<'a>( &self, - request: &'a [(N::TransactionRequest, Vec)], - ) -> RpcWithBlock)], TraceResults>; + request: &'a TraceCallList<'a, N>, + ) -> RpcWithBlock, TraceResults>; /// Parity trace transaction. async fn trace_transaction( @@ -114,9 +117,8 @@ where fn trace_call_many<'a>( &self, - request: &'a [(::TransactionRequest, Vec)], - ) -> RpcWithBlock::TransactionRequest, Vec)], TraceResults> - { + request: &'a TraceCallList<'a, N>, + ) -> RpcWithBlock, TraceResults> { RpcWithBlock::new(self.weak_client(), "trace_callMany", request) } @@ -181,6 +183,7 @@ mod test { use super::*; #[tokio::test] + #[cfg(not(windows))] async fn trace_block() { run_with_tempdir("reth-test-", |temp_dir| async move { let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); @@ -196,6 +199,7 @@ mod test { } #[tokio::test] + #[cfg(not(windows))] async fn trace_call_many() { run_with_tempdir("reth-test-", |temp_dir| async move { let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 17393c9c35e..cd49d21e56a 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -1014,13 +1014,8 @@ mod tests { use alloy_primitives::{address, b256, bytes, keccak256}; use alloy_rpc_types_eth::{request::TransactionRequest, Block}; - fn init_tracing() { - let _ = tracing_subscriber::fmt::try_init(); - } - #[tokio::test] async fn test_provider_builder() { - init_tracing(); let provider = RootProvider::::builder().with_recommended_fillers().on_anvil(); let num = provider.get_block_number().await.unwrap(); @@ -1029,7 +1024,6 @@ mod tests { #[tokio::test] async fn test_builder_helper_fn() { - init_tracing(); let provider = builder().with_recommended_fillers().on_anvil(); let num = provider.get_block_number().await.unwrap(); assert_eq!(0, num); @@ -1037,7 +1031,6 @@ mod tests { #[tokio::test] async fn test_builder_helper_fn_any_network() { - init_tracing(); let anvil = Anvil::new().spawn(); let provider = builder::().with_recommended_fillers().on_http(anvil.endpoint_url()); @@ -1048,7 +1041,6 @@ mod tests { #[cfg(feature = "reqwest")] #[tokio::test] async fn object_safety() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); // These blocks are not necessary. @@ -1084,8 +1076,6 @@ mod tests { #[cfg(feature = "ws")] #[tokio::test] async fn subscribe_blocks_http() { - init_tracing(); - let provider = ProviderBuilder::new().on_anvil_with_config(|a| a.block_time(1)); let err = provider.subscribe_blocks().await.unwrap_err(); @@ -1114,7 +1104,6 @@ mod tests { async fn subscribe_blocks_ws() { use futures::stream::StreamExt; - init_tracing(); let anvil = Anvil::new().block_time(1).spawn(); let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint()); let client = alloy_rpc_client::RpcClient::connect_pubsub(ws).await.unwrap(); @@ -1135,7 +1124,6 @@ mod tests { async fn subscribe_blocks_ws_boxed() { use futures::stream::StreamExt; - init_tracing(); let anvil = Anvil::new().block_time(1).spawn(); let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint()); let client = alloy_rpc_client::RpcClient::connect_pubsub(ws).await.unwrap(); @@ -1157,7 +1145,6 @@ mod tests { async fn subscribe_blocks_ws_remote() { use futures::stream::StreamExt; - init_tracing(); let url = "wss://eth-mainnet.g.alchemy.com/v2/viFmeVzhg6bWKVMIWWS8MhmzREB-D4f7"; let ws = alloy_rpc_client::WsConnect::new(url); let Ok(client) = alloy_rpc_client::RpcClient::connect_pubsub(ws).await else { return }; @@ -1172,7 +1159,6 @@ mod tests { #[tokio::test] async fn test_send_tx() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let tx = TransactionRequest { value: Some(U256::from(100)), @@ -1196,7 +1182,6 @@ mod tests { #[tokio::test] async fn test_watch_confirmed_tx() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let tx = TransactionRequest { value: Some(U256::from(100)), @@ -1244,7 +1229,6 @@ mod tests { #[tokio::test] async fn gets_block_number() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = provider.get_block_number().await.unwrap(); assert_eq!(0, num) @@ -1252,7 +1236,6 @@ mod tests { #[tokio::test] async fn gets_block_number_with_raw_req() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num: U64 = provider.raw_request("eth_blockNumber".into(), NoParams::default()).await.unwrap(); @@ -1261,7 +1244,6 @@ mod tests { #[tokio::test] async fn gets_transaction_count() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let count = provider .get_transaction_count(address!("328375e18E7db8F1CA9d9bA8bF3E9C94ee34136A")) @@ -1272,7 +1254,6 @@ mod tests { #[tokio::test] async fn gets_block_by_hash() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1285,7 +1266,6 @@ mod tests { #[tokio::test] async fn gets_block_by_hash_with_raw_req() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1300,7 +1280,6 @@ mod tests { #[tokio::test] async fn gets_block_by_number_full() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1310,7 +1289,6 @@ mod tests { #[tokio::test] async fn gets_block_by_number() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1320,7 +1298,6 @@ mod tests { #[tokio::test] async fn gets_client_version() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let version = provider.get_client_version().await.unwrap(); assert!(version.contains("anvil"), "{version}"); @@ -1328,7 +1305,6 @@ mod tests { #[tokio::test] async fn gets_sha3() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let data = b"alloy"; let hash = provider.get_sha3(data).await.unwrap(); @@ -1356,7 +1332,6 @@ mod tests { #[tokio::test] async fn gets_storage_at() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let addr = Address::with_last_byte(16); let storage = provider.get_storage_at(addr, U256::ZERO).await.unwrap(); @@ -1365,8 +1340,6 @@ mod tests { #[tokio::test] async fn gets_transaction_by_hash_not_found() { - init_tracing(); - let provider = ProviderBuilder::new().on_anvil(); let tx_hash = b256!("5c03fab9114ceb98994b43892ade87ddfd9ae7e8f293935c3bd29d435dc9fd95"); let tx = provider.get_transaction_by_hash(tx_hash).await.expect("failed to fetch tx"); @@ -1376,7 +1349,6 @@ mod tests { #[tokio::test] async fn gets_transaction_by_hash() { - init_tracing(); let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let req = TransactionRequest::default() @@ -1398,7 +1370,6 @@ mod tests { #[tokio::test] #[ignore] async fn gets_logs() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let filter = Filter::new() .at_block_hash(b256!( @@ -1414,7 +1385,6 @@ mod tests { #[tokio::test] #[ignore] async fn gets_tx_receipt() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let receipt = provider .get_transaction_receipt(b256!( @@ -1432,14 +1402,12 @@ mod tests { #[tokio::test] async fn gets_max_priority_fee_per_gas() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let _fee = provider.get_max_priority_fee_per_gas().await.unwrap(); } #[tokio::test] async fn gets_fee_history() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let block_number = provider.get_block_number().await.unwrap(); let fee_history = provider @@ -1455,7 +1423,6 @@ mod tests { #[tokio::test] async fn gets_block_receipts() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let receipts = provider.get_block_receipts(BlockId::Number(BlockNumberOrTag::Latest)).await.unwrap(); @@ -1464,7 +1431,6 @@ mod tests { #[tokio::test] async fn sends_raw_transaction() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let pending = provider .send_raw_transaction( @@ -1480,7 +1446,6 @@ mod tests { #[tokio::test] async fn connect_boxed() { - init_tracing(); let anvil = Anvil::new().spawn(); let provider = @@ -1503,7 +1468,6 @@ mod tests { #[tokio::test] async fn test_uncle_count() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let count = provider.get_uncle_count(0.into()).await.unwrap(); @@ -1520,7 +1484,6 @@ mod tests { use alloy_network::TransactionBuilder; use alloy_sol_types::SolValue; - init_tracing(); let url = "https://eth-mainnet.alchemyapi.io/v2/jGiK5vwDfC3F4r0bqukm-W2GqgdrxdSr"; let provider = ProviderBuilder::new().on_http(url.parse().unwrap()); let req = TransactionRequest::default() @@ -1532,7 +1495,6 @@ mod tests { #[tokio::test] async fn test_empty_transactions() { - init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let block = provider.get_block_by_number(0.into(), false).await.unwrap().unwrap(); From d03af40cced0e92654f5dfb589ccca336bc9b57e Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 9 Sep 2024 15:02:57 +0000 Subject: [PATCH 05/20] add debug_trace_call_many test --- crates/node-bindings/src/node.rs | 32 ++++++------ crates/node-bindings/src/nodes/anvil.rs | 62 +++++------------------ crates/node-bindings/src/nodes/geth.rs | 14 +++--- crates/node-bindings/src/nodes/reth.rs | 42 +++++++++++++--- crates/node-bindings/src/utils.rs | 45 +++++++++++++++++ crates/provider/src/builder.rs | 7 ++- crates/provider/src/ext/debug.rs | 67 ++++++++++++++++++++----- crates/rpc-types-eth/src/call.rs | 2 +- 8 files changed, 172 insertions(+), 99 deletions(-) diff --git a/crates/node-bindings/src/node.rs b/crates/node-bindings/src/node.rs index b89056142d2..281960e8b64 100644 --- a/crates/node-bindings/src/node.rs +++ b/crates/node-bindings/src/node.rs @@ -1,5 +1,6 @@ //! Node-related types and constants. +use alloy_primitives::hex; use std::time::Duration; use thiserror::Error; @@ -9,23 +10,7 @@ pub const NODE_STARTUP_TIMEOUT: Duration = Duration::from_secs(10); /// Timeout for waiting for the node to add a peer. pub const NODE_DIAL_LOOP_TIMEOUT: Duration = Duration::from_secs(20); -/// Errors that can occur when working with a node instance. -#[derive(Debug)] -pub enum NodeInstanceError { - /// Timed out waiting for a message from node's stderr. - Timeout(String), - - /// A line could not be read from the node's stderr. - ReadLineError(std::io::Error), - - /// The child node process's stderr was not captured. - NoStderr, - - /// The child node process's stdout was not captured. - NoStdout, -} - -/// Errors that can occur when working with the node. +/// Errors that can occur when working with the node instance. #[derive(Debug, Error)] pub enum NodeError { /// The chain id was not set. @@ -65,4 +50,17 @@ pub enum NodeError { /// Clique private key error #[error("clique address error: {0}")] CliqueAddressError(String), + + /// The private key could not be parsed. + #[error("could not parse private key")] + ParsePrivateKeyError, + /// An error occurred while deserializing a private key. + #[error("could not deserialize private key from bytes")] + DeserializePrivateKeyError, + /// An error occurred while parsing a hex string. + #[error(transparent)] + FromHexError(#[from] hex::FromHexError), + /// No keys available this node instance. + #[error("no keys available in this node instance")] + NoKeysAvailable, } diff --git a/crates/node-bindings/src/nodes/anvil.rs b/crates/node-bindings/src/nodes/anvil.rs index 0572cf0fdd1..eb3760bcde8 100644 --- a/crates/node-bindings/src/nodes/anvil.rs +++ b/crates/node-bindings/src/nodes/anvil.rs @@ -1,7 +1,8 @@ //! Utilities for launching an Anvil instance. +use crate::NodeError; use alloy_primitives::{hex, Address, ChainId}; -use k256::{ecdsa::SigningKey, SecretKey as K256SecretKey}; +use k256::{ecdsa::SigningKey, SecretKey}; use std::{ io::{BufRead, BufReader}, net::SocketAddr, @@ -10,7 +11,6 @@ use std::{ str::FromStr, time::{Duration, Instant}, }; -use thiserror::Error; use url::Url; /// How long we will wait for anvil to indicate that it is ready. @@ -22,7 +22,7 @@ const ANVIL_STARTUP_TIMEOUT_MILLIS: u64 = 10_000; #[derive(Debug)] pub struct AnvilInstance { child: Child, - private_keys: Vec, + private_keys: Vec, addresses: Vec
, port: u16, chain_id: Option, @@ -40,7 +40,7 @@ impl AnvilInstance { } /// Returns the private keys used to instantiate this instance - pub fn keys(&self) -> &[K256SecretKey] { + pub fn keys(&self) -> &[SecretKey] { &self.private_keys } @@ -89,42 +89,6 @@ impl Drop for AnvilInstance { } } -/// Errors that can occur when working with the [`Anvil`]. -#[derive(Debug, Error)] -pub enum AnvilError { - /// Spawning the anvil process failed. - #[error("could not start anvil: {0}")] - SpawnError(std::io::Error), - - /// Timed out waiting for a message from anvil's stderr. - #[error("timed out waiting for anvil to spawn; is anvil installed?")] - Timeout, - - /// A line could not be read from the geth stderr. - #[error("could not read line from anvil stderr: {0}")] - ReadLineError(std::io::Error), - - /// The child anvil process's stderr was not captured. - #[error("could not get stderr for anvil child process")] - NoStderr, - - /// The private key could not be parsed. - #[error("could not parse private key")] - ParsePrivateKeyError, - - /// An error occurred while deserializing a private key. - #[error("could not deserialize private key from bytes")] - DeserializePrivateKeyError, - - /// An error occurred while parsing a hex string. - #[error(transparent)] - FromHexError(#[from] hex::FromHexError), - - /// No keys available in anvil instance. - #[error("no keys available in anvil instance")] - NoKeysAvailable, -} - /// Builder for launching `anvil`. /// /// # Panics @@ -288,7 +252,7 @@ impl Anvil { } /// Consumes the builder and spawns `anvil`. If spawning fails, returns an error. - pub fn try_spawn(self) -> Result { + pub fn try_spawn(self) -> Result { let mut cmd = self.program.as_ref().map_or_else(|| Command::new("anvil"), Command::new); cmd.stdout(std::process::Stdio::piped()).stderr(std::process::Stdio::inherit()); let mut port = self.port.unwrap_or_default(); @@ -316,9 +280,9 @@ impl Anvil { cmd.args(self.args); - let mut child = cmd.spawn().map_err(AnvilError::SpawnError)?; + let mut child = cmd.spawn().map_err(NodeError::SpawnError)?; - let stdout = child.stdout.take().ok_or(AnvilError::NoStderr)?; + let stdout = child.stdout.take().ok_or(NodeError::NoStderr)?; let start = Instant::now(); let mut reader = BufReader::new(stdout); @@ -331,11 +295,11 @@ impl Anvil { if start + Duration::from_millis(self.timeout.unwrap_or(ANVIL_STARTUP_TIMEOUT_MILLIS)) <= Instant::now() { - return Err(AnvilError::Timeout); + return Err(NodeError::Timeout); } let mut line = String::new(); - reader.read_line(&mut line).map_err(AnvilError::ReadLineError)?; + reader.read_line(&mut line).map_err(NodeError::ReadLineError)?; trace!(target: "anvil", line); if let Some(addr) = line.strip_prefix("Listening on") { // @@ -352,10 +316,10 @@ impl Anvil { if is_private_key && line.starts_with('(') { let key_str = - line.split("0x").last().ok_or(AnvilError::ParsePrivateKeyError)?.trim(); - let key_hex = hex::decode(key_str).map_err(AnvilError::FromHexError)?; - let key = K256SecretKey::from_bytes((&key_hex[..]).into()) - .map_err(|_| AnvilError::DeserializePrivateKeyError)?; + line.split("0x").last().ok_or(NodeError::ParsePrivateKeyError)?.trim(); + let key_hex = hex::decode(key_str).map_err(NodeError::FromHexError)?; + let key = SecretKey::from_bytes((&key_hex[..]).into()) + .map_err(|_| NodeError::DeserializePrivateKeyError)?; addresses.push(Address::from_public_key(SigningKey::from(&key).verifying_key())); private_keys.push(key); } diff --git a/crates/node-bindings/src/nodes/geth.rs b/crates/node-bindings/src/nodes/geth.rs index 6363c5b393d..1f803a5db77 100644 --- a/crates/node-bindings/src/nodes/geth.rs +++ b/crates/node-bindings/src/nodes/geth.rs @@ -2,7 +2,7 @@ use crate::{ utils::{extract_endpoint, extract_value, unused_port}, - NodeError, NodeInstanceError, NODE_DIAL_LOOP_TIMEOUT, NODE_STARTUP_TIMEOUT, + NodeError, NODE_DIAL_LOOP_TIMEOUT, NODE_STARTUP_TIMEOUT, }; use alloy_genesis::{CliqueConfig, Genesis}; use alloy_primitives::Address; @@ -139,22 +139,22 @@ impl GethInstance { /// /// This leaves a `None` in its place, so calling methods that require a stderr to be present /// will fail if called after this. - pub fn stderr(&mut self) -> Result { - self.pid.stderr.take().ok_or(NodeInstanceError::NoStderr) + pub fn stderr(&mut self) -> Result { + self.pid.stderr.take().ok_or(NodeError::NoStderr) } /// Blocks until geth adds the specified peer, using 20s as the timeout. /// /// Requires the stderr to be present in the `GethInstance`. - pub fn wait_to_add_peer(&mut self, id: &str) -> Result<(), NodeInstanceError> { - let mut stderr = self.pid.stderr.as_mut().ok_or(NodeInstanceError::NoStderr)?; + pub fn wait_to_add_peer(&mut self, id: &str) -> Result<(), NodeError> { + let mut stderr = self.pid.stderr.as_mut().ok_or(NodeError::NoStderr)?; let mut err_reader = BufReader::new(&mut stderr); let mut line = String::new(); let start = Instant::now(); while start.elapsed() < NODE_DIAL_LOOP_TIMEOUT { line.clear(); - err_reader.read_line(&mut line).map_err(NodeInstanceError::ReadLineError)?; + err_reader.read_line(&mut line).map_err(NodeError::ReadLineError)?; // geth ids are truncated let truncated_id = if id.len() > 16 { &id[..16] } else { id }; @@ -162,7 +162,7 @@ impl GethInstance { return Ok(()); } } - Err(NodeInstanceError::Timeout("Timed out waiting for geth to add a peer".into())) + Err(NodeError::Timeout) } } diff --git a/crates/node-bindings/src/nodes/reth.rs b/crates/node-bindings/src/nodes/reth.rs index c99719c3e3a..ce8ae5f469c 100644 --- a/crates/node-bindings/src/nodes/reth.rs +++ b/crates/node-bindings/src/nodes/reth.rs @@ -1,7 +1,12 @@ //! Utilities for launching a Reth dev-mode instance. -use crate::{utils::extract_endpoint, NodeError, NodeInstanceError, NODE_STARTUP_TIMEOUT}; +use crate::{ + utils::{extract_endpoint, get_default_keys}, + NodeError, NODE_STARTUP_TIMEOUT, +}; use alloy_genesis::Genesis; +use alloy_primitives::Address; +use k256::SecretKey; use std::{ fs::create_dir, io::{BufRead, BufReader}, @@ -23,6 +28,8 @@ const RETH: &str = "reth"; #[derive(Debug)] pub struct RethInstance { pid: Child, + private_keys: Vec, + addresses: Vec
, http_port: u16, ws_port: u16, auth_port: Option, @@ -33,23 +40,34 @@ pub struct RethInstance { } impl RethInstance { - /// Returns the HTTP port of this instance + /// Returns the private keys used to instantiate this instance. + /// Only available in dev mode. + pub fn keys(&self) -> &[SecretKey] { + &self.private_keys + } + + /// Returns the addresses used to instantiate this instance + pub fn addresses(&self) -> &[Address] { + &self.addresses + } + + /// Returns the HTTP port of this instance. pub const fn http_port(&self) -> u16 { self.http_port } - /// Returns the WS port of this instance + /// Returns the WS port of this instance. pub const fn ws_port(&self) -> u16 { self.ws_port } - /// Returns the auth port of this instance + /// Returns the auth port of this instance. pub const fn auth_port(&self) -> Option { self.auth_port } - /// Returns the p2p port of this instance - /// If discovery is disabled, this will be `None` + /// Returns the p2p port of this instance. + /// If discovery is disabled, this will be `None`. pub const fn p2p_port(&self) -> Option { self.p2p_port } @@ -95,8 +113,8 @@ impl RethInstance { /// /// This leaves a `None` in its place, so calling methods that require a stdout to be present /// will fail if called after this. - pub fn stdout(&mut self) -> Result { - self.pid.stdout.take().ok_or(NodeInstanceError::NoStdout) + pub fn stdout(&mut self) -> Result { + self.pid.stdout.take().ok_or(NodeError::NoStdout) } } @@ -269,6 +287,9 @@ impl Reth { cmd.arg("node"); // If the `dev` flag is set, enable it. + let mut private_keys = Vec::new(); + let mut addresses = Vec::new(); + if self.dev { // Enable the dev mode. // This mode uses a local proof-of-authority consensus engine with either fixed block @@ -282,6 +303,9 @@ impl Reth { if let Some(block_time) = self.block_time { cmd.arg("--dev.block-time").arg(block_time); } + + // Set the default keys and addresses that are used in dev mode. + (private_keys, addresses) = get_default_keys(); } // If IPC is not enabled on the builder, disable it. @@ -411,6 +435,8 @@ impl Reth { Ok(RethInstance { pid: child, + private_keys, + addresses, http_port, ws_port, p2p_port: if p2p_port != 0 { Some(p2p_port) } else { None }, diff --git a/crates/node-bindings/src/utils.rs b/crates/node-bindings/src/utils.rs index a5f4ca9fed5..004605a8d10 100644 --- a/crates/node-bindings/src/utils.rs +++ b/crates/node-bindings/src/utils.rs @@ -1,10 +1,13 @@ //! Utility functions for the node bindings. +use alloy_primitives::{hex, Address}; +use k256::SecretKey; use std::{ borrow::Cow, future::Future, net::{SocketAddr, TcpListener}, path::PathBuf, + str::FromStr, }; use tempfile; @@ -68,6 +71,48 @@ pub(crate) fn extract_endpoint(key: &str, line: &str) -> Option { val.parse::().ok() } +/// Get the default private keys and addresses from the default mnemonic. +pub(crate) fn get_default_keys() -> (Vec, Vec
) { + // From the default mnemonic "test test test test test test test test test test test + // junk" populate the private keys and addresses. + let private_keys = vec![ + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", + "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", + "0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a", + "0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6", + "0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a", + "0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba", + "0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e", + "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356", + "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97", + "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6", + ] + .iter() + .map(|s| { + let key_hex = hex::decode(s).unwrap(); + SecretKey::from_bytes((&key_hex[..]).into()).unwrap() + }) + .collect::>(); + + let addresses = vec![ + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", + "0x90F79bf6EB2c4f870365E785982E1f101E93b906", + "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", + "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc", + "0x976EA74026E726554dB657fA54763abd0C3a0aa9", + "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955", + "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f", + "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720", + ] + .iter() + .map(|s| Address::from_str(s).unwrap()) + .collect::>(); + + (private_keys, addresses) +} + /// Runs the given closure with a temporary directory. pub fn run_with_tempdir_sync(prefix: &str, f: impl FnOnce(PathBuf)) { let temp_dir = tempfile::TempDir::with_prefix(prefix).unwrap(); diff --git a/crates/provider/src/builder.rs b/crates/provider/src/builder.rs index 4eda6628d2f..a7e71ef9b17 100644 --- a/crates/provider/src/builder.rs +++ b/crates/provider/src/builder.rs @@ -371,7 +371,7 @@ impl ProviderBuilder { type JoinedEthereumWalletFiller = JoinFill>; #[cfg(any(test, feature = "anvil-node"))] -type AnvilProviderResult = Result; +type AnvilProviderResult = Result; // Enabled when the `anvil` feature is enabled, or when both in test and the // `reqwest` feature is enabled. @@ -490,9 +490,8 @@ impl ProviderBuilder { let url = anvil_layer.endpoint_url(); let default_keys = anvil_layer.instance().keys().to_vec(); - let (default_key, remaining_keys) = default_keys - .split_first() - .ok_or(alloy_node_bindings::anvil::AnvilError::NoKeysAvailable)?; + let (default_key, remaining_keys) = + default_keys.split_first().ok_or(alloy_node_bindings::NodeError::NoKeysAvailable)?; let default_signer = alloy_signer_local::LocalSigner::from(default_key.clone()); let mut wallet = alloy_network::EthereumWallet::from(default_signer); diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index d7c3ca9743e..e6965b0a4da 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -2,7 +2,9 @@ use crate::Provider; use alloy_network::Network; use alloy_primitives::{hex, Bytes, TxHash, B256}; -use alloy_rpc_types_eth::{Block, BlockId, BlockNumberOrTag, TransactionRequest}; +use alloy_rpc_types_eth::{ + Block, BlockId, BlockNumberOrTag, Bundle, StateContext, TransactionRequest, +}; use alloy_rpc_types_trace::geth::{ BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult, }; @@ -122,8 +124,8 @@ pub trait DebugApi: Send + Sync { /// Not all nodes support this call. async fn debug_trace_call_many( &self, - txs: Vec, - block: BlockId, + bundles: Vec, + state_context: StateContext, trace_options: GethDebugTracingCallOptions, ) -> TransportResult>; } @@ -208,11 +210,11 @@ where async fn debug_trace_call_many( &self, - txs: Vec, - block: BlockId, + bundles: Vec, + state_context: StateContext, trace_options: GethDebugTracingCallOptions, ) -> TransportResult> { - self.client().request("debug_traceCallMany", (txs, block, trace_options)).await + self.client().request("debug_traceCallMany", (bundles, state_context, trace_options)).await } } @@ -222,11 +224,11 @@ mod test { use super::*; use alloy_network::TransactionBuilder; - use alloy_node_bindings::{utils::run_with_tempdir, Geth}; + use alloy_node_bindings::{utils::run_with_tempdir, Geth, Reth}; use alloy_primitives::{address, U256}; #[tokio::test] - async fn test_debug_trace_transaction() { + async fn debug_trace_transaction() { let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let from = provider.default_signer_address(); @@ -251,7 +253,7 @@ mod test { } #[tokio::test] - async fn test_debug_trace_call() { + async fn debug_trace_call() { let provider = ProviderBuilder::new().on_anvil_with_wallet(); let from = provider.default_signer_address(); let gas_price = provider.get_gas_price().await.unwrap(); @@ -276,7 +278,7 @@ mod test { } #[tokio::test] - async fn call_debug_get_raw_header() { + async fn debug_get_raw_header() { run_with_tempdir("geth-test-", |temp_dir| async move { let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); @@ -292,7 +294,7 @@ mod test { } #[tokio::test] - async fn call_debug_get_raw_block() { + async fn debug_get_raw_block() { run_with_tempdir("geth-test-", |temp_dir| async move { let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); @@ -308,7 +310,7 @@ mod test { } #[tokio::test] - async fn call_debug_get_raw_receipts() { + async fn debug_get_raw_receipts() { run_with_tempdir("geth-test-", |temp_dir| async move { let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); @@ -321,7 +323,7 @@ mod test { } #[tokio::test] - async fn call_debug_get_bad_blocks() { + async fn debug_get_bad_blocks() { run_with_tempdir("geth-test-", |temp_dir| async move { let geth = Geth::new().disable_discovery().data_dir(temp_dir).spawn(); let provider = ProviderBuilder::new().on_http(geth.endpoint_url()); @@ -331,4 +333,43 @@ mod test { }) .await } + + #[tokio::test] + async fn debug_trace_call_many() { + run_with_tempdir("reth-test-", |temp_dir| async move { + let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let provider = + ProviderBuilder::new().with_recommended_fillers().on_http(reth.endpoint_url()); + + let accounts = reth.addresses(); + let alice = &accounts[0]; + let bob = &accounts[1]; + + let tx1 = TransactionRequest::default() + .with_from(*alice) + .with_to(*bob) + .with_nonce(0) + .with_value(U256::from(100)); + + let tx2 = TransactionRequest::default() + .with_from(*bob) + .with_to(*alice) + .with_nonce(1) + .with_value(U256::from(100)); + + let bundles = vec![Bundle { transactions: vec![tx1, tx2], block_override: None }]; + let state_context = StateContext::default(); + let trace_options = GethDebugTracingCallOptions::default(); + let result = + provider.debug_trace_call_many(bundles, state_context, trace_options).await; + assert!(result.is_ok()); + + let traces = result.unwrap(); + assert_eq!( + serde_json::to_string(&traces).unwrap(), + r#"[[{"failed":false,"gas":21000,"returnValue":"","structLogs":[]},{"failed":false,"gas":21000,"returnValue":"","structLogs":[]}]]"#, + ); + }) + .await + } } diff --git a/crates/rpc-types-eth/src/call.rs b/crates/rpc-types-eth/src/call.rs index 23b5f6f33d9..c7828a56aad 100644 --- a/crates/rpc-types-eth/src/call.rs +++ b/crates/rpc-types-eth/src/call.rs @@ -20,7 +20,7 @@ impl From> for Bundle { } } -/// State context for callMany +/// State context for *_callMany #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct StateContext { From a9f4e76d71db84a805bd53503e06b46d492f57f9 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 9 Sep 2024 15:14:59 +0000 Subject: [PATCH 06/20] fix tests --- crates/node-bindings/src/nodes/reth.rs | 4 +-- crates/node-bindings/src/utils.rs | 43 +++++++++++++------------- crates/provider/src/ext/debug.rs | 1 + 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/node-bindings/src/nodes/reth.rs b/crates/node-bindings/src/nodes/reth.rs index ce8ae5f469c..1c649953ecb 100644 --- a/crates/node-bindings/src/nodes/reth.rs +++ b/crates/node-bindings/src/nodes/reth.rs @@ -287,8 +287,8 @@ impl Reth { cmd.arg("node"); // If the `dev` flag is set, enable it. - let mut private_keys = Vec::new(); let mut addresses = Vec::new(); + let mut private_keys = Vec::new(); if self.dev { // Enable the dev mode. @@ -305,7 +305,7 @@ impl Reth { } // Set the default keys and addresses that are used in dev mode. - (private_keys, addresses) = get_default_keys(); + (addresses, private_keys) = get_default_keys(); } // If IPC is not enabled on the builder, disable it. diff --git a/crates/node-bindings/src/utils.rs b/crates/node-bindings/src/utils.rs index 004605a8d10..50633b0117a 100644 --- a/crates/node-bindings/src/utils.rs +++ b/crates/node-bindings/src/utils.rs @@ -71,11 +71,26 @@ pub(crate) fn extract_endpoint(key: &str, line: &str) -> Option { val.parse::().ok() } -/// Get the default private keys and addresses from the default mnemonic. -pub(crate) fn get_default_keys() -> (Vec, Vec
) { - // From the default mnemonic "test test test test test test test test test test test - // junk" populate the private keys and addresses. - let private_keys = vec![ +/// Get the default private keys and addresses from the default mnemonic: +/// "test test test test test test test test test test test junk" +pub(crate) fn get_default_keys() -> (Vec
, Vec) { + let addresses = [ + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", + "0x90F79bf6EB2c4f870365E785982E1f101E93b906", + "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", + "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc", + "0x976EA74026E726554dB657fA54763abd0C3a0aa9", + "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955", + "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f", + "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720", + ] + .iter() + .map(|s| Address::from_str(s).unwrap()) + .collect::>(); + + let private_keys = [ "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", "0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a", @@ -94,23 +109,7 @@ pub(crate) fn get_default_keys() -> (Vec, Vec
) { }) .collect::>(); - let addresses = vec![ - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", - "0x90F79bf6EB2c4f870365E785982E1f101E93b906", - "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", - "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc", - "0x976EA74026E726554dB657fA54763abd0C3a0aa9", - "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955", - "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f", - "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720", - ] - .iter() - .map(|s| Address::from_str(s).unwrap()) - .collect::>(); - - (private_keys, addresses) + (addresses, private_keys) } /// Runs the given closure with a temporary directory. diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index e6965b0a4da..78d90c73d5f 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -335,6 +335,7 @@ mod test { } #[tokio::test] + #[cfg(not(windows))] async fn debug_trace_call_many() { run_with_tempdir("reth-test-", |temp_dir| async move { let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); From d877ce7d70784223d9bce25bb7fbac7d3110fa3c Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 9 Sep 2024 15:54:59 +0000 Subject: [PATCH 07/20] add trace_call --- crates/provider/src/ext/mod.rs | 2 +- crates/provider/src/ext/trace.rs | 97 +++++++++++++++++++++++++++++--- 2 files changed, 90 insertions(+), 9 deletions(-) diff --git a/crates/provider/src/ext/mod.rs b/crates/provider/src/ext/mod.rs index edcbac4c15b..a5f5c185a20 100644 --- a/crates/provider/src/ext/mod.rs +++ b/crates/provider/src/ext/mod.rs @@ -28,7 +28,7 @@ pub use net::NetApi; #[cfg(feature = "trace-api")] mod trace; #[cfg(feature = "trace-api")] -pub use trace::TraceApi; +pub use trace::{TraceApi, TraceCallList}; #[cfg(feature = "rpc-api")] mod rpc; diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 29bf5baae39..3ed1b71c231 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -11,7 +11,7 @@ use alloy_rpc_types_trace::{ use alloy_transport::{Transport, TransportResult}; /// List of trace calls for use with [`TraceApi::trace_call_many`] -pub type TraceCallList<'a, N> = &'a [(::TransactionRequest, Vec)]; +pub type TraceCallList<'a, 'b, N> = [(&'a ::TransactionRequest, &'b [TraceType])]; /// Trace namespace rpc interface that gives access to several non-standard RPC methods. #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] @@ -40,10 +40,10 @@ where /// # Note /// /// Not all nodes support this call. - fn trace_call_many<'a>( + fn trace_call_many<'a, 'b>( &self, - request: &'a TraceCallList<'a, N>, - ) -> RpcWithBlock, TraceResults>; + request: &'a TraceCallList<'a, 'b, N>, + ) -> RpcWithBlock, TraceResults>; /// Parity trace transaction. async fn trace_transaction( @@ -115,10 +115,12 @@ where RpcWithBlock::new(self.weak_client(), "trace_call", (request, trace_types)) } - fn trace_call_many<'a>( + fn trace_call_many<'a, 'b>( &self, - request: &'a TraceCallList<'a, N>, - ) -> RpcWithBlock, TraceResults> { + request: &'a TraceCallList<'a, 'b, N>, + ) -> RpcWithBlock, TraceResults> { + println!("{:?}", request); + RpcWithBlock::new(self.weak_client(), "trace_callMany", request) } @@ -178,7 +180,10 @@ where mod test { use crate::ProviderBuilder; use alloy_eips::BlockNumberOrTag; + use alloy_network::TransactionBuilder; use alloy_node_bindings::{utils::run_with_tempdir, Reth}; + use alloy_primitives::U256; + use alloy_rpc_types_eth::TransactionRequest; use super::*; @@ -193,7 +198,62 @@ mod test { assert!(result.is_ok()); let traces = result.unwrap(); - assert_eq!(traces.len(), 0); + assert_eq!(serde_json::to_string(&traces).unwrap(), "[]"); + }) + .await + } + + #[tokio::test] + #[cfg(not(windows))] + async fn trace_call() { + run_with_tempdir("reth-test-", |temp_dir| async move { + let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); + + let accounts = reth.addresses(); + let alice = &accounts[0]; + let bob = &accounts[1]; + + let tx = TransactionRequest::default() + .with_from(*alice) + .with_to(*bob) + .with_nonce(0) + .with_value(U256::from(100)); + + let result = provider.trace_call(&tx, &[TraceType::Trace]).await; + assert!(result.is_ok()); + + let traces = result.unwrap(); + assert_eq!( + serde_json::to_string_pretty(&traces).unwrap().trim(), + r#" +{ + "output": "0x", + "stateDiff": null, + "trace": [ + { + "type": "call", + "action": { + "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", + "callType": "call", + "gas": "0x2fa9e78", + "input": "0x", + "to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", + "value": "0x64" + }, + "result": { + "gasUsed": "0x0", + "output": "0x" + }, + "subtraces": 0, + "traceAddress": [] + } + ], + "vmTrace": null +} +"# + .trim(), + ); }) .await } @@ -204,6 +264,27 @@ mod test { run_with_tempdir("reth-test-", |temp_dir| async move { let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); + + let accounts = reth.addresses(); + let alice = &accounts[0]; + let bob = &accounts[1]; + + let tx1 = TransactionRequest::default() + .with_from(*alice) + .with_to(*bob) + .with_nonce(0) + .with_value(U256::from(100)); + + let tx2 = TransactionRequest::default() + .with_from(*alice) + .with_to(*bob) + .with_nonce(1) + .with_value(U256::from(100)); + + let result = provider + .trace_call_many(&[(&tx1, &[TraceType::Trace]), (&tx2, &[TraceType::Trace])]) + .await; + println!("{:?}", result); }) .await } From 5783ab1fc170c460416ceeda9ab653594da7e12a Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 9 Sep 2024 16:02:02 +0000 Subject: [PATCH 08/20] seemingly correct api results in incorrect api response from Reth --- crates/provider/src/ext/trace.rs | 51 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 3ed1b71c231..f07bdd35898 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -119,8 +119,6 @@ where &self, request: &'a TraceCallList<'a, 'b, N>, ) -> RpcWithBlock, TraceResults> { - println!("{:?}", request); - RpcWithBlock::new(self.weak_client(), "trace_callMany", request) } @@ -285,6 +283,55 @@ mod test { .trace_call_many(&[(&tx1, &[TraceType::Trace]), (&tx2, &[TraceType::Trace])]) .await; println!("{:?}", result); + + // [ + // ( + // TransactionRequest { + // from: Some(0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266), + // to: Some(Call(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)), + // gas_price: None, + // max_fee_per_gas: None, + // max_priority_fee_per_gas: None, + // max_fee_per_blob_gas: None, + // gas: None, + // value: Some(100), + // input: TransactionInput { input: None, data: None }, + // nonce: Some(0), + // chain_id: None, + // access_list: None, + // transaction_type: None, + // blob_versioned_hashes: None, + // sidecar: None, + // authorization_list: None, + // }, + // [Trace], + // ), + // ( + // TransactionRequest { + // from: Some(0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266), + // to: Some(Call(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)), + // gas_price: None, + // max_fee_per_gas: None, + // max_priority_fee_per_gas: None, + // max_fee_per_blob_gas: None, + // gas: None, + // value: Some(100), + // input: TransactionInput { input: None, data: None }, + // nonce: Some(1), + // chain_id: None, + // access_list: None, + // transaction_type: None, + // blob_versioned_hashes: None, + // sidecar: None, + // authorization_list: None, + // }, + // [Trace], + // ), + // ] + + // Err(ErrorResp(ErrorPayload { code: -32602, message: "Invalid params", data: + // Some(RawValue("invalid type: map, expected a tuple of size 2 at line 1 column 1")) + // })) }) .await } From fb8a29d6cda2f14eeaacd90e1f8a226e8d8f38e2 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 08:54:06 +0000 Subject: [PATCH 09/20] simplify types, fix request formatting --- crates/provider/src/ext/mod.rs | 2 +- crates/provider/src/ext/trace.rs | 151 ++++++++++++++++--------------- 2 files changed, 79 insertions(+), 74 deletions(-) diff --git a/crates/provider/src/ext/mod.rs b/crates/provider/src/ext/mod.rs index a5f5c185a20..edcbac4c15b 100644 --- a/crates/provider/src/ext/mod.rs +++ b/crates/provider/src/ext/mod.rs @@ -28,7 +28,7 @@ pub use net::NetApi; #[cfg(feature = "trace-api")] mod trace; #[cfg(feature = "trace-api")] -pub use trace::{TraceApi, TraceCallList}; +pub use trace::TraceApi; #[cfg(feature = "rpc-api")] mod rpc; diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index f07bdd35898..c9c748e3553 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -10,9 +10,6 @@ use alloy_rpc_types_trace::{ }; use alloy_transport::{Transport, TransportResult}; -/// List of trace calls for use with [`TraceApi::trace_call_many`] -pub type TraceCallList<'a, 'b, N> = [(&'a ::TransactionRequest, &'b [TraceType])]; - /// Trace namespace rpc interface that gives access to several non-standard RPC methods. #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] @@ -26,11 +23,11 @@ where /// # Note /// /// Not all nodes support this call. - fn trace_call<'a, 'b>( + async fn trace_call( &self, - request: &'a N::TransactionRequest, - trace_type: &'b [TraceType], - ) -> RpcWithBlock; + request: N::TransactionRequest, + trace_type: &[TraceType], + ) -> TransportResult; /// Traces multiple transactions on top of the same block, i.e. transaction `n` will be executed /// on top of the given block with all `n - 1` transaction applied first. @@ -40,10 +37,10 @@ where /// # Note /// /// Not all nodes support this call. - fn trace_call_many<'a, 'b>( + async fn trace_call_many( &self, - request: &'a TraceCallList<'a, 'b, N>, - ) -> RpcWithBlock, TraceResults>; + request: Vec<(N::TransactionRequest, &[TraceType])>, + ) -> TransportResult>; /// Parity trace transaction. async fn trace_transaction( @@ -106,20 +103,19 @@ where T: Transport + Clone, P: Provider, { - fn trace_call<'a, 'b>( + async fn trace_call( &self, - request: &'a ::TransactionRequest, - trace_types: &'b [TraceType], - ) -> RpcWithBlock::TransactionRequest, &'b [TraceType]), TraceResults> - { - RpcWithBlock::new(self.weak_client(), "trace_call", (request, trace_types)) + request: N::TransactionRequest, + trace_types: &[TraceType], + ) -> TransportResult { + self.client().request("trace_call", (request, trace_types)).await } - fn trace_call_many<'a, 'b>( + async fn trace_call_many( &self, - request: &'a TraceCallList<'a, 'b, N>, - ) -> RpcWithBlock, TraceResults> { - RpcWithBlock::new(self.weak_client(), "trace_callMany", request) + request: Vec<(N::TransactionRequest, &[TraceType])>, + ) -> TransportResult> { + self.client().request("trace_callMany", (request,)).await } async fn trace_transaction( @@ -180,7 +176,7 @@ mod test { use alloy_eips::BlockNumberOrTag; use alloy_network::TransactionBuilder; use alloy_node_bindings::{utils::run_with_tempdir, Reth}; - use alloy_primitives::U256; + use alloy_primitives::{bytes, U256}; use alloy_rpc_types_eth::TransactionRequest; use super::*; @@ -218,7 +214,7 @@ mod test { .with_nonce(0) .with_value(U256::from(100)); - let result = provider.trace_call(&tx, &[TraceType::Trace]).await; + let result = provider.trace_call(tx, &[TraceType::Trace]).await; assert!(result.is_ok()); let traces = result.unwrap(); @@ -280,58 +276,67 @@ mod test { .with_value(U256::from(100)); let result = provider - .trace_call_many(&[(&tx1, &[TraceType::Trace]), (&tx2, &[TraceType::Trace])]) + .trace_call_many(vec![(tx1, &[TraceType::Trace]), (tx2, &[TraceType::Trace])]) .await; - println!("{:?}", result); - - // [ - // ( - // TransactionRequest { - // from: Some(0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266), - // to: Some(Call(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)), - // gas_price: None, - // max_fee_per_gas: None, - // max_priority_fee_per_gas: None, - // max_fee_per_blob_gas: None, - // gas: None, - // value: Some(100), - // input: TransactionInput { input: None, data: None }, - // nonce: Some(0), - // chain_id: None, - // access_list: None, - // transaction_type: None, - // blob_versioned_hashes: None, - // sidecar: None, - // authorization_list: None, - // }, - // [Trace], - // ), - // ( - // TransactionRequest { - // from: Some(0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266), - // to: Some(Call(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)), - // gas_price: None, - // max_fee_per_gas: None, - // max_priority_fee_per_gas: None, - // max_fee_per_blob_gas: None, - // gas: None, - // value: Some(100), - // input: TransactionInput { input: None, data: None }, - // nonce: Some(1), - // chain_id: None, - // access_list: None, - // transaction_type: None, - // blob_versioned_hashes: None, - // sidecar: None, - // authorization_list: None, - // }, - // [Trace], - // ), - // ] - - // Err(ErrorResp(ErrorPayload { code: -32602, message: "Invalid params", data: - // Some(RawValue("invalid type: map, expected a tuple of size 2 at line 1 column 1")) - // })) + assert!(result.is_ok()); + + let traces = result.unwrap(); + assert_eq!( + serde_json::to_string_pretty(&traces).unwrap().trim(), + r#" +[ + { + "output": "0x", + "stateDiff": null, + "trace": [ + { + "type": "call", + "action": { + "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", + "callType": "call", + "gas": "0x2fa9e78", + "input": "0x", + "to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", + "value": "0x64" + }, + "result": { + "gasUsed": "0x0", + "output": "0x" + }, + "subtraces": 0, + "traceAddress": [] + } + ], + "vmTrace": null + }, + { + "output": "0x", + "stateDiff": null, + "trace": [ + { + "type": "call", + "action": { + "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", + "callType": "call", + "gas": "0x2fa9e78", + "input": "0x", + "to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", + "value": "0x64" + }, + "result": { + "gasUsed": "0x0", + "output": "0x" + }, + "subtraces": 0, + "traceAddress": [] + } + ], + "vmTrace": null + } +] +"# + .trim() + ); }) .await } From 8a0901ebe2cdb64a99d3ca663a26a6357b67fe65 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 10:02:10 +0000 Subject: [PATCH 10/20] revert type changes to keep compatibility with RpcWithBlock optional block --- crates/provider/src/ext/trace.rs | 42 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index c9c748e3553..4f562903432 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -10,6 +10,9 @@ use alloy_rpc_types_trace::{ }; use alloy_transport::{Transport, TransportResult}; +/// List of trace calls for use with [`TraceApi::trace_call_many`] +type TraceCallList<'a, N> = &'a [(::TransactionRequest, &'a [TraceType])]; + /// Trace namespace rpc interface that gives access to several non-standard RPC methods. #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] @@ -23,11 +26,11 @@ where /// # Note /// /// Not all nodes support this call. - async fn trace_call( + fn trace_call<'a, 'b>( &self, - request: N::TransactionRequest, - trace_type: &[TraceType], - ) -> TransportResult; + request: &'a N::TransactionRequest, + trace_type: &'b [TraceType], + ) -> RpcWithBlock; /// Traces multiple transactions on top of the same block, i.e. transaction `n` will be executed /// on top of the given block with all `n - 1` transaction applied first. @@ -37,10 +40,10 @@ where /// # Note /// /// Not all nodes support this call. - async fn trace_call_many( + fn trace_call_many<'a>( &self, - request: Vec<(N::TransactionRequest, &[TraceType])>, - ) -> TransportResult>; + request: TraceCallList<'a, N>, + ) -> RpcWithBlock,), Vec>; /// Parity trace transaction. async fn trace_transaction( @@ -103,19 +106,20 @@ where T: Transport + Clone, P: Provider, { - async fn trace_call( + fn trace_call<'a, 'b>( &self, - request: N::TransactionRequest, - trace_types: &[TraceType], - ) -> TransportResult { - self.client().request("trace_call", (request, trace_types)).await + request: &'a ::TransactionRequest, + trace_types: &'b [TraceType], + ) -> RpcWithBlock::TransactionRequest, &'b [TraceType]), TraceResults> + { + RpcWithBlock::new(self.weak_client(), "trace_call", (request, trace_types)) } - async fn trace_call_many( + fn trace_call_many<'a>( &self, - request: Vec<(N::TransactionRequest, &[TraceType])>, - ) -> TransportResult> { - self.client().request("trace_callMany", (request,)).await + request: TraceCallList<'a, N>, + ) -> RpcWithBlock,), Vec> { + RpcWithBlock::new(self.weak_client(), "trace_callMany", (request,)) } async fn trace_transaction( @@ -176,7 +180,7 @@ mod test { use alloy_eips::BlockNumberOrTag; use alloy_network::TransactionBuilder; use alloy_node_bindings::{utils::run_with_tempdir, Reth}; - use alloy_primitives::{bytes, U256}; + use alloy_primitives::U256; use alloy_rpc_types_eth::TransactionRequest; use super::*; @@ -214,7 +218,7 @@ mod test { .with_nonce(0) .with_value(U256::from(100)); - let result = provider.trace_call(tx, &[TraceType::Trace]).await; + let result = provider.trace_call(&tx, &[TraceType::Trace]).await; assert!(result.is_ok()); let traces = result.unwrap(); @@ -276,7 +280,7 @@ mod test { .with_value(U256::from(100)); let result = provider - .trace_call_many(vec![(tx1, &[TraceType::Trace]), (tx2, &[TraceType::Trace])]) + .trace_call_many(&[(tx1, &[TraceType::Trace]), (tx2, &[TraceType::Trace])]) .await; assert!(result.is_ok()); From 96062a2c922821bc8b086694ccf14d938d285784 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 10:49:30 +0000 Subject: [PATCH 11/20] format output --- crates/provider/src/ext/debug.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index 78d90c73d5f..c9a8d10813a 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -1,4 +1,5 @@ //! This module extends the Ethereum JSON-RPC provider with the Debug namespace's RPC methods. + use crate::Provider; use alloy_network::Network; use alloy_primitives::{hex, Bytes, TxHash, B256}; @@ -367,8 +368,26 @@ mod test { let traces = result.unwrap(); assert_eq!( - serde_json::to_string(&traces).unwrap(), - r#"[[{"failed":false,"gas":21000,"returnValue":"","structLogs":[]},{"failed":false,"gas":21000,"returnValue":"","structLogs":[]}]]"#, + serde_json::to_string_pretty(&traces).unwrap().trim(), + r#" +[ + [ + { + "failed": false, + "gas": 21000, + "returnValue": "", + "structLogs": [] + }, + { + "failed": false, + "gas": 21000, + "returnValue": "", + "structLogs": [] + } + ] +] +"# + .trim(), ); }) .await From 03fd742d5981fb0a97db942c47bdfafffc309e88 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 11:47:10 +0000 Subject: [PATCH 12/20] clean up, add random_instance for reduced flakiness --- crates/node-bindings/Cargo.toml | 4 +- crates/node-bindings/src/lib.rs | 3 +- crates/node-bindings/src/node.rs | 14 ++- crates/node-bindings/src/nodes/anvil.rs | 2 +- crates/node-bindings/src/nodes/geth.rs | 2 +- crates/node-bindings/src/nodes/reth.rs | 155 +++++++++++++++--------- crates/node-bindings/src/utils.rs | 44 ------- crates/provider/src/ext/admin.rs | 2 +- crates/provider/src/ext/debug.rs | 2 +- crates/provider/src/ext/net.rs | 2 +- crates/provider/src/ext/trace.rs | 8 +- crates/provider/src/ext/txpool.rs | 2 +- 12 files changed, 119 insertions(+), 121 deletions(-) diff --git a/crates/node-bindings/Cargo.toml b/crates/node-bindings/Cargo.toml index bb55e3ab08f..67d34c7ffbd 100644 --- a/crates/node-bindings/Cargo.toml +++ b/crates/node-bindings/Cargo.toml @@ -22,11 +22,9 @@ workspace = true alloy-primitives = { workspace = true, features = ["std", "k256", "serde"] } alloy-genesis.workspace = true k256.workspace = true +rand.workspace = true serde_json = { workspace = true, features = ["std"] } tempfile.workspace = true thiserror.workspace = true tracing.workspace = true url.workspace = true - -[dev-dependencies] -rand.workspace = true diff --git a/crates/node-bindings/src/lib.rs b/crates/node-bindings/src/lib.rs index 2ed26210609..74af3c9b476 100644 --- a/crates/node-bindings/src/lib.rs +++ b/crates/node-bindings/src/lib.rs @@ -21,7 +21,8 @@ pub use nodes::{ mod node; pub use node::*; -pub mod utils; +mod utils; +pub use utils::*; /// 1 Ether = 1e18 Wei == 0x0de0b6b3a7640000 Wei pub const WEI_IN_ETHER: U256 = U256::from_limbs([0x0de0b6b3a7640000, 0x0, 0x0, 0x0]); diff --git a/crates/node-bindings/src/node.rs b/crates/node-bindings/src/node.rs index 281960e8b64..8a8b94fac0c 100644 --- a/crates/node-bindings/src/node.rs +++ b/crates/node-bindings/src/node.rs @@ -13,12 +13,6 @@ pub const NODE_DIAL_LOOP_TIMEOUT: Duration = Duration::from_secs(20); /// Errors that can occur when working with the node instance. #[derive(Debug, Error)] pub enum NodeError { - /// The chain id was not set. - #[error("the chain ID was not set")] - ChainIdNotSet, - /// Could not create the data directory. - #[error("could not create directory: {0}")] - CreateDirError(std::io::Error), /// No stderr was captured from the child process. #[error("no stderr was captured from the process")] NoStderr, @@ -34,6 +28,14 @@ pub enum NodeError { /// A line could not be read from the node stderr. #[error("could not read line from node stderr: {0}")] ReadLineError(std::io::Error), + + /// The chain id was not set. + #[error("the chain ID was not set")] + ChainIdNotSet, + /// Could not create the data directory. + #[error("could not create directory: {0}")] + CreateDirError(std::io::Error), + /// Genesis error #[error("genesis error occurred: {0}")] GenesisError(String), diff --git a/crates/node-bindings/src/nodes/anvil.rs b/crates/node-bindings/src/nodes/anvil.rs index eb3760bcde8..760b3e9dbba 100644 --- a/crates/node-bindings/src/nodes/anvil.rs +++ b/crates/node-bindings/src/nodes/anvil.rs @@ -372,7 +372,7 @@ mod tests { #[test] fn assert_chain_id() { - let anvil = Anvil::new().fork("https://eth.llamarpc.com ").spawn(); + let anvil = Anvil::new().fork("https://eth.merkle.io").spawn(); assert_eq!(anvil.chain_id(), 1); } diff --git a/crates/node-bindings/src/nodes/geth.rs b/crates/node-bindings/src/nodes/geth.rs index 1f803a5db77..7303203e603 100644 --- a/crates/node-bindings/src/nodes/geth.rs +++ b/crates/node-bindings/src/nodes/geth.rs @@ -624,7 +624,7 @@ impl Geth { mod tests { use super::*; - use crate::utils::run_with_tempdir_sync; + use crate::run_with_tempdir_sync; #[test] fn port_0() { diff --git a/crates/node-bindings/src/nodes/reth.rs b/crates/node-bindings/src/nodes/reth.rs index 1c649953ecb..aebcfb06061 100644 --- a/crates/node-bindings/src/nodes/reth.rs +++ b/crates/node-bindings/src/nodes/reth.rs @@ -1,17 +1,16 @@ //! Utilities for launching a Reth dev-mode instance. -use crate::{ - utils::{extract_endpoint, get_default_keys}, - NodeError, NODE_STARTUP_TIMEOUT, -}; +use crate::{utils::extract_endpoint, NodeError, NODE_STARTUP_TIMEOUT}; use alloy_genesis::Genesis; -use alloy_primitives::Address; +use alloy_primitives::{hex, Address}; use k256::SecretKey; +use rand::Rng; use std::{ fs::create_dir, io::{BufRead, BufReader}, path::PathBuf, process::{Child, ChildStdout, Command, Stdio}, + str::FromStr, time::Instant, }; use url::Url; @@ -22,12 +21,13 @@ const API: &str = "eth,net,web3,txpool,trace,rpc,reth,ots,admin,debug"; /// The reth command const RETH: &str = "reth"; -/// A reth instance. Will close the instance when dropped. +/// A Reth instance. Will close the instance when dropped. /// /// Construct this using [`Reth`]. #[derive(Debug)] pub struct RethInstance { pid: Child, + instance: u16, private_keys: Vec, addresses: Vec
, http_port: u16, @@ -40,6 +40,11 @@ pub struct RethInstance { } impl RethInstance { + /// Returns the instance number of this instance. + pub const fn instance(&self) -> u16 { + self.instance + } + /// Returns the private keys used to instantiate this instance. /// Only available in dev mode. pub fn keys(&self) -> &[SecretKey] { @@ -138,7 +143,7 @@ impl Drop for RethInstance { /// let port = 8545u16; /// let url = format!("http://localhost:{}", port).to_string(); /// -/// let reth = Reth::new().instance(0).block_time("12sec").spawn(); +/// let reth = Reth::new().instance(1).block_time("12sec").spawn(); /// /// drop(reth); // this will kill the instance /// ``` @@ -201,13 +206,13 @@ impl Reth { self } - /// Enable `dev` mode for the reth instance. + /// Enable `dev` mode for the Reth instance. pub const fn dev(mut self) -> Self { self.dev = true; self } - /// Sets the block time for the reth instance. + /// Sets the block time for the Reth instance. /// Parses strings using /// This is only used if `dev` mode is enabled. pub fn block_time(mut self, block_time: &str) -> Self { @@ -215,45 +220,52 @@ impl Reth { self } - /// Disables discovery for the reth instance. + /// Disables discovery for the Reth instance. pub const fn disable_discovery(mut self) -> Self { self.discovery_enabled = false; self } - /// Sets the chain id for the reth instance. + /// Sets the chain id for the Reth instance. pub fn chain_or_path(mut self, chain_or_path: &str) -> Self { self.chain_or_path = Some(chain_or_path.to_string()); self } - /// Enable IPC for the reth instance. + /// Enable IPC for the Reth instance. pub const fn enable_ipc(mut self) -> Self { self.ipc_enabled = true; self } - /// Sets the instance number for the reth instance. + /// Sets the instance number for the Reth instance. pub const fn instance(mut self, instance: u16) -> Self { self.instance = instance; self } + /// Sets the instance number to a random number to reduce flakiness. + pub fn random_instance(mut self) -> Self { + // Reth limits the number of instances to 200. + self.instance = rand::thread_rng().gen_range(0..200); + self + } + /// Sets the IPC path for the socket. pub fn ipc_path>(mut self, path: T) -> Self { self.ipc_path = Some(path.into()); self } - /// Sets the data directory for reth. + /// Sets the data directory for Reth. pub fn data_dir>(mut self, path: T) -> Self { self.data_dir = Some(path.into()); self } - /// Sets the `genesis.json` for the reth instance. + /// Sets the `genesis.json` for the Reth instance. /// - /// If this is set, reth will be initialized with `reth init` and the `--datadir` option will be + /// If this is set, Reth will be initialized with `reth init` and the `--datadir` option will be /// set to the same value as `data_dir`. /// /// This is destructive and will overwrite any existing data in the data directory. @@ -280,7 +292,7 @@ impl Reth { .map_or_else(|| RETH.as_ref(), |bin| bin.as_os_str()) .to_os_string(); let mut cmd = Command::new(&bin_path); - // `reth` uses stdout for its logs + // Reth uses stdout for its logs cmd.stdout(Stdio::piped()); // Use Reth's `node` subcommand. @@ -305,7 +317,40 @@ impl Reth { } // Set the default keys and addresses that are used in dev mode. - (addresses, private_keys) = get_default_keys(); + addresses = [ + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", + "0x90F79bf6EB2c4f870365E785982E1f101E93b906", + "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", + "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc", + "0x976EA74026E726554dB657fA54763abd0C3a0aa9", + "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955", + "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f", + "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720", + ] + .iter() + .map(|s| Address::from_str(s).unwrap()) + .collect::>(); + + private_keys = [ + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", + "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", + "0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a", + "0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6", + "0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a", + "0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba", + "0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e", + "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356", + "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97", + "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6", + ] + .iter() + .map(|s| { + let key_hex = hex::decode(s).unwrap(); + SecretKey::from_bytes((&key_hex[..]).into()).unwrap() + }) + .collect::>(); } // If IPC is not enabled on the builder, disable it. @@ -435,6 +480,7 @@ impl Reth { Ok(RethInstance { pid: child, + instance: self.instance, private_keys, addresses, http_port, @@ -452,13 +498,18 @@ impl Reth { #[cfg(test)] mod tests { use super::*; - use crate::utils::run_with_tempdir_sync; + use crate::run_with_tempdir_sync; + + const DISCOVERY_PORT: u16 = 30303; + const AUTH_PORT: u16 = 8551; + const HTTP_RPC_PORT: u16 = 8545; + const WS_RPC_PORT: u16 = 8546; #[test] #[cfg(not(windows))] fn can_launch_reth() { run_with_tempdir_sync("reth-test-", |temp_dir_path| { - let reth = Reth::new().data_dir(temp_dir_path).spawn(); + let reth = Reth::new().random_instance().data_dir(temp_dir_path).spawn(); assert_ports(&reth, false); }); @@ -468,7 +519,11 @@ mod tests { #[cfg(not(windows))] fn can_launch_reth_sepolia() { run_with_tempdir_sync("reth-test-", |temp_dir_path| { - let reth = Reth::new().chain_or_path("sepolia").data_dir(temp_dir_path).spawn(); + let reth = Reth::new() + .random_instance() + .chain_or_path("sepolia") + .data_dir(temp_dir_path) + .spawn(); assert_ports(&reth, false); }); @@ -478,7 +533,12 @@ mod tests { #[cfg(not(windows))] fn can_launch_reth_dev() { run_with_tempdir_sync("reth-test-", |temp_dir_path| { - let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir_path).spawn(); + let reth = Reth::new() + .random_instance() + .dev() + .disable_discovery() + .data_dir(temp_dir_path) + .spawn(); assert_ports(&reth, true); }); @@ -489,6 +549,7 @@ mod tests { fn can_launch_reth_dev_custom_genesis() { run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new() + .random_instance() .dev() .disable_discovery() .data_dir(temp_dir_path) @@ -504,6 +565,7 @@ mod tests { fn can_launch_reth_dev_custom_blocktime() { run_with_tempdir_sync("reth-test-", |temp_dir_path| { let reth = Reth::new() + .random_instance() .dev() .disable_discovery() .block_time("1sec") @@ -514,42 +576,19 @@ mod tests { }); } - #[test] - #[cfg(not(windows))] - fn can_launch_reth_p2p_instance1() { - run_with_tempdir_sync("reth-test-", |temp_dir_path| { - let reth = Reth::new().instance(1).data_dir(temp_dir_path).spawn(); - - assert_eq!(reth.http_port(), 8545); - assert_eq!(reth.ws_port(), 8546); - assert_eq!(reth.auth_port(), Some(8551)); - assert_eq!(reth.p2p_port(), Some(30303)); - }); - } - - #[test] - #[cfg(not(windows))] - fn can_launch_reth_p2p_instance2() { - run_with_tempdir_sync("reth-test-", |temp_dir_path| { - let reth = Reth::new().instance(2).data_dir(temp_dir_path).spawn(); - - assert_eq!(reth.http_port(), 8544); - assert_eq!(reth.ws_port(), 8548); - assert_eq!(reth.auth_port(), Some(8651)); - assert_eq!(reth.p2p_port(), Some(30304)); - }); - } - - // Asserts that the ports are set correctly for the given reth instance. + // Asserts that the ports are set correctly for the given Reth instance. fn assert_ports(reth: &RethInstance, dev: bool) { - assert_eq!(reth.http_port(), 8545); - assert_eq!(reth.ws_port(), 8546); - assert_eq!(reth.auth_port(), Some(8551)); - - if dev { - assert_eq!(reth.p2p_port(), None); - } else { - assert_eq!(reth.p2p_port(), Some(30303)); - } + // Changes to the following port numbers for each instance: + // - `DISCOVERY_PORT`: default + `instance` - 1 + // - `AUTH_PORT`: default + `instance` * 100 - 100 + // - `HTTP_RPC_PORT`: default - `instance` + 1 + // - `WS_RPC_PORT`: default + `instance` * 2 - 2 + assert_eq!(reth.http_port(), HTTP_RPC_PORT - reth.instance + 1); + assert_eq!(reth.ws_port(), WS_RPC_PORT + reth.instance * 2 - 2); + assert_eq!(reth.auth_port(), Some(AUTH_PORT + reth.instance * 100 - 100)); + assert_eq!( + reth.p2p_port(), + if dev { None } else { Some(DISCOVERY_PORT + reth.instance - 1) } + ); } } diff --git a/crates/node-bindings/src/utils.rs b/crates/node-bindings/src/utils.rs index 50633b0117a..a5f4ca9fed5 100644 --- a/crates/node-bindings/src/utils.rs +++ b/crates/node-bindings/src/utils.rs @@ -1,13 +1,10 @@ //! Utility functions for the node bindings. -use alloy_primitives::{hex, Address}; -use k256::SecretKey; use std::{ borrow::Cow, future::Future, net::{SocketAddr, TcpListener}, path::PathBuf, - str::FromStr, }; use tempfile; @@ -71,47 +68,6 @@ pub(crate) fn extract_endpoint(key: &str, line: &str) -> Option { val.parse::().ok() } -/// Get the default private keys and addresses from the default mnemonic: -/// "test test test test test test test test test test test junk" -pub(crate) fn get_default_keys() -> (Vec
, Vec) { - let addresses = [ - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", - "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", - "0x90F79bf6EB2c4f870365E785982E1f101E93b906", - "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", - "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc", - "0x976EA74026E726554dB657fA54763abd0C3a0aa9", - "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955", - "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f", - "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720", - ] - .iter() - .map(|s| Address::from_str(s).unwrap()) - .collect::>(); - - let private_keys = [ - "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", - "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", - "0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a", - "0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6", - "0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a", - "0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba", - "0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e", - "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356", - "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97", - "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6", - ] - .iter() - .map(|s| { - let key_hex = hex::decode(s).unwrap(); - SecretKey::from_bytes((&key_hex[..]).into()).unwrap() - }) - .collect::>(); - - (addresses, private_keys) -} - /// Runs the given closure with a temporary directory. pub fn run_with_tempdir_sync(prefix: &str, f: impl FnOnce(PathBuf)) { let temp_dir = tempfile::TempDir::with_prefix(prefix).unwrap(); diff --git a/crates/provider/src/ext/admin.rs b/crates/provider/src/ext/admin.rs index 98cac754989..246f7d5412c 100644 --- a/crates/provider/src/ext/admin.rs +++ b/crates/provider/src/ext/admin.rs @@ -88,7 +88,7 @@ mod test { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::{utils::run_with_tempdir, Geth}; + use alloy_node_bindings::{run_with_tempdir, Geth}; #[tokio::test] async fn node_info() { diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index c9a8d10813a..b252d33e77e 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -225,7 +225,7 @@ mod test { use super::*; use alloy_network::TransactionBuilder; - use alloy_node_bindings::{utils::run_with_tempdir, Geth, Reth}; + use alloy_node_bindings::{run_with_tempdir, Geth, Reth}; use alloy_primitives::{address, U256}; #[tokio::test] diff --git a/crates/provider/src/ext/net.rs b/crates/provider/src/ext/net.rs index 92ee2e1fb21..91bea2a0ab4 100644 --- a/crates/provider/src/ext/net.rs +++ b/crates/provider/src/ext/net.rs @@ -41,7 +41,7 @@ mod test { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::{utils::run_with_tempdir, Geth}; + use alloy_node_bindings::{run_with_tempdir, Geth}; #[tokio::test] async fn call_net_version() { diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 4f562903432..5d7c214cd50 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -179,7 +179,7 @@ mod test { use crate::ProviderBuilder; use alloy_eips::BlockNumberOrTag; use alloy_network::TransactionBuilder; - use alloy_node_bindings::{utils::run_with_tempdir, Reth}; + use alloy_node_bindings::{run_with_tempdir, Reth}; use alloy_primitives::U256; use alloy_rpc_types_eth::TransactionRequest; @@ -189,7 +189,8 @@ mod test { #[cfg(not(windows))] async fn trace_block() { run_with_tempdir("reth-test-", |temp_dir| async move { - let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let reth = + Reth::new().random_instance().dev().disable_discovery().data_dir(temp_dir).spawn(); let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); let result = provider.trace_block(BlockId::Number(BlockNumberOrTag::Latest)).await; @@ -205,7 +206,8 @@ mod test { #[cfg(not(windows))] async fn trace_call() { run_with_tempdir("reth-test-", |temp_dir| async move { - let reth = Reth::new().dev().disable_discovery().data_dir(temp_dir).spawn(); + let reth = + Reth::new().random_instance().dev().disable_discovery().data_dir(temp_dir).spawn(); let provider = ProviderBuilder::new().on_http(reth.endpoint_url()); let accounts = reth.addresses(); diff --git a/crates/provider/src/ext/txpool.rs b/crates/provider/src/ext/txpool.rs index b97b1a2e4b5..0718d7e9cfd 100644 --- a/crates/provider/src/ext/txpool.rs +++ b/crates/provider/src/ext/txpool.rs @@ -78,7 +78,7 @@ mod tests { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::{utils::run_with_tempdir, Geth}; + use alloy_node_bindings::{run_with_tempdir, Geth}; #[tokio::test] async fn txpool_content() { From bbc5ebc870fd7a727e4560fa511efc174a6d6a38 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 11:47:53 +0000 Subject: [PATCH 13/20] fix clippy --- crates/node-bindings/src/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/node-bindings/src/utils.rs b/crates/node-bindings/src/utils.rs index a5f4ca9fed5..e3ee8a4511e 100644 --- a/crates/node-bindings/src/utils.rs +++ b/crates/node-bindings/src/utils.rs @@ -6,7 +6,7 @@ use std::{ net::{SocketAddr, TcpListener}, path::PathBuf, }; -use tempfile; +use tempfile::TempDir; /// A bit of hack to find an unused TCP port. /// @@ -70,7 +70,7 @@ pub(crate) fn extract_endpoint(key: &str, line: &str) -> Option { /// Runs the given closure with a temporary directory. pub fn run_with_tempdir_sync(prefix: &str, f: impl FnOnce(PathBuf)) { - let temp_dir = tempfile::TempDir::with_prefix(prefix).unwrap(); + let temp_dir = TempDir::with_prefix(prefix).unwrap(); let temp_dir_path = temp_dir.path().to_path_buf(); f(temp_dir_path); #[cfg(not(windows))] @@ -83,7 +83,7 @@ where F: FnOnce(PathBuf) -> Fut, Fut: Future, { - let temp_dir = tempfile::TempDir::with_prefix(prefix).unwrap(); + let temp_dir = TempDir::with_prefix(prefix).unwrap(); let temp_dir_path = temp_dir.path().to_path_buf(); f(temp_dir_path).await; #[cfg(not(windows))] From 157860c18ae75706746c79833989ab3735b2b673 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 11:52:18 +0000 Subject: [PATCH 14/20] add back utils namespace --- crates/node-bindings/src/lib.rs | 3 +-- crates/node-bindings/src/nodes/anvil.rs | 2 +- crates/node-bindings/src/nodes/geth.rs | 2 +- crates/node-bindings/src/nodes/reth.rs | 2 +- crates/provider/src/ext/admin.rs | 2 +- crates/provider/src/ext/debug.rs | 2 +- crates/provider/src/ext/net.rs | 2 +- crates/provider/src/ext/trace.rs | 2 +- crates/provider/src/ext/txpool.rs | 2 +- 9 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/node-bindings/src/lib.rs b/crates/node-bindings/src/lib.rs index 74af3c9b476..2ed26210609 100644 --- a/crates/node-bindings/src/lib.rs +++ b/crates/node-bindings/src/lib.rs @@ -21,8 +21,7 @@ pub use nodes::{ mod node; pub use node::*; -mod utils; -pub use utils::*; +pub mod utils; /// 1 Ether = 1e18 Wei == 0x0de0b6b3a7640000 Wei pub const WEI_IN_ETHER: U256 = U256::from_limbs([0x0de0b6b3a7640000, 0x0, 0x0, 0x0]); diff --git a/crates/node-bindings/src/nodes/anvil.rs b/crates/node-bindings/src/nodes/anvil.rs index 760b3e9dbba..fd2faa54c82 100644 --- a/crates/node-bindings/src/nodes/anvil.rs +++ b/crates/node-bindings/src/nodes/anvil.rs @@ -372,7 +372,7 @@ mod tests { #[test] fn assert_chain_id() { - let anvil = Anvil::new().fork("https://eth.merkle.io").spawn(); + let anvil = Anvil::new().fork("https://eth.llamarpc.com").spawn(); assert_eq!(anvil.chain_id(), 1); } diff --git a/crates/node-bindings/src/nodes/geth.rs b/crates/node-bindings/src/nodes/geth.rs index 7303203e603..1f803a5db77 100644 --- a/crates/node-bindings/src/nodes/geth.rs +++ b/crates/node-bindings/src/nodes/geth.rs @@ -624,7 +624,7 @@ impl Geth { mod tests { use super::*; - use crate::run_with_tempdir_sync; + use crate::utils::run_with_tempdir_sync; #[test] fn port_0() { diff --git a/crates/node-bindings/src/nodes/reth.rs b/crates/node-bindings/src/nodes/reth.rs index aebcfb06061..32595d32bd4 100644 --- a/crates/node-bindings/src/nodes/reth.rs +++ b/crates/node-bindings/src/nodes/reth.rs @@ -498,7 +498,7 @@ impl Reth { #[cfg(test)] mod tests { use super::*; - use crate::run_with_tempdir_sync; + use crate::utils::run_with_tempdir_sync; const DISCOVERY_PORT: u16 = 30303; const AUTH_PORT: u16 = 8551; diff --git a/crates/provider/src/ext/admin.rs b/crates/provider/src/ext/admin.rs index 246f7d5412c..98cac754989 100644 --- a/crates/provider/src/ext/admin.rs +++ b/crates/provider/src/ext/admin.rs @@ -88,7 +88,7 @@ mod test { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::{run_with_tempdir, Geth}; + use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn node_info() { diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index b252d33e77e..c9a8d10813a 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -225,7 +225,7 @@ mod test { use super::*; use alloy_network::TransactionBuilder; - use alloy_node_bindings::{run_with_tempdir, Geth, Reth}; + use alloy_node_bindings::{utils::run_with_tempdir, Geth, Reth}; use alloy_primitives::{address, U256}; #[tokio::test] diff --git a/crates/provider/src/ext/net.rs b/crates/provider/src/ext/net.rs index 91bea2a0ab4..92ee2e1fb21 100644 --- a/crates/provider/src/ext/net.rs +++ b/crates/provider/src/ext/net.rs @@ -41,7 +41,7 @@ mod test { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::{run_with_tempdir, Geth}; + use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn call_net_version() { diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 5d7c214cd50..7908c94fb87 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -179,7 +179,7 @@ mod test { use crate::ProviderBuilder; use alloy_eips::BlockNumberOrTag; use alloy_network::TransactionBuilder; - use alloy_node_bindings::{run_with_tempdir, Reth}; + use alloy_node_bindings::{utils::run_with_tempdir, Reth}; use alloy_primitives::U256; use alloy_rpc_types_eth::TransactionRequest; diff --git a/crates/provider/src/ext/txpool.rs b/crates/provider/src/ext/txpool.rs index 0718d7e9cfd..b97b1a2e4b5 100644 --- a/crates/provider/src/ext/txpool.rs +++ b/crates/provider/src/ext/txpool.rs @@ -78,7 +78,7 @@ mod tests { use crate::ProviderBuilder; use super::*; - use alloy_node_bindings::{run_with_tempdir, Geth}; + use alloy_node_bindings::{utils::run_with_tempdir, Geth}; #[tokio::test] async fn txpool_content() { From c83dc5740ebf3d7d837930dc33b98af93be28712 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 11:53:42 +0000 Subject: [PATCH 15/20] merge in main --- .github/workflows/ci.yml | 16 ++-- .github/workflows/no_std.yml | 25 ----- CHANGELOG.md | 59 ++++++++++++ Cargo.toml | 6 +- crates/alloy/CHANGELOG.md | 7 ++ crates/consensus/CHANGELOG.md | 31 +++++++ crates/consensus/src/header.rs | 30 +++--- crates/consensus/src/lib.rs | 1 - crates/consensus/src/receipt/receipts.rs | 4 +- crates/consensus/src/transaction/eip1559.rs | 4 +- crates/consensus/src/transaction/eip2930.rs | 4 +- crates/consensus/src/transaction/eip4844.rs | 4 +- crates/consensus/src/transaction/eip7702.rs | 30 +++--- crates/consensus/src/transaction/envelope.rs | 4 +- crates/consensus/src/transaction/legacy.rs | 4 +- crates/consensus/src/transaction/mod.rs | 4 +- crates/contract/CHANGELOG.md | 12 +++ crates/eip7547/CHANGELOG.md | 12 +++ crates/eips/CHANGELOG.md | 19 ++++ crates/eips/src/eip1898.rs | 92 ++++++++++--------- crates/eips/src/lib.rs | 3 +- crates/genesis/CHANGELOG.md | 12 +++ crates/json-rpc/CHANGELOG.md | 10 ++ crates/network-primitives/CHANGELOG.md | 21 +++++ crates/network-primitives/src/traits.rs | 3 - crates/network/CHANGELOG.md | 12 +++ crates/node-bindings/CHANGELOG.md | 20 ++++ crates/node-bindings/src/nodes/anvil.rs | 5 +- crates/provider/CHANGELOG.md | 10 ++ crates/provider/src/fillers/nonce.rs | 2 + crates/pubsub/CHANGELOG.md | 12 +++ crates/rpc-client/CHANGELOG.md | 16 ++++ crates/rpc-types-admin/CHANGELOG.md | 12 +++ crates/rpc-types-anvil/CHANGELOG.md | 12 +++ crates/rpc-types-beacon/CHANGELOG.md | 13 +++ crates/rpc-types-beacon/src/sidecar.rs | 24 ++++- crates/rpc-types-debug/CHANGELOG.md | 12 +++ crates/rpc-types-engine/CHANGELOG.md | 16 ++++ crates/rpc-types-eth/CHANGELOG.md | 32 +++++++ crates/rpc-types-eth/Cargo.toml | 20 ++-- crates/rpc-types-eth/src/account.rs | 2 + crates/rpc-types-eth/src/block.rs | 20 +++- crates/rpc-types-eth/src/call.rs | 6 ++ crates/rpc-types-eth/src/erc4337.rs | 5 +- crates/rpc-types-eth/src/fee.rs | 6 +- crates/rpc-types-eth/src/filter.rs | 26 ++++-- crates/rpc-types-eth/src/index.rs | 3 +- crates/rpc-types-eth/src/lib.rs | 15 +++ crates/rpc-types-eth/src/pubsub.rs | 1 + crates/rpc-types-eth/src/raw_log.rs | 2 + crates/rpc-types-eth/src/simulate.rs | 65 ++++++------- crates/rpc-types-eth/src/state.rs | 9 +- crates/rpc-types-eth/src/syncing.rs | 3 +- crates/rpc-types-eth/src/transaction/error.rs | 82 +++++++++++------ crates/rpc-types-eth/src/transaction/mod.rs | 6 +- .../rpc-types-eth/src/transaction/receipt.rs | 2 + .../rpc-types-eth/src/transaction/request.rs | 21 +++-- .../src/transaction/signature.rs | 4 +- crates/rpc-types-eth/src/work.rs | 2 +- crates/rpc-types-mev/CHANGELOG.md | 12 +++ crates/rpc-types-trace/CHANGELOG.md | 22 +++++ crates/rpc-types-trace/Cargo.toml | 2 +- crates/rpc-types-trace/src/otterscan.rs | 4 +- crates/rpc-types-trace/src/parity.rs | 53 +++++++++-- crates/rpc-types-txpool/CHANGELOG.md | 12 +++ crates/rpc-types/CHANGELOG.md | 12 +++ crates/rpc-types/Cargo.toml | 2 +- crates/serde/CHANGELOG.md | 12 +++ crates/signer-aws/CHANGELOG.md | 12 +++ crates/signer-gcp/CHANGELOG.md | 12 +++ crates/signer-ledger/CHANGELOG.md | 12 +++ crates/signer-local/CHANGELOG.md | 12 +++ crates/signer-trezor/CHANGELOG.md | 12 +++ crates/signer/CHANGELOG.md | 12 +++ crates/transport-http/CHANGELOG.md | 12 +++ crates/transport-ipc/CHANGELOG.md | 12 +++ crates/transport-ws/CHANGELOG.md | 12 +++ crates/transport/CHANGELOG.md | 12 +++ scripts/check_no_std.sh | 24 ++--- 79 files changed, 927 insertions(+), 263 deletions(-) delete mode 100644 .github/workflows/no_std.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 645acbc53a7..bf8b3a3ec63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,33 +127,33 @@ jobs: - name: build ledger run: cargo build -p alloy-signer-ledger --features browser --target wasm32-wasip1 - no-std: + feature-checks: runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - with: - target: riscv32imac-unknown-none-elf - uses: taiki-e/install-action@cargo-hack - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - - name: check - run: ./scripts/check_no_std.sh + - name: cargo hack + run: cargo hack check --feature-powerset --depth 1 - feature-checks: + check-no-std: + name: check no_std ${{ matrix.features }} runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + targets: riscv32imac-unknown-none-elf - uses: taiki-e/install-action@cargo-hack - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true - - name: cargo hack - run: cargo hack check --feature-powerset --depth 1 + - run: ./scripts/check_no_std.sh clippy: runs-on: ubuntu-latest diff --git a/.github/workflows/no_std.yml b/.github/workflows/no_std.yml deleted file mode 100644 index b9af136c279..00000000000 --- a/.github/workflows/no_std.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: no_std - -on: - push: - branches: [main] - pull_request: - -env: - CARGO_TERM_COLOR: always - -jobs: - check-no-std: - name: check no_std ${{ matrix.features }} - runs-on: ubuntu-latest - timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - crate: ["alloy-eips", "alloy-consensus", "alloy-genesis", "alloy-network-primitives"] - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - with: - targets: riscv32imac-unknown-none-elf - - run: cargo check --target riscv32imac-unknown-none-elf --no-default-features -p ${{ matrix.crate }} diff --git a/CHANGELOG.md b/CHANGELOG.md index fb34b4ccaba..fe15ae36cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,64 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.3](https://github.com/alloy-rs/alloy/releases/tag/v0.3.3) - 2024-09-10 + +### Bug Fixes + +- [rpc-types-trace] Use rpc-types Log in OtsReceipt ([#1261](https://github.com/alloy-rs/alloy/issues/1261)) + +### Features + +- [rpc-types-trace] Always serialize result if no error ([#1258](https://github.com/alloy-rs/alloy/issues/1258)) + +### Miscellaneous Tasks + +- Require destination for 7702 ([#1262](https://github.com/alloy-rs/alloy/issues/1262)) +- Swap BlockNumHash alias and struct name ([#1265](https://github.com/alloy-rs/alloy/issues/1265)) + +### Other + +- Implement `AsRef` for `Header` ([#1260](https://github.com/alloy-rs/alloy/issues/1260)) + +### Testing + +- Dont use fork test ([#1263](https://github.com/alloy-rs/alloy/issues/1263)) + +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Bug Fixes + +- [consensus] Remove Unused Alloc Vecs ([#1250](https://github.com/alloy-rs/alloy/issues/1250)) + +### Dependencies + +- Bump tower to 0.5 ([#1249](https://github.com/alloy-rs/alloy/issues/1249)) + +### Features + +- No_std network primitives ([#1248](https://github.com/alloy-rs/alloy/issues/1248)) +- [rpc-types-eth] AnyBlock ([#1243](https://github.com/alloy-rs/alloy/issues/1243)) +- Add Reth node bindings ([#1092](https://github.com/alloy-rs/alloy/issues/1092)) +- [rpc-types-engine] Add forkchoice state zero helpers ([#1231](https://github.com/alloy-rs/alloy/issues/1231)) +- [network-primitives] Expose more fields via block response traits ([#1229](https://github.com/alloy-rs/alloy/issues/1229)) + +### Miscellaneous Tasks + +- Release 0.3.2 +- Add aliases for Num Hash ([#1253](https://github.com/alloy-rs/alloy/issues/1253)) +- Add helpers for beacon blob bundle ([#1254](https://github.com/alloy-rs/alloy/issues/1254)) +- [eip1898] Display `RpcBlockHash` ([#1242](https://github.com/alloy-rs/alloy/issues/1242)) +- Optional derive more ([#1239](https://github.com/alloy-rs/alloy/issues/1239)) +- Derive more default features false ([#1230](https://github.com/alloy-rs/alloy/issues/1230)) + +### Other + +- Add getter trait methods to `ReceiptResponse` ([#1251](https://github.com/alloy-rs/alloy/issues/1251)) +- Impl `exceeds_allowed_future_timestamp` for `Header` ([#1237](https://github.com/alloy-rs/alloy/issues/1237)) +- Impl `is_zero_difficulty` for `Header` ([#1236](https://github.com/alloy-rs/alloy/issues/1236)) +- Impl parent_num_hash for Header ([#1238](https://github.com/alloy-rs/alloy/issues/1238)) +- Implement `Arbitrary` for `Header` ([#1235](https://github.com/alloy-rs/alloy/issues/1235)) + ## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 ### Bug Fixes @@ -31,6 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Miscellaneous Tasks +- Release 0.3.1 - [README] Add a link to `rpc-types-debug` ([#1212](https://github.com/alloy-rs/alloy/issues/1212)) - [features] Enable `consensus` and `network` along with `providers` ([#1207](https://github.com/alloy-rs/alloy/issues/1207)) diff --git a/Cargo.toml b/Cargo.toml index ef88a7a5862..c2bb401ac19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["crates/*"] resolver = "2" [workspace.package] -version = "0.3.1" +version = "0.3.3" edition = "2021" rust-version = "1.79" authors = ["Alloy Contributors"] @@ -119,6 +119,10 @@ tower = { version = "0.5", features = ["util"] } tracing = "0.1" tracing-subscriber = "0.3" +# no_std +cfg-if = "1" +hashbrown = "0.14.5" + # misc auto_impl = "1.2" base64 = "0.22" diff --git a/crates/alloy/CHANGELOG.md b/crates/alloy/CHANGELOG.md index 027485de5bb..8ca92dfdd18 100644 --- a/crates/alloy/CHANGELOG.md +++ b/crates/alloy/CHANGELOG.md @@ -5,10 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + ## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 ### Miscellaneous Tasks +- Release 0.3.1 - [features] Enable `consensus` and `network` along with `providers` ([#1207](https://github.com/alloy-rs/alloy/issues/1207)) ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 diff --git a/crates/consensus/CHANGELOG.md b/crates/consensus/CHANGELOG.md index 2efa49bcac4..44727c60c6a 100644 --- a/crates/consensus/CHANGELOG.md +++ b/crates/consensus/CHANGELOG.md @@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.3](https://github.com/alloy-rs/alloy/releases/tag/v0.3.3) - 2024-09-10 + +### Miscellaneous Tasks + +- Require destination for 7702 ([#1262](https://github.com/alloy-rs/alloy/issues/1262)) + +### Other + +- Implement `AsRef` for `Header` ([#1260](https://github.com/alloy-rs/alloy/issues/1260)) + +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Bug Fixes + +- [consensus] Remove Unused Alloc Vecs ([#1250](https://github.com/alloy-rs/alloy/issues/1250)) + +### Miscellaneous Tasks + +- Release 0.3.2 + +### Other + +- Impl `exceeds_allowed_future_timestamp` for `Header` ([#1237](https://github.com/alloy-rs/alloy/issues/1237)) +- Impl `is_zero_difficulty` for `Header` ([#1236](https://github.com/alloy-rs/alloy/issues/1236)) +- Impl parent_num_hash for Header ([#1238](https://github.com/alloy-rs/alloy/issues/1238)) +- Implement `Arbitrary` for `Header` ([#1235](https://github.com/alloy-rs/alloy/issues/1235)) + ## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 ### Bug Fixes @@ -16,6 +43,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Derive `arbitrary::Arbitrary` for `TxEip7702` ([#1216](https://github.com/alloy-rs/alloy/issues/1216)) - Implement `tx_type` for `TxEip7702` ([#1214](https://github.com/alloy-rs/alloy/issues/1214)) +### Miscellaneous Tasks + +- Release 0.3.1 + ### Other - Rm useless methods for `TxEip7702` ([#1221](https://github.com/alloy-rs/alloy/issues/1221)) diff --git a/crates/consensus/src/header.rs b/crates/consensus/src/header.rs index ae7bed24ae1..3109d9044e3 100644 --- a/crates/consensus/src/header.rs +++ b/crates/consensus/src/header.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use alloy_eips::{ eip1559::{calc_next_block_base_fee, BaseFeeParams}, eip4844::{calc_blob_gasprice, calc_excess_blob_gas}, @@ -5,16 +6,13 @@ use alloy_eips::{ BlockNumHash, }; use alloy_primitives::{ - b256, keccak256, Address, BlockNumber, Bloom, Bytes, Sealable, B256, B64, U256, + b256, keccak256, Address, BlockNumber, Bloom, Bytes, Sealable, Sealed, B256, B64, U256, }; use alloy_rlp::{ length_of_length, Buf, BufMut, Decodable, Encodable, EMPTY_LIST_CODE, EMPTY_STRING_CODE, }; use core::mem; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Ommer root of empty list. pub const EMPTY_OMMER_ROOT_HASH: B256 = b256!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"); @@ -135,6 +133,12 @@ pub struct Header { pub extra_data: Bytes, } +impl AsRef for Header { + fn as_ref(&self) -> &Self { + self + } +} + impl Default for Header { fn default() -> Self { Self { @@ -170,13 +174,6 @@ impl Sealable for Header { } impl Header { - // TODO: re-enable - - // /// Returns the parent block's number and hash - // pub fn parent_num_hash(&self) -> BlockNumHash { - // BlockNumHash { number: self.number.saturating_sub(1), hash: self.parent_hash } - // } - /// Heavy function that will calculate hash of data and will *not* save the change to metadata. /// /// Use [`Header::seal_slow`] and unlock if you need the hash to be persistent. @@ -373,6 +370,14 @@ impl Header { pub const fn exceeds_allowed_future_timestamp(&self, present_timestamp: u64) -> bool { self.timestamp > present_timestamp + ALLOWED_FUTURE_BLOCK_TIME_SECONDS } + + /// Seal the header with a known hash. + /// + /// WARNING: This method does not perform validation whether the hash is correct. + #[inline] + pub const fn seal(self, hash: B256) -> Sealed { + Sealed::new_unchecked(self, hash) + } } impl Encodable for Header { @@ -633,11 +638,10 @@ impl<'a> arbitrary::Arbitrary<'a> for Header { } } -#[cfg(test)] +#[cfg(all(test, feature = "serde"))] mod tests { use super::*; - #[cfg(feature = "serde")] #[test] fn header_serde() { let raw = r#"{"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","ommersHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","beneficiary":"0x0000000000000000000000000000000000000000","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","withdrawalsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","difficulty":"0x0","number":"0x0","gasLimit":"0x0","gasUsed":"0x0","timestamp":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","baseFeePerGas":"0x1","extraData":"0x"}"#; diff --git a/crates/consensus/src/lib.rs b/crates/consensus/src/lib.rs index 5fd91a76559..65ec35a908f 100644 --- a/crates/consensus/src/lib.rs +++ b/crates/consensus/src/lib.rs @@ -7,7 +7,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; mod account; diff --git a/crates/consensus/src/receipt/receipts.rs b/crates/consensus/src/receipt/receipts.rs index e9476a81f72..63fa657e5d7 100644 --- a/crates/consensus/src/receipt/receipts.rs +++ b/crates/consensus/src/receipt/receipts.rs @@ -1,11 +1,9 @@ use crate::receipt::{Eip658Value, TxReceipt}; +use alloc::vec::Vec; use alloy_primitives::{Bloom, Log}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable}; use core::borrow::Borrow; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Receipt containing result of transaction execution. #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize))] diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index 3f072cc8a05..108c7e8a4c6 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -1,12 +1,10 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; +use alloc::vec::Vec; use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)). #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 5917f3d741c..5ed91a2b6f0 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -1,12 +1,10 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; +use alloc::vec::Vec; use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)). #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index a4775200952..78bb4d28650 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -1,5 +1,6 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; +use alloc::vec::Vec; use alloy_eips::{eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; @@ -12,9 +13,6 @@ pub use alloy_eips::eip4844::BlobTransactionSidecar; #[doc(inline)] pub use alloy_eips::eip4844::BlobTransactionValidationError; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction) /// /// A transaction with blob hashes and max blob fee. diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index c2e704a4df8..c13bda3bf98 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -1,13 +1,13 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; -use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; +use alloc::vec::Vec; +use alloy_eips::{ + eip2930::AccessList, + eip7702::{constants::EIP7702_TX_TYPE_ID, SignedAuthorization}, +}; +use alloy_primitives::{keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; -use alloy_eips::eip7702::{constants::EIP7702_TX_TYPE_ID, SignedAuthorization}; - /// A transaction with a priority fee ([EIP-7702](https://eips.ethereum.org/EIPS/eip-7702)). #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] @@ -50,10 +50,8 @@ pub struct TxEip7702 { /// This is also known as `GasTipCap` #[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))] pub max_priority_fee_per_gas: u128, - /// The 160-bit address of the message call’s recipient or, for a contract creation - /// transaction, ∅, used here to denote the only member of B0 ; formally Tt. - #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "TxKind::is_create"))] - pub to: TxKind, + /// The 160-bit address of the message call’s recipient. + pub to: Address, /// A scalar value equal to the number of Wei to /// be transferred to the message call’s recipient or, /// in the case of contract creation, as an endowment @@ -263,7 +261,7 @@ impl TxEip7702 { mem::size_of::() + // gas_limit mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas - self.to.size() + // to + mem::size_of::
() + // to mem::size_of::() + // value self.access_list.size() + // access_list self.input.len() + // input @@ -305,7 +303,7 @@ impl Transaction for TxEip7702 { } fn to(&self) -> TxKind { - self.to + self.to.into() } fn value(&self) -> U256 { @@ -391,7 +389,7 @@ mod tests { use super::TxEip7702; use crate::SignableTransaction; use alloy_eips::eip2930::AccessList; - use alloy_primitives::{address, b256, hex, Address, Signature, TxKind, U256}; + use alloy_primitives::{address, b256, hex, Address, Signature, U256}; #[test] fn encode_decode_eip7702() { @@ -399,7 +397,7 @@ mod tests { chain_id: 1, nonce: 0x42, gas_limit: 44386, - to: address!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6").into(), + to: address!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6"), value: U256::from(0_u64), input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(), max_fee_per_gas: 0x4a817c800, @@ -430,7 +428,7 @@ mod tests { max_fee_per_gas: 0x4a817c800, max_priority_fee_per_gas: 0x3b9aca00, gas_limit: 2, - to: TxKind::Create, + to: Address::default(), value: U256::ZERO, input: vec![1, 2].into(), access_list: Default::default(), @@ -456,7 +454,7 @@ mod tests { max_fee_per_gas: 0x4a817c800, max_priority_fee_per_gas: 0x3b9aca00, gas_limit: 2, - to: Address::default().into(), + to: Address::default(), value: U256::ZERO, input: vec![1, 2].into(), access_list: Default::default(), diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index fc5c324e983..232e88ca326 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -823,7 +823,7 @@ mod tests { gas_limit: 3, max_fee_per_gas: 4, max_priority_fee_per_gas: 5, - to: Address::left_padding_from(&[5]).into(), + to: Address::left_padding_from(&[5]), value: U256::from(6_u64), input: vec![7].into(), access_list: AccessList(vec![AccessListItem { @@ -994,7 +994,7 @@ mod tests { gas_limit: u128::MAX, max_fee_per_gas: u128::MAX, max_priority_fee_per_gas: u128::MAX, - to: Address::random().into(), + to: Address::random(), value: U256::MAX, input: Bytes::new(), access_list: AccessList(vec![AccessListItem { diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index e212f93bc6d..c3ecdc5437c 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -1,14 +1,12 @@ use core::mem; +use alloc::vec::Vec; use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result}; use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Legacy transaction. #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index a4bf0ebd401..64d6edd7935 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -1,13 +1,11 @@ //! Transaction types. use crate::Signed; +use alloc::vec::Vec; use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{keccak256, ChainId, TxKind, B256, U256}; use core::any; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - mod eip1559; pub use eip1559::TxEip1559; diff --git a/crates/contract/CHANGELOG.md b/crates/contract/CHANGELOG.md index a47485754f5..870071431f2 100644 --- a/crates/contract/CHANGELOG.md +++ b/crates/contract/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/eip7547/CHANGELOG.md b/crates/eip7547/CHANGELOG.md index 1c20d59a82e..ccfb3e6e671 100644 --- a/crates/eip7547/CHANGELOG.md +++ b/crates/eip7547/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/eips/CHANGELOG.md b/crates/eips/CHANGELOG.md index a1bd97c3a68..87273665698 100644 --- a/crates/eips/CHANGELOG.md +++ b/crates/eips/CHANGELOG.md @@ -5,12 +5,31 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.3](https://github.com/alloy-rs/alloy/releases/tag/v0.3.3) - 2024-09-10 + +### Miscellaneous Tasks + +- Swap BlockNumHash alias and struct name ([#1265](https://github.com/alloy-rs/alloy/issues/1265)) + +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 +- Add aliases for Num Hash ([#1253](https://github.com/alloy-rs/alloy/issues/1253)) +- [eip1898] Display `RpcBlockHash` ([#1242](https://github.com/alloy-rs/alloy/issues/1242)) +- Optional derive more ([#1239](https://github.com/alloy-rs/alloy/issues/1239)) + ## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 ### Bug Fixes - [eips] No-std compat ([#1222](https://github.com/alloy-rs/alloy/issues/1222)) +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 16e054573bc..4b0690f78af 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -1,6 +1,6 @@ //! [EIP-1898]: https://eips.ethereum.org/EIPS/eip-1898 -use alloy_primitives::{hex::FromHexError, ruint::ParseError, BlockHash, BlockNumber, B256, U64}; +use alloy_primitives::{hex::FromHexError, ruint::ParseError, BlockHash, B256, U64}; use alloy_rlp::{bytes, Decodable, Encodable, Error as RlpError}; use core::{ fmt::{self, Debug, Display, Formatter}, @@ -393,13 +393,13 @@ impl From for BlockId { } } -impl From for BlockId { - fn from(block: BlockHashOrNumber) -> Self { +impl From for BlockId { + fn from(block: HashOrNumber) -> Self { match block { - BlockHashOrNumber::Hash(hash) => { + HashOrNumber::Hash(hash) => { Self::Hash(RpcBlockHash { block_hash: hash, require_canonical: None }) } - BlockHashOrNumber::Number(num) => Self::Number(BlockNumberOrTag::Number(num)), + HashOrNumber::Number(num) => Self::Number(BlockNumberOrTag::Number(num)), } } } @@ -600,65 +600,71 @@ impl FromStr for BlockId { } } -/// Block number and hash. +/// A number and a hash. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] -pub struct BlockNumHash { - /// Block number - pub number: BlockNumber, - /// Block hash - pub hash: BlockHash, +pub struct NumHash { + /// The number + pub number: u64, + /// The hash. + pub hash: B256, } /// Block number and hash of the forked block. -pub type ForkBlock = BlockNumHash; +pub type ForkBlock = NumHash; -impl BlockNumHash { - /// Creates a new `BlockNumHash` from a block number and hash. - pub const fn new(number: BlockNumber, hash: BlockHash) -> Self { +/// A block number and a hash +pub type BlockNumHash = NumHash; + +impl NumHash { + /// Creates a new `NumHash` from a number and hash. + pub const fn new(number: u64, hash: B256) -> Self { Self { number, hash } } - /// Consumes `Self` and returns [`BlockNumber`], [`BlockHash`] - pub const fn into_components(self) -> (BlockNumber, BlockHash) { + /// Consumes `Self` and returns the number and hash + pub const fn into_components(self) -> (u64, B256) { (self.number, self.hash) } - /// Returns whether or not the block matches the given [BlockHashOrNumber]. - pub fn matches_block_or_num(&self, block: &BlockHashOrNumber) -> bool { + /// Returns whether or not the block matches the given [HashOrNumber]. + pub fn matches_block_or_num(&self, block: &HashOrNumber) -> bool { match block { - BlockHashOrNumber::Hash(hash) => self.hash == *hash, - BlockHashOrNumber::Number(number) => self.number == *number, + HashOrNumber::Hash(hash) => self.hash == *hash, + HashOrNumber::Number(number) => self.number == *number, } } } -impl From<(BlockNumber, BlockHash)> for BlockNumHash { - fn from(val: (BlockNumber, BlockHash)) -> Self { +impl From<(u64, B256)> for NumHash { + fn from(val: (u64, B256)) -> Self { Self { number: val.0, hash: val.1 } } } -impl From<(BlockHash, BlockNumber)> for BlockNumHash { - fn from(val: (BlockHash, BlockNumber)) -> Self { +impl From<(B256, u64)> for NumHash { + fn from(val: (B256, u64)) -> Self { Self { hash: val.0, number: val.1 } } } -/// Either a block hash _or_ a block number +/// Either a hash _or_ a block number #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] -pub enum BlockHashOrNumber { - /// A block hash +pub enum HashOrNumber { + /// The hash Hash(B256), - /// A block number + /// The number Number(u64), } -// === impl BlockHashOrNumber === +/// A block hash _or_ a block number +pub type BlockHashOrNumber = HashOrNumber; + +// === impl HashOrNumber === -impl BlockHashOrNumber { - /// Returns the block number if it is a [`BlockHashOrNumber::Number`]. +impl HashOrNumber { + /// Returns the block number if it is a [`HashOrNumber::Number`]. #[inline] pub const fn as_number(self) -> Option { match self { @@ -668,32 +674,32 @@ impl BlockHashOrNumber { } } -impl From for BlockHashOrNumber { +impl From for HashOrNumber { fn from(value: B256) -> Self { Self::Hash(value) } } -impl From for BlockHashOrNumber { +impl From for HashOrNumber { fn from(value: u64) -> Self { Self::Number(value) } } -impl From for BlockHashOrNumber { +impl From for HashOrNumber { fn from(value: U64) -> Self { value.to::().into() } } -impl From for BlockHashOrNumber { +impl From for HashOrNumber { fn from(value: RpcBlockHash) -> Self { Self::Hash(value.into()) } } -/// Allows for RLP encoding of either a block hash or block number -impl Encodable for BlockHashOrNumber { +/// Allows for RLP encoding of either a hash or a number +impl Encodable for HashOrNumber { fn encode(&self, out: &mut dyn bytes::BufMut) { match self { Self::Hash(block_hash) => block_hash.encode(out), @@ -708,8 +714,8 @@ impl Encodable for BlockHashOrNumber { } } -/// Allows for RLP decoding of a block hash or block number -impl Decodable for BlockHashOrNumber { +/// Allows for RLP decoding of a hash or number +impl Decodable for HashOrNumber { fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { let header: u8 = *buf.first().ok_or(RlpError::InputTooShort)?; // if the byte string is exactly 32 bytes, decode it into a Hash @@ -730,7 +736,7 @@ impl Decodable for BlockHashOrNumber { } } -impl fmt::Display for BlockHashOrNumber { +impl fmt::Display for HashOrNumber { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Hash(hash) => write!(f, "{}", hash), @@ -739,7 +745,7 @@ impl fmt::Display for BlockHashOrNumber { } } -/// Error thrown when parsing a [BlockHashOrNumber] from a string. +/// Error thrown when parsing a [HashOrNumber] from a string. #[derive(Debug)] pub struct ParseBlockHashOrNumberError { input: alloc::string::String, @@ -760,7 +766,7 @@ impl fmt::Display for ParseBlockHashOrNumberError { #[cfg(feature = "std")] impl std::error::Error for ParseBlockHashOrNumberError {} -impl FromStr for BlockHashOrNumber { +impl FromStr for HashOrNumber { type Err = ParseBlockHashOrNumberError; fn from_str(s: &str) -> Result { diff --git a/crates/eips/src/lib.rs b/crates/eips/src/lib.rs index 393ba4f343e..2bb4b07e0cf 100644 --- a/crates/eips/src/lib.rs +++ b/crates/eips/src/lib.rs @@ -16,7 +16,8 @@ pub use eip1559::calc_next_block_base_fee; pub mod eip1898; pub use eip1898::{ - BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, RpcBlockHash, + BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, HashOrNumber, NumHash, + RpcBlockHash, }; pub mod eip2718; diff --git a/crates/genesis/CHANGELOG.md b/crates/genesis/CHANGELOG.md index a25f1dcdf92..0edc493fc42 100644 --- a/crates/genesis/CHANGELOG.md +++ b/crates/genesis/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Features diff --git a/crates/json-rpc/CHANGELOG.md b/crates/json-rpc/CHANGELOG.md index b9f9cedffae..68c637a1e41 100644 --- a/crates/json-rpc/CHANGELOG.md +++ b/crates/json-rpc/CHANGELOG.md @@ -5,12 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + ## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 ### Features - [`json-rpc`] Implement From U256 and String for SubId ([#1226](https://github.com/alloy-rs/alloy/issues/1226)) +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/network-primitives/CHANGELOG.md b/crates/network-primitives/CHANGELOG.md index a2be30b8738..3137d71f4c0 100644 --- a/crates/network-primitives/CHANGELOG.md +++ b/crates/network-primitives/CHANGELOG.md @@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Features + +- No_std network primitives ([#1248](https://github.com/alloy-rs/alloy/issues/1248)) +- [network-primitives] Expose more fields via block response traits ([#1229](https://github.com/alloy-rs/alloy/issues/1229)) + +### Miscellaneous Tasks + +- Release 0.3.2 + +### Other + +- Add getter trait methods to `ReceiptResponse` ([#1251](https://github.com/alloy-rs/alloy/issues/1251)) + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index 03f5fdf2598..53a8ef39703 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -4,9 +4,6 @@ use alloy_serde::WithOtherFields; use crate::BlockTransactions; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Receipt JSON-RPC response. pub trait ReceiptResponse { /// Address of the created contract, or `None` if the transaction was not a deployment. diff --git a/crates/network/CHANGELOG.md b/crates/network/CHANGELOG.md index ac4b8b90666..1ef0332c8cc 100644 --- a/crates/network/CHANGELOG.md +++ b/crates/network/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/node-bindings/CHANGELOG.md b/crates/node-bindings/CHANGELOG.md index 3a10b988515..656c9ad6af0 100644 --- a/crates/node-bindings/CHANGELOG.md +++ b/crates/node-bindings/CHANGELOG.md @@ -5,12 +5,32 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.3](https://github.com/alloy-rs/alloy/releases/tag/v0.3.3) - 2024-09-10 + +### Testing + +- Dont use fork test ([#1263](https://github.com/alloy-rs/alloy/issues/1263)) + +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Features + +- Add Reth node bindings ([#1092](https://github.com/alloy-rs/alloy/issues/1092)) + +### Miscellaneous Tasks + +- Release 0.3.2 + ## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 ### Bug Fixes - Anvil builder default port ([#1213](https://github.com/alloy-rs/alloy/issues/1213)) +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/node-bindings/src/nodes/anvil.rs b/crates/node-bindings/src/nodes/anvil.rs index fd2faa54c82..4b9e72076b9 100644 --- a/crates/node-bindings/src/nodes/anvil.rs +++ b/crates/node-bindings/src/nodes/anvil.rs @@ -372,8 +372,9 @@ mod tests { #[test] fn assert_chain_id() { - let anvil = Anvil::new().fork("https://eth.llamarpc.com").spawn(); - assert_eq!(anvil.chain_id(), 1); + let id = 99999; + let anvil = Anvil::new().chain_id(id).spawn(); + assert_eq!(anvil.chain_id(), id); } #[test] diff --git a/crates/provider/CHANGELOG.md b/crates/provider/CHANGELOG.md index 139e758badd..ec09db707ae 100644 --- a/crates/provider/CHANGELOG.md +++ b/crates/provider/CHANGELOG.md @@ -5,12 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + ## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 ### Features - [alloy-provider] Add abstraction for `NonceFiller` behavior ([#1108](https://github.com/alloy-rs/alloy/issues/1108)) +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/provider/src/fillers/nonce.rs b/crates/provider/src/fillers/nonce.rs index 273499bab72..ad81f83ac13 100644 --- a/crates/provider/src/fillers/nonce.rs +++ b/crates/provider/src/fillers/nonce.rs @@ -46,6 +46,8 @@ impl NonceManager for SimpleNonceManager { } } +/// Cached nonce manager +/// /// This [`NonceManager`] implementation will fetch the transaction count for any new account it /// sees, store it locally and increment the locally stored nonce as transactions are sent via /// [`Provider::send_transaction`]. diff --git a/crates/pubsub/CHANGELOG.md b/crates/pubsub/CHANGELOG.md index 171b5b2965c..30c35e4ab33 100644 --- a/crates/pubsub/CHANGELOG.md +++ b/crates/pubsub/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/rpc-client/CHANGELOG.md b/crates/rpc-client/CHANGELOG.md index 53de2a84f6b..de093c010a4 100644 --- a/crates/rpc-client/CHANGELOG.md +++ b/crates/rpc-client/CHANGELOG.md @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Dependencies + +- Bump tower to 0.5 ([#1249](https://github.com/alloy-rs/alloy/issues/1249)) + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/rpc-types-admin/CHANGELOG.md b/crates/rpc-types-admin/CHANGELOG.md index c562d3318af..e40713a2f82 100644 --- a/crates/rpc-types-admin/CHANGELOG.md +++ b/crates/rpc-types-admin/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/rpc-types-anvil/CHANGELOG.md b/crates/rpc-types-anvil/CHANGELOG.md index 109428c82ce..30d7a7cb211 100644 --- a/crates/rpc-types-anvil/CHANGELOG.md +++ b/crates/rpc-types-anvil/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/rpc-types-beacon/CHANGELOG.md b/crates/rpc-types-beacon/CHANGELOG.md index 81dbc4c816a..05b74f0e163 100644 --- a/crates/rpc-types-beacon/CHANGELOG.md +++ b/crates/rpc-types-beacon/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 +- Add helpers for beacon blob bundle ([#1254](https://github.com/alloy-rs/alloy/issues/1254)) + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/rpc-types-beacon/src/sidecar.rs b/crates/rpc-types-beacon/src/sidecar.rs index 7ec97f9ecb3..9c2866771a2 100644 --- a/crates/rpc-types-beacon/src/sidecar.rs +++ b/crates/rpc-types-beacon/src/sidecar.rs @@ -10,7 +10,29 @@ use std::vec::IntoIter; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct BeaconBlobBundle { /// Vec of individual blob data - data: Vec, + pub data: Vec, +} + +impl BeaconBlobBundle { + /// Creates a new [`BeaconBlobBundle`] from a given vector of [`BlobData`]. + pub const fn new(data: Vec) -> Self { + Self { data } + } + + /// Returns the number of blobs in the bundle. + pub fn len(&self) -> usize { + self.data.len() + } + + /// Returns if the bundle is empty. + pub fn is_empty(&self) -> bool { + self.data.is_empty() + } + + /// Returns the blob with the given index. + pub fn get_blob(&self, index: u64) -> Option<&BlobData> { + self.data.iter().find(|blob| blob.index == index) + } } /// Yields an iterator for BlobData diff --git a/crates/rpc-types-debug/CHANGELOG.md b/crates/rpc-types-debug/CHANGELOG.md index 69372189c6f..e1b76917f12 100644 --- a/crates/rpc-types-debug/CHANGELOG.md +++ b/crates/rpc-types-debug/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Features diff --git a/crates/rpc-types-engine/CHANGELOG.md b/crates/rpc-types-engine/CHANGELOG.md index a02ac157920..39cfd483a77 100644 --- a/crates/rpc-types-engine/CHANGELOG.md +++ b/crates/rpc-types-engine/CHANGELOG.md @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Features + +- [rpc-types-engine] Add forkchoice state zero helpers ([#1231](https://github.com/alloy-rs/alloy/issues/1231)) + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/rpc-types-eth/CHANGELOG.md b/crates/rpc-types-eth/CHANGELOG.md index f6cb2578afc..91abad35d20 100644 --- a/crates/rpc-types-eth/CHANGELOG.md +++ b/crates/rpc-types-eth/CHANGELOG.md @@ -5,6 +5,38 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.3](https://github.com/alloy-rs/alloy/releases/tag/v0.3.3) - 2024-09-10 + +### Miscellaneous Tasks + +- Require destination for 7702 ([#1262](https://github.com/alloy-rs/alloy/issues/1262)) + +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Bug Fixes + +- [consensus] Remove Unused Alloc Vecs ([#1250](https://github.com/alloy-rs/alloy/issues/1250)) + +### Features + +- No_std network primitives ([#1248](https://github.com/alloy-rs/alloy/issues/1248)) +- [rpc-types-eth] AnyBlock ([#1243](https://github.com/alloy-rs/alloy/issues/1243)) +- [network-primitives] Expose more fields via block response traits ([#1229](https://github.com/alloy-rs/alloy/issues/1229)) + +### Miscellaneous Tasks + +- Release 0.3.2 + +### Other + +- Add getter trait methods to `ReceiptResponse` ([#1251](https://github.com/alloy-rs/alloy/issues/1251)) + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/rpc-types-eth/Cargo.toml b/crates/rpc-types-eth/Cargo.toml index e1f36e74051..dde377f60c2 100644 --- a/crates/rpc-types-eth/Cargo.toml +++ b/crates/rpc-types-eth/Cargo.toml @@ -19,19 +19,22 @@ rustdoc-args = ["--cfg", "docsrs"] workspace = true [dependencies] -alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] } -alloy-primitives = { workspace = true, features = ["rlp", "serde", "std"] } alloy-serde.workspace = true - -alloy-consensus = { workspace = true, features = ["serde", "std"] } -alloy-eips = { workspace = true, features = ["serde", "std"] } - alloy-network-primitives.workspace = true +alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] } +alloy-primitives = { workspace = true, features = ["rlp", "serde"] } +alloy-consensus = { workspace = true, features = ["serde"] } +alloy-eips = { workspace = true, features = ["serde"] } + +derive_more = { workspace = true, features = ["display"] } itertools.workspace = true serde = { workspace = true, features = ["derive"] } serde_json.workspace = true -thiserror.workspace = true + +# `no_std` compatibility +cfg-if.workspace = true +hashbrown = { workspace = true, features = ["serde"] } # arbitrary arbitrary = { version = "1.3", features = ["derive"], optional = true } @@ -56,7 +59,10 @@ similar-asserts.workspace = true assert_matches.workspace = true [features] +default = ["std"] +std = ["alloy-primitives/std", "alloy-consensus/std", "alloy-eips/std"] arbitrary = [ + "std", "dep:arbitrary", "alloy-primitives/arbitrary", "alloy-serde/arbitrary", diff --git a/crates/rpc-types-eth/src/account.rs b/crates/rpc-types-eth/src/account.rs index 439e24dd5a3..26544f6a0ab 100644 --- a/crates/rpc-types-eth/src/account.rs +++ b/crates/rpc-types-eth/src/account.rs @@ -2,6 +2,8 @@ use alloy_primitives::{Address, Bytes, B256, B512, U256}; use alloy_serde::storage::JsonStorageKey; use serde::{Deserialize, Serialize}; +use alloc::{string::String, vec::Vec}; + // re-export account type for `eth_getAccount` pub use alloy_consensus::Account; diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index 5fd1cfa00e3..82aeebe3691 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -1,13 +1,15 @@ //! Block RPC types. use crate::{ConversionError, Transaction, Withdrawal}; +use alloc::collections::BTreeMap; use alloy_network_primitives::{ BlockResponse, BlockTransactions, HeaderResponse, TransactionResponse, }; use alloy_primitives::{Address, BlockHash, Bloom, Bytes, B256, B64, U256}; use alloy_serde::WithOtherFields; use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; + +use alloc::vec::Vec; pub use alloy_eips::{ calc_blob_gasprice, calc_excess_blob_gas, BlockHashOrNumber, BlockId, BlockNumHash, @@ -247,16 +249,26 @@ impl HeaderResponse for Header { } /// Error that can occur when converting other types to blocks -#[derive(Clone, Copy, Debug, thiserror::Error)] +#[derive(Clone, Copy, Debug, derive_more::Display)] pub enum BlockError { /// A transaction failed sender recovery - #[error("transaction failed sender recovery")] + #[display("transaction failed sender recovery")] InvalidSignature, /// A raw block failed to decode - #[error("failed to decode raw block {0}")] + #[display("failed to decode raw block {_0}")] RlpDecodeRawBlock(alloy_rlp::Error), } +#[cfg(feature = "std")] +impl std::error::Error for BlockError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::RlpDecodeRawBlock(err) => Some(err), + _ => None, + } + } +} + impl From for WithOtherFields { fn from(inner: Block) -> Self { Self { inner, other: Default::default() } diff --git a/crates/rpc-types-eth/src/call.rs b/crates/rpc-types-eth/src/call.rs index c7828a56aad..aeb2c1785ed 100644 --- a/crates/rpc-types-eth/src/call.rs +++ b/crates/rpc-types-eth/src/call.rs @@ -2,6 +2,12 @@ use crate::{request::TransactionRequest, BlockId, BlockOverrides}; use alloy_primitives::Bytes; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; + /// Bundle of transactions #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] diff --git a/crates/rpc-types-eth/src/erc4337.rs b/crates/rpc-types-eth/src/erc4337.rs index a4a3ea201bf..cf73d8d45bf 100644 --- a/crates/rpc-types-eth/src/erc4337.rs +++ b/crates/rpc-types-eth/src/erc4337.rs @@ -1,7 +1,8 @@ -use crate::{Log, TransactionReceipt}; +use crate::{collections::HashMap, Log, TransactionReceipt}; use alloy_primitives::{Address, BlockNumber, Bytes, B256, U256}; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; + +use alloc::vec::Vec; /// Options for conditional raw transaction submissions. // reference for the implementation diff --git a/crates/rpc-types-eth/src/fee.rs b/crates/rpc-types-eth/src/fee.rs index fb01699c4f9..946cfb46605 100644 --- a/crates/rpc-types-eth/src/fee.rs +++ b/crates/rpc-types-eth/src/fee.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use alloc::vec::Vec; + /// Internal struct to calculate reward percentiles #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[doc(alias = "TransactionGasAndReward")] @@ -11,13 +13,13 @@ pub struct TxGasAndReward { } impl PartialOrd for TxGasAndReward { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for TxGasAndReward { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { // compare only the reward // see: // diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index ef9ecf1e963..517259a355c 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -6,15 +6,18 @@ use serde::{ ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer, }; -use std::{ - collections::{ - hash_set::{IntoIter, Iter}, - HashSet, - }, + +use alloc::{format, string::String, vec::Vec}; + +use crate::collections::{ + hash_set::{IntoIter, Iter}, + HashSet, +}; +use core::{ hash::Hash, + iter::{FromIterator, IntoIterator}, ops::{RangeFrom, RangeInclusive, RangeToInclusive}, }; -use thiserror::Error; /// Helper type to represent a bloom filter used for matching logs. #[derive(Debug, Default)] @@ -46,7 +49,7 @@ impl From for FilterSet { } impl Hash for FilterSet { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { for value in &self.0 { value.hash(state); } @@ -154,10 +157,10 @@ impl From for Topic { } /// Represents errors that can occur when setting block filters in `FilterBlockOption`. -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, PartialEq, Eq, derive_more::Display)] pub enum FilterBlockError { /// Error indicating that the `from_block` is greater than the `to_block`. - #[error("`from_block` ({from}) is greater than `to_block` ({to})")] + #[display("`from_block` ({from}) is greater than `to_block` ({to})")] FromBlockGreaterThanToBlock { /// The starting block number, which is greater than `to`. from: u64, @@ -166,6 +169,9 @@ pub enum FilterBlockError { }, } +#[cfg(feature = "std")] +impl std::error::Error for FilterBlockError {} + /// Represents the target range of blocks for the filter #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum FilterBlockOption { @@ -593,7 +599,7 @@ impl<'de> Deserialize<'de> for Filter { impl<'de> Visitor<'de> for FilterVisitor { type Value = Filter; - fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { formatter.write_str("Filter object") } diff --git a/crates/rpc-types-eth/src/index.rs b/crates/rpc-types-eth/src/index.rs index b1183c9dc15..b583578670b 100644 --- a/crates/rpc-types-eth/src/index.rs +++ b/crates/rpc-types-eth/src/index.rs @@ -1,9 +1,10 @@ +use alloc::{format, string::String}; use alloy_primitives::U256; +use core::fmt; use serde::{ de::{Error, Visitor}, Deserialize, Deserializer, Serialize, Serializer, }; -use std::fmt; /// A hex encoded or decimal index that's intended to be used as a rust index, hence it's /// deserialized into a `usize`. diff --git a/crates/rpc-types-eth/src/lib.rs b/crates/rpc-types-eth/src/lib.rs index 14e020683df..c39a1a2c124 100644 --- a/crates/rpc-types-eth/src/lib.rs +++ b/crates/rpc-types-eth/src/lib.rs @@ -5,6 +5,21 @@ )] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(any(test, feature = "std")), no_std)] + +extern crate alloc; + +/// Standardized collections across `std` and `no_std` environments. +pub mod collections { + cfg_if::cfg_if! { + if #[cfg(feature = "std")] { + pub use std::collections::{hash_set, HashMap, HashSet}; + use hashbrown as _; + } else { + pub use hashbrown::{hash_set, HashMap, HashSet}; + } + } +} pub use alloy_eips::eip4895::Withdrawal; diff --git a/crates/rpc-types-eth/src/pubsub.rs b/crates/rpc-types-eth/src/pubsub.rs index b5e2dc512e7..f6e1ea335f2 100644 --- a/crates/rpc-types-eth/src/pubsub.rs +++ b/crates/rpc-types-eth/src/pubsub.rs @@ -1,6 +1,7 @@ //! Ethereum types for pub-sub use crate::{Filter, Header, Log, Transaction}; +use alloc::{boxed::Box, format}; use alloy_primitives::B256; use alloy_serde::WithOtherFields; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/crates/rpc-types-eth/src/raw_log.rs b/crates/rpc-types-eth/src/raw_log.rs index c1b3df43c47..53a13081d7e 100644 --- a/crates/rpc-types-eth/src/raw_log.rs +++ b/crates/rpc-types-eth/src/raw_log.rs @@ -3,6 +3,8 @@ use alloy_primitives::{Address, Bloom, Bytes, B256}; use alloy_rlp::{RlpDecodable, RlpEncodable}; +use alloc::vec::Vec; + /// Ethereum Log #[derive(Clone, Debug, Default, PartialEq, Eq, RlpDecodable, RlpEncodable)] pub struct Log { diff --git a/crates/rpc-types-eth/src/simulate.rs b/crates/rpc-types-eth/src/simulate.rs index be61122456c..e325c89ca37 100644 --- a/crates/rpc-types-eth/src/simulate.rs +++ b/crates/rpc-types-eth/src/simulate.rs @@ -1,10 +1,10 @@ //! 'eth_simulateV1' Request / Response types: -use alloy_primitives::{Address, Bytes, Log, B256}; +use crate::{state::StateOverride, Block, BlockOverrides, Log, TransactionRequest}; +use alloc::{string::String, vec::Vec}; +use alloy_primitives::Bytes; use serde::{Deserialize, Serialize}; -use crate::{state::StateOverride, BlockOverrides, TransactionRequest}; - /// The maximum number of blocks that can be simulated in a single request, pub const MAX_SIMULATE_BLOCKS: u64 = 256; @@ -15,47 +15,26 @@ pub const MAX_SIMULATE_BLOCKS: u64 = 256; #[serde(rename_all = "camelCase")] pub struct SimBlock { /// Modifications to the default block characteristics. - pub block_overrides: BlockOverrides, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub block_overrides: Option, /// State modifications to apply before executing the transactions. - pub state_overrides: StateOverride, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub state_overrides: Option, /// A vector of transactions to be simulated. pub calls: Vec, } + /// Represents the result of simulating a block. #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct SimulatedBlock { - /// The number of the block. - #[serde(with = "alloy_serde::quantity")] - pub number: u64, - /// The hash of the block. - pub hash: B256, - /// The timestamp of the block. - #[serde(with = "alloy_serde::quantity")] - pub timestamp: u64, - /// The gas limit of the block. - #[serde(with = "alloy_serde::quantity")] - pub gas_limit: u64, - /// The amount of gas used in the block. - #[serde(with = "alloy_serde::quantity")] - pub gas_used: u64, - /// The recipient of the block's fees. - pub fee_recipient: Address, - /// The base fee per gas unit for the block. - #[serde(with = "alloy_serde::quantity")] - pub base_fee_per_gas: u64, - /// The previous RANDAO value of the block. - pub prev_randao: B256, +pub struct SimulatedBlock { + /// The simulated block. + #[serde(flatten)] + pub inner: B, /// A vector of results for each call in the block. pub calls: Vec, } -/// The response type for the eth_simulateV1 method. -#[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct SimulateV1Response { - /// Simulated blocks vector. - pub simulated_blocks: Vec, -} + /// Captures the outcome of a transaction simulation. /// It includes the return value, logs produced, gas used, and the status of the transaction. #[derive(Clone, Debug, Serialize, Deserialize)] @@ -71,7 +50,7 @@ pub struct SimCallResult { pub gas_used: u64, /// The final status of the transaction, typically indicating success or failure. #[serde(with = "alloy_serde::quantity")] - pub status: u64, + pub status: bool, /// Error in case the call failed #[serde(default, skip_serializing_if = "Option::is_none")] pub error: Option, @@ -168,11 +147,21 @@ mod tests { assert_eq!(sim_opts.block_state_calls.len(), 2); let block_state_call_1 = &sim_opts.block_state_calls[0]; - assert!(block_state_call_1.state_overrides.contains_key(&address_1)); - assert_eq!(block_state_call_1.state_overrides.get(&address_1).unwrap().nonce.unwrap(), 5); + assert!(block_state_call_1.state_overrides.as_ref().unwrap().contains_key(&address_1)); + assert_eq!( + block_state_call_1 + .state_overrides + .as_ref() + .unwrap() + .get(&address_1) + .unwrap() + .nonce + .unwrap(), + 5 + ); let block_state_call_2 = &sim_opts.block_state_calls[1]; - assert!(block_state_call_2.state_overrides.contains_key(&address_1)); + assert!(block_state_call_2.state_overrides.as_ref().unwrap().contains_key(&address_1)); assert_eq!(block_state_call_2.calls.len(), 2); assert_eq!(block_state_call_2.calls[0].from.unwrap(), address_1); diff --git a/crates/rpc-types-eth/src/state.rs b/crates/rpc-types-eth/src/state.rs index 4746e5368da..e9ee08511ee 100644 --- a/crates/rpc-types-eth/src/state.rs +++ b/crates/rpc-types-eth/src/state.rs @@ -1,9 +1,9 @@ //! bindings for state overrides in eth_call -use crate::BlockOverrides; +use crate::{collections::HashMap, BlockOverrides}; +use alloc::boxed::Box; use alloy_primitives::{Address, Bytes, B256, U256}; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; /// A set of account overrides pub type StateOverride = HashMap; @@ -29,6 +29,11 @@ pub struct AccountOverride { /// the call. #[serde(default, skip_serializing_if = "Option::is_none")] pub state_diff: Option>, + /// Moves addresses precompile into the specified address. This move is done before the 'code' + /// override is set. When the specified address is not a precompile, the behaviour is undefined + /// and different clients might behave differently. + #[serde(default, skip_serializing_if = "Option::is_none", rename = "movePrecompileToAddress")] + pub move_precompile_to: Option
, } /// Helper type that bundles various overrides for EVM Execution. diff --git a/crates/rpc-types-eth/src/syncing.rs b/crates/rpc-types-eth/src/syncing.rs index f2fda6fdf17..2bfb26824d3 100644 --- a/crates/rpc-types-eth/src/syncing.rs +++ b/crates/rpc-types-eth/src/syncing.rs @@ -1,6 +1,7 @@ use alloy_primitives::{B512, U256}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::collections::BTreeMap; + +use alloc::{boxed::Box, collections::BTreeMap, string::String, vec::Vec}; /// Syncing info #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/rpc-types-eth/src/transaction/error.rs b/crates/rpc-types-eth/src/transaction/error.rs index b285cbb48a4..fdd90502512 100644 --- a/crates/rpc-types-eth/src/transaction/error.rs +++ b/crates/rpc-types-eth/src/transaction/error.rs @@ -1,73 +1,103 @@ -use std::num::TryFromIntError; +use core::num::TryFromIntError; + +use alloc::string::String; /// Error variants when converting from [crate::Transaction] to [alloy_consensus::Signed] /// transaction. -#[derive(Debug, thiserror::Error)] +#[derive(Debug, derive_more::Display)] pub enum ConversionError { /// Error during EIP-2718 transaction coding. - #[error(transparent)] - Eip2718Error(#[from] alloy_eips::eip2718::Eip2718Error), + #[display("{_0}")] + Eip2718Error(alloy_eips::eip2718::Eip2718Error), /// [`alloy_primitives::SignatureError`]. - #[error(transparent)] - SignatureError(#[from] alloy_primitives::SignatureError), + #[display("{_0}")] + SignatureError(alloy_primitives::SignatureError), /// Missing signature for transaction. - #[error("missing signature for transaction")] + #[display("missing signature for transaction")] MissingSignature, /// Missing y parity in signature. - #[error("missing y parity in signature")] + #[display("missing y parity in signature")] MissingYParity, /// Invalid signature - #[error("invalid signature")] + #[display("invalid signature")] InvalidSignature, /// Missing `chainId` field for EIP-1559 transaction. - #[error("missing `chainId` field for EIP-155 transaction")] + #[display("missing `chainId` field for EIP-155 transaction")] MissingChainId, /// Missing `gasPrice` field for Legacy transaction. - #[error("missing `gasPrice` field for Legacy transaction")] + #[display("missing `gasPrice` field for Legacy transaction")] MissingGasPrice, /// Missing `accessList` field for EIP-2930 transaction. - #[error("missing `accessList` field for EIP-2930 transaction")] + #[display("missing `accessList` field for EIP-2930 transaction")] MissingAccessList, /// Missing `maxFeePerGas` field for EIP-1559 transaction. - #[error("missing `maxFeePerGas` field for EIP-1559 transaction")] + #[display("missing `maxFeePerGas` field for EIP-1559 transaction")] MissingMaxFeePerGas, /// Missing `maxPriorityFeePerGas` field for EIP-1559 transaction. - #[error("missing `maxPriorityFeePerGas` field for EIP-1559 transaction")] + #[display("missing `maxPriorityFeePerGas` field for EIP-1559 transaction")] MissingMaxPriorityFeePerGas, /// Missing `maxFeePerBlobGas` field for EIP-1559 transaction. - #[error("missing `maxFeePerBlobGas` field for EIP-1559 transaction")] + #[display("missing `maxFeePerBlobGas` field for EIP-1559 transaction")] MissingMaxFeePerBlobGas, /// Missing `to` field for EIP-4844 transaction. - #[error("missing `to` field for EIP-4844 transaction")] + #[display("missing `to` field for EIP-4844 transaction")] MissingTo, /// Missing `blobVersionedHashes` field for EIP-4844 transaction. - #[error("missing `blobVersionedHashes` field for EIP-4844 transaction")] + #[display("missing `blobVersionedHashes` field for EIP-4844 transaction")] MissingBlobVersionedHashes, /// Missing `authorizationList` field for EIP-7702 transaction. - #[error("missing `authorizationList` field for EIP-7702 transaction")] + #[display("missing `authorizationList` field for EIP-7702 transaction")] MissingAuthorizationList, /// Missing full transactions required for block decoding - #[error("missing full transactions required for block decoding")] + #[display("missing full transactions required for block decoding")] MissingFullTransactions, /// Base fee per gas integer conversion error - #[error("base fee per gas integer conversion error: {0}")] + #[display("base fee per gas integer conversion error: {_0}")] BaseFeePerGasConversion(TryFromIntError), /// Gas limit integer conversion error - #[error("gas limit integer conversion error: {0}")] + #[display("gas limit integer conversion error: {_0}")] GasLimitConversion(TryFromIntError), /// Gas used integer conversion error - #[error("gas used integer conversion error: {0}")] + #[display("gas used integer conversion error: {_0}")] GasUsedConversion(TryFromIntError), /// Missing block number - #[error("missing block number")] + #[display("missing block number")] MissingBlockNumber, /// Blob gas used integer conversion error - #[error("blob gas used integer conversion error: {0}")] + #[display("blob gas used integer conversion error: {_0}")] BlobGasUsedConversion(TryFromIntError), /// Excess blob gas integer conversion error - #[error("excess blob gas integer conversion error: {0}")] + #[display("excess blob gas integer conversion error: {_0}")] ExcessBlobGasConversion(TryFromIntError), /// A custom Conversion Error that doesn't fit other categories. - #[error("conversion error: {0}")] + #[display("conversion error: {_0}")] Custom(String), } + +#[cfg(feature = "std")] +impl std::error::Error for ConversionError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::Eip2718Error(err) => Some(err), + Self::SignatureError(err) => Some(err), + Self::BaseFeePerGasConversion(err) => Some(err), + Self::GasLimitConversion(err) => Some(err), + Self::GasUsedConversion(err) => Some(err), + Self::BlobGasUsedConversion(err) => Some(err), + Self::ExcessBlobGasConversion(err) => Some(err), + _ => None, + } + } +} + +impl From for ConversionError { + fn from(err: alloy_eips::eip2718::Eip2718Error) -> Self { + Self::Eip2718Error(err) + } +} + +impl From for ConversionError { + fn from(err: alloy_primitives::SignatureError) -> Self { + Self::SignatureError(err) + } +} diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 6d6262cdd0f..3a46cfb3cc2 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -9,6 +9,8 @@ use alloy_network_primitives::TransactionResponse; use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, TxKind, B256, U256}; use serde::{Deserialize, Serialize}; +use alloc::vec::Vec; + pub use alloy_consensus::BlobTransactionSidecar; pub use alloy_eips::{ eip2930::{AccessList, AccessListItem, AccessListResult}, @@ -269,7 +271,7 @@ impl TryFrom for Signed { max_priority_fee_per_gas: tx .max_priority_fee_per_gas .ok_or(ConversionError::MissingMaxPriorityFeePerGas)?, - to: tx.to.into(), + to: tx.to.ok_or(ConversionError::MissingTo)?, value: tx.value, access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, authorization_list: tx @@ -325,8 +327,8 @@ mod tests { use super::*; use alloy_primitives::Signature as AlloySignature; use arbitrary::Arbitrary; + use core::str::FromStr; use rand::Rng; - use std::str::FromStr; #[test] fn arbitrary_transaction() { diff --git a/crates/rpc-types-eth/src/transaction/receipt.rs b/crates/rpc-types-eth/src/transaction/receipt.rs index 497e89e9d37..8714203ebc1 100644 --- a/crates/rpc-types-eth/src/transaction/receipt.rs +++ b/crates/rpc-types-eth/src/transaction/receipt.rs @@ -6,6 +6,8 @@ use alloy_primitives::{Address, BlockHash, TxHash, B256}; use alloy_serde::WithOtherFields; use serde::{Deserialize, Serialize}; +use alloc::vec::Vec; + /// Transaction receipt /// /// This type is generic over an inner [`ReceiptEnvelope`] which contains diff --git a/crates/rpc-types-eth/src/transaction/request.rs b/crates/rpc-types-eth/src/transaction/request.rs index aacd3f3af70..c7938f5b8ce 100644 --- a/crates/rpc-types-eth/src/transaction/request.rs +++ b/crates/rpc-types-eth/src/transaction/request.rs @@ -7,8 +7,14 @@ use alloy_consensus::{ }; use alloy_eips::eip7702::SignedAuthorization; use alloy_primitives::{Address, Bytes, ChainId, TxKind, B256, U256}; +use core::hash::Hash; use serde::{Deserialize, Serialize}; -use std::hash::Hash; + +use alloc::{ + string::{String, ToString}, + vec, + vec::Vec, +}; /// Represents _all_ transaction requests to/from RPC. #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] @@ -312,7 +318,7 @@ impl TransactionRequest { /// If required fields are missing. Use `complete_7702` to check if the /// request can be built. fn build_7702(self) -> Result { - let checked_to = self.to.ok_or("Missing 'to' field for Eip7702 transaction.")?; + let to_address = self.to.ok_or("Missing 'to' field for Eip7702 transaction.")?.to().copied().ok_or("The field `to` can only be of type TxKind::Call(Account). Please change it accordingly.")?; Ok(TxEip7702 { chain_id: self.chain_id.unwrap_or(1), @@ -324,7 +330,7 @@ impl TransactionRequest { max_priority_fee_per_gas: self .max_priority_fee_per_gas .ok_or("Missing 'max_priority_fee_per_gas' field for Eip7702 transaction.")?, - to: checked_to, + to: to_address, value: self.value.unwrap_or_default(), input: self.input.into_input().unwrap_or_default(), access_list: self.access_list.unwrap_or_default(), @@ -808,7 +814,7 @@ impl From for TransactionRequest { impl From for TransactionRequest { fn from(tx: TxEip7702) -> Self { Self { - to: if let TxKind::Call(to) = tx.to { Some(to.into()) } else { None }, + to: Some(tx.to.into()), gas: Some(tx.gas_limit), max_fee_per_gas: Some(tx.max_fee_per_gas), max_priority_fee_per_gas: Some(tx.max_priority_fee_per_gas), @@ -930,12 +936,15 @@ impl From for TransactionRequest { } /// Error thrown when both `data` and `input` fields are set and not equal. -#[derive(Debug, Default, thiserror::Error)] -#[error("both \"data\" and \"input\" are set and not equal. Please use \"input\" to pass transaction call data")] +#[derive(Debug, Default, derive_more::Display)] +#[display("both \"data\" and \"input\" are set and not equal. Please use \"input\" to pass transaction call data")] #[doc(alias = "TxInputError")] #[non_exhaustive] pub struct TransactionInputError; +#[cfg(feature = "std")] +impl std::error::Error for TransactionInputError {} + /// Error thrown when a transaction request cannot be built into a transaction. #[derive(Debug)] pub struct BuildTransactionErr { diff --git a/crates/rpc-types-eth/src/transaction/signature.rs b/crates/rpc-types-eth/src/transaction/signature.rs index 5599fc9afc6..8a32476c575 100644 --- a/crates/rpc-types-eth/src/transaction/signature.rs +++ b/crates/rpc-types-eth/src/transaction/signature.rs @@ -2,6 +2,8 @@ use alloy_primitives::U256; use serde::{Deserialize, Serialize}; +use alloc::{format, string::String}; + /// Container type for all signature fields in RPC #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -89,7 +91,7 @@ impl From for Signature { #[cfg(test)] mod tests { use super::*; - use std::str::FromStr; + use core::str::FromStr; #[test] fn deserialize_without_parity() { diff --git a/crates/rpc-types-eth/src/work.rs b/crates/rpc-types-eth/src/work.rs index b0d2a1fb7a3..cf8ec8666a7 100644 --- a/crates/rpc-types-eth/src/work.rs +++ b/crates/rpc-types-eth/src/work.rs @@ -1,9 +1,9 @@ use alloy_primitives::{B256, U256}; +use core::fmt; use serde::{ de::{Error, SeqAccess, Visitor}, Deserialize, Deserializer, Serialize, Serializer, }; -use std::fmt; /// The result of an `eth_getWork` request #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] diff --git a/crates/rpc-types-mev/CHANGELOG.md b/crates/rpc-types-mev/CHANGELOG.md index d2989edff30..9155ac895a6 100644 --- a/crates/rpc-types-mev/CHANGELOG.md +++ b/crates/rpc-types-mev/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/rpc-types-trace/CHANGELOG.md b/crates/rpc-types-trace/CHANGELOG.md index a76bb7a0944..9c973121fa3 100644 --- a/crates/rpc-types-trace/CHANGELOG.md +++ b/crates/rpc-types-trace/CHANGELOG.md @@ -5,6 +5,28 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.3](https://github.com/alloy-rs/alloy/releases/tag/v0.3.3) - 2024-09-10 + +### Bug Fixes + +- [rpc-types-trace] Use rpc-types Log in OtsReceipt ([#1261](https://github.com/alloy-rs/alloy/issues/1261)) + +### Features + +- [rpc-types-trace] Always serialize result if no error ([#1258](https://github.com/alloy-rs/alloy/issues/1258)) + +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Bug Fixes diff --git a/crates/rpc-types-trace/Cargo.toml b/crates/rpc-types-trace/Cargo.toml index 7181ff4755f..cdd3e7322b8 100644 --- a/crates/rpc-types-trace/Cargo.toml +++ b/crates/rpc-types-trace/Cargo.toml @@ -20,7 +20,7 @@ workspace = true [dependencies] alloy-primitives = { workspace = true, features = ["rlp", "serde"] } -alloy-rpc-types-eth.workspace = true +alloy-rpc-types-eth = { workspace = true, features = ["std"] } alloy-serde.workspace = true serde.workspace = true diff --git a/crates/rpc-types-trace/src/otterscan.rs b/crates/rpc-types-trace/src/otterscan.rs index 8c93ca9c9d9..903edf5a594 100644 --- a/crates/rpc-types-trace/src/otterscan.rs +++ b/crates/rpc-types-trace/src/otterscan.rs @@ -4,7 +4,7 @@ //! use alloy_primitives::{Address, Bloom, Bytes, TxHash, B256, U256}; -use alloy_rpc_types_eth::{Block, Header, Transaction, TransactionReceipt, Withdrawal}; +use alloy_rpc_types_eth::{Block, Header, Log, Transaction, TransactionReceipt, Withdrawal}; use serde::{ de::{self, Unexpected}, Deserialize, Deserializer, Serialize, Serializer, @@ -204,7 +204,7 @@ pub struct OtsReceipt { /// The logs sent from contracts. /// /// Note: this is set to null. - pub logs: Option>, + pub logs: Option>, /// The bloom filter. /// /// Note: this is set to null. diff --git a/crates/rpc-types-trace/src/parity.rs b/crates/rpc-types-trace/src/parity.rs index b6794694eb7..a740bd14780 100644 --- a/crates/rpc-types-trace/src/parity.rs +++ b/crates/rpc-types-trace/src/parity.rs @@ -429,6 +429,7 @@ pub struct TransactionTrace { #[serde(skip_serializing_if = "Option::is_none")] pub error: Option, /// Output of the trace, can be CALL or CREATE + #[serde(default)] pub result: Option, /// How many subtraces this trace has. pub subtraces: usize, @@ -498,15 +499,10 @@ impl Serialize for LocalizedTransactionTrace { if let Some(error) = error { s.serialize_field("error", error)?; } - match result { - Some(TraceOutput::Call(call)) => { - s.serialize_field("result", call)?; - } - Some(TraceOutput::Create(create)) => { - s.serialize_field("result", create)?; - } - None => {} + Some(TraceOutput::Call(call)) => s.serialize_field("result", call)?, + Some(TraceOutput::Create(create)) => s.serialize_field("result", create)?, + None => s.serialize_field("result", &None::<()>)?, } s.serialize_field("subtraces", &subtraces)?; @@ -822,6 +818,47 @@ mod tests { let serialized = serde_json::to_string_pretty(&trace).unwrap(); similar_asserts::assert_eq!(serialized, reference_data); } + + #[test] + fn test_transaction_trace_null_result() { + let trace = TransactionTrace { + action: Action::Call(CallAction { + from: Address::from_str("0x1234567890123456789012345678901234567890").unwrap(), + call_type: CallType::Call, + gas: 100000, + input: Bytes::from_str("0x1234").unwrap(), + to: Address::from_str("0x0987654321098765432109876543210987654321").unwrap(), + value: U256::from(0), + }), + ..Default::default() + }; + + let serialized = serde_json::to_string(&trace).unwrap(); + let deserialized: serde_json::Value = serde_json::from_str(&serialized).unwrap(); + + assert_eq!(deserialized["result"], serde_json::Value::Null); + assert!(deserialized.as_object().unwrap().contains_key("result")); + assert!(!deserialized.as_object().unwrap().contains_key("error")); + + let deserialized_trace: TransactionTrace = serde_json::from_str(&serialized).unwrap(); + assert_eq!(deserialized_trace.result, None); + } + + #[test] + fn test_transaction_trace_error_result() { + let trace = TransactionTrace { error: Some("Reverted".to_string()), ..Default::default() }; + + let serialized = serde_json::to_string(&trace).unwrap(); + let deserialized: serde_json::Value = serde_json::from_str(&serialized).unwrap(); + + assert_eq!(deserialized["result"], serde_json::Value::Null); + assert!(deserialized.as_object().unwrap().contains_key("result")); + assert!(deserialized.as_object().unwrap().contains_key("error")); + + let deserialized_trace: TransactionTrace = serde_json::from_str(&serialized).unwrap(); + assert_eq!(deserialized_trace.result, None); + } + #[test] fn test_nethermind_trace_result_null_output_value() { let reference_data = r#"{ diff --git a/crates/rpc-types-txpool/CHANGELOG.md b/crates/rpc-types-txpool/CHANGELOG.md index 659a3fcd676..34804304166 100644 --- a/crates/rpc-types-txpool/CHANGELOG.md +++ b/crates/rpc-types-txpool/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Features diff --git a/crates/rpc-types/CHANGELOG.md b/crates/rpc-types/CHANGELOG.md index 8e8008ac46a..3712b7274a8 100644 --- a/crates/rpc-types/CHANGELOG.md +++ b/crates/rpc-types/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Dependencies diff --git a/crates/rpc-types/Cargo.toml b/crates/rpc-types/Cargo.toml index bc5d58e1e27..0027917ddc5 100644 --- a/crates/rpc-types/Cargo.toml +++ b/crates/rpc-types/Cargo.toml @@ -35,7 +35,7 @@ serde = { workspace = true, features = ["derive", "std"] } serde_json.workspace = true [features] -default = ["eth", "alloy-rpc-types-engine?/default"] +default = ["eth", "alloy-rpc-types-engine?/default", "alloy-rpc-types-eth?/default"] admin = ["dep:alloy-rpc-types-admin"] anvil = ["dep:alloy-rpc-types-anvil"] beacon = ["dep:alloy-rpc-types-beacon"] diff --git a/crates/serde/CHANGELOG.md b/crates/serde/CHANGELOG.md index 1bfadc52d40..1c4ea73de15 100644 --- a/crates/serde/CHANGELOG.md +++ b/crates/serde/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/signer-aws/CHANGELOG.md b/crates/signer-aws/CHANGELOG.md index d4bb9f32e1e..425f689aa40 100644 --- a/crates/signer-aws/CHANGELOG.md +++ b/crates/signer-aws/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/signer-gcp/CHANGELOG.md b/crates/signer-gcp/CHANGELOG.md index ea4c97e1900..f4fbcb20723 100644 --- a/crates/signer-gcp/CHANGELOG.md +++ b/crates/signer-gcp/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Dependencies diff --git a/crates/signer-ledger/CHANGELOG.md b/crates/signer-ledger/CHANGELOG.md index b02d7671342..ff9c08f2d01 100644 --- a/crates/signer-ledger/CHANGELOG.md +++ b/crates/signer-ledger/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Dependencies diff --git a/crates/signer-local/CHANGELOG.md b/crates/signer-local/CHANGELOG.md index 82908cd00df..1f750484ca2 100644 --- a/crates/signer-local/CHANGELOG.md +++ b/crates/signer-local/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Dependencies diff --git a/crates/signer-trezor/CHANGELOG.md b/crates/signer-trezor/CHANGELOG.md index f3629b8e143..caf1d6ec28f 100644 --- a/crates/signer-trezor/CHANGELOG.md +++ b/crates/signer-trezor/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Dependencies diff --git a/crates/signer/CHANGELOG.md b/crates/signer/CHANGELOG.md index efca8a2e14d..86526cebe52 100644 --- a/crates/signer/CHANGELOG.md +++ b/crates/signer/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Features diff --git a/crates/transport-http/CHANGELOG.md b/crates/transport-http/CHANGELOG.md index a2b88a9d0af..a6adeaf56a4 100644 --- a/crates/transport-http/CHANGELOG.md +++ b/crates/transport-http/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/transport-ipc/CHANGELOG.md b/crates/transport-ipc/CHANGELOG.md index 90545888075..d9769994646 100644 --- a/crates/transport-ipc/CHANGELOG.md +++ b/crates/transport-ipc/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/transport-ws/CHANGELOG.md b/crates/transport-ws/CHANGELOG.md index 036104ab7d5..86935a70de6 100644 --- a/crates/transport-ws/CHANGELOG.md +++ b/crates/transport-ws/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Miscellaneous Tasks diff --git a/crates/transport/CHANGELOG.md b/crates/transport/CHANGELOG.md index 61ecee9f62e..9bf42aaafb7 100644 --- a/crates/transport/CHANGELOG.md +++ b/crates/transport/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2](https://github.com/alloy-rs/alloy/releases/tag/v0.3.2) - 2024-09-09 + +### Miscellaneous Tasks + +- Release 0.3.2 + +## [0.3.1](https://github.com/alloy-rs/alloy/releases/tag/v0.3.1) - 2024-09-02 + +### Miscellaneous Tasks + +- Release 0.3.1 + ## [0.3.0](https://github.com/alloy-rs/alloy/releases/tag/v0.3.0) - 2024-08-28 ### Documentation diff --git a/scripts/check_no_std.sh b/scripts/check_no_std.sh index 1aa49ec6d64..dd2f00262e0 100755 --- a/scripts/check_no_std.sh +++ b/scripts/check_no_std.sh @@ -1,24 +1,20 @@ #!/usr/bin/env bash set -eo pipefail -no_std_packages=( +target=riscv32imac-unknown-none-elf +crates=( alloy-eips alloy-genesis alloy-serde alloy-consensus + alloy-network-primitives + alloy-rpc-types-eth ) -for package in "${no_std_packages[@]}"; do - cmd="cargo +stable build -p $package --target riscv32imac-unknown-none-elf --no-default-features" - if [ -n "$CI" ]; then - echo "::group::$cmd" - else - printf "\n%s:\n %s\n" "$package" "$cmd" - fi - - $cmd - - if [ -n "$CI" ]; then - echo "::endgroup::" - fi +cmd=(cargo +stable hack check --no-default-features --target "$target") +for crate in "${crates[@]}"; do + cmd+=(-p "$crate") done + +echo "Running: ${cmd[*]}" +"${cmd[@]}" From 072cc26876e1b097f31b1d66fa342365cb260afb Mon Sep 17 00:00:00 2001 From: zerosnacks <95942363+zerosnacks@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:01:47 +0200 Subject: [PATCH 16/20] Update crates/rpc-types-eth/src/call.rs Co-authored-by: Matthias Seitz --- crates/rpc-types-eth/src/call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rpc-types-eth/src/call.rs b/crates/rpc-types-eth/src/call.rs index aeb2c1785ed..b82ed58394a 100644 --- a/crates/rpc-types-eth/src/call.rs +++ b/crates/rpc-types-eth/src/call.rs @@ -15,7 +15,7 @@ pub struct Bundle { /// All transactions to execute pub transactions: Vec, /// Block overrides to apply - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub block_override: Option, } From 4f317509da81e98f9f7aac15974ec462340e1f67 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 12:04:06 +0000 Subject: [PATCH 17/20] re-export TraceCallList --- crates/provider/src/ext/mod.rs | 2 +- crates/provider/src/ext/trace.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/provider/src/ext/mod.rs b/crates/provider/src/ext/mod.rs index edcbac4c15b..a5f5c185a20 100644 --- a/crates/provider/src/ext/mod.rs +++ b/crates/provider/src/ext/mod.rs @@ -28,7 +28,7 @@ pub use net::NetApi; #[cfg(feature = "trace-api")] mod trace; #[cfg(feature = "trace-api")] -pub use trace::TraceApi; +pub use trace::{TraceApi, TraceCallList}; #[cfg(feature = "rpc-api")] mod rpc; diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 7908c94fb87..3e1c286f147 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -11,7 +11,7 @@ use alloy_rpc_types_trace::{ use alloy_transport::{Transport, TransportResult}; /// List of trace calls for use with [`TraceApi::trace_call_many`] -type TraceCallList<'a, N> = &'a [(::TransactionRequest, &'a [TraceType])]; +pub type TraceCallList<'a, N> = &'a [(::TransactionRequest, &'a [TraceType])]; /// Trace namespace rpc interface that gives access to several non-standard RPC methods. #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] From 0dc8adcb13cbcf663cdea9b6125876b738027960 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 12:12:13 +0000 Subject: [PATCH 18/20] add back `init_tracing` --- crates/provider/src/chain.rs | 8 ++++++ crates/provider/src/ext/debug.rs | 6 +++++ crates/provider/src/provider/trait.rs | 38 +++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/crates/provider/src/chain.rs b/crates/provider/src/chain.rs index 1734bd73622..b69c0f6b700 100644 --- a/crates/provider/src/chain.rs +++ b/crates/provider/src/chain.rs @@ -134,6 +134,10 @@ mod tests { use super::*; + fn init_tracing() { + let _ = tracing_subscriber::fmt::try_init(); + } + async fn with_timeout(fut: T) -> T::Output { tokio::select! { _ = tokio::time::sleep(Duration::from_secs(1)) => panic!("Operation timed out"), @@ -143,6 +147,8 @@ mod tests { #[tokio::test] async fn yield_block() { + init_tracing(); + let anvil = Anvil::new().spawn(); let client = ReqwestClient::new_http(anvil.endpoint_url()); @@ -163,6 +169,8 @@ mod tests { // Make sure that we can process more blocks than fits in the cache. const BLOCKS_TO_MINE: usize = BLOCK_CACHE_SIZE.get() + 1; + init_tracing(); + let anvil = Anvil::new().spawn(); let client = ReqwestClient::new_http(anvil.endpoint_url()); diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index c9a8d10813a..7477cc2f2ae 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -228,8 +228,13 @@ mod test { use alloy_node_bindings::{utils::run_with_tempdir, Geth, Reth}; use alloy_primitives::{address, U256}; + fn init_tracing() { + let _ = tracing_subscriber::fmt::try_init(); + } + #[tokio::test] async fn debug_trace_transaction() { + init_tracing(); let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let from = provider.default_signer_address(); @@ -255,6 +260,7 @@ mod test { #[tokio::test] async fn debug_trace_call() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil_with_wallet(); let from = provider.default_signer_address(); let gas_price = provider.get_gas_price().await.unwrap(); diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index cd49d21e56a..17393c9c35e 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -1014,8 +1014,13 @@ mod tests { use alloy_primitives::{address, b256, bytes, keccak256}; use alloy_rpc_types_eth::{request::TransactionRequest, Block}; + fn init_tracing() { + let _ = tracing_subscriber::fmt::try_init(); + } + #[tokio::test] async fn test_provider_builder() { + init_tracing(); let provider = RootProvider::::builder().with_recommended_fillers().on_anvil(); let num = provider.get_block_number().await.unwrap(); @@ -1024,6 +1029,7 @@ mod tests { #[tokio::test] async fn test_builder_helper_fn() { + init_tracing(); let provider = builder().with_recommended_fillers().on_anvil(); let num = provider.get_block_number().await.unwrap(); assert_eq!(0, num); @@ -1031,6 +1037,7 @@ mod tests { #[tokio::test] async fn test_builder_helper_fn_any_network() { + init_tracing(); let anvil = Anvil::new().spawn(); let provider = builder::().with_recommended_fillers().on_http(anvil.endpoint_url()); @@ -1041,6 +1048,7 @@ mod tests { #[cfg(feature = "reqwest")] #[tokio::test] async fn object_safety() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); // These blocks are not necessary. @@ -1076,6 +1084,8 @@ mod tests { #[cfg(feature = "ws")] #[tokio::test] async fn subscribe_blocks_http() { + init_tracing(); + let provider = ProviderBuilder::new().on_anvil_with_config(|a| a.block_time(1)); let err = provider.subscribe_blocks().await.unwrap_err(); @@ -1104,6 +1114,7 @@ mod tests { async fn subscribe_blocks_ws() { use futures::stream::StreamExt; + init_tracing(); let anvil = Anvil::new().block_time(1).spawn(); let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint()); let client = alloy_rpc_client::RpcClient::connect_pubsub(ws).await.unwrap(); @@ -1124,6 +1135,7 @@ mod tests { async fn subscribe_blocks_ws_boxed() { use futures::stream::StreamExt; + init_tracing(); let anvil = Anvil::new().block_time(1).spawn(); let ws = alloy_rpc_client::WsConnect::new(anvil.ws_endpoint()); let client = alloy_rpc_client::RpcClient::connect_pubsub(ws).await.unwrap(); @@ -1145,6 +1157,7 @@ mod tests { async fn subscribe_blocks_ws_remote() { use futures::stream::StreamExt; + init_tracing(); let url = "wss://eth-mainnet.g.alchemy.com/v2/viFmeVzhg6bWKVMIWWS8MhmzREB-D4f7"; let ws = alloy_rpc_client::WsConnect::new(url); let Ok(client) = alloy_rpc_client::RpcClient::connect_pubsub(ws).await else { return }; @@ -1159,6 +1172,7 @@ mod tests { #[tokio::test] async fn test_send_tx() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let tx = TransactionRequest { value: Some(U256::from(100)), @@ -1182,6 +1196,7 @@ mod tests { #[tokio::test] async fn test_watch_confirmed_tx() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let tx = TransactionRequest { value: Some(U256::from(100)), @@ -1229,6 +1244,7 @@ mod tests { #[tokio::test] async fn gets_block_number() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = provider.get_block_number().await.unwrap(); assert_eq!(0, num) @@ -1236,6 +1252,7 @@ mod tests { #[tokio::test] async fn gets_block_number_with_raw_req() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num: U64 = provider.raw_request("eth_blockNumber".into(), NoParams::default()).await.unwrap(); @@ -1244,6 +1261,7 @@ mod tests { #[tokio::test] async fn gets_transaction_count() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let count = provider .get_transaction_count(address!("328375e18E7db8F1CA9d9bA8bF3E9C94ee34136A")) @@ -1254,6 +1272,7 @@ mod tests { #[tokio::test] async fn gets_block_by_hash() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1266,6 +1285,7 @@ mod tests { #[tokio::test] async fn gets_block_by_hash_with_raw_req() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1280,6 +1300,7 @@ mod tests { #[tokio::test] async fn gets_block_by_number_full() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1289,6 +1310,7 @@ mod tests { #[tokio::test] async fn gets_block_by_number() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let num = 0; let tag: BlockNumberOrTag = num.into(); @@ -1298,6 +1320,7 @@ mod tests { #[tokio::test] async fn gets_client_version() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let version = provider.get_client_version().await.unwrap(); assert!(version.contains("anvil"), "{version}"); @@ -1305,6 +1328,7 @@ mod tests { #[tokio::test] async fn gets_sha3() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let data = b"alloy"; let hash = provider.get_sha3(data).await.unwrap(); @@ -1332,6 +1356,7 @@ mod tests { #[tokio::test] async fn gets_storage_at() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let addr = Address::with_last_byte(16); let storage = provider.get_storage_at(addr, U256::ZERO).await.unwrap(); @@ -1340,6 +1365,8 @@ mod tests { #[tokio::test] async fn gets_transaction_by_hash_not_found() { + init_tracing(); + let provider = ProviderBuilder::new().on_anvil(); let tx_hash = b256!("5c03fab9114ceb98994b43892ade87ddfd9ae7e8f293935c3bd29d435dc9fd95"); let tx = provider.get_transaction_by_hash(tx_hash).await.expect("failed to fetch tx"); @@ -1349,6 +1376,7 @@ mod tests { #[tokio::test] async fn gets_transaction_by_hash() { + init_tracing(); let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let req = TransactionRequest::default() @@ -1370,6 +1398,7 @@ mod tests { #[tokio::test] #[ignore] async fn gets_logs() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let filter = Filter::new() .at_block_hash(b256!( @@ -1385,6 +1414,7 @@ mod tests { #[tokio::test] #[ignore] async fn gets_tx_receipt() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let receipt = provider .get_transaction_receipt(b256!( @@ -1402,12 +1432,14 @@ mod tests { #[tokio::test] async fn gets_max_priority_fee_per_gas() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let _fee = provider.get_max_priority_fee_per_gas().await.unwrap(); } #[tokio::test] async fn gets_fee_history() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let block_number = provider.get_block_number().await.unwrap(); let fee_history = provider @@ -1423,6 +1455,7 @@ mod tests { #[tokio::test] async fn gets_block_receipts() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let receipts = provider.get_block_receipts(BlockId::Number(BlockNumberOrTag::Latest)).await.unwrap(); @@ -1431,6 +1464,7 @@ mod tests { #[tokio::test] async fn sends_raw_transaction() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let pending = provider .send_raw_transaction( @@ -1446,6 +1480,7 @@ mod tests { #[tokio::test] async fn connect_boxed() { + init_tracing(); let anvil = Anvil::new().spawn(); let provider = @@ -1468,6 +1503,7 @@ mod tests { #[tokio::test] async fn test_uncle_count() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let count = provider.get_uncle_count(0.into()).await.unwrap(); @@ -1484,6 +1520,7 @@ mod tests { use alloy_network::TransactionBuilder; use alloy_sol_types::SolValue; + init_tracing(); let url = "https://eth-mainnet.alchemyapi.io/v2/jGiK5vwDfC3F4r0bqukm-W2GqgdrxdSr"; let provider = ProviderBuilder::new().on_http(url.parse().unwrap()); let req = TransactionRequest::default() @@ -1495,6 +1532,7 @@ mod tests { #[tokio::test] async fn test_empty_transactions() { + init_tracing(); let provider = ProviderBuilder::new().on_anvil(); let block = provider.get_block_by_number(0.into(), false).await.unwrap().unwrap(); From f3f6340d9e8855c20151d1cbd57ce580c25a4c6c Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 12:15:31 +0000 Subject: [PATCH 19/20] undo unrelated test_* prefix changes in anvil tests --- crates/provider/src/ext/anvil.rs | 62 ++++++++++++++++---------------- crates/provider/src/ext/debug.rs | 4 +-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index 9768c30794e..71ca0ff5e53 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -322,7 +322,7 @@ mod tests { // use alloy_node_bindings::Anvil; (to be used in `test_anvil_reset`) #[tokio::test] - async fn anvil_impersonate_account_stop_impersonating_account() { + async fn test_anvil_impersonate_account_stop_impersonating_account() { let provider = ProviderBuilder::new().on_anvil(); let impersonate = Address::random(); @@ -358,7 +358,7 @@ mod tests { } #[tokio::test] - async fn anvil_auto_impersonate_account() { + async fn test_anvil_auto_impersonate_account() { let provider = ProviderBuilder::new().on_anvil(); let impersonate = Address::random(); @@ -396,7 +396,7 @@ mod tests { } #[tokio::test] - async fn anvil_get_auto_mine_set_auto_mine() { + async fn test_anvil_get_auto_mine_set_auto_mine() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -411,7 +411,7 @@ mod tests { } #[tokio::test] - async fn anvil_mine() { + async fn test_anvil_mine() { let provider = ProviderBuilder::new().on_anvil(); let start_num = provider.get_block_number().await.unwrap(); @@ -424,7 +424,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_interval_mining() { + async fn test_anvil_set_interval_mining() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_interval_mining(1).await.unwrap(); @@ -439,7 +439,7 @@ mod tests { } #[tokio::test] - async fn anvil_drop_transaction() { + async fn test_anvil_drop_transaction() { let provider = ProviderBuilder::new().on_anvil_with_wallet(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -467,7 +467,7 @@ mod tests { } #[tokio::test] - async fn anvil_drop_all_transactions() { + async fn test_anvil_drop_all_transactions() { let provider = ProviderBuilder::new().on_anvil_with_wallet(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -520,7 +520,7 @@ mod tests { // } #[tokio::test] - async fn anvil_set_chain_id() { + async fn test_anvil_set_chain_id() { let provider = ProviderBuilder::new().on_anvil(); let chain_id = 1337; @@ -531,7 +531,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_balance() { + async fn test_anvil_set_balance() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -543,7 +543,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_code() { + async fn test_anvil_set_code() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -554,7 +554,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_nonce() { + async fn test_anvil_set_nonce() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -566,7 +566,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_storage_at() { + async fn test_anvil_set_storage_at() { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); @@ -579,14 +579,14 @@ mod tests { } #[tokio::test] - async fn anvil_set_logging() { + async fn test_anvil_set_logging() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_logging(true).await.unwrap(); } #[tokio::test] - async fn anvil_set_min_gas_price() { + async fn test_anvil_set_min_gas_price() { let provider = ProviderBuilder::new().on_anvil(); let gas = U256::from(1337); @@ -600,7 +600,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_next_block_base_fee_per_gas() { + async fn test_anvil_set_next_block_base_fee_per_gas() { let provider = ProviderBuilder::new().on_anvil(); let basefee = U256::from(1337); @@ -615,7 +615,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_coinbase() { + async fn test_anvil_set_coinbase() { let provider = ProviderBuilder::new().on_anvil(); let coinbase = Address::random(); @@ -629,7 +629,7 @@ mod tests { } #[tokio::test] - async fn anvil_dump_state_load_state() { + async fn test_anvil_dump_state_load_state() { let provider = ProviderBuilder::new().on_anvil(); let state = provider.anvil_dump_state().await.unwrap(); @@ -642,7 +642,7 @@ mod tests { } #[tokio::test] - async fn anvil_node_info() { + async fn test_anvil_node_info() { let provider = ProviderBuilder::new().on_anvil(); let latest_block = @@ -656,7 +656,7 @@ mod tests { } #[tokio::test] - async fn anvil_metadata() { + async fn test_anvil_metadata() { let provider = ProviderBuilder::new().on_anvil(); let client_version = provider.get_client_version().await.unwrap(); @@ -669,7 +669,7 @@ mod tests { } #[tokio::test] - async fn anvil_remove_pool_transactions() { + async fn test_anvil_remove_pool_transactions() { let provider = ProviderBuilder::new().on_anvil_with_wallet(); provider.anvil_set_auto_mine(false).await.unwrap(); @@ -698,7 +698,7 @@ mod tests { } #[tokio::test] - async fn anvil_snapshot_revert() { + async fn test_anvil_snapshot_revert() { let provider = ProviderBuilder::new().on_anvil(); let snapshot_id = provider.anvil_snapshot().await.unwrap(); @@ -734,7 +734,7 @@ mod tests { } #[tokio::test] - async fn anvil_increase_time() { + async fn test_anvil_increase_time() { let provider = ProviderBuilder::new().on_anvil(); let timestamp = provider @@ -751,7 +751,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_next_block_timestamp() { + async fn test_anvil_set_next_block_timestamp() { let provider = ProviderBuilder::new().on_anvil(); let timestamp = provider @@ -772,7 +772,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_time() { + async fn test_anvil_set_time() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_time(0).await.unwrap(); @@ -783,7 +783,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_block_gas_limit() { + async fn test_anvil_set_block_gas_limit() { let provider = ProviderBuilder::new().on_anvil(); let block_gas_limit = U256::from(1337); @@ -797,7 +797,7 @@ mod tests { } #[tokio::test] - async fn anvil_set_block_timestamp_interval_anvil_remove_block_timestamp_interval() { + async fn test_anvil_set_block_timestamp_interval_anvil_remove_block_timestamp_interval() { let provider = ProviderBuilder::new().on_anvil(); provider.anvil_set_block_timestamp_interval(1).await.unwrap(); @@ -840,7 +840,7 @@ mod tests { } #[tokio::test] - async fn evm_mine_single_block() { + async fn test_evm_mine_single_block() { let provider = ProviderBuilder::new().on_anvil(); let start_num = provider.get_block_number().await.unwrap(); @@ -872,7 +872,7 @@ mod tests { // } #[tokio::test] - async fn anvil_mine_detailed_single_block() { + async fn test_anvil_mine_detailed_single_block() { let provider = ProviderBuilder::new().on_anvil(); let start_num = provider.get_block_number().await.unwrap(); @@ -889,7 +889,7 @@ mod tests { // TODO: Fix this test, only a single block is being mined regardless of the `blocks` parameter. // #[tokio::test] - // async fn anvil_mine_detailed_with_configuration() { + // async fn test_anvil_mine_detailed_with_configuration() { // let provider = ProviderBuilder::new().on_anvil(); // let start_num = provider.get_block_number().await.unwrap(); @@ -911,7 +911,7 @@ mod tests { // } #[tokio::test] - async fn anvil_set_rpc_url() { + async fn test_anvil_set_rpc_url() { let provider = ProviderBuilder::new().on_anvil(); let url = "https://example.com".to_string(); @@ -919,7 +919,7 @@ mod tests { } #[tokio::test] - async fn eth_send_unsigned_transaction() { + async fn test_eth_send_unsigned_transaction() { let provider = ProviderBuilder::new().on_anvil(); let alice = Address::random(); diff --git a/crates/provider/src/ext/debug.rs b/crates/provider/src/ext/debug.rs index 7477cc2f2ae..7a8265ed94c 100644 --- a/crates/provider/src/ext/debug.rs +++ b/crates/provider/src/ext/debug.rs @@ -233,7 +233,7 @@ mod test { } #[tokio::test] - async fn debug_trace_transaction() { + async fn test_debug_trace_transaction() { init_tracing(); let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); let from = provider.default_signer_address(); @@ -259,7 +259,7 @@ mod test { } #[tokio::test] - async fn debug_trace_call() { + async fn test_debug_trace_call() { init_tracing(); let provider = ProviderBuilder::new().on_anvil_with_wallet(); let from = provider.default_signer_address(); From 7f76e24c729f8a9ad588f3af576287e5776ef896 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 11 Sep 2024 12:17:01 +0000 Subject: [PATCH 20/20] clean up --- crates/provider/src/ext/anvil.rs | 4 ++-- crates/rpc-types-eth/src/call.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index 71ca0ff5e53..9349e1eb8cd 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -497,7 +497,7 @@ mod tests { // TODO: Fix this test, `chain_id` is not being set correctly. // #[tokio::test] - // async fn anvil_reset() { + // async fn test_anvil_reset() { // let fork1 = Anvil::default().chain_id(777).spawn(); // let fork2 = Anvil::default().chain_id(888).spawn(); @@ -857,7 +857,7 @@ mod tests { // TODO: Fix this test, only a single block is being mined regardless of the `blocks` parameter. // #[tokio::test] - // async fn evm_mine_with_configuration() { + // async fn test_evm_mine_with_configuration() { // let provider = ProviderBuilder::new().on_anvil(); // let start_num = provider.get_block_number().await.unwrap(); diff --git a/crates/rpc-types-eth/src/call.rs b/crates/rpc-types-eth/src/call.rs index b82ed58394a..c3a5eefd54c 100644 --- a/crates/rpc-types-eth/src/call.rs +++ b/crates/rpc-types-eth/src/call.rs @@ -26,7 +26,7 @@ impl From> for Bundle { } } -/// State context for *_callMany +/// State context for callMany #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct StateContext {