juggling some files around

This commit is contained in:
Michael Zhu 2019-10-17 13:05:02 -07:00
parent f4cb8cfb7e
commit 93b02e93b9
9 changed files with 58 additions and 48 deletions

View File

@ -1,10 +1,9 @@
import { blockchainTests, expect } from '@0x/contracts-test-utils'; import { blockchainTests, expect, verifyEvents } from '@0x/contracts-test-utils';
import { import {
artifacts, artifacts,
CoordinatorRegistryContract, CoordinatorRegistryContract,
CoordinatorRegistryCoordinatorEndpointSetEventArgs, CoordinatorRegistryCoordinatorEndpointSetEventArgs,
CoordinatorTestFactory,
} from '../src'; } from '../src';
// tslint:disable:no-unnecessary-type-assertion // tslint:disable:no-unnecessary-type-assertion
@ -71,7 +70,7 @@ blockchainTests.resets('Coordinator Registry tests', env => {
coordinatorOperator, coordinatorOperator,
coordinatorEndpoint, coordinatorEndpoint,
}; };
CoordinatorTestFactory.verifyEvents(txReceipt, [expectedEvent], 'CoordinatorEndpointSet'); verifyEvents(txReceipt, [expectedEvent], 'CoordinatorEndpointSet');
}); });
}); });
}); });

View File

@ -1,4 +1,3 @@
export { hashUtils } from './hash_utils'; export { hashUtils } from './hash_utils';
export { ApprovalFactory } from './approval_factory'; export { ApprovalFactory } from './approval_factory';
export { CoordinatorTestFactory } from './coordinator_test_factory';
export * from './types'; export * from './types';

View File

