From 93b02e93b9183bcb369764234fbc4a3263e5c960 Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Thu, 17 Oct 2019 13:05:02 -0700 Subject: [PATCH] juggling some files around --- .../coordinator/test/coordinator_registry.ts | 5 +- contracts/coordinator/test/utils/index.ts | 1 - .../test/coordinator}/coordinator.ts | 3 +- .../coordinator}/coordinator_test_factory.ts | 27 ++--------- .../deployment_manager_test.ts | 2 +- .../deployment_mananger.ts | 47 ++++++++++++------- .../test/{ => deployment}/deployment_test.ts | 0 contracts/test-utils/src/index.ts | 2 +- contracts/test-utils/src/log_utils.ts | 19 +++++++- 9 files changed, 58 insertions(+), 48 deletions(-) rename contracts/{coordinator/test => integrations/test/coordinator}/coordinator.ts (99%) rename contracts/{coordinator/test/utils => integrations/test/coordinator}/coordinator_test_factory.ts (91%) rename contracts/integrations/test/{ => deployment}/deployment_manager_test.ts (99%) rename contracts/integrations/test/{utils => deployment}/deployment_mananger.ts (97%) rename contracts/integrations/test/{ => deployment}/deployment_test.ts (100%) diff --git a/contracts/coordinator/test/coordinator_registry.ts b/contracts/coordinator/test/coordinator_registry.ts index ef20a0eaf8..f8b1da9d3c 100644 --- a/contracts/coordinator/test/coordinator_registry.ts +++ b/contracts/coordinator/test/coordinator_registry.ts @@ -1,10 +1,9 @@ -import { blockchainTests, expect } from '@0x/contracts-test-utils'; +import { blockchainTests, expect, verifyEvents } from '@0x/contracts-test-utils'; import { artifacts, CoordinatorRegistryContract, CoordinatorRegistryCoordinatorEndpointSetEventArgs, - CoordinatorTestFactory, } from '../src'; // tslint:disable:no-unnecessary-type-assertion @@ -71,7 +70,7 @@ blockchainTests.resets('Coordinator Registry tests', env => { coordinatorOperator, coordinatorEndpoint, }; - CoordinatorTestFactory.verifyEvents(txReceipt, [expectedEvent], 'CoordinatorEndpointSet'); + verifyEvents(txReceipt, [expectedEvent], 'CoordinatorEndpointSet'); }); }); }); diff --git a/contracts/coordinator/test/utils/index.ts b/contracts/coordinator/test/utils/index.ts index a724673f47..bd5bd79dae 100644 --- a/contracts/coordinator/test/utils/index.ts +++ b/contracts/coordinator/test/utils/index.ts @@ -1,4 +1,3 @@ export { hashUtils } from './hash_utils'; export { ApprovalFactory } from './approval_factory'; -export { CoordinatorTestFactory } from './coordinator_test_factory'; export * from './types'; diff --git a/contracts/coordinator/test/coordinator.ts b/contracts/integrations/test/coordinator/coordinator.ts similarity index 99% rename from contracts/coordinator/test/coordinator.ts rename to contracts/integrations/test/coordinator/coordinator.ts index 02db8841e3..c4671a7994 100644 --- a/contracts/coordinator/test/coordinator.ts +++ b/contracts/integrations/test/coordinator/coordinator.ts @@ -1,4 +1,5 @@ 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 exchangeArtifacts, @@ -19,7 +20,7 @@ import { import { assetDataUtils, CoordinatorRevertErrors, transactionHashUtils } from '@0x/order-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 blockchainTests.resets('Coordinator tests', env => { diff --git a/contracts/coordinator/test/utils/coordinator_test_factory.ts b/contracts/integrations/test/coordinator/coordinator_test_factory.ts similarity index 91% rename from contracts/coordinator/test/utils/coordinator_test_factory.ts rename to contracts/integrations/test/coordinator/coordinator_test_factory.ts index caca5877da..bd3ba81f2d 100644 --- a/contracts/coordinator/test/utils/coordinator_test_factory.ts +++ b/contracts/integrations/test/coordinator/coordinator_test_factory.ts @@ -1,4 +1,5 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; +import { CoordinatorContract } from '@0x/contracts-coordinator'; import { ExchangeCancelEventArgs, ExchangeCancelUpToEventArgs, @@ -6,31 +7,17 @@ import { ExchangeFillEventArgs, ExchangeFunctionName, } 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 { SignedOrder, SignedZeroExTransaction } from '@0x/types'; import { BigNumber, RevertError } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types'; import * as _ from 'lodash'; -import { CoordinatorContract } from '../../src'; - export class CoordinatorTestFactory { private readonly _addresses: string[]; private readonly _protocolFee: BigNumber; - public static verifyEvents( - txReceipt: TransactionReceiptWithDecodedLogs, - expectedEvents: TEventArgs[], - eventName: string, - ): void { - const logs = filterLogsToArguments(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 { return { makerAddress: order.makerAddress, @@ -89,11 +76,7 @@ export class CoordinatorTestFactory { } const transactionReceipt = await tx; - CoordinatorTestFactory.verifyEvents( - transactionReceipt, - orders.map(order => this._expectedFillEvent(order)), - ExchangeEvents.Fill, - ); + verifyEvents(transactionReceipt, orders.map(order => this._expectedFillEvent(order)), ExchangeEvents.Fill); const expectedBalances = this._getExpectedBalances(initBalances, orders, transactionReceipt, txData.value); await this._verifyBalancesAsync(expectedBalances); @@ -121,9 +104,9 @@ export class CoordinatorTestFactory { orderSenderAddress: this._coordinatorContract.address, orderEpoch: new BigNumber(1), }; - CoordinatorTestFactory.verifyEvents(transactionReceipt, [expectedEvent], ExchangeEvents.CancelUpTo); + verifyEvents(transactionReceipt, [expectedEvent], ExchangeEvents.CancelUpTo); } else { - CoordinatorTestFactory.verifyEvents( + verifyEvents( transactionReceipt, orders.map(order => CoordinatorTestFactory._expectedCancelEvent(order)), ExchangeEvents.Cancel, diff --git a/contracts/integrations/test/deployment_manager_test.ts b/contracts/integrations/test/deployment/deployment_manager_test.ts similarity index 99% rename from contracts/integrations/test/deployment_manager_test.ts rename to contracts/integrations/test/deployment/deployment_manager_test.ts index 04a2272384..359f165922 100644 --- a/contracts/integrations/test/deployment_manager_test.ts +++ b/contracts/integrations/test/deployment/deployment_manager_test.ts @@ -2,7 +2,7 @@ import { Authorizable, Ownable } from '@0x/contracts-exchange'; import { constants as stakingConstants } from '@0x/contracts-staking'; import { blockchainTests, expect } from '@0x/contracts-test-utils'; -import { DeploymentManager } from './utils/deployment_mananger'; +import { DeploymentManager } from './deployment_mananger'; blockchainTests('Deployment Manager', env => { let owner: string; diff --git a/contracts/integrations/test/utils/deployment_mananger.ts b/contracts/integrations/test/deployment/deployment_mananger.ts similarity index 97% rename from contracts/integrations/test/utils/deployment_mananger.ts rename to contracts/integrations/test/deployment/deployment_mananger.ts index d222880ede..03b4cbb324 100644 --- a/contracts/integrations/test/utils/deployment_mananger.ts +++ b/contracts/integrations/test/deployment/deployment_mananger.ts @@ -106,9 +106,9 @@ interface StakingContracts { // Contract wrappers for tokens. interface TokenContracts { - erc1155: ERC1155MintableContract[]; erc20: DummyERC20TokenContract[]; erc721: DummyERC721TokenContract[]; + erc1155: ERC1155MintableContract[]; weth: WETH9Contract; zrx: ZRXTokenContract; } @@ -411,23 +411,22 @@ export class DeploymentManager { txDefaults: Partial, options: Partial, ): Promise { - const numErc1155TokensToDeploy = - options.numErc1155TokensToDeploy || constants.NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY; - const numErc20TokensToDeploy = options.numErc20TokensToDeploy || constants.NUM_DUMMY_ERC20_TO_DEPLOY; - const numErc721TokensToDeploy = options.numErc721TokensToDeploy || constants.NUM_DUMMY_ERC721_TO_DEPLOY; - - const erc1155 = await Promise.all( - _.times( - numErc1155TokensToDeploy, - async () => - await ERC1155MintableContract.deployFrom0xArtifactAsync( - ERC1155Artifacts.ERC1155Mintable, - environment.provider, - txDefaults, - ERC1155Artifacts, - ), - ), + const numErc20TokensToDeploy = _.get( + options, + ['numErc20TokensToDeploy'], + constants.NUM_DUMMY_ERC20_CONTRACTS_TO_DEPLOY, ); + 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( _.times( 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( ERC20Artifacts.WETH9, @@ -473,9 +484,9 @@ export class DeploymentManager { ); return { - erc1155, erc20, erc721, + erc1155, weth, zrx, }; diff --git a/contracts/integrations/test/deployment_test.ts b/contracts/integrations/test/deployment/deployment_test.ts similarity index 100% rename from contracts/integrations/test/deployment_test.ts rename to contracts/integrations/test/deployment/deployment_test.ts diff --git a/contracts/test-utils/src/index.ts b/contracts/test-utils/src/index.ts index 1753c590c4..48121d3870 100644 --- a/contracts/test-utils/src/index.ts +++ b/contracts/test-utils/src/index.ts @@ -15,7 +15,7 @@ export { export { getLatestBlockTimestampAsync, increaseTimeAndMineBlockAsync } from './block_timestamp'; export { provider, txDefaults, web3Wrapper } from './web3_wrapper'; export { LogDecoder } from './log_decoder'; -export { filterLogs, filterLogsToArguments } from './log_utils'; +export { filterLogs, filterLogsToArguments, verifyEvents } from './log_utils'; export { signingUtils } from './signing_utils'; export { orderUtils } from './order_utils'; export { typeEncodingUtils } from './type_encoding_utils'; diff --git a/contracts/test-utils/src/log_utils.ts b/contracts/test-utils/src/log_utils.ts index ae95ace2f8..8c09add427 100644 --- a/contracts/test-utils/src/log_utils.ts +++ b/contracts/test-utils/src/log_utils.ts @@ -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 @@ -15,3 +17,18 @@ export function filterLogs(logs: LogEntry[], event: string): Array(logs: LogEntry[], event: string): TEventArgs[] { return filterLogs(logs, event).map(log => log.args); } + +/** + * Verifies that a transaction emitted the expected events of a particular type. + */ +export function verifyEvents( + txReceipt: TransactionReceiptWithDecodedLogs, + expectedEvents: TEventArgs[], + eventName: string, +): void { + const logs = filterLogsToArguments(txReceipt.logs, eventName); + expect(logs.length).to.eq(expectedEvents.length); + logs.forEach((log, index) => { + expect(log).to.deep.equal(expectedEvents[index]); + }); +}