Merge pull request #2307 from 0xProject/fix/integration-tests/tslint

`@0x/contracts-integrations`: Enable tslint and fix lint errors
This commit is contained in:
mzhu25
2019-10-31 16:23:35 -07:00
committed by GitHub
19 changed files with 203 additions and 126 deletions

View File

@@ -21,7 +21,7 @@ export class Actor {
public readonly name: string;
public readonly privateKey: Buffer;
public readonly deployment: DeploymentManager;
protected readonly transactionFactory: TransactionFactory;
protected readonly _transactionFactory: TransactionFactory;
constructor(config: ActorConfig) {
Actor.count++;
@@ -29,7 +29,7 @@ export class Actor {
this.name = config.name || this.address;
this.deployment = config.deployment;
this.privateKey = constants.TESTRPC_PRIVATE_KEYS[config.deployment.accounts.indexOf(this.address)];
this.transactionFactory = new TransactionFactory(
this._transactionFactory = new TransactionFactory(
this.privateKey,
config.deployment.exchange.address,
config.deployment.chainId,
@@ -99,6 +99,6 @@ export class Actor {
customTransactionParams: Partial<ZeroExTransaction>,
signatureType: SignatureType = SignatureType.EthSign,
): Promise<SignedZeroExTransaction> {
return this.transactionFactory.newSignedTransactionAsync(customTransactionParams, signatureType);
return this._transactionFactory.newSignedTransactionAsync(customTransactionParams, signatureType);
}
}

View File

@@ -4,11 +4,24 @@ import { SignatureType, SignedZeroExTransaction } from '@0x/types';
import { Actor, ActorConfig, Constructor } from './base';
export interface FeeRecipientConfig extends ActorConfig {
interface FeeRecipientConfig extends ActorConfig {
verifyingContract?: BaseContract;
}
export function FeeRecipientMixin<TBase extends Constructor>(Base: TBase) {
export interface FeeRecipientInterface {
approvalFactory?: ApprovalFactory;
signCoordinatorApproval: (
transaction: SignedZeroExTransaction,
txOrigin: string,
signatureType?: SignatureType,
) => SignedCoordinatorApproval;
}
/**
* This mixin encapsulates functionaltiy associated with fee recipients within the 0x ecosystem.
* As of writing, the only extra functionality provided is signing Coordinator approvals.
*/
export function FeeRecipientMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<FeeRecipientInterface> {
return class extends Base {
public readonly actor: Actor;
public readonly approvalFactory?: ApprovalFactory;
@@ -19,6 +32,7 @@ export function FeeRecipientMixin<TBase extends Constructor>(Base: TBase) {
* base class).
*/
constructor(...args: any[]) {
// tslint:disable-next-line:no-inferred-empty-object-type
super(...args);
this.actor = (this as any) as Actor;

View File

@@ -1,8 +1,8 @@
import { Actor } from './base';
import { KeeperMixin } from './keeper';
import { MakerMixin } from './maker';
import { PoolOperatorMixin } from './pool_operator';
import { StakerMixin } from './staker';
import { KeeperMixin } from './keeper';
export class OperatorMaker extends PoolOperatorMixin(MakerMixin(Actor)) {}
export class StakerMaker extends StakerMixin(MakerMixin(Actor)) {}

View File

@@ -5,7 +5,16 @@ import { BlockParamLiteral, TransactionReceiptWithDecodedLogs } from 'ethereum-t
import { Actor, Constructor } from './base';
export function KeeperMixin<TBase extends Constructor>(Base: TBase) {
export interface KeeperInterface {
endEpochAsync: (shouldFastForward?: boolean) => Promise<TransactionReceiptWithDecodedLogs>;
finalizePoolsAsync: (poolIds?: string[]) => Promise<TransactionReceiptWithDecodedLogs[]>;
}
/**
* This mixin encapsulates functionaltiy associated with keepers within the 0x ecosystem.
* This includes ending epochs sand finalizing pools in the staking system.
*/
export function KeeperMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<KeeperInterface> {
return class extends Base {
public readonly actor: Actor;
@@ -15,6 +24,7 @@ export function KeeperMixin<TBase extends Constructor>(Base: TBase) {
* class).
*/
constructor(...args: any[]) {
// tslint:disable-next-line:no-inferred-empty-object-type
super(...args);
this.actor = (this as any) as Actor;
}
@@ -58,11 +68,10 @@ export function KeeperMixin<TBase extends Constructor>(Base: TBase) {
}
return Promise.all(
poolIds.map(
async poolId =>
await stakingWrapper.finalizePool.awaitTransactionSuccessAsync(poolId, {
from: this.actor.address,
}),
poolIds.map(async poolId =>
stakingWrapper.finalizePool.awaitTransactionSuccessAsync(poolId, {
from: this.actor.address,
}),
),
);
}

View File

@@ -4,11 +4,23 @@ import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { Actor, ActorConfig, Constructor } from './base';
export interface MakerConfig extends ActorConfig {
interface MakerConfig extends ActorConfig {
orderConfig: Partial<Order>;
}
export function MakerMixin<TBase extends Constructor>(Base: TBase) {
export interface MakerInterface {
makerPoolId?: string;
orderFactory: OrderFactory;
signOrderAsync: (customOrderParams?: Partial<Order>) => Promise<SignedOrder>;
cancelOrderAsync: (order: SignedOrder) => Promise<TransactionReceiptWithDecodedLogs>;
joinStakingPoolAsync: (poolId: string) => Promise<TransactionReceiptWithDecodedLogs>;
}
/**
* This mixin encapsulates functionaltiy associated with makers within the 0x ecosystem.
* This includes signing and canceling orders, as well as joining a staking pool as a maker.
*/
export function MakerMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<MakerInterface> {
return class extends Base {
public makerPoolId?: string;
public readonly actor: Actor;
@@ -20,6 +32,7 @@ export function MakerMixin<TBase extends Constructor>(Base: TBase) {
* class).
*/
constructor(...args: any[]) {
// tslint:disable-next-line:no-inferred-empty-object-type
super(...args);
this.actor = (this as any) as Actor;

View File

@@ -2,11 +2,24 @@ import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { Actor, Constructor } from './base';
export interface OperatorShareByPoolId {
interface OperatorShareByPoolId {
[poolId: string]: number;
}
export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase) {
export interface PoolOperatorInterface {
operatorShares: OperatorShareByPoolId;
createStakingPoolAsync: (operatorShare: number, addOperatorAsMaker?: boolean) => Promise<string>;
decreaseOperatorShareAsync: (
poolId: string,
newOperatorShare: number,
) => Promise<TransactionReceiptWithDecodedLogs>;
}
/**
* This mixin encapsulates functionaltiy associated with pool operators within the 0x ecosystem.
* This includes creating staking pools and decreasing the operator share of a pool.
*/
export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<PoolOperatorInterface> {
return class extends Base {
public readonly operatorShares: OperatorShareByPoolId = {};
public readonly actor: Actor;
@@ -17,6 +30,7 @@ export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase) {
* base class).
*/
constructor(...args: any[]) {
// tslint:disable-next-line:no-inferred-empty-object-type
super(...args);
this.actor = (this as any) as Actor;
}

View File

@@ -3,7 +3,15 @@ import { BigNumber } from '@0x/utils';
import { Actor, Constructor } from './base';
export function StakerMixin<TBase extends Constructor>(Base: TBase) {
export interface StakerInterface {
stakeAsync: (amount: BigNumber, poolId?: string) => Promise<void>;
}
/**
* This mixin encapsulates functionaltiy associated with stakers within the 0x ecosystem.
* This includes staking ZRX (and optionally delegating it to a specific pool).
*/
export function StakerMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<StakerInterface> {
return class extends Base {
public readonly actor: Actor;
@@ -13,6 +21,7 @@ export function StakerMixin<TBase extends Constructor>(Base: TBase) {
* class).
*/
constructor(...args: any[]) {
// tslint:disable-next-line:no-inferred-empty-object-type
super(...args);
this.actor = (this as any) as Actor;
}

View File

@@ -2,10 +2,23 @@ import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
import { Actor, Constructor } from './base';
import { DeploymentManager } from '../utils/deployment_manager';
export function TakerMixin<TBase extends Constructor>(Base: TBase) {
import { Actor, Constructor } from './base';
export interface TakerInterface {
fillOrderAsync: (
order: SignedOrder,
fillAmount: BigNumber,
txData?: Partial<TxData>,
) => Promise<TransactionReceiptWithDecodedLogs>;
}
/**
* This mixin encapsulates functionaltiy associated with takers within the 0x ecosystem.
* As of writing, the only extra functionality provided is a utility wrapper around `fillOrder`,
*/
export function TakerMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<TakerInterface> {
return class extends Base {
public readonly actor: Actor;
@@ -15,6 +28,7 @@ export function TakerMixin<TBase extends Constructor>(Base: TBase) {
* class).
*/
constructor(...args: any[]) {
// tslint:disable-next-line:no-inferred-empty-object-type
super(...args);
this.actor = (this as any) as Actor;
}

View File

@@ -0,0 +1,6 @@
{
"extends": ["@0x/tslint-config"],
"rules": {
"max-classes-per-file": false
}
}

View File

@@ -3,6 +3,10 @@ import * as _ from 'lodash';
import { Actor } from './base';
/**
* Utility function to convert Actors into an object mapping readable names to addresses.
* Useful for BalanceStore.
*/
export function actorAddressesByName(actors: Actor[]): TokenOwnersByName {
return _.zipObject(actors.map(actor => actor.name), actors.map(actor => actor.address));
}

View File

@@ -1,7 +1,6 @@
import { CoordinatorContract, SignedCoordinatorApproval } from '@0x/contracts-coordinator';
import {
BlockchainBalanceStore,
LocalBalanceStore,
constants as exchangeConstants,
ExchangeCancelEventArgs,
ExchangeCancelUpToEventArgs,
@@ -9,17 +8,19 @@ import {
ExchangeEvents,
ExchangeFillEventArgs,
ExchangeFunctionName,
LocalBalanceStore,
} from '@0x/contracts-exchange';
import { blockchainTests, expect, hexConcat, hexSlice, verifyEvents } from '@0x/contracts-test-utils';
import { blockchainTests, constants, expect, hexConcat, hexSlice, verifyEvents } from '@0x/contracts-test-utils';
import { assetDataUtils, CoordinatorRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils';
import { SignedOrder, SignedZeroExTransaction } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { Actor, actorAddressesByName, FeeRecipient, Maker } from '../actors';
import { deployCoordinatorAsync } from './deploy_coordinator';
import { DeploymentManager } from '../utils/deployment_manager';
import { deployCoordinatorAsync } from './deploy_coordinator';
// tslint:disable:no-unnecessary-type-assertion
blockchainTests.resets('Coordinator integration tests', env => {
let deployment: DeploymentManager;
@@ -59,11 +60,11 @@ blockchainTests.resets('Coordinator integration tests', env => {
},
});
taker.configureERC20TokenAsync(takerToken);
taker.configureERC20TokenAsync(takerFeeToken);
taker.configureERC20TokenAsync(deployment.tokens.weth, deployment.staking.stakingProxy.address);
maker.configureERC20TokenAsync(makerToken);
maker.configureERC20TokenAsync(makerFeeToken);
await taker.configureERC20TokenAsync(takerToken);
await taker.configureERC20TokenAsync(takerFeeToken);
await taker.configureERC20TokenAsync(deployment.tokens.weth, deployment.staking.stakingProxy.address);
await maker.configureERC20TokenAsync(makerToken);
await maker.configureERC20TokenAsync(makerFeeToken);
balanceStore = new BlockchainBalanceStore(
{
@@ -79,8 +80,9 @@ blockchainTests.resets('Coordinator integration tests', env => {
function simulateFills(
orders: SignedOrder[],
txReceipt: TransactionReceiptWithDecodedLogs,
msgValue: BigNumber = new BigNumber(0),
msgValue?: BigNumber,
): LocalBalanceStore {
let remainingValue = msgValue || constants.ZERO_AMOUNT;
const localBalanceStore = LocalBalanceStore.create(balanceStore);
// Transaction gas cost
localBalanceStore.burnGas(txReceipt.from, DeploymentManager.gasPrice.times(txReceipt.gasUsed));
@@ -106,13 +108,13 @@ blockchainTests.resets('Coordinator integration tests', env => {
);
// Protocol fee
if (msgValue.isGreaterThanOrEqualTo(DeploymentManager.protocolFee)) {
if (remainingValue.isGreaterThanOrEqualTo(DeploymentManager.protocolFee)) {
localBalanceStore.sendEth(
txReceipt.from,
deployment.staking.stakingProxy.address,
DeploymentManager.protocolFee,
);
msgValue = msgValue.minus(DeploymentManager.protocolFee);
remainingValue = remainingValue.minus(DeploymentManager.protocolFee);
} else {
localBalanceStore.transferAsset(
taker.address,

View File

@@ -5,11 +5,14 @@ import { BigNumber } from '@0x/utils';
import { DeploymentManager } from '../utils/deployment_manager';
/**
* Deploys a Coordinator contract configured to work alongside the provided `deployment`.
*/
export async function deployCoordinatorAsync(
deployment: DeploymentManager,
environment: BlockchainTestsEnvironment,
): Promise<CoordinatorContract> {
return await CoordinatorContract.deployFrom0xArtifactAsync(
return CoordinatorContract.deployFrom0xArtifactAsync(
artifacts.Coordinator,
environment.provider,
deployment.txDefaults,

View File

@@ -5,11 +5,14 @@ import { assetDataUtils } from '@0x/order-utils';
import { DeploymentManager } from '../utils/deployment_manager';
/**
* Deploys a Forwarder contract configured to work alongside the provided `deployment`.
*/
export async function deployForwarderAsync(
deployment: DeploymentManager,
environment: BlockchainTestsEnvironment,
): Promise<ForwarderContract> {
return await ForwarderContract.deployFrom0xArtifactAsync(
return ForwarderContract.deployFrom0xArtifactAsync(
artifacts.Forwarder,
environment.provider,
deployment.txDefaults,

View File

@@ -19,9 +19,10 @@ import { assetDataUtils, ForwarderRevertErrors } from '@0x/order-utils';
import { BigNumber } from '@0x/utils';
import { Actor, actorAddressesByName, FeeRecipient, Maker } from '../actors';
import { DeploymentManager } from '../utils/deployment_manager';
import { deployForwarderAsync } from './deploy_forwarder';
import { ForwarderTestFactory } from './forwarder_test_factory';
import { DeploymentManager } from '../utils/deployment_manager';
blockchainTests('Forwarder integration tests', env => {
let deployment: DeploymentManager;
@@ -71,7 +72,7 @@ blockchainTests('Forwarder integration tests', env => {
feeRecipientAddress: orderFeeRecipient.address,
makerAssetAmount: toBaseUnitAmount(2),
takerAssetAmount: toBaseUnitAmount(1),
makerAssetData: makerAssetData,
makerAssetData,
takerAssetData: wethAssetData,
takerFee: constants.ZERO_AMOUNT,
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(makerFeeToken.address),
@@ -79,9 +80,9 @@ blockchainTests('Forwarder integration tests', env => {
},
});
maker.configureERC20TokenAsync(makerToken);
maker.configureERC20TokenAsync(makerFeeToken);
maker.configureERC20TokenAsync(anotherErc20Token);
await maker.configureERC20TokenAsync(makerToken);
await maker.configureERC20TokenAsync(makerFeeToken);
await maker.configureERC20TokenAsync(anotherErc20Token);
await forwarder.approveMakerAssetProxy.awaitTransactionSuccessAsync(makerAssetData);
[nftId] = await maker.configureERC721TokenAsync(erc721Token);
@@ -111,7 +112,6 @@ blockchainTests('Forwarder integration tests', env => {
blockchainTests.resets('constructor', () => {
it('should revert if assetProxy is unregistered', async () => {
const chainId = await env.getChainIdAsync();
const wethAssetData = assetDataUtils.encodeERC20AssetData(deployment.tokens.weth.address);
const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
exchangeArtifacts.Exchange,
env.provider,

View File

@@ -1,11 +1,4 @@
import {
blockchainTests,
constants,
expect,
filterLogsToArguments,
getRandomInteger,
hexRandom,
} from '@0x/contracts-test-utils';
import { blockchainTests, constants, expect, filterLogsToArguments, getRandomInteger } from '@0x/contracts-test-utils';
import { BigNumber, StringRevertError } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
@@ -30,10 +23,9 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should call the before function with the provided arguments', async () => {
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion(exampleContract.returnInteger, {
before: async (input: BigNumber) => {
before: async (_input: BigNumber) => {
sideEffectTarget = randomInput;
},
after: async (beforeInfo: any, result: Result, input: BigNumber) => {},
});
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
await assertion.executeAsync(randomInput);
@@ -43,8 +35,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should call the after function with the provided arguments', async () => {
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion(exampleContract.returnInteger, {
before: async (input: BigNumber) => {},
after: async (beforeInfo: any, result: Result, input: BigNumber) => {
after: async (_beforeInfo: any, _result: Result, input: BigNumber) => {
sideEffectTarget = input;
},
});
@@ -54,10 +45,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
});
it('should not fail immediately if the wrapped function fails', async () => {
const assertion = new FunctionAssertion(exampleContract.emptyRevert, {
before: async () => {},
after: async (beforeInfo: any, result: Result) => {},
});
const assertion = new FunctionAssertion<{}>(exampleContract.emptyRevert);
await assertion.executeAsync();
});
@@ -65,10 +53,10 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion(exampleContract.returnInteger, {
before: async (input: BigNumber) => {
before: async (_input: BigNumber) => {
return randomInput;
},
after: async (beforeInfo: any, result: Result, input: BigNumber) => {
after: async (beforeInfo: any, _result: Result, _input: BigNumber) => {
sideEffectTarget = beforeInfo;
},
});
@@ -79,8 +67,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should pass the result from the function call to "after"', async () => {
let sideEffectTarget = ZERO_AMOUNT;
const assertion = new FunctionAssertion(exampleContract.returnInteger, {
before: async (input: BigNumber) => {},
after: async (beforeInfo: any, result: Result, input: BigNumber) => {
after: async (_beforeInfo: any, result: Result, _input: BigNumber) => {
sideEffectTarget = result.data;
},
});
@@ -90,12 +77,9 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
});
it('should pass the receipt from the function call to "after"', async () => {
let sideEffectTarget = {} as TransactionReceiptWithDecodedLogs;
let sideEffectTarget: TransactionReceiptWithDecodedLogs;
const assertion = new FunctionAssertion(exampleContract.emitEvent, {
before: async (input: string) => {
return {};
},
after: async (beforeInfo: {}, result: Result, input: string) => {
after: async (_beforeInfo: any, result: Result, _input: string) => {
if (result.receipt) {
sideEffectTarget = result.receipt;
}
@@ -107,7 +91,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
// Ensure that the correct events were emitted.
const [event] = filterLogsToArguments<TestFrameworkEventEventArgs>(
sideEffectTarget.logs,
sideEffectTarget!.logs, // tslint:disable-line:no-non-null-assertion
TestFrameworkEvents.Event,
);
expect(event).to.be.deep.eq({ input });
@@ -116,10 +100,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
it('should pass the error to "after" if the function call fails', async () => {
let sideEffectTarget: Error;
const assertion = new FunctionAssertion(exampleContract.stringRevert, {
before: async string => {
return {};
},
after: async (any, result: Result, string) => {
after: async (_beforeInfo: any, result: Result, _input: string) => {
sideEffectTarget = result.data;
},
});
@@ -127,11 +108,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
await assertion.executeAsync(message);
const expectedError = new StringRevertError(message);
return expect(
new Promise((resolve, reject) => {
reject(sideEffectTarget);
}),
).to.revertWith(expectedError);
return expect(Promise.reject(sideEffectTarget!)).to.revertWith(expectedError); // tslint:disable-line
});
});
});

View File

@@ -1,4 +1,3 @@
import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
import { IERC20TokenEvents, IERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
import {
BlockchainBalanceStore,
@@ -14,13 +13,13 @@ import {
IStakingEventsRewardsPaidEventArgs,
IStakingEventsStakingPoolEarnedRewardsInEpochEventArgs,
} from '@0x/contracts-staking';
import { SignedOrder } from '@0x/types';
import { blockchainTests, constants, expect, toBaseUnitAmount, verifyEvents } from '@0x/contracts-test-utils';
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
import { toBaseUnitAmount, verifyEvents } from '@0x/contracts-test-utils';
import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { Taker, actorAddressesByName, FeeRecipient, Maker, OperatorStakerMaker, StakerKeeper } from '../actors';
import { actorAddressesByName, FeeRecipient, Maker, OperatorStakerMaker, StakerKeeper, Taker } from '../actors';
import { DeploymentManager } from '../utils/deployment_manager';
blockchainTests.resets('fillOrder integration tests', env => {
@@ -78,7 +77,7 @@ blockchainTests.resets('fillOrder integration tests', env => {
await delegator.configureERC20TokenAsync(deployment.tokens.zrx);
// Create a staking pool with the operator as a maker.
poolId = await operator.createStakingPoolAsync(0.95 * stakingConstants.PPM, true);
poolId = await operator.createStakingPoolAsync(stakingConstants.PPM * 0.95, true);
// A vanilla maker joins the pool as well.
await maker.joinStakingPoolAsync(poolId);
@@ -97,8 +96,9 @@ blockchainTests.resets('fillOrder integration tests', env => {
function simulateFill(
order: SignedOrder,
txReceipt: TransactionReceiptWithDecodedLogs,
msgValue: BigNumber = DeploymentManager.protocolFee,
msgValue?: BigNumber,
): LocalBalanceStore {
let remainingValue = msgValue !== undefined ? msgValue : DeploymentManager.protocolFee;
const localBalanceStore = LocalBalanceStore.create(balanceStore);
// Transaction gas cost
localBalanceStore.burnGas(txReceipt.from, DeploymentManager.gasPrice.times(txReceipt.gasUsed));
@@ -109,13 +109,13 @@ blockchainTests.resets('fillOrder integration tests', env => {
localBalanceStore.transferAsset(maker.address, taker.address, order.makerAssetAmount, order.makerAssetData);
// Protocol fee
if (msgValue.isGreaterThanOrEqualTo(DeploymentManager.protocolFee)) {
if (remainingValue.isGreaterThanOrEqualTo(DeploymentManager.protocolFee)) {
localBalanceStore.sendEth(
txReceipt.from,
deployment.staking.stakingProxy.address,
DeploymentManager.protocolFee,
);
msgValue = msgValue.minus(DeploymentManager.protocolFee);
remainingValue = remainingValue.minus(DeploymentManager.protocolFee);
} else {
localBalanceStore.transferAsset(
taker.address,

View File

@@ -7,7 +7,7 @@ import {
StaticCallProxyContract,
} from '@0x/contracts-asset-proxy';
import { artifacts as ERC1155Artifacts, ERC1155MintableContract } from '@0x/contracts-erc1155';
import { DummyERC20TokenContract, artifacts as ERC20Artifacts, WETH9Contract } from '@0x/contracts-erc20';
import { artifacts as ERC20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20';
import { artifacts as ERC721Artifacts, DummyERC721TokenContract } from '@0x/contracts-erc721';
import {
artifacts as exchangeArtifacts,
@@ -256,8 +256,8 @@ export class DeploymentManager {
/**
* Configures an exchange contract with staking contracts
* @param exchange
* @param staking
* @param exchange The Exchange contract.
* @param staking The Staking contracts.
* @param owner An owner address to use when configuring the asset proxies.
*/
protected static async _configureExchangeWithStakingAsync(
@@ -413,45 +413,39 @@ export class DeploymentManager {
: constants.NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY;
const erc20 = await Promise.all(
_.times(
numErc20TokensToDeploy,
async () =>
await DummyERC20TokenContract.deployFrom0xArtifactAsync(
ERC20Artifacts.DummyERC20Token,
environment.provider,
txDefaults,
ERC20Artifacts,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
constants.DUMMY_TOKEN_DECIMALS,
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
),
_.times(numErc20TokensToDeploy, async () =>
DummyERC20TokenContract.deployFrom0xArtifactAsync(
ERC20Artifacts.DummyERC20Token,
environment.provider,
txDefaults,
ERC20Artifacts,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
constants.DUMMY_TOKEN_DECIMALS,
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
),
),
);
const erc721 = await Promise.all(
_.times(
numErc721TokensToDeploy,
async () =>
await DummyERC721TokenContract.deployFrom0xArtifactAsync(
ERC721Artifacts.DummyERC721Token,
environment.provider,
txDefaults,
ERC721Artifacts,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
),
_.times(numErc721TokensToDeploy, async () =>
DummyERC721TokenContract.deployFrom0xArtifactAsync(
ERC721Artifacts.DummyERC721Token,
environment.provider,
txDefaults,
ERC721Artifacts,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
),
),
);
const erc1155 = await Promise.all(
_.times(
numErc1155TokensToDeploy,
async () =>
await ERC1155MintableContract.deployFrom0xArtifactAsync(
ERC1155Artifacts.ERC1155Mintable,
environment.provider,
txDefaults,
ERC1155Artifacts,
),
_.times(numErc1155TokensToDeploy, async () =>
ERC1155MintableContract.deployFrom0xArtifactAsync(
ERC1155Artifacts.ERC1155Mintable,
environment.provider,
txDefaults,
ERC1155Artifacts,
),
),
);
@@ -492,3 +486,4 @@ export class DeploymentManager {
public txDefaults: Partial<TxData>,
) {}
}
// tslint:disable:max-file-line-count

View File

@@ -1,9 +1,9 @@
import { PromiseWithTransactionHash } from '@0x/base-contract';
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';
import { decodeThrownErrorAsRevertError } from '@0x/utils';
import { BlockParam, CallData, TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
// tslint:disable:max-classes-per-file
export interface ContractGetterFunction {
callAsync: (...args: any[]) => Promise<any>;
}
@@ -60,8 +60,12 @@ export class FunctionAssertion<TBefore> implements Assertion {
// The wrapper function that will be wrapped in assertions.
public wrapperFunction: ContractWrapperFunction;
constructor(wrapperFunction: ContractWrapperFunction, condition: Condition<TBefore>) {
this.condition = condition;
constructor(wrapperFunction: ContractWrapperFunction, condition: Partial<Condition<TBefore>> = {}) {
this.condition = {
before: _.noop.bind(this),
after: _.noop.bind(this),
...condition,
};
this.wrapperFunction = wrapperFunction;
}
@@ -74,7 +78,7 @@ export class FunctionAssertion<TBefore> implements Assertion {
const beforeInfo = await this.condition.before(...args);
// Initialize the callResult so that the default success value is true.
let callResult: Result = { success: true };
const callResult: Result = { success: true };
// Try to make the call to the function. If it is successful, pass the
// result and receipt to the after condition.
@@ -123,10 +127,11 @@ class MetaAssertion implements Assertion {
) {}
public async executeAsync(): Promise<void> {
let idx: number;
while ((idx = this.indexGenerator()) > 0) {
let idx = this.indexGenerator();
while (idx > 0) {
const args = await this.assertionGenerators[idx].generator();
this.assertionGenerators[idx].assertion.executeAsync(...args);
await this.assertionGenerators[idx].assertion.executeAsync(...args);
idx = this.indexGenerator();
}
}
}

View File

@@ -0,0 +1,9 @@
{
"extends": ["@0x/tslint-config"],
"rules": {
"custom-no-magic-numbers": false
},
"linterOptions": {
"exclude": ["src/artifacts.ts"]
}
}