@@ -373,4 +373,48 @@ contract LibBytesTest is SoladyTest {
373373 assertEq (uint160 (LibBytes.msbToAddress (x)), msb);
374374 assertEq (uint160 (LibBytes.lsbToAddress (x)), lsb);
375375 }
376+
377+ function testCheckInCalldata (bytes memory child ) public view {
378+ this .checkInCalldata (child, abi.encode (child));
379+ }
380+
381+ function testCheckInCalldata () public pure {
382+ LibBytes.checkInCalldata (msg .data , msg .data );
383+ }
384+
385+ function checkInCalldata (bytes calldata expectedChild , bytes calldata encoded ) public pure {
386+ bytes calldata child;
387+ /// @solidity memory-safe-assembly
388+ assembly {
389+ child.offset := add (0x20 , add (encoded.offset, calldataload (encoded.offset)))
390+ child.length := calldataload (add (encoded.offset, calldataload (encoded.offset)))
391+ }
392+ LibBytes.checkInCalldata (child, encoded);
393+ LibBytes.checkInCalldata (child, msg .data );
394+ LibBytes.checkInCalldata (encoded, msg .data );
395+ require (keccak256 (expectedChild) == keccak256 (child));
396+ }
397+
398+ function testCheckInCalldata (bytes [] memory children ) public view {
399+ this .checkInCalldata (children, abi.encode (children));
400+ }
401+
402+ function checkInCalldata (bytes [] calldata expectedChildren , bytes calldata encoded )
403+ public
404+ pure
405+ {
406+ bytes [] calldata children;
407+ /// @solidity memory-safe-assembly
408+ assembly {
409+ children.offset := add (0x20 , add (encoded.offset, calldataload (encoded.offset)))
410+ children.length := calldataload (add (encoded.offset, calldataload (encoded.offset)))
411+ }
412+ LibBytes.checkInCalldata (children, encoded);
413+ LibBytes.checkInCalldata (expectedChildren, msg .data );
414+ LibBytes.checkInCalldata (children, msg .data );
415+ require (expectedChildren.length == children.length );
416+ for (uint256 i; i < children.length ; ++ i) {
417+ require (keccak256 (expectedChildren[i]) == keccak256 (children[i]));
418+ }
419+ }
376420}
0 commit comments