Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into issue-3521-fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Mar 19, 2024
2 parents 3c48666 + 0026488 commit e1f8a95
Show file tree
Hide file tree
Showing 64 changed files with 1,435 additions and 1,439 deletions.
331 changes: 176 additions & 155 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resolver = "2"
[workspace.package]
version = "0.2.0"
edition = "2021"
rust-version = "1.75" # Remember to update clippy.toml as well
rust-version = "1.76" # Remember to update clippy.toml as well
authors = ["Foundry Contributors"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/foundry-rs/foundry"
Expand All @@ -46,6 +46,7 @@ debug = 1
# Solc and artifacts
foundry-compilers.opt-level = 3
solang-parser.opt-level = 3
lalrpop-util.opt-level = 3
serde_json.opt-level = 3

# EVM
Expand Down Expand Up @@ -138,7 +139,7 @@ foundry-linking = { path = "crates/linking" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.2.3", default-features = false }
foundry-compilers = { version = "0.3.9", default-features = false }
foundry-compilers = { version = "0.3.13", default-features = false }

## revm
# no default features to avoid c-kzg
Expand All @@ -156,7 +157,6 @@ ethers-contract-abigen = { version = "2.0.14", default-features = false }
ethers-providers = { version = "2.0.14", default-features = false }
ethers-signers = { version = "2.0.14", default-features = false }
ethers-middleware = { version = "2.0.14", default-features = false }
ethers-solc = { version = "2.0.14", default-features = false }

## alloy
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "9ac2c90", default-features = false }
Expand Down Expand Up @@ -186,26 +186,27 @@ alloy-rlp = "0.3.3"
solang-parser = "=0.3.3"

## misc
arrayvec = "0.7"
base64 = "0.22"
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
color-eyre = "0.6"
derive_more = "0.99"
evm-disassembler = "0.5"
eyre = "0.6"
hex = { package = "const-hex", version = "1.6", features = ["hex"] }
itertools = "0.11"
itertools = "0.12"
jsonpath_lib = "0.3"
k256 = "0.13"
pretty_assertions = "1.4"
protobuf = "=3.2.0"
rand = "0.8"
rustc-hash = "1.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
base64 = "0.21"
strum = "0.26"
toml = "0.8"
tracing = "0.1"
tracing-subscriber = "0.3"
evm-disassembler = "0.4"
vergen = { version = "8", default-features = false }
k256 = "0.13"

axum = "0.6"
hyper = "0.14"
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.75"
msrv = "1.76"
4 changes: 3 additions & 1 deletion crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ clap_complete_fig = "4"
ethereum-forkid = "0.12"

[dev-dependencies]
alloy-json-abi.workspace = true
ethers = { workspace = true, features = ["abigen"] }
ethers-core = { workspace = true, features = ["optimism"] }
ethers-solc = { workspace = true, features = ["project-util", "full"] }
foundry-compilers = { workspace = true, features = ["project-util", "full"] }

pretty_assertions = "1.3.0"
tokio = { version = "1", features = ["full"] }
crc = "3.0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@ impl EthApi {
}
}

let nonce = self.backend.get_nonce(address, Some(block_request)).await?;
let nonce = self.backend.get_nonce(address, block_request).await?;

