From a15e28f2852e3e1f40814ab30e0b06180aab795d Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Wed, 28 Feb 2024 12:29:13 -0800 Subject: [PATCH] fails with encodePacked, passes with encode --- contracts/test/libraries/OutputReader.t.sol | 71 +++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/contracts/test/libraries/OutputReader.t.sol b/contracts/test/libraries/OutputReader.t.sol index 7abdfb8e..6f2cf54c 100644 --- a/contracts/test/libraries/OutputReader.t.sol +++ b/contracts/test/libraries/OutputReader.t.sol @@ -43,9 +43,12 @@ contract OutputReaderTest is Test { function test_ReadUint128() public { bytes memory output = abi.encodePacked(uint128(1)); + console.logBytes(output); uint256 offset = 0; uint128 value; (offset, value) = OutputReader.readUint128(output, 0); + console.log("offset", offset); + console.log("value", value); assertEq(offset, 16); assertEq(value, 1); } @@ -71,4 +74,72 @@ contract OutputReaderTest is Test { assertEq(offset, 32); assertEq(value2, 2); } + + // function test_ReadUint64() public { + // bytes memory output = abi.encodePacked(uint128(1)); + // console.logBytes(output); + // uint256 offset = 0; + // uint64 value; + // (offset, value) = OutputReader.readUint64(output, 0); + // console.log("offset", offset); + // console.log("value", value); + // assertEq(offset, 16); + // assertEq(value, 1); + // } + + // function testFuzz_ReadUint64(uint128 v) public { + // bytes memory output = abi.encodePacked(v); + // uint256 offset = 0; + // uint64 value; + // (offset, value) = OutputReader.readUint64(output, 0); + // assertEq(offset, 16); + // assertEq(value, v); + // } + + // function test_ReadUint64Multiple() public { + // bytes memory output = abi.encodePacked(uint128(1), uint128(2)); + // uint256 offset = 0; + // uint64 value1; + // uint64 value2; + // (offset, value1) = OutputReader.readUint64(output, 0); + // assertEq(offset, 16); + // assertEq(value1, 1); + // (offset, value2) = OutputReader.readUint64(output, offset); + // assertEq(offset, 32); + // assertEq(value2, 2); + // } + + // function test_ReadUint32() public { + // bytes memory output = abi.encodePacked(uint128(1)); + // console.logBytes(output); + // uint256 offset = 0; + // uint32 value; + // (offset, value) = OutputReader.readUint32(output, 0); + // console.log("offset", offset); + // console.log("value", value); + // assertEq(offset, 16); + // assertEq(value, 1); + // } + + // function testFuzz_ReadUint32(uint128 v) public { + // bytes memory output = abi.encodePacked(v); + // uint256 offset = 0; + // uint32 value; + // (offset, value) = OutputReader.readUint32(output, 0); + // assertEq(offset, 16); + // assertEq(value, v); + // } + + // function test_ReadUint32Multiple() public { + // bytes memory output = abi.encodePacked(uint32(1), uint32(2)); + // uint256 offset = 0; + // uint32 value1; + // uint32 value2; + // (offset, value1) = OutputReader.readUint32(output, 0); + // assertEq(offset, 16); + // assertEq(value1, 1); + // (offset, value2) = OutputReader.readUint32(output, offset); + // assertEq(offset, 32); + // assertEq(value2, 2); + // } }