From c951978a3fbcbcfe9ed65c9e99e420facdee772f Mon Sep 17 00:00:00 2001 From: JP <89362795+0xJayPi@users.noreply.github.com> Date: Sat, 10 Aug 2024 00:12:38 +0200 Subject: [PATCH] `FraxTest` Coverage (#23) * 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 --- .gitignore | 3 ++- test/TestSlotDump.t.sol | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 40280f2..3650933 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ node_modules # build dist -.vscode \ No newline at end of file +.vscode +package-lock.json \ No newline at end of file diff --git a/test/TestSlotDump.t.sol b/test/TestSlotDump.t.sol index 7f853f2..9a09446 100644 --- a/test/TestSlotDump.t.sol +++ b/test/TestSlotDump.t.sol @@ -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);