diff --git a/contracts/utils/contracts/test/TestLibBytes.sol b/contracts/utils/contracts/test/TestLibBytes.sol index 4743be66e6..29000bb788 100644 --- a/contracts/utils/contracts/test/TestLibBytes.sol +++ b/contracts/utils/contracts/test/TestLibBytes.sol @@ -279,10 +279,10 @@ contract TestLibBytes { ) public pure - returns (bytes memory result) + returns (bytes memory result, bytes memory original) { result = LibBytes.slice(b, from, to); - return result; + return (result, b); } /// @dev Returns a slice from a byte array without preserving the input. @@ -298,9 +298,9 @@ contract TestLibBytes { ) public pure - returns (bytes memory result) + returns (bytes memory result, bytes memory original) { result = LibBytes.sliceDestructive(b, from, to); - return result; + return (result, b); } } diff --git a/contracts/utils/test/lib_bytes.ts b/contracts/utils/test/lib_bytes.ts index 282fa768c6..cedcb9d80a 100644 --- a/contracts/utils/test/lib_bytes.ts +++ b/contracts/utils/test/lib_bytes.ts @@ -883,7 +883,16 @@ describe('LibBytes', () => { it('should return a byte array of length 0 if from == to', async () => { const from = new BigNumber(0); const to = from; - const result = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to); + const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to); + expect(original).to.eq(byteArrayLongerThan32Bytes); + expect(result).to.eq(constants.NULL_BYTES); + }); + it('should return a byte array of length 0 if from == to == b.length', async () => { + const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2; + const from = new BigNumber(byteLen); + const to = from; + const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to); + expect(original).to.eq(byteArrayLongerThan32Bytes); expect(result).to.eq(constants.NULL_BYTES); }); it('should revert if to > input.length', async () => { @@ -898,15 +907,17 @@ describe('LibBytes', () => { it('should slice a section of the input', async () => { const from = new BigNumber(1); const to = new BigNumber(2); - const result = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to); + const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to); const expectedResult = `0x${byteArrayLongerThan32Bytes.slice(4, 6)}`; + expect(original).to.eq(byteArrayLongerThan32Bytes); expect(result).to.eq(expectedResult); }); it('should copy the entire input if from = 0 and to = input.length', async () => { const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2; const from = new BigNumber(0); const to = new BigNumber(byteLen); - const result = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to); + const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to); + expect(original).to.eq(byteArrayLongerThan32Bytes); expect(result).to.eq(byteArrayLongerThan32Bytes); }); }); @@ -923,7 +934,14 @@ describe('LibBytes', () => { it('should return a byte array of length 0 if from == to', async () => { const from = new BigNumber(0); const to = from; - const result = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to); + const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to); + expect(result).to.eq(constants.NULL_BYTES); + }); + it('should return a byte array of length 0 if from == to == b.length', async () => { + const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2; + const from = new BigNumber(byteLen); + const to = from; + const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to); expect(result).to.eq(constants.NULL_BYTES); }); it('should revert if to > input.length', async () => { @@ -938,7 +956,7 @@ describe('LibBytes', () => { it('should slice a section of the input', async () => { const from = new BigNumber(1); const to = new BigNumber(2); - const result = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to); + const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to); const expectedResult = `0x${byteArrayLongerThan32Bytes.slice(4, 6)}`; expect(result).to.eq(expectedResult); }); @@ -946,7 +964,7 @@ describe('LibBytes', () => { const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2; const from = new BigNumber(0); const to = new BigNumber(byteLen); - const result = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to); + const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to); expect(result).to.eq(byteArrayLongerThan32Bytes); }); });