diff options
Diffstat (limited to 'packages/utils')
4 files changed, 10 insertions, 22 deletions
diff --git a/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts b/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts index a091e55b9..4252b782c 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts @@ -9,6 +9,8 @@ import { DecodingRules } from '../../utils/rules'; import { DataType } from '../data_type'; import { DataTypeFactory } from '../interfaces'; +import * as ethUtil from 'ethereumjs-util'; + export abstract class AbstractBlobDataType extends DataType { protected _sizeKnownAtCompileTime: 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 d7105ff5f..5eb29c47b 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 @@ -13,6 +13,7 @@ import { DataType } from '../data_type'; import { DataTypeFactory, MemberIndexByName } from '../interfaces'; import { AbstractPointerDataType } from './pointer'; +import { logUtils } from '../../../log_utils'; export abstract class AbstractSetDataType extends DataType { protected readonly _arrayLength: number | undefined; @@ -134,22 +135,16 @@ export abstract class AbstractSetDataType extends DataType { const block = new SetCalldataBlock(this.getDataItem().name, this.getSignature(), parentName); // Create blocks for members of set. const memberCalldataBlocks: CalldataBlock[] = []; - let duplicateObj = _.cloneDeep(obj) as {[key:string]: any}; _.forEach(this._memberIndexByName, (memberIndex: number, memberName: string) => { if (!(memberName in obj)) { throw new Error( `Could not assign tuple to object: missing key '${memberName}' in object ${JSON.stringify(obj)}`, ); } - const memberValue: any = duplicateObj[memberName]; + const memberValue: any = (obj as {[key:string]: any})[memberName]; const memberBlock = this._members[memberIndex].generateCalldataBlock(memberValue, block); memberCalldataBlocks.push(memberBlock); - delete duplicateObj[memberName]; }); - // Sanity check that all members have been included. - if (Object.keys(duplicateObj).length !== 0) { - throw new Error(`Could not assign tuple to object: unrecognized keys ${Object.keys(duplicateObj)}`); - } // Associate member blocks with Set block. block.setMembers(memberCalldataBlocks); return block; 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 44456cd0a..212e2ca6b 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/method.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts @@ -35,6 +35,12 @@ export class MethodDataType extends AbstractSetDataType { return value; } + public decodeAsArray(returndata: string, rules?: DecodingRules): any { + const value = this.decode(returndata, rules); + const valuesAsArray = _.isObject(value) ? _.values(value) : [value]; + return valuesAsArray; + } + public encodeReturnValues(value: any, rules?: EncodingRules): string { const returnData = this._returnDataType.encode(value, rules); return returnData; 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 919b71c55..3c7bafc0a 100644 --- a/packages/utils/test/abi_encoder/evm_data_types_test.ts +++ b/packages/utils/test/abi_encoder/evm_data_types_test.ts @@ -407,21 +407,6 @@ describe('ABI Encoder: EVM Data Type Encoding/Decoding', () => { dataType.encode(args, encodingRules); }).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: 'bool' }], - }; - const dataType = new AbiEncoder.Tuple(testDataItem); - // Construct args to be encoded - 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 keys unknown_field"); - }); }); describe('Address', () => { |