Skip to content

Commit 6cbf390

Browse files
authored
fix(cheatcodes): record state diff only if balance changed (#9658)
1 parent 82cf61d commit 6cbf390

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

crates/cheatcodes/src/evm.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,15 +1149,15 @@ fn get_recorded_state_diffs(state: &mut Cheatcodes) -> BTreeMap<Address, Account
11491149
account_access.oldBalance != account_access.newBalance
11501150
})
11511151
.for_each(|account_access| {
1152-
let account_diff = state_diffs.entry(account_access.account).or_insert_with(|| {
1153-
AccountStateDiffs {
1154-
label: state.labels.get(&account_access.account).cloned(),
1155-
..Default::default()
1156-
}
1157-
});
1158-
11591152
// Record account balance diffs.
11601153
if account_access.oldBalance != account_access.newBalance {
1154+
let account_diff =
1155+
state_diffs.entry(account_access.account).or_insert_with(|| {
1156+
AccountStateDiffs {
1157+
label: state.labels.get(&account_access.account).cloned(),
1158+
..Default::default()
1159+
}
1160+
});
11611161
// Update balance diff. Do not overwrite the initial balance if already set.
11621162
if let Some(diff) = &mut account_diff.balance_diff {
11631163
diff.new_value = account_access.newBalance;

testdata/default/repros/Issue9643.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ contract Issue9643Test is DSTest {
4242
proxied.setCounter(42);
4343
string memory rawDiff = vm.getStateDiffJson();
4444
assertEq(
45-
"{\"0x2e234dae75c793f67a35089c9d99245e1c58470b\":{\"label\":null,\"balanceDiff\":null,\"stateDiff\":{\"0x0000000000000000000000000000000000000000000000000000000000000000\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x000000000000000000000000000000000000000000000000000000000000002a\"}}},\"0x5615deb798bb3e4dfa0139dfa1b3d433cc23b72f\":{\"label\":null,\"balanceDiff\":null,\"stateDiff\":{}}}",
45+
"{\"0x2e234dae75c793f67a35089c9d99245e1c58470b\":{\"label\":null,\"balanceDiff\":null,\"stateDiff\":{\"0x0000000000000000000000000000000000000000000000000000000000000000\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x000000000000000000000000000000000000000000000000000000000000002a\"}}}}",
4646
rawDiff
4747
);
4848
}

0 commit comments

Comments
 (0)