diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-05-22 06:59:58 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-05-31 08:11:30 +0800 |
commit | 822e319efea9c862702ddf589eb2344ff02e5bc5 (patch) | |
tree | ae5421da5b6ac84c318ed1aa66445222be45a579 /packages/contracts/test/libraries/lib_bytes.ts | |
parent | 6d462fc961da2ba4d5502ad6b71654c1715550d9 (diff) | |
download | dexon-sol-tools-822e319efea9c862702ddf589eb2344ff02e5bc5.tar.gz dexon-sol-tools-822e319efea9c862702ddf589eb2344ff02e5bc5.tar.zst dexon-sol-tools-822e319efea9c862702ddf589eb2344ff02e5bc5.zip |
Use last byte of signature as signature type
Diffstat (limited to 'packages/contracts/test/libraries/lib_bytes.ts')
-rw-r--r-- | packages/contracts/test/libraries/lib_bytes.ts | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index c85cee5e3..4eedad25d 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -22,6 +22,7 @@ describe('LibBytes', () => { let owner: string; let libBytes: TestLibBytesContract; const byteArrayShorterThan32Bytes = '0x012345'; + const byteArrayShorterThan20Bytes = byteArrayShorterThan32Bytes; const byteArrayLongerThan32Bytes = '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'; const byteArrayLongerThan32BytesFirstBytesSwapped = @@ -60,39 +61,35 @@ describe('LibBytes', () => { await blockchainLifecycle.revertAsync(); }); - describe('deepCopyBytes', () => { - const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2; - it('should return a byte array of length 0 if len is 0', async () => { - const index = new BigNumber(0); - const len = new BigNumber(0); - const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); - expect(copy).to.equal(constants.NULL_BYTES); + describe('popByte', () => { + it('should revert if length is 0', async () => { + return expect(libBytes.publicPopByte.callAsync(constants.NULL_BYTES)).to.be.rejectedWith(constants.REVERT); }); - it('should throw if start index + length to copy is greater than length of byte array', async () => { - const index = new BigNumber(0); - const len = new BigNumber(byteArrayLongerThan32BytesLen + 1); - return expect( - libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len), - ).to.be.rejectedWith(constants.REVERT); + it('should pop the last byte from the input and return it', async () => { + const [newBytes, poppedByte] = await libBytes.publicPopByte.callAsync(byteArrayLongerThan32Bytes); + const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -2); + const expectedPoppedByte = `0x${byteArrayLongerThan32Bytes.slice(-2)}`; + expect(newBytes).to.equal(expectedNewBytes); + expect(poppedByte).to.equal(expectedPoppedByte); }); + }); - it('should copy the entire byte array if index = 0 and len = b.length', async () => { - const index = new BigNumber(0); - const len = new BigNumber(byteArrayLongerThan32BytesLen); - const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); - expect(copy).to.equal(byteArrayLongerThan32Bytes); + describe('popAddress', () => { + it('should revert if length is less than 20', async () => { + return expect(libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes)).to.be.rejectedWith( + constants.REVERT, + ); }); - it('should copy part of the byte array if area to copy is less than b.length', async () => { - const index = new BigNumber(10); - const len = new BigNumber(4); - const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len); - const expectedCopy = `0x${byteArrayLongerThan32Bytes.slice(22, 30)}`; - expect(copy).to.equal(expectedCopy); + it('should pop the last 20 bytes from the input and return it', async () => { + const [newBytes, poppedAddress] = await libBytes.publicPopAddress.callAsync(byteArrayLongerThan32Bytes); + const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -40); + const expectedPoppedAddress = `0x${byteArrayLongerThan32Bytes.slice(-40)}`; + expect(newBytes).to.equal(expectedNewBytes); + expect(poppedAddress).to.equal(expectedPoppedAddress); }); }); - describe('areBytesEqual', () => { it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => { const areBytesEqual = await libBytes.publicAreBytesEqual.callAsync( |