Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into issue-9637
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Jan 9, 2025
2 parents 084abf3 + 82cf61d commit 95fc7bb
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/cast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ where
_ => "avalanche",
}
}
"0x23a2658170ba70d014ba0d0d2709f8fbfe2fa660cd868c5f282f991eecbe38ee" => "ink",
"0xe5fd5cf0be56af58ad5751b401410d6b7a09d830fa459789746a3d0dd1c79834" => "ink-sepolia",
_ => "unknown",
})
}
Expand Down
13 changes: 10 additions & 3 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,12 @@ 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(AccountStateDiffs {
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 {
Expand All @@ -1171,6 +1172,12 @@ fn get_recorded_state_diffs(state: &mut Cheatcodes) -> BTreeMap<Address, Account
// Record account state diffs.
for storage_access in &account_access.storageAccesses {
if storage_access.isWrite && !storage_access.reverted {
let account_diff = state_diffs
.entry(storage_access.account)
.or_insert_with(|| AccountStateDiffs {
label: state.labels.get(&storage_access.account).cloned(),
..Default::default()
});
// Update state diff. Do not overwrite the initial value if already set.
match account_diff.state_diff.entry(storage_access.slot) {
Entry::Vacant(slot_state_diff) => {
Expand Down
6 changes: 0 additions & 6 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,12 +1059,6 @@ impl Config {
remove_test_dir(&self.fuzz.failure_persist_dir);
remove_test_dir(&self.invariant.failure_persist_dir);

// Remove snapshot directory.
let snapshot_dir = project.root().join(&self.snapshots);
if snapshot_dir.exists() {
let _ = fs::remove_dir_all(&snapshot_dir);
}

Ok(())
}

Expand Down
11 changes: 0 additions & 11 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,6 @@ impl TestArgs {
// Create test options from general project settings and compiler output.
let project_root = &project.paths.root;

// Remove the snapshots directory if it exists.
// This is to ensure that we don't have any stale snapshots.
// If `FORGE_SNAPSHOT_CHECK` is set, we don't remove the snapshots directory as it is
// required for comparison.
if std::env::var_os("FORGE_SNAPSHOT_CHECK").is_none() {
let snapshot_dir = project_root.join(&config.snapshots);
if snapshot_dir.exists() {
let _ = fs::remove_dir_all(project_root.join(&config.snapshots));
}
}

let should_debug = self.debug;
let should_draw = self.flamegraph || self.flamechart;

Expand Down
3 changes: 3 additions & 0 deletions crates/forge/tests/it/repros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,6 @@ test_repro!(8639);

// https://github.com/foundry-rs/foundry/issues/8566
test_repro!(8566);

// https://github.com/foundry-rs/foundry/issues/9643
test_repro!(9643);
49 changes: 49 additions & 0 deletions testdata/default/repros/Issue9643.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";

contract Mock {
uint256 private counter;

function setCounter(uint256 _counter) external {
counter = _counter;
}
}

contract DelegateProxy {
address internal implementation;

constructor(address mock) {
implementation = mock;
}

fallback() external payable {
address addr = implementation;

assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), addr, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
}

contract Issue9643Test is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function test_storage_json_diff() public {
vm.startStateDiffRecording();
Mock proxied = Mock(address(new DelegateProxy(address(new Mock()))));
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\":{}}}",
rawDiff
);
}
}

0 comments on commit 95fc7bb

Please sign in to comment.