Skip to content

Commit

Permalink
fails with encodePacked, passes with encode
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Feb 28, 2024
1 parent 177ec1a commit a15e28f
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions contracts/test/libraries/OutputReader.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
// }
}

0 comments on commit a15e28f

Please sign in to comment.