From e01038f35750b4a41b1eda5a4ea3da976027eee2 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:05:14 -0700 Subject: [PATCH] Bump alloy to use `get_receipt` hotfix (#7772) * bump alloy to include `get_receipt` hotfix * refactor: alloy bump breaking changes * fix(cast): doctests * fix(forge/tests): can_broadcast_script_skipping_simulation * fix(forge): create tests --- Cargo.lock | 80 ++++++++++---------- Cargo.toml | 51 +++++++------ crates/anvil/core/src/eth/transaction/mod.rs | 20 ++--- crates/anvil/src/eth/api.rs | 7 +- crates/anvil/src/eth/backend/fork.rs | 24 +++--- crates/anvil/src/eth/backend/mem/mod.rs | 8 +- crates/anvil/src/eth/pool/mod.rs | 4 +- crates/anvil/tests/it/api.rs | 7 +- crates/anvil/tests/it/fork.rs | 80 ++++++++++++-------- crates/anvil/tests/it/genesis.rs | 3 +- crates/anvil/tests/it/transaction.rs | 4 +- crates/anvil/tests/it/wsapi.rs | 3 +- crates/cast/bin/cmd/access_list.rs | 6 +- crates/cast/bin/cmd/call.rs | 9 ++- crates/cast/bin/cmd/estimate.rs | 10 +-- crates/cast/bin/cmd/mktx.rs | 4 +- crates/cast/bin/cmd/send.rs | 9 ++- crates/cast/bin/cmd/storage.rs | 3 +- crates/cast/bin/main.rs | 4 +- crates/cast/bin/tx.rs | 16 ++-- crates/cast/src/lib.rs | 39 +++++++--- crates/cheatcodes/src/inspector.rs | 4 +- crates/common/src/fmt/ui.rs | 2 +- crates/common/src/transactions.rs | 2 +- crates/evm/core/src/fork/backend.rs | 6 +- crates/forge/bin/cmd/create.rs | 13 ++-- crates/script/src/broadcast.rs | 16 +++- crates/script/src/lib.rs | 10 ++- crates/script/src/simulate.rs | 5 +- crates/script/src/transaction.rs | 4 +- crates/test-utils/Cargo.toml | 1 + crates/test-utils/src/script.rs | 23 ++++-- crates/verify/src/bytecode.rs | 5 +- crates/wallets/src/wallet_signer.rs | 8 +- 34 files changed, 284 insertions(+), 206 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0082e8412ebb..a4ab4783e9a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-eips", "alloy-primitives", @@ -94,7 +94,7 @@ dependencies = [ [[package]] name = "alloy-contract" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-dyn-abi", "alloy-json-abi", @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "alloy-dyn-abi" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872f239c15befa27cc4f0d3d82a70b3365c2d0202562bf906eb93b299fa31882" +checksum = "22ab339ca7b4ea9115f0578c941abc80a171edf8e5eadd01e6c4237b68db8083" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -133,7 +133,7 @@ dependencies = [ [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -147,7 +147,7 @@ dependencies = [ [[package]] name = "alloy-genesis" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-primitives", "alloy-serde", @@ -156,9 +156,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a35ddfd27576474322a5869e4c123e5f3e7b2177297c18e4e82ea501cb125b" +checksum = "44294729c145cf7ae65feab544b5b81fb2bb7e2fd060214842eb3989a1e9d882" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -169,7 +169,7 @@ dependencies = [ [[package]] name = "alloy-json-rpc" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-primitives", "serde", @@ -181,7 +181,7 @@ dependencies = [ [[package]] name = "alloy-network" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-consensus", "alloy-eips", @@ -189,6 +189,7 @@ dependencies = [ "alloy-primitives", "alloy-rpc-types", "alloy-signer", + "alloy-sol-types", "async-trait", "futures-utils-wasm", "thiserror", @@ -196,9 +197,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99bbad0a6b588ef4aec1b5ddbbfdacd9ef04e00b979617765b03174318ee1f3a" +checksum = "50c715249705afa1e32be79dabfd35e2ef0f1cc02ad2cf48c9d1e20026ee637b" dependencies = [ "alloy-rlp", "arbitrary", @@ -224,7 +225,7 @@ dependencies = [ [[package]] name = "alloy-provider" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-eips", "alloy-json-rpc", @@ -255,7 +256,7 @@ dependencies = [ [[package]] name = "alloy-pubsub" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -295,7 +296,7 @@ dependencies = [ [[package]] name = "alloy-rpc-client" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -319,7 +320,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-consensus", "alloy-eips", @@ -337,7 +338,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types-trace" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -349,7 +350,7 @@ dependencies = [ [[package]] name = "alloy-serde" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-primitives", "serde", @@ -359,7 +360,7 @@ dependencies = [ [[package]] name = "alloy-signer" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-dyn-abi", "alloy-primitives", @@ -374,7 +375,7 @@ dependencies = [ [[package]] name = "alloy-signer-aws" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-consensus", "alloy-network", @@ -391,7 +392,7 @@ dependencies = [ [[package]] name = "alloy-signer-ledger" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-consensus", "alloy-network", @@ -408,7 +409,7 @@ dependencies = [ [[package]] name = "alloy-signer-trezor" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-consensus", "alloy-network", @@ -424,7 +425,7 @@ dependencies = [ [[package]] name = "alloy-signer-wallet" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-consensus", "alloy-network", @@ -442,9 +443,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "452d929748ac948a10481fff4123affead32c553cf362841c5103dd508bdfc16" +checksum = "bef9a94a27345fb31e3fcb5f5e9f592bb4847493b07fa1e47dd9fde2222f2e28" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", @@ -461,9 +462,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df64e094f6d2099339f9e82b5b38440b159757b6920878f28316243f8166c8d1" +checksum = "c31fe73cd259527e24dc2dbfe64bc95e5ddfcd2b2731f670a11ff72b2be2c25b" dependencies = [ "alloy-json-abi", "const-hex", @@ -478,18 +479,18 @@ dependencies = [ [[package]] name = "alloy-sol-type-parser" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715f4d09a330cc181fc7c361b5c5c2766408fa59a0bac60349dcb7baabd404cc" +checksum = "8c8d6e74e4feeaa2bcfdecfd3da247ab53c67bd654ba1907270c32e02b142331" dependencies = [ "winnow 0.6.6", ] [[package]] name = "alloy-sol-types" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bc2d6dfc2a19fd56644494479510f98b1ee929e04cf0d4aa45e98baa3e545b" +checksum = "afaffed78bfb17526375754931e045f96018aa810844b29c7aef823266dd4b4b" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -501,7 +502,7 @@ dependencies = [ [[package]] name = "alloy-transport" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-json-rpc", "base64 0.22.0", @@ -519,7 +520,7 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -532,7 +533,7 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -550,7 +551,7 @@ dependencies = [ [[package]] name = "alloy-transport-ws" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7629f79#7629f79e3ffb6abd0be901a06deed2ab9f695e4e" +source = "git+https://github.com/alloy-rs/alloy?rev=8808d21#8808d21677ed9a05ff04000ac7f4acdd2fde94e3" dependencies = [ "alloy-pubsub", "alloy-transport", @@ -4050,6 +4051,7 @@ version = "0.2.0" dependencies = [ "alloy-primitives", "alloy-provider", + "alloy-rpc-types", "eyre", "fd-lock 4.0.2", "foundry-common", @@ -5832,7 +5834,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate 2.0.0", "proc-macro2", "quote", "syn 2.0.60", @@ -6971,7 +6973,7 @@ dependencies = [ [[package]] name = "revm-inspectors" version = "0.1.0" -source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=413b892#413b892dd936d117c52d47ba07d195b09a7f1216" +source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=813d7e7#813d7e73a090d426935e63d9308bdd2c945a58c4" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -8071,9 +8073,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4497156948bd342b52038035a6fa514a89626e37af9d2c52a5e8d8ebcc7ee479" +checksum = "70aba06097b6eda3c15f6eebab8a6339e121475bcf08bbe6758807e716c372a1" dependencies = [ "paste", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 4ef7befcbafc..08b4080bfaa1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -144,7 +144,7 @@ foundry-compilers = { version = "0.3.18", default-features = false } # no default features to avoid c-kzg revm = { version = "8", default-features = false } revm-primitives = { version = "3", default-features = false } -revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "413b892", features = [ +revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "813d7e7", features = [ "serde", ] } @@ -158,28 +158,28 @@ 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 = "7629f79", default-features = false } -alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-pubsub = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-rpc-types-trace = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-signer-aws = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-signer-ledger = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-signer-trezor = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "7629f79", default-features = false } -alloy-primitives = { version = "0.7.0", features = ["getrandom"] } +alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +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-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 } +alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-signer-aws = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-signer-ledger = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-signer-trezor = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "8808d21", default-features = false } +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" @@ -192,7 +192,10 @@ solang-parser = "=0.3.3" ## misc arrayvec = "0.7" base64 = "0.22" -chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } +chrono = { version = "0.4", default-features = false, features = [ + "clock", + "std", +] } color-eyre = "0.6" derive_more = "0.99" evm-disassembler = "0.5" diff --git a/crates/anvil/core/src/eth/transaction/mod.rs b/crates/anvil/core/src/eth/transaction/mod.rs index 70f887f1e2e5..2617266364bb 100644 --- a/crates/anvil/core/src/eth/transaction/mod.rs +++ b/crates/anvil/core/src/eth/transaction/mod.rs @@ -58,12 +58,13 @@ 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::("sourceHash")?.ok()?, - kind: to.into(), + kind: to, mint: other.get_deserialized::("mint")?.ok()?, value: value.unwrap_or_default(), gas_limit: gas.unwrap_or_default(), @@ -92,10 +93,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: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, + to, chain_id: None, })) } @@ -108,10 +106,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: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, + to, chain_id: 0, access_list: access_list.unwrap_or_default(), })) @@ -129,16 +124,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: match to { - Some(to) => TxKind::Call(to), - None => TxKind::Create, - }, + to, chain_id: 0, access_list: access_list.unwrap_or_default(), })) } // EIP4844 - (Some(3), None, _, _, _, Some(_), Some(_), Some(sidecar), Some(to)) => { + (Some(3), None, _, _, _, Some(_), Some(_), Some(sidecar), TxKind::Call(to)) => { let tx = TxEip4844 { nonce: nonce.unwrap_or_default(), max_fee_per_gas: max_fee_per_gas.unwrap_or_default(), diff --git a/crates/anvil/src/eth/api.rs b/crates/anvil/src/eth/api.rs index 1ed664a349b5..10689de90f28 100644 --- a/crates/anvil/src/eth/api.rs +++ b/crates/anvil/src/eth/api.rs @@ -2025,9 +2025,9 @@ impl EthApi { fn convert(tx: Arc) -> TxpoolInspectSummary { let tx = &tx.pending_transaction.transaction; let to = tx.to(); - let gas_price = U256::from(tx.gas_price()); + let gas_price = tx.gas_price(); let value = tx.value(); - let gas = U256::from(tx.gas_limit()); + let gas = tx.gas_limit(); TxpoolInspectSummary { to, value, gas, gas_price } } @@ -2188,9 +2188,10 @@ 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 likely_transfer = request.input.clone().into_input().is_none(); if likely_transfer { - if let Some(to) = request.to { + if let Some(to) = 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); diff --git a/crates/anvil/src/eth/backend/fork.rs b/crates/anvil/src/eth/backend/fork.rs index 3727740cd51a..0f4a04f86a81 100644 --- a/crates/anvil/src/eth/backend/fork.rs +++ b/crates/anvil/src/eth/backend/fork.rs @@ -1,8 +1,8 @@ //! Support for forking off another client use crate::eth::{backend::db::Db, error::BlockchainError}; -use alloy_primitives::{Address, Bytes, StorageValue, B256, U256, U64}; -use alloy_provider::Provider; +use alloy_primitives::{Address, Bytes, StorageValue, B256, U256}; +use alloy_provider::{debug::DebugApi, Provider}; use alloy_rpc_types::{ request::TransactionRequest, AccessListWithGasUsed, Block, BlockId, BlockNumberOrTag as BlockNumber, BlockTransactions, EIP1186AccountProofResponse, FeeHistory, @@ -162,7 +162,7 @@ impl ClientFork { keys: Vec, block_number: Option, ) -> Result { - self.provider().get_proof(address, keys, block_number).await + self.provider().get_proof(address, keys, block_number.unwrap_or(BlockId::latest())).await } /// Sends `eth_call` @@ -172,7 +172,7 @@ impl ClientFork { block: Option, ) -> Result { let block = block.unwrap_or(BlockNumber::Latest); - let res = self.provider().call(request, Some(block.into())).await?; + let res = self.provider().call(request, block.into()).await?; Ok(res) } @@ -184,7 +184,7 @@ impl ClientFork { block: Option, ) -> Result { let block = block.unwrap_or(BlockNumber::Latest); - let res = self.provider().estimate_gas(request, Some(block.into())).await?; + let res = self.provider().estimate_gas(request, block.into()).await?; Ok(res) } @@ -195,7 +195,9 @@ impl ClientFork { request: &WithOtherFields, block: Option, ) -> Result { - self.provider().create_access_list(request, block.map(|b| b.into())).await + self.provider() + .create_access_list(request, block.unwrap_or(BlockNumber::Latest).into()) + .await } pub async fn storage_at( @@ -204,7 +206,9 @@ impl ClientFork { index: U256, number: Option, ) -> Result { - self.provider().get_storage_at(address, index, number.map(Into::into)).await + self.provider() + .get_storage_at(address, index, number.unwrap_or(BlockNumber::Latest).into()) + .await } pub async fn logs(&self, filter: &Filter) -> Result, TransportError> { @@ -245,12 +249,12 @@ impl ClientFork { blocknumber: u64, ) -> Result { trace!(target: "backend::fork", "get_balance={:?}", address); - self.provider().get_balance(address, Some(blocknumber.into())).await + self.provider().get_balance(address, blocknumber.into()).await } pub async fn get_nonce(&self, address: Address, block: u64) -> Result { trace!(target: "backend::fork", "get_nonce={:?}", address); - self.provider().get_transaction_count(address, Some(block.into())).await + self.provider().get_transaction_count(address, block.into()).await } pub async fn transaction_by_block_number_and_index( @@ -532,7 +536,7 @@ impl ClientFork { let mut uncles = Vec::with_capacity(block.uncles.len()); for (uncle_idx, _) in block.uncles.iter().enumerate() { let uncle = - match self.provider().get_uncle(block_number.into(), U64::from(uncle_idx)).await? { + match self.provider().get_uncle(block_number.into(), uncle_idx as u64).await? { Some(u) => u, None => return Ok(None), }; diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index 3b5fdc73f577..1e82700ed87c 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -35,7 +35,7 @@ use crate::{ NodeConfig, PrecompileFactory, }; use alloy_consensus::{Header, Receipt, ReceiptWithBloom}; -use alloy_primitives::{keccak256, Address, Bytes, TxHash, B256, U256, U64}; +use alloy_primitives::{keccak256, Address, Bytes, TxHash, TxKind, B256, U256, U64}; use alloy_rpc_types::{ request::TransactionRequest, serde_helpers::JsonStorageKey, state::StateOverride, AccessList, Block as AlloyBlock, BlockId, BlockNumberOrTag as BlockNumber, @@ -1120,7 +1120,7 @@ impl Backend { let gas_price = gas_price.or(max_fee_per_gas).unwrap_or_else(|| self.gas_price()); let caller = from.unwrap_or_default(); - + let to = if let Some(TxKind::Call(addr)) = to { Some(addr) } else { None }; env.tx = TxEnv { caller, gas_limit: gas_limit as u64, @@ -1223,7 +1223,7 @@ impl Backend { D: DatabaseRef, { let from = request.from.unwrap_or_default(); - let to = if let Some(to) = request.to { + let to = if let Some(TxKind::Call(to)) = request.to { to } else { let nonce = state.basic_ref(from)?.unwrap_or_default().nonce; @@ -2038,7 +2038,7 @@ impl Backend { let inner = TransactionReceipt { inner, transaction_hash: info.transaction_hash, - transaction_index: info.transaction_index, + transaction_index: Some(info.transaction_index), block_number: Some(block.header.number), gas_used: info.gas_used, contract_address: info.contract_address, diff --git a/crates/anvil/src/eth/pool/mod.rs b/crates/anvil/src/eth/pool/mod.rs index 6748855008c3..ace226fe5e74 100644 --- a/crates/anvil/src/eth/pool/mod.rs +++ b/crates/anvil/src/eth/pool/mod.rs @@ -75,8 +75,8 @@ impl Pool { /// Returns the number of tx that are ready and queued for further execution pub fn txpool_status(&self) -> TxpoolStatus { // Note: naming differs here compared to geth's `TxpoolStatus` - let pending = U64::from(self.ready_transactions().count()); - let queued = U64::from(self.inner.read().pending_transactions.len()); + let pending = self.ready_transactions().count() as u64; + let queued = self.inner.read().pending_transactions.len() as u64; TxpoolStatus { pending, queued } } diff --git a/crates/anvil/tests/it/api.rs b/crates/anvil/tests/it/api.rs index acf9a0f9834a..1afa76df1cbf 100644 --- a/crates/anvil/tests/it/api.rs +++ b/crates/anvil/tests/it/api.rs @@ -4,7 +4,8 @@ use crate::{ abi::{MulticallContract, SimpleStorage}, utils::ethers_http_provider, }; -use alloy_primitives::{Address as rAddress, B256, U256 as rU256}; +use alloy_eips::BlockId; +use alloy_primitives::{Address as rAddress, TxKind, B256, U256 as rU256}; use alloy_provider::Provider; use alloy_rpc_types::{ request::{TransactionInput as CallInput, TransactionRequest as CallRequest}, @@ -45,7 +46,7 @@ async fn can_dev_get_balance() { let genesis_balance = handle.genesis_balance(); for acc in handle.genesis_accounts() { - let balance = provider.get_balance(acc, None).await.unwrap(); + let balance = provider.get_balance(acc, BlockId::latest()).await.unwrap(); assert_eq!(balance, genesis_balance); } } @@ -246,7 +247,7 @@ where .call( WithOtherFields::new(CallRequest { input: CallInput::maybe_input(call.tx.data().cloned().map(|b| b.0.into())), - to: Some(to.to_alloy()), + to: Some(TxKind::Call(to.to_alloy())), ..Default::default() }), None, diff --git a/crates/anvil/tests/it/fork.rs b/crates/anvil/tests/it/fork.rs index 717e0c57828c..f22d22a91704 100644 --- a/crates/anvil/tests/it/fork.rs +++ b/crates/anvil/tests/it/fork.rs @@ -4,11 +4,11 @@ use crate::{ abi::*, utils::{self, ethers_http_provider}, }; -use alloy_primitives::{address, U256 as rU256}; +use alloy_primitives::{address, TxKind, U256 as rU256}; use alloy_provider::Provider as AlloyProvider; use alloy_rpc_types::{ request::{TransactionInput, TransactionRequest as CallRequest}, - BlockNumberOrTag, WithOtherFields, + BlockId, BlockNumberOrTag, WithOtherFields, }; use anvil::{eth::EthApi, spawn, NodeConfig, NodeHandle}; use anvil_core::types::Forking; @@ -273,8 +273,8 @@ async fn test_fork_snapshotting() { let to = accounts[1].address(); let block_number = provider.get_block_number().await.unwrap(); - let initial_nonce = provider.get_transaction_count(from, None).await.unwrap(); - let balance_before = provider.get_balance(to, None).await.unwrap(); + let initial_nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); + let balance_before = provider.get_balance(to, BlockId::latest()).await.unwrap(); let amount = handle.genesis_balance().checked_div(rU256::from(2u64)).unwrap(); let provider = ethers_http_provider(&handle.http_endpoint()); @@ -287,18 +287,18 @@ async fn test_fork_snapshotting() { let provider = handle.http_provider(); - let nonce = provider.get_transaction_count(from, None).await.unwrap(); + let nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); assert_eq!(nonce, initial_nonce + 1); - let to_balance = provider.get_balance(to, None).await.unwrap(); + let to_balance = provider.get_balance(to, BlockId::latest()).await.unwrap(); assert_eq!(balance_before.saturating_add(amount), to_balance); assert!(api.evm_revert(snapshot).await.unwrap()); - let nonce = provider.get_transaction_count(from, None).await.unwrap(); + let nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); assert_eq!(nonce, initial_nonce); - let balance = provider.get_balance(from, None).await.unwrap(); + let balance = provider.get_balance(from, BlockId::latest()).await.unwrap(); assert_eq!(balance, handle.genesis_balance()); - let balance = provider.get_balance(to, None).await.unwrap(); + let balance = provider.get_balance(to, BlockId::latest()).await.unwrap(); assert_eq!(balance, handle.genesis_balance()); assert_eq!(block_number, provider.get_block_number().await.unwrap()); } @@ -315,8 +315,8 @@ async fn test_fork_snapshotting_repeated() { let to = accounts[1].address(); let block_number = provider.get_block_number().await.unwrap(); - let initial_nonce = provider.get_transaction_count(from, None).await.unwrap(); - let balance_before = provider.get_balance(to, None).await.unwrap(); + let initial_nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); + let balance_before = provider.get_balance(to, BlockId::latest()).await.unwrap(); let amount = handle.genesis_balance().checked_div(rU256::from(92u64)).unwrap(); let tx = TransactionRequest::new() @@ -326,20 +326,20 @@ async fn test_fork_snapshotting_repeated() { let tx_provider = ethers_http_provider(&handle.http_endpoint()); let _ = tx_provider.send_transaction(tx, None).await.unwrap().await.unwrap().unwrap(); - let nonce = provider.get_transaction_count(from, None).await.unwrap(); + let nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); assert_eq!(nonce, initial_nonce + 1); - let to_balance = provider.get_balance(to, None).await.unwrap(); + let to_balance = provider.get_balance(to, BlockId::latest()).await.unwrap(); assert_eq!(balance_before.saturating_add(amount), to_balance); let _second_snapshot = api.evm_snapshot().await.unwrap(); assert!(api.evm_revert(snapshot).await.unwrap()); - let nonce = provider.get_transaction_count(from, None).await.unwrap(); + let nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); assert_eq!(nonce, initial_nonce); - let balance = provider.get_balance(from, None).await.unwrap(); + let balance = provider.get_balance(from, BlockId::latest()).await.unwrap(); assert_eq!(balance, handle.genesis_balance()); - let balance = provider.get_balance(to, None).await.unwrap(); + let balance = provider.get_balance(to, BlockId::latest()).await.unwrap(); assert_eq!(balance, handle.genesis_balance()); assert_eq!(block_number, provider.get_block_number().await.unwrap()); @@ -366,8 +366,8 @@ async fn test_fork_snapshotting_blocks() { let to = accounts[1].address(); let block_number = provider.get_block_number().await.unwrap(); - let initial_nonce = provider.get_transaction_count(from, None).await.unwrap(); - let balance_before = provider.get_balance(to, None).await.unwrap(); + let initial_nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); + let balance_before = provider.get_balance(to, BlockId::latest()).await.unwrap(); let amount = handle.genesis_balance().checked_div(rU256::from(2u64)).unwrap(); // send the transaction @@ -380,26 +380,29 @@ async fn test_fork_snapshotting_blocks() { let block_number_after = provider.get_block_number().await.unwrap(); assert_eq!(block_number_after, block_number + 1); - let nonce = provider.get_transaction_count(from, None).await.unwrap(); + let nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); assert_eq!(nonce, initial_nonce + 1); - let to_balance = provider.get_balance(to, None).await.unwrap(); + let to_balance = provider.get_balance(to, BlockId::latest()).await.unwrap(); assert_eq!(balance_before.saturating_add(amount), to_balance); // revert snapshot assert!(api.evm_revert(snapshot).await.unwrap()); - assert_eq!(initial_nonce, provider.get_transaction_count(from, None).await.unwrap()); + assert_eq!( + initial_nonce, + provider.get_transaction_count(from, BlockId::latest()).await.unwrap() + ); let block_number_after = provider.get_block_number().await.unwrap(); assert_eq!(block_number_after, block_number); // repeat transaction let _ = tx_provider.send_transaction(tx.clone(), None).await.unwrap().await.unwrap().unwrap(); - let nonce = provider.get_transaction_count(from, None).await.unwrap(); + let nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); assert_eq!(nonce, initial_nonce + 1); // revert again: nothing to revert since snapshot gone assert!(!api.evm_revert(snapshot).await.unwrap()); - let nonce = provider.get_transaction_count(from, None).await.unwrap(); + let nonce = provider.get_transaction_count(from, BlockId::latest()).await.unwrap(); assert_eq!(nonce, initial_nonce + 1); let block_number_after = provider.get_block_number().await.unwrap(); assert_eq!(block_number_after, block_number + 1); @@ -469,31 +472,46 @@ async fn can_reset_properly() { let origin_nonce = 1u64; origin_api.anvil_set_nonce(account, rU256::from(origin_nonce)).await.unwrap(); - assert_eq!(origin_nonce, origin_provider.get_transaction_count(account, None).await.unwrap()); + assert_eq!( + origin_nonce, + origin_provider.get_transaction_count(account, BlockId::latest()).await.unwrap() + ); let (fork_api, fork_handle) = spawn(NodeConfig::test().with_eth_rpc_url(Some(origin_handle.http_endpoint()))).await; let fork_provider = fork_handle.http_provider(); let fork_tx_provider = ethers_http_provider(&fork_handle.http_endpoint()); - assert_eq!(origin_nonce, fork_provider.get_transaction_count(account, None).await.unwrap()); + assert_eq!( + origin_nonce, + fork_provider.get_transaction_count(account, BlockId::latest()).await.unwrap() + ); let to = Address::random(); - let to_balance = fork_provider.get_balance(to.to_alloy(), None).await.unwrap(); + let to_balance = fork_provider.get_balance(to.to_alloy(), BlockId::latest()).await.unwrap(); let tx = TransactionRequest::new().from(account.to_ethers()).to(to).value(1337u64); let tx = fork_tx_provider.send_transaction(tx, None).await.unwrap().await.unwrap().unwrap(); // nonce incremented by 1 - assert_eq!(origin_nonce + 1, fork_provider.get_transaction_count(account, None).await.unwrap()); + assert_eq!( + origin_nonce + 1, + fork_provider.get_transaction_count(account, BlockId::latest()).await.unwrap() + ); // resetting to origin state fork_api.anvil_reset(Some(Forking::default())).await.unwrap(); // nonce reset to origin - assert_eq!(origin_nonce, fork_provider.get_transaction_count(account, None).await.unwrap()); + assert_eq!( + origin_nonce, + fork_provider.get_transaction_count(account, BlockId::latest()).await.unwrap() + ); // balance is reset - assert_eq!(to_balance, fork_provider.get_balance(to.to_alloy(), None).await.unwrap()); + assert_eq!( + to_balance, + fork_provider.get_balance(to.to_alloy(), BlockId::latest()).await.unwrap() + ); // tx does not exist anymore assert!(fork_tx_provider.get_transaction(tx.transaction_hash).await.is_err()) @@ -790,7 +808,7 @@ async fn test_fork_call() { let res1 = api .call( WithOtherFields::new(CallRequest { - to: Some(to.to_alloy()), + to: Some(TxKind::Call(to.to_alloy())), input: input.to_alloy().into(), ..Default::default() }), @@ -1179,7 +1197,7 @@ async fn test_fork_execution_reverted() { let resp = api .call( WithOtherFields::new(CallRequest { - to: Some(address!("Fd6CC4F251eaE6d02f9F7B41D1e80464D3d2F377")), + to: Some(TxKind::Call(address!("Fd6CC4F251eaE6d02f9F7B41D1e80464D3d2F377"))), input: TransactionInput::new("0x8f283b3c".as_bytes().into()), ..Default::default() }), diff --git a/crates/anvil/tests/it/genesis.rs b/crates/anvil/tests/it/genesis.rs index 0b243db3edb9..c8157e160164 100644 --- a/crates/anvil/tests/it/genesis.rs +++ b/crates/anvil/tests/it/genesis.rs @@ -2,6 +2,7 @@ use std::str::FromStr; +use alloy_eips::BlockId; use alloy_genesis::Genesis; use alloy_primitives::{Address, U256}; use alloy_provider::Provider; @@ -44,7 +45,7 @@ async fn can_apply_genesis() { assert_eq!(provider.get_chain_id().await.unwrap(), 19763u64); let addr: Address = Address::from_str("71562b71999873db5b286df957af199ec94617f7").unwrap(); - let balance = provider.get_balance(addr, None).await.unwrap(); + let balance = provider.get_balance(addr, BlockId::latest()).await.unwrap(); let expected: U256 = U256::from_str_radix("ffffffffffffffffffffffffff", 16).unwrap(); assert_eq!(balance, expected); diff --git a/crates/anvil/tests/it/transaction.rs b/crates/anvil/tests/it/transaction.rs index 46c059374c60..6dfae6a8d2a7 100644 --- a/crates/anvil/tests/it/transaction.rs +++ b/crates/anvil/tests/it/transaction.rs @@ -963,7 +963,7 @@ async fn estimates_gas_on_pending_by_default() { let tx = AlloyTransactionRequest::default() .from(recipient.to_alloy()) - .to(Some(sender.to_alloy())) + .to(sender.to_alloy()) .value(rU256::from(1e10)) .input(Bytes::from(vec![0x42]).into()); api.estimate_gas(WithOtherFields::new(tx), None, None).await.unwrap(); @@ -979,7 +979,7 @@ async fn test_estimate_gas() { let tx = AlloyTransactionRequest::default() .from(recipient.to_alloy()) - .to(Some(sender.to_alloy())) + .to(sender.to_alloy()) .value(rU256::from(1e10)) .input(Bytes::from(vec![0x42]).into()); // Expect the gas estimation to fail due to insufficient funds. diff --git a/crates/anvil/tests/it/wsapi.rs b/crates/anvil/tests/it/wsapi.rs index ce0c4d6a4387..58bad12ebcef 100644 --- a/crates/anvil/tests/it/wsapi.rs +++ b/crates/anvil/tests/it/wsapi.rs @@ -1,5 +1,6 @@ //! general eth api tests with websocket provider +use alloy_eips::BlockId; use alloy_provider::Provider; use anvil::{spawn, NodeConfig}; use ethers::types::U256; @@ -24,7 +25,7 @@ async fn can_dev_get_balance_ws() { let genesis_balance = handle.genesis_balance(); for acc in handle.genesis_accounts() { - let balance = provider.get_balance(acc, None).await.unwrap(); + let balance = provider.get_balance(acc, BlockId::latest()).await.unwrap(); assert_eq!(balance, genesis_balance); } } diff --git a/crates/cast/bin/cmd/access_list.rs b/crates/cast/bin/cmd/access_list.rs index ed572628de66..d344017f629d 100644 --- a/crates/cast/bin/cmd/access_list.rs +++ b/crates/cast/bin/cmd/access_list.rs @@ -1,5 +1,5 @@ use alloy_network::{AnyNetwork, TransactionBuilder}; -use alloy_primitives::Address; +use alloy_primitives::{Address, Bytes}; use alloy_provider::Provider; use alloy_rpc_types::{BlockId, TransactionRequest, WithOtherFields}; use alloy_transport::Transport; @@ -105,7 +105,7 @@ async fn access_list, T: Transport + Clone>( to_json: bool, ) -> Result<()> { let mut req = WithOtherFields::::default() - .with_to(to.into()) + .with_to(to.unwrap_or_default()) .with_from(from) .with_value(tx.value.unwrap_or_default()) .with_chain_id(chain.id()); @@ -127,7 +127,7 @@ async fn access_list, T: Transport + Clone>( Vec::new() }; - req.set_input(data.into()); + req.set_input::(data.into()); let cast = Cast::new(&provider); diff --git a/crates/cast/bin/cmd/call.rs b/crates/cast/bin/cmd/call.rs index eeb09d5c0442..32b4ec794e2b 100644 --- a/crates/cast/bin/cmd/call.rs +++ b/crates/cast/bin/cmd/call.rs @@ -1,5 +1,5 @@ use alloy_network::TransactionBuilder; -use alloy_primitives::U256; +use alloy_primitives::{Bytes, TxKind, U256}; use alloy_rpc_types::{BlockId, TransactionRequest, WithOtherFields}; use cast::Cast; use clap::Parser; @@ -122,7 +122,7 @@ impl CallArgs { }; let mut req = WithOtherFields::::default() - .with_to(to.into()) + .with_to(to.unwrap_or_default()) .with_from(sender) .with_value(tx.value.unwrap_or_default()); @@ -209,9 +209,10 @@ impl CallArgs { let mut executor = TracingExecutor::new(env, fork, evm_version, debug); + let to = if let Some(TxKind::Call(to)) = req.to { Some(to) } else { None }; let trace = TraceResult::from(executor.call_raw_committing( sender, - req.to.expect("an address to be here"), + to.expect("an address to be here"), data.into(), req.value.unwrap_or_default(), )?); @@ -225,7 +226,7 @@ impl CallArgs { } }; - req.set_input(data.into()); + req.set_input::(data.into()); println!("{}", Cast::new(provider).call(&req, func.as_ref(), block).await?); diff --git a/crates/cast/bin/cmd/estimate.rs b/crates/cast/bin/cmd/estimate.rs index 55149937b8a6..6ee33ed26715 100644 --- a/crates/cast/bin/cmd/estimate.rs +++ b/crates/cast/bin/cmd/estimate.rs @@ -1,7 +1,7 @@ use alloy_network::TransactionBuilder; -use alloy_primitives::U256; +use alloy_primitives::{Bytes, U256}; use alloy_provider::Provider; -use alloy_rpc_types::{TransactionRequest, WithOtherFields}; +use alloy_rpc_types::{BlockId, TransactionRequest, WithOtherFields}; use clap::Parser; use eyre::Result; use foundry_cli::{ @@ -94,7 +94,7 @@ impl EstimateArgs { }; let mut req = WithOtherFields::::default() - .with_to(to.into()) + .with_to(to.unwrap_or_default()) .with_from(from) .with_value(value.unwrap_or_default()); @@ -121,9 +121,9 @@ impl EstimateArgs { } }; - req.set_input(data.into()); + req.set_input::(data.into()); - let gas = provider.estimate_gas(&req, None).await?; + let gas = provider.estimate_gas(&req, BlockId::latest()).await?; println!("{gas}"); Ok(()) } diff --git a/crates/cast/bin/cmd/mktx.rs b/crates/cast/bin/cmd/mktx.rs index def6d46f4b27..e26115da32ab 100644 --- a/crates/cast/bin/cmd/mktx.rs +++ b/crates/cast/bin/cmd/mktx.rs @@ -2,6 +2,7 @@ use crate::tx; use alloy_network::{eip2718::Encodable2718, EthereumSigner, TransactionBuilder}; use alloy_primitives::U64; use alloy_provider::Provider; +use alloy_rpc_types::BlockId; use alloy_signer::Signer; use clap::Parser; use eyre::Result; @@ -89,7 +90,8 @@ impl MakeTxArgs { tx::validate_from_address(eth.wallet.from, from)?; if resend { - tx.nonce = Some(U64::from(provider.get_transaction_count(from, None).await?)); + tx.nonce = + Some(U64::from(provider.get_transaction_count(from, BlockId::latest()).await?)); } let provider = get_provider(&config)?; diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index b24de5fba294..7799f522691d 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -2,6 +2,7 @@ use crate::tx; use alloy_network::{AnyNetwork, EthereumSigner}; use alloy_primitives::{Address, U64}; use alloy_provider::{Provider, ProviderBuilder}; +use alloy_rpc_types::BlockId; use alloy_signer::Signer; use alloy_transport::Transport; use cast::Cast; @@ -142,8 +143,9 @@ impl SendTxArgs { } if resend { - tx.nonce = - Some(U64::from(provider.get_transaction_count(config.sender, None).await?)); + tx.nonce = Some(U64::from( + provider.get_transaction_count(config.sender, BlockId::latest()).await?, + )); } cast_send( @@ -173,7 +175,8 @@ impl SendTxArgs { tx::validate_from_address(eth.wallet.from, from)?; if resend { - tx.nonce = Some(U64::from(provider.get_transaction_count(from, None).await?)); + tx.nonce = + Some(U64::from(provider.get_transaction_count(from, BlockId::latest()).await?)); } let signer = EthereumSigner::from(signer); diff --git a/crates/cast/bin/cmd/storage.rs b/crates/cast/bin/cmd/storage.rs index 0bf041b8a9cf..18411165ea13 100644 --- a/crates/cast/bin/cmd/storage.rs +++ b/crates/cast/bin/cmd/storage.rs @@ -230,7 +230,8 @@ async fn fetch_storage_slots, T: Transport + Clone>( ) -> Result> { let requests = layout.storage.iter().map(|storage_slot| async { let slot = B256::from(U256::from_str(&storage_slot.slot)?); - let raw_slot_value = provider.get_storage_at(address, slot.into(), block).await?; + let raw_slot_value = + provider.get_storage_at(address, slot.into(), block.unwrap_or_default()).await?; let value = StorageValue { slot, raw_slot_value: raw_slot_value.into() }; diff --git a/crates/cast/bin/main.rs b/crates/cast/bin/main.rs index 565cd6eda7a8..e1b411864bd2 100644 --- a/crates/cast/bin/main.rs +++ b/crates/cast/bin/main.rs @@ -346,7 +346,9 @@ async fn main() -> Result<()> { let config = Config::from(&rpc); let provider = utils::get_provider(&config)?; let address = address.resolve(&provider).await?; - let value = provider.get_proof(address, slots.into_iter().collect(), block).await?; + let value = provider + .get_proof(address, slots.into_iter().collect(), block.unwrap_or(BlockId::latest())) + .await?; println!("{}", serde_json::to_string(&value)?); } CastSubcommand::Rpc(cmd) => cmd.run().await?, diff --git a/crates/cast/bin/tx.rs b/crates/cast/bin/tx.rs index 98f7bf67e4c4..184da16d6dca 100644 --- a/crates/cast/bin/tx.rs +++ b/crates/cast/bin/tx.rs @@ -1,8 +1,8 @@ use alloy_json_abi::Function; use alloy_network::{AnyNetwork, TransactionBuilder}; -use alloy_primitives::{Address, U256}; +use alloy_primitives::{Address, Bytes, U256}; use alloy_provider::Provider; -use alloy_rpc_types::{TransactionRequest, WithOtherFields}; +use alloy_rpc_types::{BlockId, TransactionRequest, WithOtherFields}; use alloy_transport::Transport; use eyre::Result; use foundry_cli::{opts::TransactionOpts, utils::parse_function_args}; @@ -56,10 +56,12 @@ pub async fn build_tx< let chain = chain.into(); let from = from.into().resolve(provider).await?; - let to = if let Some(to) = to { Some(to.into().resolve(provider).await?) } else { None }; + // TODO: Possible bug here? + let to: Option
= + if let Some(to) = to { Some(to.into().resolve(provider).await?) } else { None }; let mut req = WithOtherFields::new(TransactionRequest::default()) - .with_to(to.into()) + .with_to(to.unwrap_or_default()) .with_from(from) .with_value(tx.value.unwrap_or_default()) .with_chain_id(chain.id()); @@ -67,7 +69,7 @@ pub async fn build_tx< req.set_nonce(if let Some(nonce) = tx.nonce { nonce.to() } else { - provider.get_transaction_count(from, None).await? + provider.get_transaction_count(from, BlockId::latest()).await? }); if tx.legacy || chain.is_legacy() { @@ -110,12 +112,12 @@ pub async fn build_tx< (Vec::new(), None) }; - req.set_input(data.into()); + req.set_input::(data.into()); req.set_gas_limit(if let Some(gas_limit) = tx.gas_limit { gas_limit.to() } else { - provider.estimate_gas(&req, None).await? + provider.estimate_gas(&req, BlockId::latest()).await? }); Ok((req, func)) diff --git a/crates/cast/src/lib.rs b/crates/cast/src/lib.rs index d63bbc33e370..1f26acbee85a 100644 --- a/crates/cast/src/lib.rs +++ b/crates/cast/src/lib.rs @@ -4,7 +4,7 @@ use alloy_json_abi::{ContractObject, Function}; use alloy_network::AnyNetwork; use alloy_primitives::{ utils::{keccak256, ParseUnits, Unit}, - Address, Keccak256, TxHash, B256, I256, U256, + Address, Keccak256, TxHash, TxKind, B256, I256, U256, }; use alloy_provider::{ network::eip2718::{Decodable2718, Encodable2718}, @@ -106,7 +106,7 @@ where /// let to = Address::from_str("0xB3C95ff08316fb2F2e3E52Ee82F8e7b605Aa1304")?; /// let greeting = greetingCall { i: U256::from(5) }.abi_encode(); /// let bytes = Bytes::from_iter(greeting.iter()); - /// let tx = TransactionRequest::default().to(Some(to)).input(bytes.into()); + /// let tx = TransactionRequest::default().to(to).input(bytes.into()); /// let tx = WithOtherFields::new(tx); /// let cast = Cast::new(alloy_provider); /// let data = cast.call(&tx, None, None).await?; @@ -120,7 +120,7 @@ where func: Option<&Function>, block: Option, ) -> Result { - let res = self.provider.call(req, block).await?; + let res = self.provider.call(req, block.unwrap_or(BlockId::latest())).await?; let mut decoded = vec![]; @@ -132,7 +132,7 @@ where // ensure the address is a contract if res.is_empty() { // check that the recipient is a contract that can be called - if let Some(addr) = req.to { + if let Some(TxKind::Call(addr)) = req.to { if let Ok(code) = self.provider.get_code_at(addr, block.unwrap_or_default()).await { @@ -140,6 +140,10 @@ where eyre::bail!("contract {addr:?} does not have any code") } } + } else if Some(TxKind::Create) == req.to { + eyre::bail!("tx req is a contract deployment"); + } else { + eyre::bail!("recipient is None"); } } return Err(err).wrap_err( @@ -179,7 +183,7 @@ where /// let to = Address::from_str("0xB3C95ff08316fb2F2e3E52Ee82F8e7b605Aa1304")?; /// let greeting = greetingCall { i: U256::from(5) }.abi_encode(); /// let bytes = Bytes::from_iter(greeting.iter()); - /// let tx = TransactionRequest::default().to(Some(to)).input(bytes.into()); + /// let tx = TransactionRequest::default().to(to).input(bytes.into()); /// let tx = WithOtherFields::new(tx); /// let cast = Cast::new(&provider); /// let access_list = cast.access_list(&tx, None, false).await?; @@ -193,7 +197,8 @@ where block: Option, to_json: bool, ) -> Result { - let access_list = self.provider.create_access_list(req, block).await?; + let access_list = + self.provider.create_access_list(req, block.unwrap_or(BlockId::latest())).await?; let res = if to_json { serde_json::to_string(&access_list)? } else { @@ -215,7 +220,7 @@ where } pub async fn balance(&self, who: Address, block: Option) -> Result { - Ok(self.provider.get_balance(who, block).await?) + Ok(self.provider.get_balance(who, block.unwrap_or(BlockId::latest())).await?) } /// Sends a transaction to the specified address @@ -243,7 +248,7 @@ where /// let gas = U256::from_str("200000").unwrap(); /// let value = U256::from_str("1").unwrap(); /// let nonce = U256::from_str("1").unwrap(); - /// let tx = TransactionRequest::default().to(Some(to)).input(bytes.into()).from(from); + /// let tx = TransactionRequest::default().to(to).input(bytes.into()).from(from); /// let tx = WithOtherFields::new(tx); /// let cast = Cast::new(provider); /// let data = cast.send(tx).await?; @@ -467,7 +472,7 @@ where /// # } /// ``` pub async fn nonce(&self, who: Address, block: Option) -> Result { - Ok(self.provider.get_transaction_count(who, block).await?) + Ok(self.provider.get_transaction_count(who, block.unwrap_or(BlockId::latest())).await?) } /// # Example @@ -491,7 +496,10 @@ where pub async fn implementation(&self, who: Address, block: Option) -> Result { let slot = B256::from_str("0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc")?; - let value = self.provider.get_storage_at(who, slot.into(), block).await?; + let value = self + .provider + .get_storage_at(who, slot.into(), block.unwrap_or(BlockId::latest())) + .await?; let addr = Address::from_word(value.into()); Ok(format!("{addr:?}")) } @@ -517,7 +525,10 @@ where pub async fn admin(&self, who: Address, block: Option) -> Result { let slot = B256::from_str("0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103")?; - let value = self.provider.get_storage_at(who, slot.into(), block).await?; + let value = self + .provider + .get_storage_at(who, slot.into(), block.unwrap_or(BlockId::latest())) + .await?; let addr = Address::from_word(value.into()); Ok(format!("{addr:?}")) } @@ -756,7 +767,11 @@ where ) -> Result { Ok(format!( "{:?}", - B256::from(self.provider.get_storage_at(from, slot.into(), block).await?) + B256::from( + self.provider + .get_storage_at(from, slot.into(), block.unwrap_or(BlockId::latest())) + .await? + ) )) } diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index 64d2e70a4f98..68418e2823a7 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -15,7 +15,7 @@ use crate::{ CheatsConfig, CheatsCtxt, DynCheatcode, Error, Result, Vm, Vm::AccountAccess, }; -use alloy_primitives::{Address, Bytes, Log, B256, U256}; +use alloy_primitives::{Address, Bytes, Log, TxKind, B256, U256}; use alloy_rpc_types::request::{TransactionInput, TransactionRequest}; use alloy_sol_types::{SolInterface, SolValue}; use foundry_common::{evm::Breakpoints, provider::alloy::RpcUrl, SELECTOR_LEN}; @@ -915,7 +915,7 @@ impl Inspector for Cheatcodes { rpc: ecx.db.active_fork_url(), transaction: TransactionRequest { from: Some(broadcast.new_origin), - to: Some(call.contract), + to: Some(TxKind::Call(call.contract)), value: Some(call.transfer.value), input: TransactionInput::new(call.input.clone()), nonce: Some(account.info.nonce), diff --git a/crates/common/src/fmt/ui.rs b/crates/common/src/fmt/ui.rs index 1607b6d104dc..26db7038cc1b 100644 --- a/crates/common/src/fmt/ui.rs +++ b/crates/common/src/fmt/ui.rs @@ -453,7 +453,7 @@ pub fn get_pretty_tx_receipt_attr( } "transactionHash" | "transaction_hash" => Some(receipt.receipt.transaction_hash.pretty()), "transactionIndex" | "transaction_index" => { - Some(receipt.receipt.transaction_index.to_string()) + Some(receipt.receipt.transaction_index.pretty()) } "type" | "transaction_type" => Some(receipt.receipt.inner.inner.r#type.to_string()), "revertReason" | "revert_reason" => Some(receipt.revert_reason.pretty()), diff --git a/crates/common/src/transactions.rs b/crates/common/src/transactions.rs index cf3f5a89a75a..1f7d6228eef3 100644 --- a/crates/common/src/transactions.rs +++ b/crates/common/src/transactions.rs @@ -50,7 +50,7 @@ impl TransactionReceiptWithRevertReason { match provider .call( &WithOtherFields::new(transaction.inner.into()), - Some(BlockId::Hash(block_hash.into())), + BlockId::Hash(block_hash.into()), ) .await { diff --git a/crates/evm/core/src/fork/backend.rs b/crates/evm/core/src/fork/backend.rs index f6da76fc5c42..5daa4e96ce52 100644 --- a/crates/evm/core/src/fork/backend.rs +++ b/crates/evm/core/src/fork/backend.rs @@ -187,7 +187,7 @@ where trace!(target: "backendhandler", %address, %idx, "preparing storage request"); entry.insert(vec![listener]); let provider = self.provider.clone(); - let block_id = self.block_id; + let block_id = self.block_id.unwrap_or(BlockId::latest()); let fut = Box::pin(async move { let storage = provider.get_storage_at(address, idx, block_id).await.map_err(Into::into); @@ -202,11 +202,11 @@ where fn get_account_req(&self, address: Address) -> ProviderRequest { trace!(target: "backendhandler", "preparing account request, address={:?}", address); let provider = self.provider.clone(); - let block_id = self.block_id; + let block_id = self.block_id.unwrap_or(BlockId::latest()); let fut = Box::pin(async move { let balance = provider.get_balance(address, block_id); let nonce = provider.get_transaction_count(address, block_id); - let code = provider.get_code_at(address, block_id.unwrap_or_default()); + let code = provider.get_code_at(address, block_id); let resp = tokio::try_join!(balance, nonce, code).map_err(Into::into); (resp, address) }); diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 68b303362efd..dfa1c003e63f 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -4,7 +4,7 @@ use alloy_json_abi::{Constructor, JsonAbi}; use alloy_network::{AnyNetwork, EthereumSigner, TransactionBuilder}; use alloy_primitives::{Address, Bytes}; use alloy_provider::{Provider, ProviderBuilder}; -use alloy_rpc_types::{AnyTransactionReceipt, TransactionRequest, WithOtherFields}; +use alloy_rpc_types::{AnyTransactionReceipt, BlockId, TransactionRequest, WithOtherFields}; use alloy_signer::Signer; use alloy_transport::{Transport, TransportError}; use clap::{Parser, ValueHint}; @@ -233,17 +233,20 @@ impl CreateArgs { deployer.tx.set_from(deployer_address); deployer.tx.set_chain_id(chain); - + // `to` field must be set explicitly, cannot be None. + if deployer.tx.to.is_none() { + deployer.tx.set_create(); + } deployer.tx.set_nonce(if let Some(nonce) = self.tx.nonce { Ok(nonce.to()) } else { - provider.get_transaction_count(deployer_address, None).await + provider.get_transaction_count(deployer_address, BlockId::latest()).await }?); deployer.tx.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { Ok(gas_limit.to()) } else { - provider.estimate_gas(&deployer.tx, None).await + provider.estimate_gas(&deployer.tx, BlockId::latest()).await }?); // set tx value if specified @@ -557,7 +560,7 @@ where }; // create the tx object. Since we're deploying a contract, `to` is `None` - let tx = WithOtherFields::new(TransactionRequest::default().input(data.into()).to(None)); + let tx = WithOtherFields::new(TransactionRequest::default().input(data.into())); Ok(Deployer { client: self.client.clone(), diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index 0cb5b0c9c529..cd4decfcbe33 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -4,7 +4,7 @@ use crate::{ ScriptConfig, }; use alloy_chains::Chain; -use alloy_eips::eip2718::Encodable2718; +use alloy_eips::{eip2718::Encodable2718, BlockId}; use alloy_network::{AnyNetwork, EthereumSigner, TransactionBuilder}; use alloy_primitives::{utils::format_units, Address, TxHash}; use alloy_provider::{utils::Eip1559Estimation, Provider}; @@ -45,7 +45,10 @@ where tx.gas = None; tx.set_gas_limit( - provider.estimate_gas(tx, None).await.wrap_err("Failed to estimate gas for tx")? * + provider + .estimate_gas(tx, BlockId::latest()) + .await + .wrap_err("Failed to estimate gas for tx")? * estimate_multiplier as u128 / 100, ); @@ -55,7 +58,7 @@ where pub async fn next_nonce(caller: Address, provider_url: &str) -> eyre::Result { let provider = try_get_http_provider(provider_url) .wrap_err_with(|| format!("bad fork_url provider: {provider_url}"))?; - Ok(provider.get_transaction_count(caller, None).await?) + Ok(provider.get_transaction_count(caller, BlockId::latest()).await?) } pub async fn send_transaction( @@ -70,7 +73,7 @@ pub async fn send_transaction( let from = tx.from.expect("no sender"); if sequential_broadcast { - let nonce = provider.get_transaction_count(from, None).await?; + let nonce = provider.get_transaction_count(from, BlockId::latest()).await?; let tx_nonce = tx.nonce.expect("no nonce"); if nonce != tx_nonce { @@ -287,6 +290,11 @@ impl BundledState { let mut tx = tx.clone(); tx.set_chain_id(sequence.chain); + // Set TxKind::Create explicityly to satify `check_reqd_fields` in alloy + if tx.to().is_none() { + tx.set_create(); + } + if let Some(gas_price) = gas_price { tx.set_gas_price(gas_price); } else { diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index bbdda84ae55c..9500c4d714e3 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -6,7 +6,7 @@ extern crate tracing; use self::transaction::AdditionalContract; use crate::runner::ScriptRunner; use alloy_json_abi::{Function, JsonAbi}; -use alloy_primitives::{Address, Bytes, Log, U256}; +use alloy_primitives::{Address, Bytes, Log, TxKind, U256}; use alloy_signer::Signer; use broadcast::next_nonce; use build::PreprocessedState; @@ -400,13 +400,15 @@ impl ScriptArgs { let mut offset = 0; // Find if it's a CREATE or CREATE2. Otherwise, skip transaction. - if let Some(to) = to { + if let Some(TxKind::Call(to)) = to { if to == DEFAULT_CREATE2_DEPLOYER { // Size of the salt prefix. offset = 32; + } else { + continue; } - } else if to.is_some() { - continue; + } else if let Some(TxKind::Create) = to { + // Pass } // Find artifact with a deployment code same as the data. diff --git a/crates/script/src/simulate.rs b/crates/script/src/simulate.rs index 87f9b3515fb2..37926e3080cd 100644 --- a/crates/script/src/simulate.rs +++ b/crates/script/src/simulate.rs @@ -13,7 +13,7 @@ use crate::{ ScriptArgs, ScriptConfig, ScriptResult, }; use alloy_network::TransactionBuilder; -use alloy_primitives::{utils::format_units, Address, U256}; +use alloy_primitives::{utils::format_units, Address, TxKind, U256}; use eyre::{Context, Result}; use foundry_cheatcodes::{BroadcastableTransactions, ScriptWallets}; use foundry_cli::utils::{has_different_gas_calc, now}; @@ -99,11 +99,12 @@ impl PreSimulationState { let mut runner = runners.get(&rpc).expect("invalid rpc url").write(); let mut tx = transaction.transaction; + let to = if let Some(TxKind::Call(to)) = tx.to { Some(to) } else { None }; let result = runner .simulate( tx.from .expect("transaction doesn't have a `from` address at execution time"), - tx.to, + to, tx.input.clone().into_input(), tx.value, ) diff --git a/crates/script/src/transaction.rs b/crates/script/src/transaction.rs index 3f5405db6f68..534b4964138b 100644 --- a/crates/script/src/transaction.rs +++ b/crates/script/src/transaction.rs @@ -1,6 +1,6 @@ use super::ScriptResult; use alloy_dyn_abi::JsonAbiExt; -use alloy_primitives::{Address, Bytes, B256}; +use alloy_primitives::{Address, Bytes, TxKind, B256}; use alloy_rpc_types::{request::TransactionRequest, WithOtherFields}; use eyre::{ContextCompat, Result, WrapErr}; use foundry_common::{fmt::format_token_raw, provider::alloy::RpcUrl, ContractData, SELECTOR_LEN}; @@ -71,7 +71,7 @@ impl TransactionWithMetadata { metadata.is_fixed_gas_limit = is_fixed_gas_limit; // Specify if any contract was directly created with this transaction - if let Some(to) = metadata.transaction.to { + if let Some(TxKind::Call(to)) = metadata.transaction.to { if to == DEFAULT_CREATE2_DEPLOYER { metadata.set_create( true, diff --git a/crates/test-utils/Cargo.toml b/crates/test-utils/Cargo.toml index 195048711779..a73c53a394c2 100644 --- a/crates/test-utils/Cargo.toml +++ b/crates/test-utils/Cargo.toml @@ -18,6 +18,7 @@ foundry-config.workspace = true alloy-primitives.workspace = true alloy-provider.workspace = true +alloy-rpc-types.workspace = true eyre.workspace = true fd-lock = "4.0.0" diff --git a/crates/test-utils/src/script.rs b/crates/test-utils/src/script.rs index fecbc9f5f07f..3fa5f07f8995 100644 --- a/crates/test-utils/src/script.rs +++ b/crates/test-utils/src/script.rs @@ -1,6 +1,7 @@ use crate::{init_tracing, TestCommand}; use alloy_primitives::Address; use alloy_provider::Provider; +use alloy_rpc_types::BlockId; use eyre::Result; use foundry_common::provider::alloy::{get_http_provider, RetryProvider}; use std::{collections::BTreeMap, fs, path::Path, str::FromStr}; @@ -117,7 +118,7 @@ impl ScriptTester { if let Some(provider) = &self.provider { let nonce = provider - .get_transaction_count(self.accounts_pub[index as usize], None) + .get_transaction_count(self.accounts_pub[index as usize], BlockId::latest()) .await .unwrap(); self.nonces.insert(index, nonce); @@ -128,8 +129,13 @@ impl ScriptTester { pub async fn load_addresses(&mut self, addresses: &[Address]) -> &mut Self { for &address in addresses { - let nonce = - self.provider.as_ref().unwrap().get_transaction_count(address, None).await.unwrap(); + let nonce = self + .provider + .as_ref() + .unwrap() + .get_transaction_count(address, BlockId::latest()) + .await + .unwrap(); self.address_nonces.insert(address, nonce); } self @@ -169,8 +175,13 @@ impl ScriptTester { pub async fn assert_nonce_increment(&mut self, keys_indexes: &[(u32, u32)]) -> &mut Self { for &(private_key_slot, expected_increment) in keys_indexes { let addr = self.accounts_pub[private_key_slot as usize]; - let nonce = - self.provider.as_ref().unwrap().get_transaction_count(addr, None).await.unwrap(); + let nonce = self + .provider + .as_ref() + .unwrap() + .get_transaction_count(addr, BlockId::latest()) + .await + .unwrap(); let prev_nonce = self.nonces.get(&private_key_slot).unwrap(); assert_eq!( @@ -193,7 +204,7 @@ impl ScriptTester { .provider .as_ref() .unwrap() - .get_transaction_count(*address, None) + .get_transaction_count(*address, BlockId::latest()) .await .unwrap(); let prev_nonce = self.address_nonces.get(address).unwrap(); diff --git a/crates/verify/src/bytecode.rs b/crates/verify/src/bytecode.rs index 6f8d44ff9ad2..91963752d9ba 100644 --- a/crates/verify/src/bytecode.rs +++ b/crates/verify/src/bytecode.rs @@ -286,9 +286,8 @@ impl VerifyBytecodeArgs { // Workaround for the NonceTooHigh issue as we're not simulating prior txs of the same // block. let prev_block_id = BlockId::Number(BlockNumberOrTag::Number(simulation_block - 1)); - let prev_block_nonce = provider - .get_transaction_count(creation_data.contract_creator, Some(prev_block_id)) - .await?; + let prev_block_nonce = + provider.get_transaction_count(creation_data.contract_creator, prev_block_id).await?; transaction.nonce = prev_block_nonce; if let Some(ref block) = block { diff --git a/crates/wallets/src/wallet_signer.rs b/crates/wallets/src/wallet_signer.rs index 9cf4478e2d8b..37526559c7f0 100644 --- a/crates/wallets/src/wallet_signer.rs +++ b/crates/wallets/src/wallet_signer.rs @@ -91,7 +91,7 @@ impl WalletSigner { } } WalletSigner::Aws(aws) => { - senders.push(aws.address()); + senders.push(alloy_signer::Signer::address(aws)); } } Ok(senders) @@ -142,7 +142,7 @@ impl Signer for WalletSigner { } fn address(&self) -> Address { - delegate!(self, inner => inner.address()) + delegate!(self, inner => alloy_signer::Signer::address(inner)) } fn chain_id(&self) -> Option { @@ -180,6 +180,10 @@ impl TxSigner for WalletSigner { ) -> alloy_signer::Result { delegate!(self, inner => inner.sign_transaction(tx)).await } + + fn address(&self) -> Address { + delegate!(self, inner => alloy_signer::Signer::address(inner)) + } } /// Signers that require user action to be obtained.