Skip to content

Commit 1e03143

Browse files
4meta5mattsse
andauthored
only add privkey to script wallets if broadcast is successful (#4828)
Co-authored-by: Matthias Seitz <[email protected]>
1 parent 7fbe257 commit 1e03143

File tree

1 file changed

+6
-2
lines changed
  • evm/src/executor/inspector/cheatcodes

1 file changed

+6
-2
lines changed

evm/src/executor/inspector/cheatcodes/env.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ fn broadcast(
108108

109109
/// Sets up broadcasting from a script with the sender derived from `private_key`
110110
/// Adds this private key to `state`'s `script_wallets` vector to later be used for signing
111+
/// iff broadcast is successful
111112
fn broadcast_key(
112113
state: &mut Cheatcodes,
113114
private_key: U256,
@@ -120,9 +121,12 @@ fn broadcast_key(
120121
let key = super::util::parse_private_key(private_key)?;
121122
let wallet = LocalWallet::from(key).with_chain_id(chain_id.as_u64());
122123
let new_origin = wallet.address();
123-
state.script_wallets.push(wallet);
124124

125-
broadcast(state, new_origin, original_caller, original_origin, depth, single_call)
125+
let result = broadcast(state, new_origin, original_caller, original_origin, depth, single_call);
126+
if result.is_ok() {
127+
state.script_wallets.push(wallet);
128+
}
129+
result
126130
}
127131

128132
fn prank(

0 commit comments

Comments
 (0)