aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-09 05:57:36 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:10 +0800
commit8b91727364c205cd2bd44abdabd62c1044dd13d4 (patch)
tree92bdaa2550955b4e81daa75f600561dd5d4a474c
parent8f61f6d0f9532e95fd32cbab8dd0344b42de2da7 (diff)
downloaddexon-sol-tools-8b91727364c205cd2bd44abdabd62c1044dd13d4.tar
dexon-sol-tools-8b91727364c205cd2bd44abdabd62c1044dd13d4.tar.gz
dexon-sol-tools-8b91727364c205cd2bd44abdabd62c1044dd13d4.tar.bz2
dexon-sol-tools-8b91727364c205cd2bd44abdabd62c1044dd13d4.tar.lz
dexon-sol-tools-8b91727364c205cd2bd44abdabd62c1044dd13d4.tar.xz
dexon-sol-tools-8b91727364c205cd2bd44abdabd62c1044dd13d4.tar.zst
dexon-sol-tools-8b91727364c205cd2bd44abdabd62c1044dd13d4.zip
types with default widths
-rw-r--r--packages/order-utils/test/abi_encoder.ts22
-rw-r--r--packages/order-utils/test/abi_encoder_test.ts12
-rw-r--r--packages/order-utils/test/abi_samples.ts35
3 files changed, 56 insertions, 13 deletions
diff --git a/packages/order-utils/test/abi_encoder.ts b/packages/order-utils/test/abi_encoder.ts
index 83ecc2f9a..bcd427dee 100644
--- a/packages/order-utils/test/abi_encoder.ts
+++ b/packages/order-utils/test/abi_encoder.ts
@@ -781,20 +781,16 @@ export class SolArray extends DynamicDataType {
}
public getSignature(): string {
- let type = this.type;
- if (this.type === 'tuple') {
- let tupleDataItem = {
- type: 'tuple',
- name: 'N/A',
- } as DataItem;
- const tupleComponents = this.getDataItem().components;
- if (tupleComponents !== undefined) {
- tupleDataItem.components = tupleComponents;
- }
- const tuple = new Tuple(tupleDataItem);
- type = tuple.getSignature();
+ let dataItem = {
+ type: this.type,
+ name: 'N/A',
+ } as DataItem;
+ const components = this.getDataItem().components;
+ if (components !== undefined) {
+ dataItem.components = components;
}
-
+ const elementDataType = DataTypeFactory.mapDataItemToDataType(dataItem);
+ const type = elementDataType.getSignature();
if (this.length.equals(SolArray.UNDEFINED_LENGTH)) {
return `${type}[]`;
}
diff --git a/packages/order-utils/test/abi_encoder_test.ts b/packages/order-utils/test/abi_encoder_test.ts
index cea33112d..ad43e70a3 100644
--- a/packages/order-utils/test/abi_encoder_test.ts
+++ b/packages/order-utils/test/abi_encoder_test.ts
@@ -134,6 +134,18 @@ describe.only('ABI Encoder', () => {
expect(calldata).to.be.equal(expectedCalldata);*/
});
+ it.only('Types with default widths', async () => {
+ const method = new AbiEncoder.Method(AbiSamples.typesWithDefaultWidthsAbi);
+ const args = [new BigNumber(1), new BigNumber(-1), '0x56', [new BigNumber(1)], [new BigNumber(-1)], ['0x56']];
+ const calldata = method.encode(args);
+ console.log(calldata);
+ console.log('*'.repeat(40));
+ console.log(method.getSignature());
+ console.log(JSON.stringify(args));
+ const expectedCalldata = '0x09f2b0c30000000000000000000000000000000000000000000000000000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000015600000000000000000000000000000000000000000000000000000000000000';
+ expect(calldata).to.be.equal(expectedCalldata);
+ });
+
it('Array of Static Tuples (Array has defined length)', async () => {
const method = new AbiEncoder.Method(AbiSamples.arrayOfStaticTuplesWithDefinedLengthAbi);
diff --git a/packages/order-utils/test/abi_samples.ts b/packages/order-utils/test/abi_samples.ts
index 7939cbaeb..921408724 100644
--- a/packages/order-utils/test/abi_samples.ts
+++ b/packages/order-utils/test/abi_samples.ts
@@ -34,6 +34,41 @@ export const stringAbi = {
type: 'function',
} as MethodAbi;
+export const typesWithDefaultWidthsAbi = {
+ constant: false,
+ inputs: [
+ {
+ name: 'someUint',
+ type: 'uint',
+ },
+ {
+ name: 'someInt',
+ type: 'int',
+ },
+ {
+ name: 'someByte',
+ type: 'byte',
+ },
+ {
+ name: 'someUint',
+ type: 'uint[]',
+ },
+ {
+ name: 'someInt',
+ type: 'int[]',
+ },
+ {
+ name: 'someByte',
+ type: 'byte[]',
+ },
+ ],
+ name: 'simpleFunction',
+ outputs: [],
+ payable: false,
+ stateMutability: 'nonpayable',
+ type: 'function',
+} as MethodAbi;
+
export const multiDimensionalArraysStaticTypeAbi = {
constant: false,
inputs: [