Skip to content

Commit f4ca88f

Browse files
committed
feat: encode / deocde
1 parent 629799f commit f4ca88f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

test/EncodingDecoding.t.sol

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,30 @@ contract EncodingDecodingTest is Test {
2222

2323
assertEq(lqty, decodedLqty);
2424
assertEq(averageTimestamp, decodedAverageTimestamp);
25+
26+
// Redo
27+
uint224 reEncoded = EncodingDecoding.encodeLQTYAllocation(decodedLqty, decodedAverageTimestamp);
28+
(uint88 reDecodedLqty, uint32 reDecodedAverageTimestamp) = EncodingDecoding.decodeLQTYAllocation(encodedValue);
29+
30+
assertEq(reEncoded, encodedValue);
31+
assertEq(reDecodedLqty, decodedLqty);
32+
assertEq(reDecodedAverageTimestamp, decodedAverageTimestamp);
33+
}
34+
35+
36+
/// We expect this test to fail as the encoding is ambigous past u120
37+
function test_fail_encoding_not_equal_reproducer() public {
38+
_receive_undo_compare(18371677541005923091065047412368542483005086202);
39+
}
40+
41+
// receive -> undo -> check -> redo -> compare
42+
function test_receive_undo_compare(uint120 encodedValue) public {
43+
_receive_undo_compare(encodedValue);
2544
}
2645

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

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

39-
function test_encoding_not_equal_reproducer() public {
40-
test_receive_undo_compare(18371677541005923091065047412368542483005086202);
41-
}
59+
4260
}

0 commit comments

Comments
 (0)