Skip to content

Commit

Permalink
chore: fmt, switch to local tx request type in the meanwhile for opti…
Browse files Browse the repository at this point in the history
…mism tests
  • Loading branch information
Evalir committed Nov 28, 2023
1 parent 7b84b66 commit 6797d2d
Show file tree
Hide file tree
Showing 40 changed files with 430 additions and 323 deletions.
226 changes: 130 additions & 96 deletions crates/anvil/core/src/eth/mod.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/anvil/core/src/eth/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub mod empty_params {
/// A module that deserializes either a BlockNumberOrTag, or a simple number.
pub mod lenient_block_number {
use alloy_rpc_types::BlockNumberOrTag;
use serde::{Deserializer, Deserialize};
use serde::{Deserialize, Deserializer};
/// Following the spec the block parameter is either:
///
/// > HEX String - an integer block number
Expand All @@ -69,8 +69,8 @@ pub mod lenient_block_number {
///
/// <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1898.md>
///
/// EIP-1898 does not all calls that use `BlockNumber` like `eth_getBlockByNumber` and doesn't list
/// raw integers as supported.
/// EIP-1898 does not all calls that use `BlockNumber` like `eth_getBlockByNumber` and doesn't
/// list raw integers as supported.
///
/// However, there are dev node implementations that support integers, such as ganache: <https://github.com/foundry-rs/foundry/issues/1868>
///
Expand Down Expand Up @@ -107,4 +107,4 @@ pub mod lenient_block_number {
}
}
}
}
}
2 changes: 1 addition & 1 deletion crates/anvil/core/src/eth/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pub struct AccountOverride {
pub state_diff: Option<HashMap<H256, H256>>,
}