@ -1,4 +1,5 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { ApprovalFactory, artifacts, CoordinatorContract } from '@0x/contracts-coordinator';
import { artifacts as erc20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20'; import { artifacts as erc20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20';
import { import {
artifacts as exchangeArtifacts, artifacts as exchangeArtifacts,
@ -19,7 +20,7 @@ import {
import { assetDataUtils, CoordinatorRevertErrors, transactionHashUtils } from '@0x/order-utils'; import { assetDataUtils, CoordinatorRevertErrors, transactionHashUtils } from '@0x/order-utils';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import { ApprovalFactory, artifacts, CoordinatorContract, CoordinatorTestFactory } from '../src'; import { CoordinatorTestFactory } from './coordinator_test_factory';
// tslint:disable:no-unnecessary-type-assertion // tslint:disable:no-unnecessary-type-assertion
blockchainTests.resets('Coordinator tests', env => { blockchainTests.resets('Coordinator tests', env => {

View File

@ -1,4 +1,5 @@
import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { CoordinatorContract } from '@0x/contracts-coordinator';
import { import {
ExchangeCancelEventArgs, ExchangeCancelEventArgs,
ExchangeCancelUpToEventArgs, ExchangeCancelUpToEventArgs,
@ -6,31 +7,17 @@ import {
ExchangeFillEventArgs, ExchangeFillEventArgs,
ExchangeFunctionName, ExchangeFunctionName,
} from '@0x/contracts-exchange'; } from '@0x/contracts-exchange';
import { expect, filterLogsToArguments, Numberish, TokenBalances, web3Wrapper } from '@0x/contracts-test-utils'; import { expect, Numberish, TokenBalances, verifyEvents, web3Wrapper } from '@0x/contracts-test-utils';
import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
import { SignedOrder, SignedZeroExTransaction } from '@0x/types'; import { SignedOrder, SignedZeroExTransaction } from '@0x/types';
import { BigNumber, RevertError } from '@0x/utils'; import { BigNumber, RevertError } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types'; import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { CoordinatorContract } from '../../src';
export class CoordinatorTestFactory { export class CoordinatorTestFactory {
private readonly _addresses: string[]; private readonly _addresses: string[];
private readonly _protocolFee: BigNumber; private readonly _protocolFee: BigNumber;
public static verifyEvents<TEventArgs>(
txReceipt: TransactionReceiptWithDecodedLogs,
expectedEvents: TEventArgs[],
eventName: string,
): void {
const logs = filterLogsToArguments<TEventArgs>(txReceipt.logs, eventName);
expect(logs.length).to.eq(expectedEvents.length);
logs.forEach((log, index) => {
expect(log).to.deep.equal(expectedEvents[index]);
});
}
private static _expectedCancelEvent(order: SignedOrder): ExchangeCancelEventArgs { private static _expectedCancelEvent(order: SignedOrder): ExchangeCancelEventArgs {
return { return {
makerAddress: order.makerAddress, makerAddress: order.makerAddress,
@ -89,11 +76,7 @@ export class CoordinatorTestFactory {
} }
const transactionReceipt = await tx; const transactionReceipt = await tx;
CoordinatorTestFactory.verifyEvents( verifyEvents(transactionReceipt, orders.map(order => this._expectedFillEvent(order)), ExchangeEvents.Fill);
transactionReceipt,
orders.map(order => this._expectedFillEvent(order)),
ExchangeEvents.Fill,
);
const expectedBalances = this._getExpectedBalances(initBalances, orders, transactionReceipt, txData.value); const expectedBalances = this._getExpectedBalances(initBalances, orders, transactionReceipt, txData.value);
await this._verifyBalancesAsync(expectedBalances); await this._verifyBalancesAsync(expectedBalances);
@ -121,9 +104,9 @@ export class CoordinatorTestFactory {
orderSenderAddress: this._coordinatorContract.address, orderSenderAddress: this._coordinatorContract.address,
orderEpoch: new BigNumber(1), orderEpoch: new BigNumber(1),
}; };
CoordinatorTestFactory.verifyEvents(transactionReceipt, [expectedEvent], ExchangeEvents.CancelUpTo); verifyEvents(transactionReceipt, [expectedEvent], ExchangeEvents.CancelUpTo);
} else { } else {
CoordinatorTestFactory.verifyEvents( verifyEvents(
transactionReceipt, transactionReceipt,
orders.map(order => CoordinatorTestFactory._expectedCancelEvent(order)), orders.map(order => CoordinatorTestFactory._expectedCancelEvent(order)),
ExchangeEvents.Cancel, ExchangeEvents.Cancel,

View File

@ -2,7 +2,7 @@ import { Authorizable, Ownable } from '@0x/contracts-exchange';
import { constants as stakingConstants } from '@0x/contracts-staking'; import { constants as stakingConstants } from '@0x/contracts-staking';
import { blockchainTests, expect } from '@0x/contracts-test-utils'; import { blockchainTests, expect } from '@0x/contracts-test-utils';
import { DeploymentManager } from './utils/deployment_mananger'; import { DeploymentManager } from './deployment_mananger';
blockchainTests('Deployment Manager', env => { blockchainTests('Deployment Manager', env => {
let owner: string; let owner: string;

View File

@ -106,9 +106,9 @@ interface StakingContracts {
// Contract wrappers for tokens. // Contract wrappers for tokens.
interface TokenContracts { interface TokenContracts {
erc1155: ERC1155MintableContract[];
erc20: DummyERC20TokenContract[]; erc20: DummyERC20TokenContract[];
erc721: DummyERC721TokenContract[]; erc721: DummyERC721TokenContract[];
erc1155: ERC1155MintableContract[];
weth: WETH9Contract; weth: WETH9Contract;
zrx: ZRXTokenContract; zrx: ZRXTokenContract;
} }
@ -411,23 +411,22 @@ export class DeploymentManager {
txDefaults: Partial<TxData>, txDefaults: Partial<TxData>,
options: Partial<DeploymentOptions>, options: Partial<DeploymentOptions>,
): Promise<TokenContracts> { ): Promise<TokenContracts> {
const numErc1155TokensToDeploy = const numErc20TokensToDeploy = _.get(
options.numErc1155TokensToDeploy || constants.NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY; options,
const numErc20TokensToDeploy = options.numErc20TokensToDeploy || constants.NUM_DUMMY_ERC20_TO_DEPLOY; ['numErc20TokensToDeploy'],
const numErc721TokensToDeploy = options.numErc721TokensToDeploy || constants.NUM_DUMMY_ERC721_TO_DEPLOY; constants.NUM_DUMMY_ERC20_CONTRACTS_TO_DEPLOY,
const erc1155 = await Promise.all(
_.times(
numErc1155TokensToDeploy,
async () =>
await ERC1155MintableContract.deployFrom0xArtifactAsync(
ERC1155Artifacts.ERC1155Mintable,
environment.provider,
txDefaults,
ERC1155Artifacts,
),
),
); );
const numErc721TokensToDeploy = _.get(
options,
['numErc721TokensToDeploy'],
constants.NUM_DUMMY_ERC721_CONTRACTS_TO_DEPLOY,
);
const numErc1155TokensToDeploy = _.get(
options,
['numErc1155TokensToDeploy'],
constants.NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY,
);
const erc20 = await Promise.all( const erc20 = await Promise.all(
_.times( _.times(
numErc20TokensToDeploy, numErc20TokensToDeploy,
@ -458,6 +457,18 @@ export class DeploymentManager {
), ),
), ),
); );
const erc1155 = await Promise.all(
_.times(
numErc1155TokensToDeploy,
async () =>
await ERC1155MintableContract.deployFrom0xArtifactAsync(
ERC1155Artifacts.ERC1155Mintable,
environment.provider,
txDefaults,
ERC1155Artifacts,
),
),
);
const weth = await WETH9Contract.deployFrom0xArtifactAsync( const weth = await WETH9Contract.deployFrom0xArtifactAsync(
ERC20Artifacts.WETH9, ERC20Artifacts.WETH9,
@ -473,9 +484,9 @@ export class DeploymentManager {
); );
return { return {
erc1155,
erc20, erc20,
erc721, erc721,
erc1155,
weth, weth,
zrx, zrx,
}; };

View File

@ -15,7 +15,7 @@ export {
export { getLatestBlockTimestampAsync, increaseTimeAndMineBlockAsync } from './block_timestamp'; export { getLatestBlockTimestampAsync, increaseTimeAndMineBlockAsync } from './block_timestamp';
export { provider, txDefaults, web3Wrapper } from './web3_wrapper'; export { provider, txDefaults, web3Wrapper } from './web3_wrapper';
export { LogDecoder } from './log_decoder'; export { LogDecoder } from './log_decoder';
export { filterLogs, filterLogsToArguments } from './log_utils'; export { filterLogs, filterLogsToArguments, verifyEvents } from './log_utils';
export { signingUtils } from './signing_utils'; export { signingUtils } from './signing_utils';
export { orderUtils } from './order_utils'; export { orderUtils } from './order_utils';
export { typeEncodingUtils } from './type_encoding_utils'; export { typeEncodingUtils } from './type_encoding_utils';

View File

@ -1,4 +1,6 @@
import { LogEntry, LogWithDecodedArgs } from 'ethereum-types'; import { LogEntry, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { expect } from './chai_setup';
// tslint:disable no-unnecessary-type-assertion // tslint:disable no-unnecessary-type-assertion
@ -15,3 +17,18 @@ export function filterLogs<TEventArgs>(logs: LogEntry[], event: string): Array<L
export function filterLogsToArguments<TEventArgs>(logs: LogEntry[], event: string): TEventArgs[] { export function filterLogsToArguments<TEventArgs>(logs: LogEntry[], event: string): TEventArgs[] {
return filterLogs<TEventArgs>(logs, event).map(log => log.args); return filterLogs<TEventArgs>(logs, event).map(log => log.args);
} }
/**
* Verifies that a transaction emitted the expected events of a particular type.
*/
export function verifyEvents<TEventArgs>(
txReceipt: TransactionReceiptWithDecodedLogs,
expectedEvents: TEventArgs[],
eventName: string,
): void {
const logs = filterLogsToArguments<TEventArgs>(txReceipt.logs, eventName);
expect(logs.length).to.eq(expectedEvents.length);
logs.forEach((log, index) => {
expect(log).to.deep.equal(expectedEvents[index]);
});
}