Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Generic Storage Slot Viewer #20

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading