Skip to content

Commit

Permalink
Add dynamic encoding abi test
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Feb 12, 2024
1 parent 3f4ae73 commit 682a7c7
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions test/flags_no_go.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,106 @@ contract FlagsTestNoGo is Test {
bytes memory decoded = decompressor.call(encoded);
assertEq(decoded, data);
}

function test_encodeDynamicABI_simple(
bytes4 _selector,
bytes32 _arg1,
bytes calldata _arg2
) external {
bytes memory encoded = abi.encodePacked(
DECODE_ANY,
FLAG_READ_DYNAMIC_ABI,
uint8(0),
_selector,
uint8(2),
uint8((
uint8(1) << 1
))
);

encoded = abi.encodePacked(
encoded,
FLAG_READ_WORD_32,
_arg1,
FLAG_READ_N_BYTES,
FLAG_READ_WORD_8,
uint64(_arg2.length),
_arg2
);

bytes memory decoded = decompressor.call(encoded);
assertEq(decoded, abi.encodeWithSelector(
_selector,
_arg1,
_arg2
));
}

function test_encodeDynamicABI(
bytes4 _selector,
bytes32 _arg1,
bytes32 _arg2,
bytes calldata _arg3,
bytes32 _arg4,
bytes calldata _arg5,
bytes calldata _arg6
) external {
bytes memory encoded = abi.encodePacked(
DECODE_ANY,
FLAG_READ_DYNAMIC_ABI,
uint8(0),
_selector,
uint8(6),
uint8((
uint8(1) << 2 |
uint8(1) << 4 |
uint8(1) << 5
))
);

encoded = abi.encodePacked(
encoded,
FLAG_READ_WORD_32,
_arg1,
FLAG_READ_WORD_32,
_arg2
);

encoded = abi.encodePacked(
encoded,
FLAG_READ_N_BYTES,
FLAG_READ_WORD_4,
uint32(_arg3.length),
_arg3
);

encoded = abi.encodePacked(
encoded,
FLAG_READ_WORD_32,
_arg4,
FLAG_READ_N_BYTES,
FLAG_READ_WORD_8,
uint64(_arg5.length),
_arg5
);

encoded = abi.encodePacked(
encoded,
FLAG_READ_N_BYTES,
FLAG_READ_WORD_16,
uint128(_arg6.length),
_arg6
);

bytes memory decoded = decompressor.call(encoded);
assertEq(decoded, abi.encodeWithSelector(
_selector,
_arg1,
_arg2,
_arg3,
_arg4,
_arg5,
_arg6
));
}
}

0 comments on commit 682a7c7

Please sign in to comment.