aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2019-02-07 09:21:19 +0800
committerGreg Hysen <greg.hysen@gmail.com>2019-02-09 08:25:30 +0800
commit3d2babd059551fc0e1a571d3cf1cb544ec85f52c (patch)
tree4f98bc9cb27db72706a460ea7eca87120b9e8f4f /packages/utils
parentd9c4c74a56c913e90f3c76566c64950fec86063b (diff)
downloaddexon-0x-contracts-3d2babd059551fc0e1a571d3cf1cb544ec85f52c.tar
dexon-0x-contracts-3d2babd059551fc0e1a571d3cf1cb544ec85f52c.tar.gz
dexon-0x-contracts-3d2babd059551fc0e1a571d3cf1cb544ec85f52c.tar.bz2
dexon-0x-contracts-3d2babd059551fc0e1a571d3cf1cb544ec85f52c.tar.lz
dexon-0x-contracts-3d2babd059551fc0e1a571d3cf1cb544ec85f52c.tar.xz
dexon-0x-contracts-3d2babd059551fc0e1a571d3cf1cb544ec85f52c.tar.zst
dexon-0x-contracts-3d2babd059551fc0e1a571d3cf1cb544ec85f52c.zip
Tests for transaction decoder
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/test/transaction_decoder_test.ts54
1 files changed, 53 insertions, 1 deletions
diff --git a/packages/utils/test/transaction_decoder_test.ts b/packages/utils/test/transaction_decoder_test.ts
index bc40f4840..3845bb134 100644
--- a/packages/utils/test/transaction_decoder_test.ts
+++ b/packages/utils/test/transaction_decoder_test.ts
@@ -1,9 +1,61 @@
import * as chai from 'chai';
+import { MethodAbi } from 'ethereum-types';
import 'mocha';
import { chaiSetup } from './utils/chai_setup';
+import { AbiEncoder, TransactionDecoder } from '../src';
chaiSetup.configure();
const expect = chai.expect;
-describe.only('TransactionDecoder', () => {});
+describe('TransactionDecoder', () => {
+ it('should successfully add a new ABI and decode tx data for it', async () => {
+ // Add new ABI
+ const abi: MethodAbi = {
+ name: 'foobar',
+ type: 'function',
+ inputs: [
+ {
+ name: 'addr',
+ type: 'address',
+ },
+ ],
+ outputs: [
+ {
+ name: 'butter',
+ type: 'string',
+ },
+ ],
+ constant: false,
+ payable: false,
+ stateMutability: 'pure',
+ };
+ const contractName = 'newContract';
+ const contractAddress = '0x0001020304050607080900010203040506070809';
+ const networkId = 1;
+ const contractInfo = [
+ {
+ contractAddress,
+ networkId,
+ },
+ ];
+ const transactionDecoder = new TransactionDecoder();
+ transactionDecoder.addABI([abi], contractName, contractInfo);
+ // Create some tx data
+ const foobarEncoder = new AbiEncoder.Method(abi);
+ const foobarSignature = foobarEncoder.getSignature();
+ const foobarTxData = foobarEncoder.encode([contractAddress]);
+ // Decode tx data using contract name
+ const decodedTxData = transactionDecoder.decode(foobarTxData, { contractName });
+ const expectedFunctionName = abi.name;
+ const expectedFunctionArguments = {
+ addr: contractAddress,
+ };
+ expect(decodedTxData.functionName).to.be.equal(expectedFunctionName);
+ expect(decodedTxData.functionSignature).to.be.equal(foobarSignature);
+ expect(decodedTxData.functionArguments).to.be.deep.equal(expectedFunctionArguments);
+ // Decode tx data using contract address
+ const decodedTxDataDecodedWithAddress = transactionDecoder.decode(foobarTxData, { contractAddress });
+ expect(decodedTxDataDecodedWithAddress).to.be.deep.equal(decodedTxData);
+ });
+});