diff --git a/crates/provider/src/blocks.rs b/crates/provider/src/blocks.rs index 1716a99ac76..6bcf25ccc46 100644 --- a/crates/provider/src/blocks.rs +++ b/crates/provider/src/blocks.rs @@ -182,7 +182,6 @@ mod tests { use super::*; use crate::{ext::AnvilApi, Provider, ProviderBuilder}; use alloy_node_bindings::Anvil; - use alloy_primitives::U256; use std::{future::Future, time::Duration}; async fn timeout(future: T) -> T::Output { @@ -215,7 +214,7 @@ mod tests { } // We will also use provider to manipulate anvil instance via RPC. - provider.anvil_mine(Some(U256::from(1)), None).await.unwrap(); + provider.anvil_mine(Some(1), None).await.unwrap(); let block = timeout(stream.next()).await.expect("Block wasn't fetched"); assert_eq!(block.header.number, 1); @@ -246,7 +245,7 @@ mod tests { } // We will also use provider to manipulate anvil instance via RPC. - provider.anvil_mine(Some(U256::from(BLOCKS_TO_MINE)), None).await.unwrap(); + provider.anvil_mine(Some(BLOCKS_TO_MINE as u64), None).await.unwrap(); let blocks = timeout(stream.take(BLOCKS_TO_MINE).collect::>()).await; assert_eq!(blocks.len(), BLOCKS_TO_MINE); diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index 85f073ad28c..8668c2cf0d7 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -2,7 +2,7 @@ use crate::Provider; use alloy_network::Network; -use alloy_primitives::{Address, Bytes, TxHash, B256, U256}; +use alloy_primitives::{Address, Bytes, TxHash, B256, U128, U256, U64}; use alloy_rpc_types_anvil::{Forking, Metadata, MineOptions, NodeInfo, ReorgOptions}; use alloy_rpc_types_eth::Block; use alloy_transport::TransportResult; @@ -34,8 +34,8 @@ pub trait AnvilApi: Send + Sync { /// Mines a series of blocks. async fn anvil_mine( &self, - num_blocks: Option, - interval: Option, + num_blocks: Option, + interval: Option, ) -> TransportResult<()>; /// Sets the mining behavior to interval with the given interval (seconds). @@ -62,7 +62,7 @@ pub trait AnvilApi: Send + Sync { async fn anvil_set_code(&self, address: Address, code: Bytes) -> TransportResult<()>; /// Sets the nonce of an address. - async fn anvil_set_nonce(&self, address: Address, nonce: U256) -> TransportResult<()>; + async fn anvil_set_nonce(&self, address: Address, nonce: u64) -> TransportResult<()>; /// Writes a single slot of the account's storage. async fn anvil_set_storage_at( @@ -76,10 +76,10 @@ pub trait AnvilApi: Send + Sync { async fn anvil_set_logging(&self, enable: bool) -> TransportResult<()>; /// Set the minimum gas price for the node. - async fn anvil_set_min_gas_price(&self, gas: U256) -> TransportResult<()>; + async fn anvil_set_min_gas_price(&self, gas: u128) -> TransportResult<()>; /// Sets the base fee of the next block. - async fn anvil_set_next_block_base_fee_per_gas(&self, basefee: U256) -> TransportResult<()>; + async fn anvil_set_next_block_base_fee_per_gas(&self, basefee: u128) -> TransportResult<()>; /// Sets the coinbase address. async fn anvil_set_coinbase(&self, address: Address) -> TransportResult<()>; @@ -109,7 +109,7 @@ pub trait AnvilApi: Send + Sync { async fn anvil_revert(&self, id: U256) -> TransportResult; /// Jump forward in time by the given amount of time, in seconds. - async fn anvil_increase_time(&self, seconds: U256) -> TransportResult; + async fn anvil_increase_time(&self, seconds: u64) -> TransportResult; /// Similar to `evm_increaseTime` but takes the exact timestamp that you want in the next block. async fn anvil_set_next_block_timestamp(&self, timestamp: u64) -> TransportResult<()>; @@ -119,7 +119,7 @@ pub trait AnvilApi: Send + Sync { async fn anvil_set_time(&self, timestamp: u64) -> TransportResult; /// Set the next block gas limit. - async fn anvil_set_block_gas_limit(&self, gas_limit: U256) -> TransportResult; + async fn anvil_set_block_gas_limit(&self, gas_limit: u64) -> TransportResult; /// Sets an interval for the block timestamp. async fn anvil_set_block_timestamp_interval(&self, seconds: u64) -> TransportResult<()>; @@ -177,10 +177,12 @@ where async fn anvil_mine( &self, - num_blocks: Option, - interval: Option, + num_blocks: Option, + interval: Option, ) -> TransportResult<()> { - self.client().request("anvil_mine", (num_blocks, interval)).await + self.client() + .request("anvil_mine", (num_blocks.map(U64::from), interval.map(U64::from))) + .await } async fn anvil_set_interval_mining(&self, secs: u64) -> TransportResult<()> { @@ -211,8 +213,8 @@ where self.client().request("anvil_setCode", (address, code)).await } - async fn anvil_set_nonce(&self, address: Address, nonce: U256) -> TransportResult<()> { - self.client().request("anvil_setNonce", (address, nonce)).await + async fn anvil_set_nonce(&self, address: Address, nonce: u64) -> TransportResult<()> { + self.client().request("anvil_setNonce", (address, U64::from(nonce))).await } async fn anvil_set_storage_at( @@ -228,12 +230,12 @@ where self.client().request("anvil_setLoggingEnabled", (enable,)).await } - async fn anvil_set_min_gas_price(&self, gas: U256) -> TransportResult<()> { - self.client().request("anvil_setMinGasPrice", (gas,)).await + async fn anvil_set_min_gas_price(&self, gas: u128) -> TransportResult<()> { + self.client().request("anvil_setMinGasPrice", (U128::from(gas),)).await } - async fn anvil_set_next_block_base_fee_per_gas(&self, basefee: U256) -> TransportResult<()> { - self.client().request("anvil_setNextBlockBaseFeePerGas", (basefee,)).await + async fn anvil_set_next_block_base_fee_per_gas(&self, basefee: u128) -> TransportResult<()> { + self.client().request("anvil_setNextBlockBaseFeePerGas", (U128::from(basefee),)).await } async fn anvil_set_coinbase(&self, address: Address) -> TransportResult<()> { @@ -268,8 +270,8 @@ where self.client().request("evm_revert", (id,)).await } - async fn anvil_increase_time(&self, seconds: U256) -> TransportResult { - self.client().request("evm_increaseTime", (seconds,)).await + async fn anvil_increase_time(&self, seconds: u64) -> TransportResult { + self.client().request("evm_increaseTime", (U64::from(seconds),)).await } async fn anvil_set_next_block_timestamp(&self, seconds: u64) -> TransportResult<()> { @@ -280,8 +282,8 @@ where self.client().request("evm_setTime", (timestamp,)).await } - async fn anvil_set_block_gas_limit(&self, gas_limit: U256) -> TransportResult { - self.client().request("evm_setBlockGasLimit", (gas_limit,)).await + async fn anvil_set_block_gas_limit(&self, gas_limit: u64) -> TransportResult { + self.client().request("evm_setBlockGasLimit", (U64::from(gas_limit),)).await } async fn anvil_set_block_timestamp_interval(&self, seconds: u64) -> TransportResult<()> { @@ -423,7 +425,7 @@ mod tests { let start_num = provider.get_block_number().await.unwrap(); - provider.anvil_mine(Some(U256::from(10)), None).await.unwrap(); + provider.anvil_mine(Some(10), None).await.unwrap(); let num = provider.get_block_number().await.unwrap(); @@ -565,11 +567,11 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); let address = Address::random(); - let nonce = U256::from(1337); + let nonce = 1337; provider.anvil_set_nonce(address, nonce).await.unwrap(); let new_nonce = provider.get_transaction_count(address).await.unwrap(); - assert_eq!(new_nonce, nonce.to::()); + assert_eq!(new_nonce, nonce); } #[tokio::test] @@ -598,7 +600,7 @@ mod tests { let gas = U256::from(1337); - if let Err(e) = provider.anvil_set_min_gas_price(gas).await { + if let Err(e) = provider.anvil_set_min_gas_price(gas.try_into().unwrap()).await { assert_eq!( e.to_string(), "server returned an error response: error code -32602: anvil_setMinGasPrice is not supported when EIP-1559 is active" @@ -610,7 +612,7 @@ mod tests { async fn test_anvil_set_next_block_base_fee_per_gas() { let provider = ProviderBuilder::new().on_anvil(); - let basefee = U256::from(1337); + let basefee = 1337; provider.anvil_set_next_block_base_fee_per_gas(basefee).await.unwrap(); provider.evm_mine(None).await.unwrap(); @@ -621,7 +623,7 @@ mod tests { .unwrap() .unwrap(); - assert_eq!(block.header.base_fee_per_gas, Some(basefee.to::())); + assert_eq!(block.header.base_fee_per_gas, Some(basefee as u64)); } #[tokio::test] @@ -761,7 +763,7 @@ mod tests { .header .timestamp; - let seconds = provider.anvil_increase_time(U256::from(1337)).await.unwrap(); + let seconds = provider.anvil_increase_time(1337).await.unwrap(); assert_eq!(timestamp as i64 + seconds, timestamp as i64 + 1337_i64); } @@ -805,7 +807,7 @@ mod tests { async fn test_anvil_set_block_gas_limit() { let provider = ProviderBuilder::new().on_anvil(); - let block_gas_limit = U256::from(1337); + let block_gas_limit = 1337; assert!(provider.anvil_set_block_gas_limit(block_gas_limit).await.unwrap()); provider.evm_mine(None).await.unwrap(); @@ -815,7 +817,7 @@ mod tests { .await .unwrap() .unwrap(); - assert_eq!(block_gas_limit.to::(), latest_block.header.gas_limit); + assert_eq!(block_gas_limit, latest_block.header.gas_limit); } #[tokio::test] @@ -951,7 +953,7 @@ mod tests { let provider = ProviderBuilder::new().on_anvil(); // Mine two blocks - provider.anvil_mine(Some(U256::from(2)), None).await.unwrap(); + provider.anvil_mine(Some(2), None).await.unwrap(); let reorged_block = provider .get_block_by_number(2.into(), BlockTransactionsKind::Hashes) diff --git a/crates/provider/src/fillers/nonce.rs b/crates/provider/src/fillers/nonce.rs index b52ea2c442e..82bd4488f00 100644 --- a/crates/provider/src/fillers/nonce.rs +++ b/crates/provider/src/fillers/nonce.rs @@ -199,7 +199,7 @@ mod tests { { use crate::ext::AnvilApi; filler.nonce_manager.nonces.clear(); - provider.anvil_set_nonce(address, U256::from(69)).await.unwrap(); + provider.anvil_set_nonce(address, 69).await.unwrap(); check_nonces(&filler, &provider, address, 69).await; } } diff --git a/crates/rpc-types-anvil/src/lib.rs b/crates/rpc-types-anvil/src/lib.rs index 8bbd90dcbb9..59c9ed342de 100644 --- a/crates/rpc-types-anvil/src/lib.rs +++ b/crates/rpc-types-anvil/src/lib.rs @@ -85,13 +85,16 @@ pub struct NodeInfo { #[serde(rename_all = "camelCase")] pub struct NodeEnvironment { /// Base fee of the current block - pub base_fee: U256, + #[serde(with = "alloy_serde::quantity")] + pub base_fee: u128, /// Chain id of the node. pub chain_id: ChainId, /// Configured block gas limit - pub gas_limit: U256, + #[serde(with = "alloy_serde::quantity")] + pub gas_limit: u64, /// Configured gas price - pub gas_price: U256, + #[serde(with = "alloy_serde::quantity")] + pub gas_price: u128, } /// The node's fork configuration.