Skip to content

Commit

Permalink
Add Generic Storage Slot Viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2o17 committed May 21, 2024
1 parent 65b1f01 commit 798f40f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/FraxTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity >=0.8.0;

import { console2 as console, StdAssertions, StdChains, StdCheats, stdError, StdInvariant, stdJson, stdMath, StdStorage, stdStorage, StdUtils, Vm, StdStyle, TestBase, DSTest, Test } from "forge-std/Test.sol";

import { VmHelper } from "./VmHelper.sol";
import { Strings } from "src/StringsHelper.sol";

abstract contract FraxTest is VmHelper, Test {
uint256[] internal snapShotIds;
Expand All @@ -30,5 +30,16 @@ abstract contract FraxTest is VmHelper, Test {
}
}

function dumpStorageLayout(address target, uint256 slotsToDump) internal view {
console.log("===================================");
console.log("Storage dump for: ", target);
console.log("===================================");
for (uint i; i <= slotsToDump; i++) {
bytes32 slot = vm.load(target, bytes32(uint256(i)));
string memory exp = Strings.toHexString(uint256(slot), 32);
console.log("slot", i, ":", exp);
}
}

error VmDidNotRevert(uint256 _snapshotId);
}
26 changes: 26 additions & 0 deletions test/TestSlotDump.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: ISC
pragma solidity >=0.8.0;

import "../src/FraxTest.sol";

contract TestSlotDump is FraxTest {
address instance;

function testDumpSlots() public {
instance = address(new Bravo());
dumpStorageLayout(instance, 15);
}
}

// ================== Helpers =============

contract Alpha {
address owner = address(0xC0ffee);
address pendingOwner;
}

contract Bravo is Alpha {
bytes32 someValue = bytes32(type(uint).max);
uint256[5] gap;
bytes32 someOtherValue = 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
}

0 comments on commit 798f40f

Please sign in to comment.