juggling some files around
This commit is contained in:
parent
f4cb8cfb7e
commit
93b02e93b9
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,3 @@
|
||||
export { hashUtils } from './hash_utils';
|
||||
export { ApprovalFactory } from './approval_factory';
|
||||
export { CoordinatorTestFactory } from './coordinator_test_factory';
|
||||
export * from './types';
|
||||
|
@ -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 => {
|
@ -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<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 {
|
||||
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,
|
@ -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;
|
@ -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<TxData>,
|
||||
options: Partial<DeploymentOptions>,
|
||||
): Promise<TokenContracts> {
|
||||
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,
|
||||
};
|
@ -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';
|
||||
|
@ -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<TEventArgs>(logs: LogEntry[], event: string): Array<L
|
||||
export function filterLogsToArguments<TEventArgs>(logs: LogEntry[], event: string): TEventArgs[] {
|
||||
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]);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user