protocol/contracts/utils/test/log_decoding.ts
Xianny f0d7d10fe7
update abi-gen with new method interfaces (#2325)
* update abi-gen with new method interfaces

* wip: get all packages to build

* wip: get all packages to build

* Fix two contract wrapper calls

* Export necessary types part of the contract wrapper public interfaces

* Revive and fix wrapper_unit_tests

* Remove duplicate type

* Fix lib_exchange_rich_error_decoder tests

* Fix remaining test failures in contracts-* packages

* Prettier fixes

* remove transactionHelper

* lint and update changelogs

* Fix prettier

* Revert changes to reference docs

* Add back changelog already published and add revert changelog entry

* Add missing CHANGELOG entries

* Add missing comma

* Update mesh-rpc-client dep

* Update Mesh RPC logic in @0x/orderbook to v6.0.1-beta

* Align package versions
2019-11-14 11:22:29 -05:00

107 lines
5.0 KiB
TypeScript

import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import { DecodedLogArgs, LogWithDecodedArgs } from 'ethereum-types';
import { artifacts } from './artifacts';
import { TestLogDecodingContract } from './wrappers';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('TestLogDecoding', () => {
let testLogDecodingWithDependencies: TestLogDecodingContract;
let testLogDecodingDeployedWithoutDependencies: TestLogDecodingContract;
const expectedEvent = {
foo: new BigNumber(256),
bar: '0x1234',
car: '4321',
};
const expectedDownstreamEvent = {
lorem: new BigNumber(256),
ipsum: '4321',
};
const emptyDependencyList = {};
before(async () => {
testLogDecodingDeployedWithoutDependencies = await TestLogDecodingContract.deployFrom0xArtifactAsync(
artifacts.TestLogDecoding,
provider,
txDefaults,
emptyDependencyList,
);
testLogDecodingWithDependencies = await TestLogDecodingContract.deployFrom0xArtifactAsync(
artifacts.TestLogDecoding,
provider,
txDefaults,
artifacts,
);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('Decoding Log Arguments', () => {
it('should decode locally emitted event args when no dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingDeployedWithoutDependencies
.emitEvent()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
});
it('should not decode event args when no dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingDeployedWithoutDependencies
.emitEventDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.undefined();
});
it('should decode args for local but not downstream event when no dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingDeployedWithoutDependencies
.emitEventsLocalAndDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(2);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[1] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.undefined();
});
it('should decode locally emitted event args when dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingWithDependencies.emitEvent().awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
});
it('should decode downstream event args when dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingWithDependencies
.emitEventDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(1);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(
expectedDownstreamEvent,
);
});
it('should decode args for both local and downstream events when dependencies are passed into wrapper', async () => {
const txReceipt = await testLogDecodingWithDependencies
.emitEventsLocalAndDownstream()
.awaitTransactionSuccessAsync();
expect(txReceipt.logs.length).to.be.equal(2);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
// tslint:disable no-unnecessary-type-assertion
expect((txReceipt.logs[1] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(
expectedDownstreamEvent,
);
});
});
});