aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-08 06:23:50 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36 (patch)
tree6f448f71af9b347540a11236b3f3738b374f08d1 /packages
parent7de7fe782398eded47598046699fdc0915597e33 (diff)
downloaddexon-sol-tools-39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36.tar
dexon-sol-tools-39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36.tar.gz
dexon-sol-tools-39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36.tar.bz2
dexon-sol-tools-39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36.tar.lz
dexon-sol-tools-39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36.tar.xz
dexon-sol-tools-39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36.tar.zst
dexon-sol-tools-39fa26b2f3b4c34c7ff4aa87d6b99ff1af8a4c36.zip
arrays with dynamic size
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts23
1 files changed, 20 insertions, 3 deletions
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', () => {