Ok(nonce)
}
Expand Down
29 changes: 12 additions & 17 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,19 +1789,19 @@ impl Backend {
pub async fn get_nonce(
&self,
address: Address,
block_request: Option<BlockRequest>,
block_request: BlockRequest,
) -> Result<U256, BlockchainError> {
if let Some(BlockRequest::Pending(pool_transactions)) = block_request.as_ref() {
if let BlockRequest::Pending(pool_transactions) = &block_request {
if let Some(value) = get_pool_transactions_nonce(pool_transactions, address) {
return Ok(value);
}
}
let final_block_request = match block_request {
Some(BlockRequest::Pending(_)) => Some(BlockRequest::Number(self.best_number())),
Some(BlockRequest::Number(bn)) => Some(BlockRequest::Number(bn)),
None => None,
BlockRequest::Pending(_) => BlockRequest::Number(self.best_number()),
BlockRequest::Number(bn) => BlockRequest::Number(bn),
};
self.with_database_at(final_block_request, |db, _| {

self.with_database_at(Some(final_block_request), |db, _| {
trace!(target: "backend", "get nonce for {:?}", address);
Ok(U256::from(db.basic_ref(address)?.unwrap_or_default().nonce))
})
Expand Down Expand Up @@ -2276,19 +2276,14 @@ fn get_pool_transactions_nonce(
pool_transactions: &[Arc<PoolTransaction>],
address: Address,
) -> Option<U256> {
let highest_nonce_tx = pool_transactions
if let Some(highest_nonce) = pool_transactions
.iter()
.filter(|tx| *tx.pending_transaction.sender() == address)
.reduce(|accum, item| {
let nonce = item.pending_transaction.nonce();
if nonce > accum.pending_transaction.nonce() {
item
} else {
accum
}
});
if let Some(highest_nonce_tx) = highest_nonce_tx {
return Some(highest_nonce_tx.pending_transaction.nonce().saturating_add(U256::from(1)));
.map(|tx| tx.pending_transaction.nonce())
.max()
{
let tx_count = highest_nonce.saturating_add(U256::from(1));
return Some(tx_count)
}
None
}
Expand Down
15 changes: 6 additions & 9 deletions crates/anvil/src/hardfork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ impl Hardfork {
Hardfork::ArrowGlacier => 13773000,
Hardfork::GrayGlacier => 15050000,
Hardfork::Paris => 15537394,
Hardfork::Shanghai | Hardfork::Latest => 17034870,

// TODO: set block number after activation
Hardfork::Cancun => unreachable!(),
Hardfork::Shanghai => 17034870,
Hardfork::Cancun | Hardfork::Latest => 19426587,
}
}

Expand Down Expand Up @@ -94,7 +92,7 @@ impl Hardfork {
Hardfork::Paris => ForkId { hash: ForkHash([0x4f, 0xb8, 0xa8, 0x72]), next: 17034870 },
Hardfork::Shanghai | Hardfork::Latest => {
// update `next` when another fork block num is known
ForkId { hash: ForkHash([0xc1, 0xfd, 0xf1, 0x81]), next: 0 }
ForkId { hash: ForkHash([0xc1, 0xfd, 0xf1, 0x81]), next: 19426587 }
}
Hardfork::Cancun => {
// TODO: set fork hash once known
Expand Down Expand Up @@ -152,10 +150,8 @@ impl From<Hardfork> for SpecId {
Hardfork::ArrowGlacier => SpecId::LONDON,
Hardfork::GrayGlacier => SpecId::GRAY_GLACIER,
Hardfork::Paris => SpecId::MERGE,
Hardfork::Shanghai | Hardfork::Latest => SpecId::SHANGHAI,

// TODO: switch to latest after activation
Hardfork::Cancun => SpecId::CANCUN,
Hardfork::Shanghai => SpecId::SHANGHAI,
Hardfork::Cancun | Hardfork::Latest => SpecId::CANCUN,
}
}
}
Expand All @@ -182,6 +178,7 @@ impl<T: Into<BlockNumberOrTag>> From<T> for Hardfork {
_i if num < 13_773_000 => Hardfork::London,
_i if num < 15_050_000 => Hardfork::ArrowGlacier,
_i if num < 17_034_870 => Hardfork::Paris,
_i if num < 19_426_587 => Hardfork::Shanghai,
_ => Hardfork::Latest,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/anvil_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ async fn can_get_node_info() {
current_block_number: U64([0]).to_alloy(),
current_block_timestamp: 1,
current_block_hash: block.hash.unwrap().to_alloy(),
hard_fork: SpecId::SHANGHAI,
hard_fork: SpecId::CANCUN,
transaction_order: "fees".to_owned(),
environment: NodeEnvironment {
base_fee: U256::from_str("0x3b9aca00").unwrap().to_alloy(),
Expand Down
13 changes: 8 additions & 5 deletions crates/anvil/tests/it/ganache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! tests against local ganache for local debug purposes
#![allow(unused)]
use crate::init_tracing;
use crate::{
init_tracing,
utils::{ContractInstanceCompat, DeploymentTxFactoryCompat},
};
use ethers::{
abi::Address,
contract::{Contract, ContractFactory, ContractInstance},
Expand All @@ -11,7 +14,7 @@ use ethers::{
types::{BlockNumber, U256},
utils::hex,
};
use ethers_solc::{project_util::TempProject, Artifact};
use foundry_compilers::{project_util::TempProject, Artifact};
use std::sync::Arc;

// the mnemonic used to start the local ganache instance
Expand Down Expand Up @@ -115,7 +118,7 @@ contract Contract {

let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let factory = ContractFactory::new(abi.unwrap(), bytecode.unwrap(), Arc::clone(&client));
let factory = ContractFactory::new_compat(abi.unwrap(), bytecode.unwrap(), Arc::clone(&client));
let contract = factory.deploy(()).unwrap().legacy().send().await;
contract.unwrap_err();
}
Expand Down Expand Up @@ -153,13 +156,13 @@ contract Contract {
let client = Arc::new(http_client());

// deploy successfully
let factory = ContractFactory::new(abi.clone().unwrap(), bytecode.unwrap(), client);
let factory = ContractFactory::new_compat(abi.clone().unwrap(), bytecode.unwrap(), client);
let contract = factory.deploy(()).unwrap().legacy().send().await.unwrap();
let provider = SignerMiddleware::new(
Provider::<Http>::try_from("http://127.0.0.1:8545").unwrap(),
ganache_wallet2(),
);
let contract = ContractInstance::new(contract.address(), abi.unwrap(), provider);
let contract = ContractInstance::new_compat(contract.address(), abi.unwrap(), provider);
let resp = contract.method::<_, U256>("getSecret", ()).unwrap().legacy().call().await;
resp.unwrap_err();

Expand Down
11 changes: 7 additions & 4 deletions crates/anvil/tests/it/geth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! tests against local geth for local debug purposes

use crate::abi::VENDING_MACHINE_CONTRACT;
use crate::{
abi::VENDING_MACHINE_CONTRACT,
utils::{ContractInstanceCompat, DeploymentTxFactoryCompat},
};
use ethers::{
abi::Address,
contract::{Contract, ContractFactory},
Expand All @@ -9,7 +12,7 @@ use ethers::{
types::U256,
utils::WEI_IN_ETHER,
};
use ethers_solc::{project_util::TempProject, Artifact};
use foundry_compilers::{project_util::TempProject, Artifact};
use futures::StreamExt;
use std::sync::Arc;
use tokio::time::timeout;
Expand Down Expand Up @@ -52,15 +55,15 @@ async fn test_geth_revert_transaction() {

// deploy successfully
let factory =
ContractFactory::new(abi.clone().unwrap(), bytecode.unwrap(), Arc::clone(&client));
ContractFactory::new_compat(abi.clone().unwrap(), bytecode.unwrap(), Arc::clone(&client));

let mut tx = factory.deploy(()).unwrap().tx;
tx.set_from(account);

let resp = client.send_transaction(tx, None).await.unwrap().await.unwrap().unwrap();

let contract =
Contract::<Provider<_>>::new(resp.contract_address.unwrap(), abi.unwrap(), client);
Contract::<Provider<_>>::new_compat(resp.contract_address.unwrap(), abi.unwrap(), client);

let ten = WEI_IN_ETHER.saturating_mul(10u64.into());
let call = contract.method::<_, ()>("buyRevert", ten).unwrap().value(ten).from(account);
Expand Down
20 changes: 11 additions & 9 deletions crates/anvil/tests/it/otterscan.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! tests for otterscan endpoints
use crate::{
abi::MulticallContract,
utils::{ethers_http_provider, ethers_ws_provider},
utils::{
ethers_http_provider, ethers_ws_provider, ContractInstanceCompat, DeploymentTxFactoryCompat,
},
};
use alloy_primitives::U256 as rU256;
use alloy_rpc_types::{BlockNumberOrTag, BlockTransactions};
Expand All @@ -19,8 +21,8 @@ use ethers::{
types::{Bytes, TransactionRequest},
utils::get_contract_address,
};
use ethers_solc::{project_util::TempProject, Artifact};
use foundry_common::types::{ToAlloy, ToEthers};
use foundry_compilers::{project_util::TempProject, Artifact};
use std::{collections::VecDeque, str::FromStr, sync::Arc};

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -136,10 +138,10 @@ contract Contract {
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

// deploy successfully
let factory = ContractFactory::new(abi.clone().unwrap(), bytecode.unwrap(), client);
let factory = ContractFactory::new_compat(abi.clone().unwrap(), bytecode.unwrap(), client);
let contract = factory.deploy(()).unwrap().send().await.unwrap();

let contract = ContractInstance::new(
let contract = ContractInstance::new_compat(
contract.address(),
abi.unwrap(),
SignerMiddleware::new(ethers_http_provider(&handle.http_endpoint()), wallets[1].clone()),
Expand Down Expand Up @@ -194,10 +196,10 @@ contract Contract {
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

// deploy successfully
let factory = ContractFactory::new(abi.clone().unwrap(), bytecode.unwrap(), client);
let factory = ContractFactory::new_compat(abi.clone().unwrap(), bytecode.unwrap(), client);
let contract = factory.deploy(()).unwrap().send().await.unwrap();

let contract = ContractInstance::new(
let contract = ContractInstance::new_compat(
contract.address(),
abi.unwrap(),
SignerMiddleware::new(ethers_http_provider(&handle.http_endpoint()), wallets[1].clone()),
Expand Down Expand Up @@ -307,10 +309,10 @@ contract Contract {
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

// deploy successfully
let factory = ContractFactory::new(abi.clone().unwrap(), bytecode.unwrap(), client);
let factory = ContractFactory::new_compat(abi.clone().unwrap(), bytecode.unwrap(), client);
let contract = factory.deploy(()).unwrap().send().await.unwrap();

let contract = ContractInstance::new(
let contract = ContractInstance::new_compat(
contract.address(),
abi.unwrap(),
SignerMiddleware::new(ethers_http_provider(&handle.http_endpoint()), wallets[1].clone()),
Expand Down Expand Up @@ -397,7 +399,7 @@ contract Contract {
let client = Arc::new(SignerMiddleware::new(provider, wallet));

// deploy successfully
let factory = ContractFactory::new(abi.clone().unwrap(), bytecode.unwrap(), client);
let factory = ContractFactory::new_compat(abi.clone().unwrap(), bytecode.unwrap(), client);
let contract = factory.deploy(()).unwrap().send().await.unwrap();

let call = contract.method::<_, ()>("trigger_revert", ()).unwrap().gas(150_000u64);
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ethers::{
types::U256,
utils::WEI_IN_ETHER,
};
use ethers_solc::{project_util::TempProject, Artifact};
use foundry_compilers::{project_util::TempProject, Artifact};
use std::sync::Arc;

#[tokio::test(flavor = "multi_thread")]
Expand Down
Loading

0 comments on commit e1f8a95

Please sign in to comment.