aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-20 06:30:23 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-01-15 02:49:44 +0800
commit7991de9ed0b5f1e8a38097d902eae09cc6b5cf11 (patch)
tree3aaaa01876f4639d0165f75b65c2e55f4e7b4368
parente9a82905e35041d36c4c9be75e11c0399ee96b89 (diff)
downloaddexon-sol-tools-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar
dexon-sol-tools-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.gz
dexon-sol-tools-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.bz2
dexon-sol-tools-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.lz
dexon-sol-tools-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.xz
dexon-sol-tools-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.tar.zst
dexon-sol-tools-7991de9ed0b5f1e8a38097d902eae09cc6b5cf11.zip
Generalized `create` for signature / dataItems. Cleaner.
-rw-r--r--packages/utils/src/abi_encoder/evm_data_type_factory.ts23
-rw-r--r--packages/utils/src/abi_encoder/index.ts3
-rw-r--r--packages/utils/src/abi_encoder/utils/signatureParser.ts63
-rw-r--r--packages/utils/test/abi_encoder/evm_data_types_test.ts264
4 files changed, 166 insertions, 187 deletions
diff --git a/packages/utils/src/abi_encoder/evm_data_type_factory.ts b/packages/utils/src/abi_encoder/evm_data_type_factory.ts
index 4cc124e0a..5ff7366d6 100644
--- a/packages/utils/src/abi_encoder/evm_data_type_factory.ts
+++ b/packages/utils/src/abi_encoder/evm_data_type_factory.ts
@@ -2,6 +2,8 @@
import { DataItem, MethodAbi } from 'ethereum-types';
import * as _ from 'lodash';
+import { generateDataItemsFromSignature } from './utils/signatureParser';
+
import { DataType } from './abstract_data_types/data_type';
import { DataTypeFactory } from './abstract_data_types/interfaces';
import { AddressDataType } from './evm_data_types/address';
@@ -129,4 +131,25 @@ export class EvmDataTypeFactory implements DataTypeFactory {
private constructor() {}
}
+
+// Convenience function
+export function create(input: DataItem | DataItem[] | string): DataType {
+ // Handle different types of input
+ let dataItems: DataItem[] = [];
+ if (typeof(input) === 'string') {
+ dataItems = generateDataItemsFromSignature(input);
+ } else if(input instanceof Array) {
+ dataItems = input as DataItem[];
+ } else {
+ dataItems = [input as DataItem];
+ }
+ // Create single data item from input
+ let dataItem: DataItem = dataItems.length === 1 ? dataItems[0] : {
+ name: '',
+ type: 'tuple',
+ components: dataItems
+ };
+ // Create data type
+ return EvmDataTypeFactory.getInstance().create(dataItem);
+}
/* tslint:enable no-construct */
diff --git a/packages/utils/src/abi_encoder/index.ts b/packages/utils/src/abi_encoder/index.ts
index 23422dd8b..f7f1ceedc 100644
--- a/packages/utils/src/abi_encoder/index.ts
+++ b/packages/utils/src/abi_encoder/index.ts
@@ -11,5 +11,6 @@ export {
String,
Tuple,
UInt,
+ create,
} from './evm_data_type_factory';
-export { fromSignature } from './utils/signatureParser';
+//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
index fe5127032..9c1a59c82 100644
--- a/packages/utils/src/abi_encoder/utils/signatureParser.ts
+++ b/packages/utils/src/abi_encoder/utils/signatureParser.ts
@@ -1,67 +1,22 @@
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);
+export function generateDataItemFromSignature(signature: string): DataItem {
+ const dataItems = generateDataItemsFromSignature(signature);
if (dataItems.length === 1) {
- return EvmDataTypes.EvmDataTypeFactory.getInstance().create(dataItems[0]);
+ return dataItems[0];
}
- // this is a tuple
- return EvmDataTypes.EvmDataTypeFactory.getInstance().create({
+ // signature represents a tuple
+ return {
name: '',
type: 'tuple',
components: dataItems
- });
-}
+ };
+}*/
-function generateDataItems(signature: string): DataItem[] {
+export function generateDataItemsFromSignature(signature: string): DataItem[] {
let trimmedSignature = signature;
if (signature.startsWith('(')) {
if(!signature.endsWith(')')) {
@@ -116,7 +71,7 @@ function generateDataItems(signature: string): DataItem[] {
case ',':
if (parenCount === 0) {
//throw new Error(`Generating Data Items`);
- const components = currToken.startsWith('(') ? generateDataItems(currToken) : [];
+ const components = currToken.startsWith('(') ? generateDataItemsFromSignature(currToken) : [];
const isTuple = !_.isEmpty(components);
const isArray = currTokenIsArray;
let dataItem: DataItem = {name: currTokenName, type: ''};
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 4faa5a21f..919b71c55 100644
--- a/packages/utils/test/abi_encoder/evm_data_types_test.ts
+++ b/packages/utils/test/abi_encoder/evm_data_types_test.ts
@@ -27,9 +27,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic size; Static elements', async () => {
// Create DataType object
@@ -46,9 +46,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Fixed size; Dynamic elements', async () => {
// Create DataType object
@@ -65,9 +65,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic size; Dynamic elements', async () => {
// Create DataType object
@@ -84,9 +84,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic Size; Multidimensional; Dynamic Elements', async () => {
// Create DataType object
@@ -106,9 +106,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic Size; Multidimensional; Static Elements', async () => {
// Create DataType object
@@ -128,9 +128,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Static Size; Multidimensional; Static Elements', async () => {
// Create DataType object
@@ -149,9 +149,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Static Size; Multidimensional; Dynamic Elements', async () => {
// Create DataType object
@@ -170,9 +170,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Static size; Too Few Elements', async () => {
// Create DataType object
@@ -230,9 +230,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args, encodingRules);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Dynamic elements only', async () => {
// Create DataType object
@@ -254,9 +254,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Static Array', async () => {
// Create DataType object
@@ -278,9 +278,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Dynamic Array', async () => {
// Create DataType object
@@ -302,9 +302,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Static Multidimensional Array', async () => {
// Create DataType object
@@ -328,9 +328,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Nested Dynamic Multidimensional Array', async () => {
// Create DataType object
@@ -354,9 +354,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Static and dynamic elements mixed', async () => {
// Create DataType object
@@ -388,9 +388,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Missing Key', async () => {
// Create DataType object
@@ -439,9 +439,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Invalid Address - input is not valid hex', async () => {
// Create DataType object
@@ -482,9 +482,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('False', async () => {
// Create DataType object
@@ -500,9 +500,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
});
@@ -528,9 +528,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Negative Base Case', async () => {
// Create DataType object
@@ -546,9 +546,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Positive Value', async () => {
// Create DataType object
@@ -564,9 +564,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Negative Value', async () => {
// Create DataType object
@@ -582,9 +582,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int256 - Value too large', async () => {
// Create DataType object
@@ -622,9 +622,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Negative Base Case', async () => {
// Create DataType object
@@ -640,9 +640,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Positive Value', async () => {
// Create DataType object
@@ -658,9 +658,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Negative Value', async () => {
// Create DataType object
@@ -676,9 +676,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Int32 - Value too large', async () => {
// Create DataType object
@@ -726,9 +726,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt256 - Positive Value', async () => {
// Create DataType object
@@ -744,9 +744,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt256 - Zero Value', async () => {
// Create DataType object
@@ -762,9 +762,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt256 - Value too large', async () => {
// Create DataType object
@@ -802,9 +802,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt32 - Positive Value', async () => {
// Create DataType object
@@ -820,9 +820,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt32 - Zero Value', async () => {
// Create DataType object
@@ -838,9 +838,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('UInt32 - Value too large', async () => {
// Create DataType object
@@ -881,9 +881,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Single Byte (bytes1)', async () => {
// Create DataType object
@@ -899,9 +899,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('4 Bytes (bytes4)', async () => {
// Create DataType object
@@ -917,9 +917,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('4 Bytes (bytes4); Encoder must pad input', async () => {
// Create DataType object
@@ -937,9 +937,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('32 Bytes (bytes32)', async () => {
// Create DataType object
@@ -955,9 +955,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('32 Bytes (bytes32); Encoder must pad input', async () => {
// Create DataType object
@@ -975,9 +975,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Should throw when pass in too many bytes (bytes4)', async () => {
// Create DataType object
@@ -1046,9 +1046,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Spans multiple EVM words', async () => {
// Create DataType object
@@ -1067,9 +1067,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Input as Buffer', async () => {
// Create DataType object
@@ -1088,9 +1088,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Should throw when pass in bad hex (no 0x prefix)', async () => {
// Create DataType object
@@ -1133,9 +1133,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('Spans multiple EVM words', async () => {
// Create DataType object
@@ -1154,9 +1154,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
it('String that begins with 0x prefix', async () => {
// Create DataType object
@@ -1175,9 +1175,9 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => {
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);
+ const dataTypecreate = AbiEncoder.create(dataType.getSignature(true));
+ const encodedArgscreate = dataTypecreate.encode(args);
+ expect(encodedArgscreate).to.be.deep.equal(expectedEncodedArgs);
});
});
});