aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-20 05:01:22 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-15 02:49:44 +0800
commite9a82905e35041d36c4c9be75e11c0399ee96b89 (patch)
treebd49ab279ae96fb0248b252e55399f3ce50c4793 /packages
parentf8684d6a776724d0172c30126a7277885ed4e966 (diff)
downloaddexon-sol-tools-e9a82905e35041d36c4c9be75e11c0399ee96b89.tar
dexon-sol-tools-e9a82905e35041d36c4c9be75e11c0399ee96b89.tar.gz
dexon-sol-tools-e9a82905e35041d36c4c9be75e11c0399ee96b89.tar.bz2
dexon-sol-tools-e9a82905e35041d36c4c9be75e11c0399ee96b89.tar.lz
dexon-sol-tools-e9a82905e35041d36c4c9be75e11c0399ee96b89.tar.xz
dexon-sol-tools-e9a82905e35041d36c4c9be75e11c0399ee96b89.tar.zst
dexon-sol-tools-e9a82905e35041d36c4c9be75e11c0399ee96b89.zip
Abi Encoder tests fixed + added a signature parser for cases where MethodAbi/DataItems are not readily available
Diffstat (limited to 'packages')
-rw-r--r--packages/utils/src/abi_encoder/abstract_data_types/data_type.ts10
-rw-r--r--packages/utils/src/abi_encoder/abstract_data_types/types/set.ts4
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/address.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/array.ts18
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/bool.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/int.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/method.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/pointer.ts8
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/string.ts2
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/tuple.ts17
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/uint.ts2
-rw-r--r--packages/utils/src/abi_encoder/index.ts1
-rw-r--r--packages/utils/src/abi_encoder/utils/signatureParser.ts154
-rw-r--r--packages/utils/test/abi_encoder/evm_data_types_test.ts184
-rw-r--r--packages/utils/test/abi_encoder/methods_test.ts62
-rw-r--r--packages/utils/test/abi_encoder/optimizer_test.ts36
-rw-r--r--packages/utils/test/abi_encoder/return_values_test.ts12
-rw-r--r--packages/utils/test/abi_encoder/signature_tests.ts0
20 files changed, 449 insertions, 73 deletions
diff --git a/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts b/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts
index 13cc87e2a..5bd6aae03 100644
--- a/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts
+++ b/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts
@@ -51,8 +51,16 @@ export abstract class DataType {
return value;
}
+ public getSignature(detailed?: boolean): string {
+ if (_.isEmpty(this._dataItem.name) || !detailed) return this.getSignatureType();
+ const name = this.getDataItem().name;
+ const shortName = name.indexOf('.') > 0 ? name.substr(name.lastIndexOf('.') + 1) : name;
+ const detailedSignature = `${shortName} ${this.getSignatureType()}`;
+ return detailedSignature;
+ }
+
public abstract generateCalldataBlock(value: any, parentBlock?: CalldataBlock): CalldataBlock;
public abstract generateValue(calldata: RawCalldata, rules: DecodingRules): any;
- public abstract getSignature(): string;
+ public abstract getSignatureType(): string;
public abstract isStatic(): boolean;
}
diff --git a/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts b/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts
index 73e9cf778..d7105ff5f 100644
--- a/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts
+++ b/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts
@@ -155,11 +155,11 @@ export abstract class AbstractSetDataType extends DataType {
return block;
}
- protected _computeSignatureOfMembers(): string {
+ protected _computeSignatureOfMembers(detailed?: boolean): string {
// Compute signature of members
let signature = `(`;
_.each(this._members, (member: DataType, i: number) => {
- signature += member.getSignature();
+ signature += member.getSignature(detailed);
if (i < this._members.length - 1) {
signature += ',';
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/address.ts b/packages/utils/src/abi_encoder/evm_data_types/address.ts
index 3ab823019..2278830eb 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/address.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/address.ts
@@ -43,7 +43,7 @@ export class AddressDataType extends AbstractBlobDataType {
return valueLowercase;
}
- public getSignature(): string {
+ public getSignatureType(): string {
return SolidityTypes.Address;
}
/* tslint:enable prefer-function-over-method */
diff --git a/packages/utils/src/abi_encoder/evm_data_types/array.ts b/packages/utils/src/abi_encoder/evm_data_types/array.ts
index 7595cb667..8b71dc913 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/array.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/array.ts
@@ -38,22 +38,30 @@ export class ArrayDataType extends AbstractSetDataType {
this._arraySignature = this._computeSignature();
}
- public getSignature(): string {
- return this._arraySignature;
+ public getSignatureType(): string {
+ return this._computeSignature(false);
}
- private _computeSignature(): string {
+ public getSignature(detailed?: boolean): string {
+ if (_.isEmpty(this.getDataItem().name) || !detailed) return this.getSignatureType();
+ const name = this.getDataItem().name;
+ const shortName = name.indexOf('.') > 0 ? name.substr(name.lastIndexOf('.') + 1) : name;
+ const detailedSignature = `${shortName} ${this._computeSignature(detailed)}`;
+ return detailedSignature;
+ }
+
+ private _computeSignature(detailed?: boolean): string {
// Compute signature for a single array element
const elementDataItem: DataItem = {
type: this._elementType,
- name: 'N/A',
+ name: '',
};
const elementComponents = this.getDataItem().components;
if (!_.isUndefined(elementComponents)) {
elementDataItem.components = elementComponents;
}
const elementDataType = this.getFactory().create(elementDataItem);
- const elementSignature = elementDataType.getSignature();
+ const elementSignature = elementDataType.getSignature(detailed);
// Construct signature for array of type `element`
if (_.isUndefined(this._arrayLength)) {
return `${elementSignature}[]`;
diff --git a/packages/utils/src/abi_encoder/evm_data_types/bool.ts b/packages/utils/src/abi_encoder/evm_data_types/bool.ts
index d713d5a94..7f91f34e6 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/bool.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/bool.ts
@@ -46,7 +46,7 @@ export class BoolDataType extends AbstractBlobDataType {
return value;
}
- public getSignature(): string {
+ public getSignatureType(): string {
return SolidityTypes.Bool;
}
/* tslint:enable prefer-function-over-method */
diff --git a/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts b/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
index 5277efd6c..fa38b63c0 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts
@@ -65,7 +65,7 @@ export class DynamicBytesDataType extends AbstractBlobDataType {
return value;
}
- public getSignature(): string {
+ public getSignatureType(): string {
return SolidityTypes.Bytes;
}
/* tslint:enable prefer-function-over-method */
diff --git a/packages/utils/src/abi_encoder/evm_data_types/int.ts b/packages/utils/src/abi_encoder/evm_data_types/int.ts
index c9f734799..865a76545 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/int.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts
@@ -56,7 +56,7 @@ export class IntDataType extends AbstractBlobDataType {
return value;
}
- public getSignature(): string {
+ public getSignatureType(): string {
return `${SolidityTypes.Int}${this._width}`;
}
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/method.ts b/packages/utils/src/abi_encoder/evm_data_types/method.ts
index bae0fdb5d..44456cd0a 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/method.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts
@@ -57,7 +57,7 @@ export class MethodDataType extends AbstractSetDataType {
return returnValue;
}
- public getSignature(): string {
+ public getSignatureType(): string {
return this._methodSignature;
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/pointer.ts b/packages/utils/src/abi_encoder/evm_data_types/pointer.ts
index 389e75927..8c3afe0c3 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/pointer.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/pointer.ts
@@ -11,7 +11,11 @@ export class PointerDataType extends AbstractPointerDataType {
super(dataItem, dataTypeFactory, destDataType, parentDataType);
}
- public getSignature(): string {
- return this._destination.getSignature();
+ public getSignatureType(): string {
+ return this._destination.getSignature(false);
+ }
+
+ public getSignature(detailed?: boolean): string {
+ return this._destination.getSignature(detailed);
}
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts
index 2e371c505..cbf1957d7 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts
@@ -36,7 +36,7 @@ export class StaticBytesDataType extends AbstractBlobDataType {
this._width = StaticBytesDataType._decodeWidthFromType(dataItem.type);
}
- public getSignature(): string {
+ public getSignatureType(): string {
// Note that `byte` reduces to `bytes1`
return `${SolidityTypes.Bytes}${this._width}`;
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/string.ts b/packages/utils/src/abi_encoder/evm_data_types/string.ts
index 91a72ad3f..97ac46442 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/string.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/string.ts
@@ -52,7 +52,7 @@ export class StringDataType extends AbstractBlobDataType {
return value;
}
- public getSignature(): string {
+ public getSignatureType(): string {
return SolidityTypes.String;
}
/* tslint:enable prefer-function-over-method */
diff --git a/packages/utils/src/abi_encoder/evm_data_types/tuple.ts b/packages/utils/src/abi_encoder/evm_data_types/tuple.ts
index 31593c882..587653f49 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/tuple.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/tuple.ts
@@ -1,10 +1,11 @@
import { DataItem, SolidityTypes } from 'ethereum-types';
+import * as _ from 'lodash';
import { DataTypeFactory } from '../abstract_data_types/interfaces';
import { AbstractSetDataType } from '../abstract_data_types/types/set';
export class TupleDataType extends AbstractSetDataType {
- private readonly _signature: string;
+ //private readonly _signature: string;
public static matchType(type: string): boolean {
return type === SolidityTypes.Tuple;
@@ -15,10 +16,18 @@ export class TupleDataType extends AbstractSetDataType {
if (!TupleDataType.matchType(dataItem.type)) {
throw new Error(`Tried to instantiate Tuple with bad input: ${dataItem}`);
}
- this._signature = this._computeSignatureOfMembers();
+ //this._signature =
}
- public getSignature(): string {
- return this._signature;
+ public getSignatureType(): string {
+ return this._computeSignatureOfMembers(false);
+ }
+
+ public getSignature(detailed?: boolean): string {
+ if (_.isEmpty(this.getDataItem().name) || !detailed) return this.getSignatureType();
+ const name = this.getDataItem().name;
+ const shortName = name.indexOf('.') > 0 ? name.substr(name.lastIndexOf('.') + 1) : name;
+ const detailedSignature = `${shortName} ${this._computeSignatureOfMembers(detailed)}`;
+ return detailedSignature;
}
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/uint.ts b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
index 06cde4eea..86d2705f0 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
@@ -55,7 +55,7 @@ export class UIntDataType extends AbstractBlobDataType {
return value;
}
- public getSignature(): string {
+ public getSignatureType(): string {
return `${SolidityTypes.Uint}${this._width}`;
}
}
diff --git a/packages/utils/src/abi_encoder/index.ts b/packages/utils/src/abi_encoder/index.ts
index baf844ac6..23422dd8b 100644
--- a/packages/utils/src/abi_encoder/index.ts
+++ b/packages/utils/src/abi_encoder/index.ts
@@ -12,3 +12,4 @@ export {
Tuple,
UInt,
} from './evm_data_type_factory';
+export { fromSignature } from './utils/signatureParser';
diff --git a/packages/utils/src/abi_encoder/utils/signatureParser.ts b/packages/utils/src/abi_encoder/utils/signatureParser.ts
new file mode 100644
index 000000000..fe5127032
--- /dev/null
+++ b/packages/utils/src/abi_encoder/utils/signatureParser.ts
@@ -0,0 +1,154 @@
+import * as _ from 'lodash';
+
+import { DataType } from '../abstract_data_types/data_type';
+import { DataItem } from 'ethereum-protocol';
+import { MethodAbi } from 'ethereum-types';
+import * as EvmDataTypes from '../evm_data_type_factory';
+
+// Valid signatures:
+// functionName(param1, param2, ...): (output1, output2, ...)
+// functionName(param1, param2, ...)
+// (param1, param2, ...)
+/*
+export function fromSignature(signature: string): DataType {
+ const maxSignatureIndex = signature.length - 1;
+ // Function name
+ const isFunction = signature.startsWith('function ');
+ // Output components
+ const outputComponentsBeginIndex = signature.indexOf(':');
+ const outputComponentsEndIndex = outputComponentsBeginIndex >= 0 ? maxSignatureIndex : 0;
+ const hasOutputComponents = outputComponentsBeginIndex >= 0;
+ const outputComponentsSignature = hasOutputComponents ? signature.substring(outputComponentsBeginIndex, outputComponentsEndIndex + 1) : "";
+ // Input components
+ const inputComponentsBeginIndex = signature.indexOf('(');
+ const inputComponentsEndIndex = hasOutputComponents ? outputComponentsBeginIndex : maxSignatureIndex;
+ const inputComponentsSignature = signature.substring(inputComponentsBeginIndex, inputComponentsEndIndex + 1);
+ // Function anme
+ const functionName = signature.substr(0, inputComponentsBeginIndex);
+ const isFunction = !_.isEmpty(functionName);
+
+ console.log(`sig - ` + inputComponentsSignature);
+ // Create data type
+ let dataType: DataType;
+ if (isFunction) {
+ const methodAbi = {
+ type: 'function',
+ name: functionName,
+ inputs: generateDataItems(inputComponentsSignature),
+ outputs: !_.isEmpty(outputComponentsSignature) ? generateDataItems(outputComponentsSignature) : [],
+ } as MethodAbi;
+ dataType = new EvmDataTypes.Method(methodAbi);
+ } else if(hasOutputComponents) {
+ throw new Error(`Invalid signature: Contains outputs but no function name.`);
+ } else {
+ const inputDataItem = generateDataItem(inputComponentsSignature);
+ console.log(JSON.stringify(inputDataItem));
+ dataType = EvmDataTypes.EvmDataTypeFactory.getInstance().create(inputDataItem);
+ }
+ return dataType;
+}*/
+
+export function fromSignature(signature: string): DataType {
+ const dataItems = generateDataItems(signature);
+ if (dataItems.length === 1) {
+ return EvmDataTypes.EvmDataTypeFactory.getInstance().create(dataItems[0]);
+ }
+ // this is a tuple
+ return EvmDataTypes.EvmDataTypeFactory.getInstance().create({
+ name: '',
+ type: 'tuple',
+ components: dataItems
+ });
+}
+
+function generateDataItems(signature: string): DataItem[] {
+ let trimmedSignature = signature;
+ if (signature.startsWith('(')) {
+ if(!signature.endsWith(')')) {
+ throw new Error(`Failed to generate data item. Must end with ')'`);
+ }
+ trimmedSignature = signature.substr(1, signature.length - 2);
+ }
+ trimmedSignature += ',';
+ let currTokenIsArray = false;
+ let currTokenArrayModifier = "";
+ let isParsingArrayModifier = false;
+ let currToken = '';
+ let parenCount = 0;
+ let currTokenName = '';
+ const dataItems: DataItem[] = [];
+ for(const char of trimmedSignature) {
+ // Tokenize the type string while keeping track of parentheses.
+ switch (char) {
+ case '(':
+ parenCount += 1;
+ currToken += char;
+ break;
+ case ')':
+ parenCount -= 1;
+ currToken += char;
+ break;
+ case '[':
+ if (parenCount === 0) {
+ isParsingArrayModifier = true;
+ currTokenIsArray = true;
+ currTokenArrayModifier += "[";
+ } else {
+ currToken += char;
+ }
+ break;
+ case ']':
+ if (parenCount === 0) {
+ isParsingArrayModifier = false;
+ currTokenArrayModifier += ']';
+ } else {
+ currToken += char;
+ }
+ break;
+ case ' ':
+ if (parenCount === 0) {
+ currTokenName = currToken;
+ currToken = "";
+ } else {
+ currToken += char;
+ }
+ break;
+ case ',':
+ if (parenCount === 0) {
+ //throw new Error(`Generating Data Items`);
+ const components = currToken.startsWith('(') ? generateDataItems(currToken) : [];
+ const isTuple = !_.isEmpty(components);
+ const isArray = currTokenIsArray;
+ let dataItem: DataItem = {name: currTokenName, type: ''};
+ if (isTuple) {
+ dataItem.type = 'tuple';
+ dataItem.components = components;
+ } else {
+ dataItem.type = currToken;
+ }
+ if (isArray) {
+ dataItem.type += currTokenArrayModifier;
+ }
+
+ dataItems.push(dataItem);
+
+ currTokenName = '';
+ currToken = '';
+ currTokenIsArray = false;
+ currTokenArrayModifier = "";
+ break;
+ } else {
+ currToken += char;
+ break;
+ }
+ default:
+ if (isParsingArrayModifier) {
+ currTokenArrayModifier += char;
+ } else {
+ currToken += char;
+ }
+ break;
+ }
+ }
+ return dataItems;
+} \ No newline at end of file
diff --git a/packages/utils/test/abi_encoder/evm_data_types_test.ts b/packages/utils/test/abi_encoder/evm_data_types_test.ts
index 55d582d10..4faa5a21f 100644
--- a/packages/utils/test/abi_encoder/evm_data_types_test.ts
+++ b/packages/utils/test/abi_encoder/evm_data_types_test.ts
@@ -26,6 +26,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic size; Static elements', async () => {
// Create DataType object
@@ -41,6 +45,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Fixed size; Dynamic elements', async () => {
// Create DataType object
@@ -56,6 +64,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic size; Dynamic elements', async () => {
// Create DataType object
@@ -71,6 +83,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic Size; Multidimensional; Dynamic Elements', async () => {
// Create DataType object
@@ -89,6 +105,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic Size; Multidimensional; Static Elements', async () => {
// Create DataType object
@@ -107,6 +127,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Static Size; Multidimensional; Static Elements', async () => {
// Create DataType object
@@ -124,6 +148,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Static Size; Multidimensional; Dynamic Elements', async () => {
// Create DataType object
@@ -141,6 +169,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Static size; Too Few Elements', async () => {
// Create DataType object
@@ -197,6 +229,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args, encodingRules);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic elements only', async () => {
// Create DataType object
@@ -217,6 +253,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Static Array', async () => {
// Create DataType object
@@ -237,6 +277,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Dynamic Array', async () => {
// Create DataType object
@@ -257,6 +301,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Static Multidimensional Array', async () => {
// Create DataType object
@@ -279,6 +327,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Dynamic Multidimensional Array', async () => {
// Create DataType object
@@ -301,6 +353,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Static and dynamic elements mixed', async () => {
// Create DataType object
@@ -331,6 +387,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
const decodedArgs = dataType.decode(encodedArgs, decodingRules);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Missing Key', async () => {
// Create DataType object
@@ -345,22 +405,22 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Encode Args and validate result
expect(() => {
dataType.encode(args, encodingRules);
- }).to.throw('Could not assign tuple to object: missing keys field_2');
+ }).to.throw('Could not assign tuple to object: missing key \'field_2\' in object {"field_1":"-5"}');
});
it('Bad Key', async () => {
// Create DataType object
const testDataItem = {
name: 'Tuple',
type: 'tuple',
- components: [{ name: 'field_1', type: 'int32' }, { name: 'field_2', type: 'bool' }],
+ components: [{name: 'field_1', type: 'bool' }],
};
const dataType = new AbiEncoder.Tuple(testDataItem);
// Construct args to be encoded
- const args = { unknown_field: new BigNumber(-5) };
+ const args = { field_1: true, unknown_field: new BigNumber(-5) };
// Encode Args and validate result
expect(() => {
dataType.encode(args, encodingRules);
- }).to.throw("Could not assign tuple to object: unrecognized key 'unknown_field' in object Tuple");
+ }).to.throw("Could not assign tuple to object: unrecognized keys unknown_field");
});
});
@@ -378,6 +438,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Invalid Address - input is not valid hex', async () => {
// Create DataType object
@@ -417,6 +481,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('False', async () => {
// Create DataType object
@@ -431,6 +499,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
});
@@ -455,6 +527,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Negative Base Case', async () => {
// Create DataType object
@@ -469,6 +545,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Positive Value', async () => {
// Create DataType object
@@ -483,6 +563,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Negative Value', async () => {
// Create DataType object
@@ -497,6 +581,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Value too large', async () => {
// Create DataType object
@@ -533,6 +621,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Negative Base Case', async () => {
// Create DataType object
@@ -547,6 +639,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Positive Value', async () => {
// Create DataType object
@@ -561,6 +657,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Negative Value', async () => {
// Create DataType object
@@ -575,6 +675,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Value too large', async () => {
// Create DataType object
@@ -621,6 +725,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt256 - Positive Value', async () => {
// Create DataType object
@@ -635,6 +743,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt256 - Zero Value', async () => {
// Create DataType object
@@ -649,6 +761,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt256 - Value too large', async () => {
// Create DataType object
@@ -685,6 +801,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt32 - Positive Value', async () => {
// Create DataType object
@@ -699,6 +819,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt32 - Zero Value', async () => {
// Create DataType object
@@ -713,6 +837,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt32 - Value too large', async () => {
// Create DataType object
@@ -752,6 +880,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Single Byte (bytes1)', async () => {
// Create DataType object
@@ -766,6 +898,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('4 Bytes (bytes4)', async () => {
// Create DataType object
@@ -780,6 +916,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('4 Bytes (bytes4); Encoder must pad input', async () => {
// Create DataType object
@@ -796,6 +936,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodedArgs = dataType.decode(encodedArgs);
const paddedArgs = '0x1a180000';
expect(decodedArgs).to.be.deep.equal(paddedArgs);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('32 Bytes (bytes32)', async () => {
// Create DataType object
@@ -810,6 +954,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('32 Bytes (bytes32); Encoder must pad input', async () => {
// Create DataType object
@@ -826,6 +974,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
const decodedArgs = dataType.decode(encodedArgs);
const paddedArgs = '0x1a18bf6100000000000000000000000000000000000000000000000000000000';
expect(decodedArgs).to.be.deep.equal(paddedArgs);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Should throw when pass in too many bytes (bytes4)', async () => {
// Create DataType object
@@ -893,6 +1045,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Spans multiple EVM words', async () => {
// Create DataType object
@@ -910,6 +1066,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Input as Buffer', async () => {
// Create DataType object
@@ -927,6 +1087,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Should throw when pass in bad hex (no 0x prefix)', async () => {
// Create DataType object
@@ -968,6 +1132,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('Spans multiple EVM words', async () => {
// Create DataType object
@@ -985,6 +1153,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
it('String that begins with 0x prefix', async () => {
// Create DataType object
@@ -1002,6 +1174,10 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
// Decode Encoded Args and validate result
const decodedArgs = dataType.decode(encodedArgs);
expect(decodedArgs).to.be.deep.equal(args);
+ // Validate signature
+ const dataTypeFromSignature = AbiEncoder.fromSignature(dataType.getSignature(true));
+ const encodedArgsFromSignature = dataTypeFromSignature.encode(args);
+ expect(encodedArgsFromSignature).to.be.deep.equal(expectedEncodedArgs);
});
});
});
diff --git a/packages/utils/test/abi_encoder/methods_test.ts b/packages/utils/test/abi_encoder/methods_test.ts
index a0525967e..684d7c4b3 100644
--- a/packages/utils/test/abi_encoder/methods_test.ts
+++ b/packages/utils/test/abi_encoder/methods_test.ts
@@ -21,7 +21,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x09f2b0c30000000000000000000000000000000000000000000000000000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000015600000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Array of Static Tuples (Array has defined length)', async () => {
@@ -40,7 +41,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x9eb20969000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Array of Static Tuples (Array has dynamic length)', async () => {
@@ -59,7 +61,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x63275d6e00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Array of Dynamic Tuples (Array has defined length)', async () => {
@@ -78,7 +81,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0xdeedb00f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000013400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000138000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023136000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Array of Dynamic Tuples (Array has dynamic length)', async () => {
@@ -97,7 +101,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x60c847fb000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000013400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000138000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023132000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000023136000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Multidimensional Arrays / Static Members', async () => {
@@ -109,8 +114,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
const argsLength = 8;
for (let i = 0; i < argsLength; ++i) {
args.push([
- [[new BigNumber(++value), new BigNumber(++value)], [new BigNumber(++value), new BigNumber(++value)]],
- [[new BigNumber(++value), new BigNumber(++value)], [new BigNumber(++value), new BigNumber(++value)]],
+ [[++value, ++value], [++value, ++value]],
+ [[++value, ++value], [++value, ++value]],
]);
}
const calldata = method.encode(args, encodingRules);
@@ -118,9 +123,9 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
const expectedCalldata =
'0xc2f47d6f00000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000480000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000d400000000000000000000000000000000000000000000000000000000000000e600000000000000000000000000000000000000000000000000000000000000039000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000003b000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000003d000000000000000000000000000000000000000000000000000000000000003e000000000000000000000000000000000000000000000000000000000000003f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001500000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001700000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000019000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001d000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000001f000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000230000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000025000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000027000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000029000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002b000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000002f0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003100000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000000000003400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000035000000000000000000000000000000000000000000000000000000000000003600000000000000000000000000000000000000000000000000000000000000370000000000000000000000000000000000000000000000000000000000000038';
expect(calldata).to.be.equal(expectedCalldata);
- expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Multidimensional Arrays / Dynamic Members', async () => {
@@ -148,7 +153,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x81534ebd0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000052000000000000000000000000000000000000000000000000000000000000009a00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000131000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000013300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000137000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000139000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002313000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000023131000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000231320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002313300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023134000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000231350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002313600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000231370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002313800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000023139000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000232300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000023231000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000232320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002323300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023234000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000232350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002323600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000232370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002323800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002323900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002333100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000023332000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Fixed Length Array / Dynamic Members', async () => {
@@ -161,7 +167,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x243a6e6e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000005427261766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034e657700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Fixed Length Array / Dynamic Members', async () => {
@@ -174,7 +181,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x243a6e6e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000005427261766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034e657700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Unfixed Length Array / Dynamic Members ABI', async () => {
@@ -187,33 +195,36 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x13e751a900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000005427261766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034e657700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Unfixed Length Array / Static Members ABI', async () => {
// Generate calldata
const method = new AbiEncoder.Method(AbiSamples.dynamicArrayStaticMembersAbi);
- const args = [[new BigNumber(127), new BigNumber(14), new BigNumber(54)]];
+ const args = [[127, 14, 54]];
const calldata = method.encode(args, encodingRules);
// Validate calldata
const expectedCalldata =
'0x4fc8a83300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000036';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Fixed Length Array / Static Members ABI', async () => {
// Generate calldata
const method = new AbiEncoder.Method(AbiSamples.staticArrayAbi);
- const args = [[new BigNumber(127), new BigNumber(14), new BigNumber(54)]];
+ const args = [[127, 14, 54]];
const calldata = method.encode(args, encodingRules);
// Validate calldata
const expectedCalldata =
'0xf68ade72000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000036';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Array ABI', async () => {
@@ -226,7 +237,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x13e751a900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000373697800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005736576656e000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Static Tuple', async () => {
@@ -240,7 +252,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0xa9125e150000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Dynamic Tuple (Array input)', async () => {
@@ -254,7 +267,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x5b998f3500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Dynamic Tuple (Object input)', async () => {
@@ -268,7 +282,8 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x5b998f3500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000046669766500000000000000000000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Large, Flat ABI', async () => {
@@ -291,13 +306,14 @@ describe('ABI Encoder: Method Encoding / Decoding', () => {
'0x312d4d42000000000000000000000000000000000000000000000000000000000f4d9feefffffffffffffffffffffffffffffffffffffffffffffffffffffffff0b26012000000000000000000000000000000000000000000000000000000000006a0444300000000000000000000000000000000000000000000000000000000000000000102030405060708091112131415161718192021222324252627282930313200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f4980000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000003800010203040506070809111213141516171819202122232425262728293031320809111213141516171819202122232425262728293031320000000000000000000000000000000000000000000000000000000000000000000000000000002c4c6974746c65207065746572207069706572207069706564206120706970696e672070657070657220706f740000000000000000000000000000000000000000';
expect(calldata).to.be.equal(expectedCalldata);
// Validate decoding
- const decodedValue = method.decode(calldata);
+ const decodingRules = {structsAsObjects: false};
+ const decodedValue = method.decode(calldata, decodingRules);
expect(decodedValue).to.be.deep.equal(args);
});
it('Large, Nested ABI', async () => {
// Construct Calldata
const method = new AbiEncoder.Method(AbiSamples.largeNestedAbi);
- const someStaticArray = [new BigNumber(127), new BigNumber(14), new BigNumber(54)];
+ const someStaticArray = [127, 14, 54];
const someStaticArrayWithDynamicMembers = [
'the little piping piper piped a piping pipper papper',
'the kid knows how to write poems, what can I say -- I guess theres a lot I could say to try to fill this line with a lot of text.',
diff --git a/packages/utils/test/abi_encoder/optimizer_test.ts b/packages/utils/test/abi_encoder/optimizer_test.ts
index ee0654ec3..ac8999168 100644
--- a/packages/utils/test/abi_encoder/optimizer_test.ts
+++ b/packages/utils/test/abi_encoder/optimizer_test.ts
@@ -23,7 +23,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x7221063300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000096';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Dynamic Arrays with Dynamic Elements', async () => {
@@ -38,7 +38,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0xbb4f12e300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Static Arrays with Static Elements (should not optimize)', async () => {
@@ -55,7 +55,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
const unoptimizedCalldata = method.encode(args);
expect(optimizedCalldata).to.be.equal(unoptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Static Arrays with Dynamic Elements', async () => {
@@ -70,7 +70,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x9fe31f8e0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Array Elements (should optimize)', async () => {
@@ -84,7 +84,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x13e751a900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Tuple Fields', async () => {
@@ -98,7 +98,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x16780a5e000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Strings', async () => {
@@ -115,7 +115,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x07370bfa00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Bytes', async () => {
@@ -133,7 +133,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x6045e42900000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002801020304050607080910111213141516171819202122232425262728293031323334353637383940000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Tuples', async () => {
@@ -148,7 +148,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x564f826d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000006792a000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20576f726c642100000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Fields Across Two Tuples', async () => {
@@ -164,7 +164,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x564f826d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20576f726c642100000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Arrays, Nested in Separate Tuples', async () => {
@@ -180,7 +180,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x18970a9e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000000000000000c80000000000000000000000000000000000000000000000000000000000000035657874726120617267756d656e7420746f2070726576656e742065786163746c79206d61746368696e6720746865207475706c65730000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Tuples, Nested in Separate Tuples', async () => {
@@ -196,7 +196,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x0b4d2e6a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20576f726c6421000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035657874726120617267756d656e7420746f2070726576656e742065786163746c79206d61746368696e6720746865207475706c65730000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Two-Dimensional Arrays', async () => {
@@ -211,7 +211,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x0d28c4f9000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000003466f6f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003426172000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035a61610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000003466f6f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003426172000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035a61610000000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Duplicate Array, Nested within Separate Two-Dimensional Arrays', async () => {
@@ -226,14 +226,14 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x0d28c4f900000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003466f6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000548656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000034261720000000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Array Elements Duplicated as Tuple Fields', async () => {
// Generate calldata
const method = new AbiEncoder.Method(OptimizedAbis.arrayElementsDuplicatedAsTupleFields);
- const array = [new BigNumber(100), new BigNumber(150), new BigNumber(200), new BigNumber(225)];
- const tuple = [[array[0]], [array[1]], [array[2]], [array[3]]];
+ const array = [100, 150, 200, 225];
+ const tuple = [[new BigNumber(array[0])], [new BigNumber(array[1])], [new BigNumber(array[2])], [new BigNumber(array[3])]];
const args = [array, tuple];
// Validata calldata
const optimizedCalldata = method.encode(args, encodingRules);
@@ -241,7 +241,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0x5b5c78fd0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000e1';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
it('Array Elements Duplicated as Separate Parameter', async () => {
@@ -256,7 +256,7 @@ describe('ABI Encoder: Optimized Method Encoding/Decoding', () => {
'0xe0e0d34900000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000005576f726c64000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000';
expect(optimizedCalldata).to.be.equal(expectedOptimizedCalldata);
// Validate decoding
- const decodedArgs = method.decode(optimizedCalldata);
+ const decodedArgs = method.decode(optimizedCalldata, {structsAsObjects: false});
expect(decodedArgs).to.be.deep.equal(args);
});
});
diff --git a/packages/utils/test/abi_encoder/return_values_test.ts b/packages/utils/test/abi_encoder/return_values_test.ts
index 104c7f5db..b5b9dfd64 100644
--- a/packages/utils/test/abi_encoder/return_values_test.ts
+++ b/packages/utils/test/abi_encoder/return_values_test.ts
@@ -15,7 +15,7 @@ describe('ABI Encoder: Return Value Encoding/Decoding', () => {
// Decode return value
const method = new AbiEncoder.Method(ReturnValueAbis.noReturnValues);
const returnValue = '0x';
- const decodedReturnValue = method.decodeReturnValues(returnValue);
+ const decodedReturnValue = method.decodeReturnValues(returnValue, {structsAsObjects: false});
const expectedDecodedReturnValue: any[] = [];
expect(decodedReturnValue).to.be.deep.equal(expectedDecodedReturnValue);
});
@@ -24,7 +24,7 @@ describe('ABI Encoder: Return Value Encoding/Decoding', () => {
const method = new AbiEncoder.Method(ReturnValueAbis.singleStaticReturnValue);
const returnValue = ['0x01020304'];
const encodedReturnValue = method.encodeReturnValues(returnValue, encodingRules);
- const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue, {structsAsObjects: false});
// Validate decoded return value
expect(decodedReturnValue).to.be.deep.equal(returnValue);
});
@@ -33,7 +33,7 @@ describe('ABI Encoder: Return Value Encoding/Decoding', () => {
const method = new AbiEncoder.Method(ReturnValueAbis.multipleStaticReturnValues);
const returnValue = ['0x01020304', '0x05060708'];
const encodedReturnValue = method.encodeReturnValues(returnValue, encodingRules);
- const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue, {structsAsObjects: false});
// Validate decoded return value
expect(decodedReturnValue).to.be.deep.equal(returnValue);
});
@@ -42,7 +42,7 @@ describe('ABI Encoder: Return Value Encoding/Decoding', () => {
const method = new AbiEncoder.Method(ReturnValueAbis.singleDynamicReturnValue);
const returnValue = ['0x01020304'];
const encodedReturnValue = method.encodeReturnValues(returnValue, encodingRules);
- const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue, {structsAsObjects: false});
// Validate decoded return value
expect(decodedReturnValue).to.be.deep.equal(returnValue);
});
@@ -51,7 +51,7 @@ describe('ABI Encoder: Return Value Encoding/Decoding', () => {
const method = new AbiEncoder.Method(ReturnValueAbis.multipleDynamicReturnValues);
const returnValue = ['0x01020304', '0x05060708'];
const encodedReturnValue = method.encodeReturnValues(returnValue, encodingRules);
- const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue, {structsAsObjects: false});
// Validate decoded return value
expect(decodedReturnValue).to.be.deep.equal(returnValue);
});
@@ -60,7 +60,7 @@ describe('ABI Encoder: Return Value Encoding/Decoding', () => {
const method = new AbiEncoder.Method(ReturnValueAbis.mixedStaticAndDynamicReturnValues);
const returnValue = ['0x01020304', '0x05060708'];
const encodedReturnValue = method.encodeReturnValues(returnValue, encodingRules);
- const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue, {structsAsObjects: false});
// Validate decoded return value
expect(decodedReturnValue).to.be.deep.equal(returnValue);
});
diff --git a/packages/utils/test/abi_encoder/signature_tests.ts b/packages/utils/test/abi_encoder/signature_tests.ts
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/packages/utils/test/abi_encoder/signature_tests.ts