pub type StateOverride = HashMap<Address, AccountOverride>;
pub type StateOverride = HashMap<Address, AccountOverride>;
73 changes: 52 additions & 21 deletions crates/anvil/core/src/eth/transaction/ethers_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
use super::EthTransactionRequest;
use crate::eth::{
proof::AccountProof,
state::{AccountOverride, StateOverride as EthStateOverride},
transaction::{
EIP1559TransactionRequest, EIP2930TransactionRequest, LegacyTransactionRequest,
MaybeImpersonatedTransaction, TypedTransaction, TypedTransactionRequest,
DepositTransactionRequest,
}, state::{StateOverride as EthStateOverride, AccountOverride},
DepositTransactionRequest, EIP1559TransactionRequest, EIP2930TransactionRequest,
LegacyTransactionRequest, MaybeImpersonatedTransaction, TypedTransaction,
TypedTransactionRequest,
},
};
use alloy_primitives::{U128 as rU128, U256 as rU256, U64 as rU64};
use alloy_rpc_types::{
state::{AccountOverride as AlloyAccountOverride, StateOverride},
AccessList as AlloyAccessList, CallRequest, Signature, Transaction as AlloyTransaction,
TransactionRequest as AlloyTransactionRequest, state::{StateOverride, AccountOverride as AlloyAccountOverride},
TransactionRequest as AlloyTransactionRequest,
};
use ethers_core::types::{
transaction::{
eip2718::TypedTransaction as EthersTypedTransactionRequest,
eip2930::{AccessList, AccessListItem}, optimism::DepositTransaction,
eip2930::{AccessList, AccessListItem},
optimism::DepositTransaction,
},
Address, BigEndianHash, Eip1559TransactionRequest as EthersEip1559TransactionRequest,
Eip2930TransactionRequest as EthersEip2930TransactionRequest, NameOrAddress, StorageProof,
Expand Down Expand Up @@ -117,24 +120,52 @@ pub fn from_ethers_access_list(access_list: AccessList) -> AlloyAccessList {

pub fn to_ethers_state_override(ov: StateOverride) -> EthStateOverride {
ov.into_iter()
.map(|(addr, o)| (addr.to_ethers(), AccountOverride {
nonce: o.nonce.map(|n| n.to::<u64>()),
balance: o.balance.map(|b| b.to_ethers()),
code: o.code.map(|c| c.0.into()),
state_diff: o.state_diff.map(|s| s.into_iter().map(|(k, v)| (k.to_ethers(), H256::from_uint(&v.to_ethers()))).collect()),
state: o.state.map(|s| s.into_iter().map(|(k, v)| (k.to_ethers(), H256::from_uint(&v.to_ethers()))).collect()),
})).collect()
.map(|(addr, o)| {
(
addr.to_ethers(),
AccountOverride {
nonce: o.nonce.map(|n| n.to::<u64>()),
balance: o.balance.map(|b| b.to_ethers()),
code: o.code.map(|c| c.0.into()),
state_diff: o.state_diff.map(|s| {
s.into_iter()
.map(|(k, v)| (k.to_ethers(), H256::from_uint(&v.to_ethers())))
.collect()
}),
state: o.state.map(|s| {
s.into_iter()
.map(|(k, v)| (k.to_ethers(), H256::from_uint(&v.to_ethers())))
.collect()
}),
},
)
})
.collect()
}

pub fn to_alloy_state_override(ov: EthStateOverride) -> StateOverride {
ov.into_iter()
.map(|(addr, o)| (addr.to_alloy(), AlloyAccountOverride {
nonce: o.nonce.map(rU64::from),
balance: o.balance.map(|b| b.to_alloy()),
code: o.code.map(|c| c.0.into()),
state_diff: o.state_diff.map(|s| s.into_iter().map(|(k, v)| (k.to_alloy(), rU256::from_be_bytes(v.to_alloy().0))).collect()),
state: o.state.map(|s| s.into_iter().map(|(k, v)| (k.to_alloy(), rU256::from_be_bytes(v.to_alloy().0))).collect()),
})).collect()
.map(|(addr, o)| {
(
addr.to_alloy(),
AlloyAccountOverride {
nonce: o.nonce.map(rU64::from),
balance: o.balance.map(|b| b.to_alloy()),
code: o.code.map(|c| c.0.into()),
state_diff: o.state_diff.map(|s| {
s.into_iter()
.map(|(k, v)| (k.to_alloy(), rU256::from_be_bytes(v.to_alloy().0)))
.collect()
}),
state: o.state.map(|s| {
s.into_iter()
.map(|(k, v)| (k.to_alloy(), rU256::from_be_bytes(v.to_alloy().0)))
.collect()
}),
},
)
})
.collect()
}

impl From<TypedTransactionRequest> for EthersTypedTransactionRequest {
Expand Down Expand Up @@ -455,7 +486,7 @@ fn to_alloy_transaction_with_hash_and_sender(
transaction_type: None,
max_fee_per_blob_gas: None,
blob_versioned_hashes: vec![],
}
},
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use std::ops::Deref;
mod ethers_compat;

pub use ethers_compat::{
call_to_internal_tx_request, from_ethers_access_list, to_alloy_proof, to_ethers_access_list,
to_internal_tx_request, to_ethers_state_override, to_alloy_state_override
call_to_internal_tx_request, from_ethers_access_list, to_alloy_proof, to_alloy_state_override,
to_ethers_access_list, to_ethers_state_override, to_internal_tx_request,
};

/// The signature used to bypass signing via the `eth_sendUnsignedTransaction` cheat RPC
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/core/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_primitives::{TxHash, B256, U256, U64};
use std::collections::BTreeMap;
use revm::primitives::SpecId;
use std::collections::BTreeMap;

#[cfg(feature = "serde")]
use serde::{de::Error, Deserializer, Serializer};
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::{
genesis::Genesis,
AccountGenerator, Hardfork, NodeConfig, CHAIN_ID,
};
use alloy_primitives::U256;
use anvil_server::ServerConfig;
use clap::Parser;
use foundry_common::types::ToAlloy;
use core::fmt;
use ethers::{
signers::coins_bip39::{English, Mnemonic},
utils::WEI_IN_ETHER,
};
use alloy_primitives::U256;
use foundry_common::types::ToAlloy;
use foundry_config::{Chain, Config};
use futures::FutureExt;
use rand::{rngs::StdRng, SeedableRng};
Expand Down
12 changes: 8 additions & 4 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use ethers::{
utils::{format_ether, hex, to_checksum, WEI_IN_ETHER},
};
use foundry_common::{
provider::alloy::ProviderBuilder, types::{ToAlloy, ToEthers},
ALCHEMY_FREE_TIER_CUPS, NON_ARCHIVE_NODE_WARNING,
REQUEST_TIMEOUT,
provider::alloy::ProviderBuilder,
types::{ToAlloy, ToEthers},
ALCHEMY_FREE_TIER_CUPS, NON_ARCHIVE_NODE_WARNING, REQUEST_TIMEOUT,
};
use foundry_config::Config;
use foundry_evm::{
Expand Down Expand Up @@ -824,7 +824,11 @@ impl NodeConfig {
},
tx: TxEnv { chain_id: self.get_chain_id().into(), ..Default::default() },
};
let fees = FeeManager::new(env.cfg.spec_id, self.get_base_fee().to_ethers(), self.get_gas_price().to_ethers());
let fees = FeeManager::new(
env.cfg.spec_id,
self.get_base_fee().to_ethers(),
self.get_gas_price().to_ethers(),
);

let (db, fork): (Arc<tokio::sync::RwLock<Box<dyn Db>>>, Option<ClientFork>) =
if let Some(eth_rpc_url) = self.eth_rpc_url.clone() {
Expand Down
Loading

0 comments on commit 6797d2d

Please sign in to comment.