From 384cd2f6059bba994a6af2992a7df4909e24897c Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Wed, 13 Jun 2018 18:12:45 +0200 Subject: Add trailing garbage testcase for LibBytes.equals --- .../src/contracts/current/test/TestLibBytes/TestLibBytes.sol | 11 +++++++++++ packages/contracts/test/libraries/lib_bytes.ts | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol index 60ee3db7f..d14022a64 100644 --- a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol +++ b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol @@ -61,6 +61,17 @@ contract TestLibBytes { equal = lhs.equals(rhs); return equal; } + + function publicEqualsPop1(bytes memory lhs, bytes memory rhs) + public + pure + returns (bool equal) + { + lhs.popByte(); + rhs.popByte(); + equal = lhs.equals(rhs); + return equal; + } /// @dev Performs a deep copy of a byte array onto another byte array of greater than or equal length. /// @param dest Byte array that will be overwritten with source bytes. diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 0c8431a6a..5edb5835a 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -172,6 +172,16 @@ describe('LibBytes', () => { ); return expect(equals).to.be.false(); }); + + describe('should ignore trailing data', () => { + it('should return true when both < 32 bytes', async () => { + const equals = await libBytes.publicEqualsPop1.callAsync( + '0x0102', + '0x0103', + ); + return expect(equals).to.be.true(); + }); + }); }); describe('deepCopyBytes', () => { -- cgit