aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/libraries/lib_bytes.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-10 07:27:50 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-31 08:11:30 +0800
commita5a7217c8f24fe98275fd9927ca8c5e5f140c6f3 (patch)
treef58846c928d05047265b471638eab11d627bdc99 /packages/contracts/test/libraries/lib_bytes.ts
parentc0cf55b40bb4a13cfd94a506bf125f6eb57c6767 (diff)
downloaddexon-0x-contracts-a5a7217c8f24fe98275fd9927ca8c5e5f140c6f3.tar.gz
dexon-0x-contracts-a5a7217c8f24fe98275fd9927ca8c5e5f140c6f3.tar.zst
dexon-0x-contracts-a5a7217c8f24fe98275fd9927ca8c5e5f140c6f3.zip
Add deepCopyBytes method to LibBytes
Diffstat (limited to 'packages/contracts/test/libraries/lib_bytes.ts')
-rw-r--r--packages/contracts/test/libraries/lib_bytes.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts
index 968bac300..1fd30a3e0 100644
--- a/packages/contracts/test/libraries/lib_bytes.ts
+++ b/packages/contracts/test/libraries/lib_bytes.ts
@@ -60,6 +60,40 @@ describe('LibBytes', () => {
await blockchainLifecycle.revertAsync();
});
+ describe.only('deepCopyBytes', () => {
+ const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
+ it('should throw if length of copy is 0', async () => {
+ const index = new BigNumber(0);
+ const len = new BigNumber(0);
+ return expect(
+ libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len),
+ ).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 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);
+ });
+
+ 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);
+ });
+ });
+
describe('areBytesEqual', () => {
it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => {
const areBytesEqual = await libBytes.publicAreBytesEqual.callAsync(