Skip to content

Commit

Permalink
feat: encode / deocde
Browse files Browse the repository at this point in the history
  • Loading branch information
GalloDaSballo committed Oct 14, 2024
1 parent 629799f commit f4ca88f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions test/EncodingDecoding.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,30 @@ contract EncodingDecodingTest is Test {

assertEq(lqty, decodedLqty);
assertEq(averageTimestamp, decodedAverageTimestamp);

// Redo
uint224 reEncoded = EncodingDecoding.encodeLQTYAllocation(decodedLqty, decodedAverageTimestamp);
(uint88 reDecodedLqty, uint32 reDecodedAverageTimestamp) = EncodingDecoding.decodeLQTYAllocation(encodedValue);

assertEq(reEncoded, encodedValue);
assertEq(reDecodedLqty, decodedLqty);
assertEq(reDecodedAverageTimestamp, decodedAverageTimestamp);
}


/// We expect this test to fail as the encoding is ambigous past u120
function test_fail_encoding_not_equal_reproducer() public {
_receive_undo_compare(18371677541005923091065047412368542483005086202);
}

// receive -> undo -> check -> redo -> compare
function test_receive_undo_compare(uint120 encodedValue) public {
_receive_undo_compare(encodedValue);
}

// receive -> undo -> check -> redo -> compare
function test_receive_undo_compare(uint224 encodedValue) public {
function _receive_undo_compare(uint224 encodedValue) public {
/// These values fail because we could pass a value that is bigger than intended
(uint88 decodedLqty, uint32 decodedAverageTimestamp) = EncodingDecoding.decodeLQTYAllocation(encodedValue);

uint224 encodedValue2 = EncodingDecoding.encodeLQTYAllocation(decodedLqty, decodedAverageTimestamp);
Expand All @@ -36,7 +56,5 @@ contract EncodingDecodingTest is Test {
assertEq(decodedAverageTimestamp, decodedAverageTimestamp2, "decoded timestamps not equal");
}

function test_encoding_not_equal_reproducer() public {
test_receive_undo_compare(18371677541005923091065047412368542483005086202);
}

}

0 comments on commit f4ca88f

Please sign in to comment.