From 39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Wed, 7 Nov 2018 14:23:50 -0800 Subject: arrays with dynamic size --- packages/order-utils/test/abi_encoder_test.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'packages/order-utils/test/abi_encoder_test.ts') diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts index a455e6a00..0d7f68780 100644 --- a/packages/order-utils/test/abi_encoder_test.ts +++ b/packages/order-utils/test/abi_encoder_test.ts @@ -592,7 +592,7 @@ namespace AbiEncoder { } export class SolArray extends DynamicDataType { - static matcher = RegExp('^(.+)\\[([0-9]d*)\\]$'); + static matcher = RegExp('^(.+)\\[([0-9]*)\\]$'); static UNDEFINED_LENGTH = new BigNumber(-1); length: BigNumber = SolArray.UNDEFINED_LENGTH; type: string = '[undefined]'; @@ -601,14 +601,19 @@ namespace AbiEncoder { super(dataItem); const matches = SolArray.matcher.exec(dataItem.type); expect(matches).to.be.not.null(); + console.log(JSON.stringify(matches)); if (matches === null || matches.length !== 3) { throw new Error(`Could not parse array: ${dataItem.type}`); } else if (matches[1] === undefined) { throw new Error(`Could not parse array type: ${dataItem.type}`); } else if (matches[2] === undefined) { - // Parse out array type and length + throw new Error(`Could not parse array length: ${dataItem.type}`); + } + + // Check if length is undefined + if (matches[2] === '') { this.type = matches[1]; - this.length = new BigNumber(SolArray.UNDEFINED_LENGTH); + this.length = SolArray.UNDEFINED_LENGTH; return; } @@ -886,6 +891,18 @@ describe.only('ABI Encoder', () => { console.log('*'.repeat(60)); console.log(hexValue); }); + + it.only('sample undefined size', async () => { + const testDataItem = { name: 'testArray', type: 'int[]' }; + const dataType = new AbiEncoder.SolArray(testDataItem); + console.log(JSON.stringify(dataType, null, 4)); + console.log('*'.repeat(60)); + dataType.assignValue([new BigNumber(5), new BigNumber(6)]); + console.log(JSON.stringify(dataType, null, 4)); + const hexValue = dataType.getHexValue(); + console.log('*'.repeat(60)); + console.log(hexValue); + }); }); describe('Just a Greg, Eh', () => { -- cgit v1.2.3