Skip to content

Commit

Permalink
Upgrade to latest version of Alloy and port Anvil tests (foundry-rs#7701
Browse files Browse the repository at this point in the history
)

* add: alloy utils and fix anvil tests

* fix: clippy

* migrate`can_order_transactions` test

* migrate(anvil/tests): transactions - `can_respect_nonces`, `can_replace_transaction`, `can_reject_too_high_gas_limits`, `can_reject_underpriced_replacement`

* add: provider with signer utils

* use: sol! in abi

* start porting anvil_api tests

* additional tests

* add: can_impersonate_gnosis_safe

* add: can_impersonate_multiple_account

* add: can_mine_manually +  test_set_next_timestamp

* more tests

* add: test_can_set_storage_bsc_fork

* port the rest of the tests, final test is blocked on lack of txpool_inspect methods on the provider, see alloy-rs/alloy#502

* simplify types

* use provider_with_signer, unclear exactly if it will interact as expected in relation to impersonation

* migrate(anvil/tests): `can_deploy_greeter_http`, `can_deploy_and_mine_manually` tx tests migrated to alloy

* migrate(anvil/tests): `can_mine_automatically`, `can_call_greeter_historic` tx tests to alloy

* migrate(anvil/test): tx tests migrated to alloy - TODOs remaining

* migrate transaction::test_tx_access_list to alloy

* nit

* migrate(anvil/tests): transactions::call_past_state

* migrate(anvil/tests): can_handle_multiple_concurrent_deploys_with_same_nonce & can_handle_multiple_concurrent_transactions_with_same_nonce tx tests

* migrate: tx test stream_pending_txs - fix TODO

* start on api

* finish api examples, softly blocked on simulated call overrides - needs some more investigation

* clean up imports

* specify from on contract builder

* finish ganache tests

* wrap up ganache, start on gas

* add gas tests

* considering these tests are ignored is it necessary to keep them around?

* add back ganache and geth

* port geth

* add ipc

* add txpool, missing methods

* migrates(anvil/tests): `fork` tests to alloy - fix TODOs

* migrate(anvil/tests): trace tests to alloy - fix `debug_*` TODO

* bump alloy - satisfy clippy

* bump alloy & migrate sign examples

* fix revm-inspectors

* use latest evm-inspectors version

* start fixing broken test ports

* fix test_tip_above_fee_cap

* fix broken tests, long running websocket / ipc tests still have issues

* add can_call_with_state_override test

* re-enable txpool test body

* add logs:get_past_events test

* add logs:get_all_events

* add logs:watch_events

* pubsub utils

* yash/anvil-to-alloy (foundry-rs#7705)

* migrate(anvil/tests): pubsub

* pubsub tests to alloy

* nit

* nits

* nit:test_sub_new_heads_fast

* fix api:can_get_pending_block

* temporarily change ipc_provider to connect_pubsub, add ignores to breaking tests relying on foundry-rs#389

* fix gas:test_respect_base_fee

* fix api:can_call_on_pending_block

* add note on broken test to revisit, all tests should run now

* add temp attempt at optimism port, not behaving an expected and a lot of conversions

* revert for now

* start porting otterscan

* continue adding otterscan tests

* another otterscan test case

* finish otterscan tests

* clean up imports

* start porting revert tests

* fix(anvil/tests): TODOs

* bump alloy

* nit

* nits

* bump alloy to fix test_fork_uncles_fetch

* fmt nits

* nit

* rm abigen from abi

* nit

* rm unused ethers utils

* finish revert examples

* clean up imports and commits, use dynamic complilation where previously implemented

* port optimism

* lift comment to todo

* clean up imports, start porting leftover ethers references

* inline alloy namespace in foundry-common

* remove runtime_client, unnecessary imports

* fix: test_sub_new_heads_fast using workaround

* port jwt

* update alloy / alloy-core / evm-inspectors

* remove hex dep

* add missing hex

* implement txkind change, issues around test running - spotty

* cast differently, still not working

* rm ignore fork tests

* fix: clippy

* nits

* fix flaky test, make sure block is available by mining it

* fix cargo hack check

* ignore specific ipc error on windows

* append to previous commit, same ipc issue

* http_provider(&handle.http_endpoint()) -> handle.http_provider()

* apply for ws_provider and ipc_provider as well, re-enable can_remove_pool_transactions

* refactor test_sub_new_heads_fast

* remove redundant RpcUrl alias

* temp enable ipc tests for windows with debug

* attempt fix of ipc issue with tempfile, as used in Alloy test suite

* fix(anvil/tests): can_replace_transaction

* explicitly enable mocking for tests

* attempt ipc prefix

* enhance error, ignore failing ipc tests on windows for now

---------

Co-authored-by: Yash Atreya <44857776+yash-atreya@users.noreply.github.com>
  • Loading branch information
zerosnacks and yash-atreya authored Apr 26, 2024
1 parent d21c3e7 commit d431f74
Show file tree
Hide file tree
Showing 73 changed files with 3,133 additions and 3,708 deletions.
79 changes: 61 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ ethers-contract = { version = "2.0.14", default-features = false }
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 }

