Skip to content

Commit

Permalink
FraxTest Coverage (#23)
Browse files Browse the repository at this point in the history
* Initial commit

* Coverage added for unpackBitsAndLogUin(bytes32,uint256,uint256)

* Coverage added for unpackBitsAndLogUin(uint256,uint256,uint256)

* Removed package-lock.json and updated .gitignore accordingly

* Removed package-lock.json

* Reverted foundry.toml unexpected update
  • Loading branch information
CanonicalJP authored Aug 9, 2024
1 parent cca73b7 commit c951978
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ node_modules
# build
dist

.vscode
.vscode
package-lock.json
23 changes: 20 additions & 3 deletions test/TestSlotDump.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@ contract TestSlotDump is FraxTest {
dumpStorageLayout(instance, 15);
}

function testUnpackSlot() public {
function testUnpackSlotBytes() public {
instance = address(new Charlie());
dumpStorageLayout(instance, 15);

bytes32 packedSlot = vm.load(address(instance), bytes32(uint(9)));
uint256 unpacked1 = unpackBits(packedSlot, 0, 96);
uint256 unpacked2 = unpackBits(packedSlot, 96, 160);
uint256 unpacked1 = unpackBitsAndLogUint(packedSlot, 0, 96);
uint256 unpacked2 = unpackBitsAndLogUint(packedSlot, 96, 160);

/// @notice `unpacked1` is `uint96` expressed as `uint256`
assertEq(22222222222222222222, unpacked1);
assertEq(22222222222222222222, uint96(unpacked1));

/// @notice `unpacked2` is `address` expressed as `uint256`
assertEq(uint256(uint160(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)), unpacked2);
assertEq(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, address(uint160(unpacked2)));
}

function testUnpackSlotUint() public {
instance = address(new Charlie());
dumpStorageLayout(instance, 15);

uint256 packedSlot = uint256(vm.load(address(instance), bytes32(uint(9))));
uint256 unpacked1 = unpackBitsAndLogUint(packedSlot, 0, 96);
uint256 unpacked2 = unpackBitsAndLogUint(packedSlot, 96, 160);

/// @notice `unpacked1` is `uint96` expressed as `uint256`
assertEq(22222222222222222222, unpacked1);
Expand Down

0 comments on commit c951978

Please sign in to comment.