Skip to content

Commit

Permalink
fix(cheatcodes): record state diff only if balance changed (#9658)
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy authored Jan 9, 2025
1 parent 82cf61d commit 6cbf390
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,15 +1149,15 @@ fn get_recorded_state_diffs(state: &mut Cheatcodes) -> BTreeMap<Address, Account
account_access.oldBalance != account_access.newBalance
})
.for_each(|account_access| {
let account_diff = state_diffs.entry(account_access.account).or_insert_with(|| {
AccountStateDiffs {
label: state.labels.get(&account_access.account).cloned(),
..Default::default()
}
});

// Record account balance diffs.
if account_access.oldBalance != account_access.newBalance {
let account_diff =
state_diffs.entry(account_access.account).or_insert_with(|| {
AccountStateDiffs {
label: state.labels.get(&account_access.account).cloned(),
..Default::default()
}
});
// Update balance diff. Do not overwrite the initial balance if already set.
if let Some(diff) = &mut account_diff.balance_diff {
diff.new_value = account_access.newBalance;
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/repros/Issue9643.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract Issue9643Test is DSTest {
proxied.setCounter(42);
string memory rawDiff = vm.getStateDiffJson();
assertEq(
"{\"0x2e234dae75c793f67a35089c9d99245e1c58470b\":{\"label\":null,\"balanceDiff\":null,\"stateDiff\":{\"0x0000000000000000000000000000000000000000000000000000000000000000\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x000000000000000000000000000000000000000000000000000000000000002a\"}}},\"0x5615deb798bb3e4dfa0139dfa1b3d433cc23b72f\":{\"label\":null,\"balanceDiff\":null,\"stateDiff\":{}}}",
"{\"0x2e234dae75c793f67a35089c9d99245e1c58470b\":{\"label\":null,\"balanceDiff\":null,\"stateDiff\":{\"0x0000000000000000000000000000000000000000000000000000000000000000\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x000000000000000000000000000000000000000000000000000000000000002a\"}}}}",
rawDiff
);
}
Expand Down

0 comments on commit 6cbf390

Please sign in to comment.