## alloy
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
Expand All @@ -168,6 +167,7 @@ alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "8808d2
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-rpc-types-trace = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
Expand All @@ -180,10 +180,10 @@ alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "8808d
alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false }
alloy-primitives = { version = "0.7.1", features = ["getrandom"] }
alloy-dyn-abi = "0.7.0"
alloy-json-abi = "0.7.0"
alloy-sol-types = "0.7.0"
syn-solidity = "0.7.0"
alloy-dyn-abi = "0.7.1"
alloy-json-abi = "0.7.1"
alloy-sol-types = "0.7.1"
syn-solidity = "0.7.1"
alloy-chains = "0.1"
alloy-trie = "0.3.1"
alloy-rlp = "0.3.3"
Expand Down
19 changes: 16 additions & 3 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ path = "src/anvil.rs"
required-features = ["cli"]

[build-dependencies]
vergen = { workspace = true, default-features = false, features = ["build", "git", "gitcl"] }
vergen = { workspace = true, default-features = false, features = [
"build",
"git",
"gitcl",
] }

[dependencies]
# foundry internal
Expand All @@ -34,6 +38,7 @@ k256.workspace = true
ethers = { workspace = true, features = ["rustls", "ws", "ipc", "optimism"] }
alloy-primitives = { workspace = true, features = ["serde"] }
alloy-consensus = { workspace = true, features = ["k256", "kzg"] }
alloy-contract = { workspace = true, features = ["pubsub"] }
alloy-network.workspace = true
alloy-eips.workspace = true
alloy-rlp.workspace = true
Expand Down Expand Up @@ -77,7 +82,11 @@ rand = "0.8"
eyre.workspace = true

# cli
clap = { version = "4", features = ["derive", "env", "wrap_help"], optional = true }
clap = { version = "4", features = [
"derive",
"env",
"wrap_help",
], optional = true }
clap_complete = { version = "4", optional = true }
chrono.workspace = true
auto_impl = "1"
Expand All @@ -94,8 +103,12 @@ alloy-json-abi.workspace = true
ethers = { workspace = true, features = ["abigen", "optimism"] }
ethers-core = { workspace = true, features = ["optimism"] }
foundry-compilers = { workspace = true, features = ["project-util", "full"] }
alloy-rpc-client = { workspace = true, features = ["pubsub"] }
alloy-transport-ipc = { workspace = true, features = ["mock"] }
alloy-transport-ws.workspace = true
alloy-json-rpc.workspace = true
alloy-pubsub.workspace = true
foundry-test-utils.workspace = true

pretty_assertions.workspace = true
tokio = { version = "1", features = ["full"] }
crc = "3.0.1"
Expand Down
16 changes: 9 additions & 7 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ pub fn transaction_request_to_typed(
other,
} = tx;

