Skip to content

Commit

Permalink
fix: vm.broadcastRawTransaction (#9378)
Browse files Browse the repository at this point in the history
fix: vm.broadcastRawTransaction
  • Loading branch information
klkvr authored Nov 22, 2024
1 parent 41b4359 commit 2bc7125
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions crates/common/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionRequest>> {
match self {
Self::Unsigned(tx) => Some(tx),
Expand Down
13 changes: 9 additions & 4 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -2039,8 +2039,7 @@ forgetest_async!(can_deploy_library_create2_different_sender, |prj, cmd| {

// <https://github.com/foundry-rs/foundry/issues/8993>
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(
Expand All @@ -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(
Expand Down Expand Up @@ -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| {
Expand Down
7 changes: 6 additions & 1 deletion crates/script/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<AddressHashSet>();

if required_addresses.contains(&Config::DEFAULT_SENDER) {
Expand Down

0 comments on commit 2bc7125

Please sign in to comment.