aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/test
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-20 10:42:40 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:11 +0800
commitb0ebc6fa14adc08c074bea4d275cc31504c95d55 (patch)
tree8b8b371176efc97d68a0fa8de6ebbce685d7cdfb /packages/utils/test
parent6daa79ec12557c06a5d4d6876dd086d554addb24 (diff)
downloaddexon-0x-contracts-b0ebc6fa14adc08c074bea4d275cc31504c95d55.tar.gz
dexon-0x-contracts-b0ebc6fa14adc08c074bea4d275cc31504c95d55.tar.zst
dexon-0x-contracts-b0ebc6fa14adc08c074bea4d275cc31504c95d55.zip
Tests for decoding return values + Ability to encode return values
Diffstat (limited to 'packages/utils/test')
-rw-r--r--packages/utils/test/abi_encoder_test.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/packages/utils/test/abi_encoder_test.ts b/packages/utils/test/abi_encoder_test.ts
index b672d0023..0220984b0 100644
--- a/packages/utils/test/abi_encoder_test.ts
+++ b/packages/utils/test/abi_encoder_test.ts
@@ -5,6 +5,7 @@ import { chaiSetup } from './utils/chai_setup';
import { BigNumber, AbiEncoder } from '../src/';
import * as AbiSamples from './abi_samples';
import * as OptimizedAbis from './optimizer_abis';
+import * as ReturnValueAbis from './return_value_abis';
import { DecodingRules } from '../src/abi_encoder';
import ethUtil = require('ethereumjs-util');
@@ -12,6 +13,74 @@ chaiSetup.configure();
const expect = chai.expect;
describe.only('ABI Encoder', () => {
+ describe('Decode Return Values', () => {
+ it('No Return Value', async () => {
+ // Decode return value
+ const method = new AbiEncoder.Method(ReturnValueAbis.noReturnValues);
+ const returnValue = '0x';
+ const decodedReturnValue = method.decodeReturnValues(returnValue);
+ const expectedDecodedReturnValue: any[] = [];
+ const decodedReturnValueJson = JSON.stringify(decodedReturnValue);
+ const expectedDecodedReturnValueJson = JSON.stringify(expectedDecodedReturnValue);
+ expect(decodedReturnValueJson).to.be.equal(expectedDecodedReturnValueJson);
+ });
+ it('Single static return value', async () => {
+ // Generate Return Value
+ const method = new AbiEncoder.Method(ReturnValueAbis.singleStaticReturnValue);
+ const returnValue = ['0x01020304'];
+ const encodedReturnValue = method.encodeReturnValues(returnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ // Validate decoded return value
+ const decodedReturnValueJson = JSON.stringify(decodedReturnValue);
+ const expectedDecodedReturnValueJson = JSON.stringify(returnValue);
+ expect(decodedReturnValueJson).to.be.equal(expectedDecodedReturnValueJson);
+ });
+ it('Multiple static return values', async () => {
+ // Generate Return Value
+ const method = new AbiEncoder.Method(ReturnValueAbis.multipleStaticReturnValues);
+ const returnValue = ['0x01020304', '0x05060708'];
+ const encodedReturnValue = method.encodeReturnValues(returnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ // Validate decoded return value
+ const decodedReturnValueJson = JSON.stringify(decodedReturnValue);
+ const expectedDecodedReturnValueJson = JSON.stringify(returnValue);
+ expect(decodedReturnValueJson).to.be.equal(expectedDecodedReturnValueJson);
+ });
+ it('Single dynamic return value', async () => {
+ // Generate Return Value
+ const method = new AbiEncoder.Method(ReturnValueAbis.singleDynamicReturnValue);
+ const returnValue = ['0x01020304'];
+ const encodedReturnValue = method.encodeReturnValues(returnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ // Validate decoded return value
+ const decodedReturnValueJson = JSON.stringify(decodedReturnValue);
+ const expectedDecodedReturnValueJson = JSON.stringify(returnValue);
+ expect(decodedReturnValueJson).to.be.equal(expectedDecodedReturnValueJson);
+ });
+ it('Multiple dynamic return values', async () => {
+ // Generate Return Value
+ const method = new AbiEncoder.Method(ReturnValueAbis.multipleDynamicReturnValues);
+ const returnValue = ['0x01020304', '0x05060708'];
+ const encodedReturnValue = method.encodeReturnValues(returnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ // Validate decoded return value
+ const decodedReturnValueJson = JSON.stringify(decodedReturnValue);
+ const expectedDecodedReturnValueJson = JSON.stringify(returnValue);
+ expect(decodedReturnValueJson).to.be.equal(expectedDecodedReturnValueJson);
+ });
+ it('Mixed static/dynamic return values', async () => {
+ // Generate Return Value
+ const method = new AbiEncoder.Method(ReturnValueAbis.mixedStaticAndDynamicReturnValues);
+ const returnValue = ['0x01020304', '0x05060708'];
+ const encodedReturnValue = method.encodeReturnValues(returnValue);
+ const decodedReturnValue = method.decodeReturnValues(encodedReturnValue);
+ // Validate decoded return value
+ const decodedReturnValueJson = JSON.stringify(decodedReturnValue);
+ const expectedDecodedReturnValueJson = JSON.stringify(returnValue);
+ expect(decodedReturnValueJson).to.be.equal(expectedDecodedReturnValueJson);
+ });
+ });
+
describe('Optimizer', () => {
it('Duplicate Dynamic Arrays with Static Elements', async () => {
// Generate calldata