From f824e29dac09497e06052533a0d82e2c70fdadee Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Fri, 22 Nov 2024 05:39:03 +0400 Subject: [PATCH] fix: `vm.broadcastRawTransaction` (#9378) fix: vm.broadcastRawTransaction --- crates/common/src/transactions.rs | 4 ++++ crates/forge/tests/cli/script.rs | 13 +++++++++---- crates/script/src/broadcast.rs | 7 ++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/common/src/transactions.rs b/crates/common/src/transactions.rs index b319da0d877b4..a05a46eaed236 100644 --- a/crates/common/src/transactions.rs +++ b/crates/common/src/transactions.rs @@ -179,6 +179,10 @@ impl TransactionMaybeSigned { Ok(Self::Signed { tx, from }) } + pub fn is_unsigned(&self) -> bool { + matches!(self, Self::Unsigned(_)) + } + pub fn as_unsigned_mut(&mut self) -> Option<&mut WithOtherFields> { match self { Self::Unsigned(tx) => Some(tx), diff --git a/crates/forge/tests/cli/script.rs b/crates/forge/tests/cli/script.rs index 82c61ccbc3887..38e702a1b22fb 100644 --- a/crates/forge/tests/cli/script.rs +++ b/crates/forge/tests/cli/script.rs @@ -1,7 +1,7 @@ //! Contains various tests related to `forge script`. use crate::constants::TEMPLATE_CONTRACT; -use alloy_primitives::{hex, Address, Bytes}; +use alloy_primitives::{address, hex, Address, Bytes}; use anvil::{spawn, NodeConfig}; use forge_script_sequence::ScriptSequence; use foundry_test_utils::{ @@ -2039,8 +2039,7 @@ forgetest_async!(can_deploy_library_create2_different_sender, |prj, cmd| { // forgetest_async!(test_broadcast_raw_create2_deployer, |prj, cmd| { - let (_api, handle) = - spawn(NodeConfig::test().with_disable_default_create2_deployer(true)).await; + let (api, handle) = spawn(NodeConfig::test().with_disable_default_create2_deployer(true)).await; foundry_test_utils::util::initialize(prj.root()); prj.add_script( @@ -2051,7 +2050,7 @@ import "forge-std/Script.sol"; contract SimpleScript is Script { function run() external { // send funds to create2 factory deployer - vm.broadcast(); + vm.startBroadcast(); payable(0x3fAB184622Dc19b6109349B94811493BF2a45362).transfer(10000000 gwei); // deploy create2 factory vm.broadcastRawTransaction( @@ -2104,6 +2103,12 @@ ONCHAIN EXECUTION COMPLETE & SUCCESSFUL. "#]]); + + assert!(!api + .get_code(address!("4e59b44847b379578588920cA78FbF26c0B4956C"), Default::default()) + .await + .unwrap() + .is_empty()); }); forgetest_init!(can_get_script_wallets, |prj, cmd| { diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index 4058aa6c59b3f..51e8baf5b3be8 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -213,7 +213,12 @@ impl BundledState { .sequence .sequences() .iter() - .flat_map(|sequence| sequence.transactions().map(|tx| tx.from().expect("missing from"))) + .flat_map(|sequence| { + sequence + .transactions() + .filter(|tx| tx.is_unsigned()) + .map(|tx| tx.from().expect("missing from")) + }) .collect::(); if required_addresses.contains(&Config::DEFAULT_SENDER) {