diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-12-20 05:01:22 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2019-01-15 02:49:44 +0800 |
commit | e9a82905e35041d36c4c9be75e11c0399ee96b89 (patch) | |
tree | bd49ab279ae96fb0248b252e55399f3ce50c4793 /packages/utils/test | |
parent | f8684d6a776724d0172c30126a7277885ed4e966 (diff) | |
download | dexon-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/utils/test')
-rw-r--r-- | packages/utils/test/abi_encoder/evm_data_types_test.ts | 184 | ||||
-rw-r--r-- | packages/utils/test/abi_encoder/methods_test.ts | 62 | ||||
-rw-r--r-- | packages/utils/test/abi_encoder/optimizer_test.ts | 36 | ||||
-rw-r--r-- | packages/utils/test/abi_encoder/return_values_test.ts | 12 | ||||
-rw-r--r-- | packages/utils/test/abi_encoder/signature_tests.ts | 0 |
5 files changed, 243 insertions, 51 deletions
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 |