let to = if let Some(TxKind::Call(to)) = to { TxKind::Call(to) } else { TxKind::Create };
// Special case: OP-stack deposit tx
if transaction_type == Some(126) {
return Some(TypedTransactionRequest::Deposit(DepositTransactionRequest {
from: from.unwrap_or_default(),
source_hash: other.get_deserialized::<B256>("sourceHash")?.ok()?,
kind: to,
kind: to.unwrap_or_default(),
mint: other.get_deserialized::<U256>("mint")?.ok()?,
value: value.unwrap_or_default(),
gas_limit: gas.unwrap_or_default(),
Expand Down Expand Up @@ -93,7 +92,7 @@ pub fn transaction_request_to_typed(
gas_limit: gas.unwrap_or_default(),
value: value.unwrap_or(U256::ZERO),
input: input.into_input().unwrap_or_default(),
to,
to: to.unwrap_or_default(),
chain_id: None,
}))
}
Expand All @@ -106,7 +105,7 @@ pub fn transaction_request_to_typed(
gas_limit: gas.unwrap_or_default(),
value: value.unwrap_or(U256::ZERO),
input: input.into_input().unwrap_or_default(),
to,
to: to.unwrap_or_default(),
chain_id: 0,
access_list: access_list.unwrap_or_default(),
}))
Expand All @@ -124,13 +123,13 @@ pub fn transaction_request_to_typed(
gas_limit: gas.unwrap_or_default(),
value: value.unwrap_or(U256::ZERO),
input: input.into_input().unwrap_or_default(),
to,
to: to.unwrap_or_default(),
chain_id: 0,
access_list: access_list.unwrap_or_default(),
}))
}
// EIP4844
(Some(3), None, _, _, _, Some(_), Some(_), Some(sidecar), TxKind::Call(to)) => {
(Some(3), None, _, _, _, Some(_), Some(_), Some(sidecar), Some(to)) => {
let tx = TxEip4844 {
nonce: nonce.unwrap_or_default(),
max_fee_per_gas: max_fee_per_gas.unwrap_or_default(),
Expand All @@ -139,7 +138,10 @@ pub fn transaction_request_to_typed(
gas_limit: gas.unwrap_or_default(),
value: value.unwrap_or(U256::ZERO),
input: input.into_input().unwrap_or_default(),
to,
to: match to {
TxKind::Call(to) => to,
TxKind::Create => Address::ZERO,
},
chain_id: 0,
access_list: access_list.unwrap_or_default(),
blob_versioned_hashes: blob_versioned_hashes.unwrap_or_default(),
Expand Down
3 changes: 1 addition & 2 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use alloy_signer_wallet::{
use alloy_transport::{Transport, TransportError};
use anvil_server::ServerConfig;
use foundry_common::{
provider::alloy::ProviderBuilder, ALCHEMY_FREE_TIER_CUPS, NON_ARCHIVE_NODE_WARNING,
REQUEST_TIMEOUT,
provider::ProviderBuilder, ALCHEMY_FREE_TIER_CUPS, NON_ARCHIVE_NODE_WARNING, REQUEST_TIMEOUT,
};
use foundry_config::Config;
use foundry_evm::{
Expand Down
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use anvil_core::{
},
};
use anvil_rpc::{error::RpcError, response::ResponseResult};
use foundry_common::provider::alloy::ProviderBuilder;
use foundry_common::provider::ProviderBuilder;
use foundry_evm::{
backend::DatabaseError,
decode::RevertDecoder,
Expand Down Expand Up @@ -2188,11 +2188,11 @@ impl EthApi {
{
// If the request is a simple native token transfer we can optimize
// We assume it's a transfer if we have no input data.
let to = if let Some(TxKind::Call(to)) = request.to { Some(to) } else { None };
let to = request.to.as_ref().and_then(TxKind::to);
let likely_transfer = request.input.clone().into_input().is_none();
if likely_transfer {
if let Some(to) = to {
if let Ok(target_code) = self.backend.get_code_with_state(&state, to) {
if let Ok(target_code) = self.backend.get_code_with_state(&state, *to) {
if target_code.as_ref().is_empty() {
return Ok(MIN_TRANSACTION_GAS);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use alloy_rpc_types_trace::{
};
use alloy_transport::TransportError;
use anvil_core::eth::transaction::{convert_to_anvil_receipt, ReceiptResponse};
use foundry_common::provider::alloy::{ProviderBuilder, RetryProvider};
use foundry_common::provider::{ProviderBuilder, RetryProvider};
use parking_lot::{
lock_api::{RwLockReadGuard, RwLockWriteGuard},
RawRwLock, RwLock,
Expand Down
Loading

0 comments on commit d431f74

Please sign in to comment.