Skip to content

Commit 2134240

Browse files
committed
coverage
1 parent 04a2424 commit 2134240

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/utils/AbiDecode.t.sol

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,42 @@ contract AbiDecodeTest is Test {
4040
}
4141
}
4242

43+
function testDecodeDegenerateCase() public view {
44+
bytes memory buffer = abi.encodePacked(uint256(0x00)); // offset to itself + length = 0
45+
46+
(bool success, Memory.Slice output) = buffer.tryDecodeBytes();
47+
assertTrue(success);
48+
assertEq(output.toBytes(), new bytes(0));
49+
50+
(bool successCalldata, bytes memory outputCalldata) = this.__tryDecodeBytesCalldata(buffer);
51+
assertTrue(successCalldata);
52+
assertEq(outputCalldata, new bytes(0));
53+
}
54+
55+
function testDecodeOutOfBoundOffset() public view {
56+
bytes memory buffer = abi.encodePacked(uint256(0x20));
57+
58+
(bool success, Memory.Slice output) = buffer.tryDecodeBytes();
59+
assertFalse(success);
60+
assertEq(output.toBytes(), new bytes(0));
61+
62+
(bool successCalldata, bytes memory outputCalldata) = this.__tryDecodeBytesCalldata(buffer);
63+
assertFalse(successCalldata);
64+
assertEq(outputCalldata, new bytes(0));
65+
}
66+
67+
function testDecodeLengthExceedsBuffer() public view {
68+
bytes memory buffer = abi.encodePacked(uint256(0x20), uint256(0x40));
69+
70+
(bool success, Memory.Slice output) = buffer.tryDecodeBytes();
71+
assertFalse(success);
72+
assertEq(output.toBytes(), new bytes(0));
73+
74+
(bool successCalldata, bytes memory outputCalldata) = this.__tryDecodeBytesCalldata(buffer);
75+
assertFalse(successCalldata);
76+
assertEq(outputCalldata, new bytes(0));
77+
}
78+
4379
function __tryDecodeBytesCalldata(
4480
bytes calldata buffer
4581
) external pure returns (bool success, bytes calldata output) {

0 commit comments

Comments
 (0)