Skip to content

Commit

Permalink
Improve ABI testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Feb 12, 2024
1 parent 5e43a5f commit c16f43c
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions test/flags.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,24 @@ contract FlagsTest is Test {
}

function test_abiEncode1(bytes4 _selector, bytes32 _param1) external {
vm.assume(_param1 != bytes32(0));
bytes memory data = abi.encodePacked(_selector, _param1);
bytes memory encoded = vm.encodeAny(data)
.useStorage(false)
.allowOps("FLAG_ABI_0_PARAM")
.allowOps("FLAG_READ_WORD")
.allowOps("LITERAL_ZERO")
.run();
bytes memory decoded = decompressor.call(encoded);
assertEq(data, decoded);
}

function test_abiEncode2(bytes4 _selector, bytes32 _param1, bytes32 _param2) external {
vm.assume(_param1 != bytes32(0));
vm.assume(_param2 != bytes32(0));
bytes memory data = abi.encodePacked(_selector, _param1, _param2);
bytes memory encoded = vm.encodeAny(data)
.useStorage(false)
.allowOps("FLAG_ABI_0_PARAM")
.allowOps("FLAG_READ_WORD")
.allowOps("LITERAL_ZERO")
.run();
bytes memory decoded = decompressor.call(encoded);
assertEq(data, decoded);
Expand All @@ -167,14 +166,12 @@ contract FlagsTest is Test {
bytes32 _param2,
bytes32 _param3
) external {
vm.assume(_param1 != bytes32(0));
vm.assume(_param2 != bytes32(0));
vm.assume(_param3 != bytes32(0));
bytes memory data = abi.encodePacked(_selector, _param1, _param2, _param3);
bytes memory encoded = vm.encodeAny(data)
.useStorage(false)
.allowOps("FLAG_ABI_0_PARAM")
.allowOps("FLAG_READ_WORD")
.allowOps("LITERAL_ZERO")
.run();
bytes memory decoded = decompressor.call(encoded);
assertEq(data, decoded);
Expand All @@ -187,15 +184,12 @@ contract FlagsTest is Test {
bytes32 _param3,
bytes32 _param4
) external {
vm.assume(_param1 != bytes32(0));
vm.assume(_param2 != bytes32(0));
vm.assume(_param3 != bytes32(0));
vm.assume(_param4 != bytes32(0));
bytes memory data = abi.encodePacked(_selector, _param1, _param2, _param3, _param4);
bytes memory encoded = vm.encodeAny(data)
.useStorage(false)
.allowOps("FLAG_ABI_0_PARAM")
.allowOps("FLAG_READ_WORD")
.allowOps("LITERAL_ZERO")
.run();
bytes memory decoded = decompressor.call(encoded);
assertEq(data, decoded);
Expand All @@ -209,16 +203,12 @@ contract FlagsTest is Test {
bytes32 _param4,
bytes32 _param5
) external {
vm.assume(_param1 != bytes32(0));
vm.assume(_param2 != bytes32(0));
vm.assume(_param3 != bytes32(0));
vm.assume(_param4 != bytes32(0));
vm.assume(_param5 != bytes32(0));
bytes memory data = abi.encodePacked(_selector, _param1, _param2, _param3, _param4);
bytes memory data = abi.encodePacked(_selector, _param1, _param2, _param3, _param4, _param5);
bytes memory encoded = vm.encodeAny(data)
.useStorage(false)
.allowOps("FLAG_ABI_0_PARAM")
.allowOps("FLAG_READ_WORD")
.allowOps("LITERAL_ZERO")
.run();
bytes memory decoded = decompressor.call(encoded);
assertEq(data, decoded);
Expand All @@ -233,17 +223,12 @@ contract FlagsTest is Test {
bytes32 _param5,
bytes32 _param6
) external {
vm.assume(_param1 != bytes32(0));
vm.assume(_param2 != bytes32(0));
vm.assume(_param3 != bytes32(0));
vm.assume(_param4 != bytes32(0));
vm.assume(_param5 != bytes32(0));
vm.assume(_param6 != bytes32(0));
bytes memory data = abi.encodePacked(_selector, _param1, _param2, _param3, _param4);
bytes memory data = abi.encodePacked(_selector, _param1, _param2, _param3, _param4, _param5, _param6);
bytes memory encoded = vm.encodeAny(data)
.useStorage(false)
.allowOps("FLAG_ABI_0_PARAM")
.allowOps("FLAG_READ_WORD")
.allowOps("LITERAL_ZERO")
.run();
bytes memory decoded = decompressor.call(encoded);
assertEq(data, decoded);
Expand Down

0 comments on commit c16f43c

Please sign in to comment.