Addressed some review feedback
This commit is contained in:
parent
ce11271866
commit
19f5153d0e
@ -3,9 +3,11 @@ import { KeeperMixin } from './keeper';
|
|||||||
import { MakerMixin } from './maker';
|
import { MakerMixin } from './maker';
|
||||||
import { PoolOperatorMixin } from './pool_operator';
|
import { PoolOperatorMixin } from './pool_operator';
|
||||||
import { StakerMixin } from './staker';
|
import { StakerMixin } from './staker';
|
||||||
|
import { TakerMixin } from './taker';
|
||||||
|
|
||||||
export class OperatorMaker extends PoolOperatorMixin(MakerMixin(Actor)) {}
|
export class OperatorMaker extends PoolOperatorMixin(MakerMixin(Actor)) {}
|
||||||
export class StakerMaker extends StakerMixin(MakerMixin(Actor)) {}
|
export class StakerMaker extends StakerMixin(MakerMixin(Actor)) {}
|
||||||
export class StakerOperator extends StakerMixin(PoolOperatorMixin(Actor)) {}
|
export class StakerOperator extends StakerMixin(PoolOperatorMixin(Actor)) {}
|
||||||
export class OperatorStakerMaker extends PoolOperatorMixin(StakerMixin(MakerMixin(Actor))) {}
|
export class OperatorStakerMaker extends PoolOperatorMixin(StakerMixin(MakerMixin(Actor))) {}
|
||||||
export class StakerKeeper extends StakerMixin(KeeperMixin(Actor)) {}
|
export class StakerKeeper extends StakerMixin(KeeperMixin(Actor)) {}
|
||||||
|
export class MakerTaker extends MakerMixin(TakerMixin(Actor)) {}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import { constants, OrderFactory } from '@0x/contracts-test-utils';
|
import { constants, OrderFactory } from '@0x/contracts-test-utils';
|
||||||
import { Order, SignedOrder } from '@0x/types';
|
import { Order, SignedOrder } from '@0x/types';
|
||||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||||
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
|
import { AssertionResult } from '../assertions/function_assertion';
|
||||||
|
import { validJoinStakingPoolAssertion } from '../assertions/joinStakingPool';
|
||||||
|
|
||||||
import { Actor, ActorConfig, Constructor } from './base';
|
import { Actor, ActorConfig, Constructor } from './base';
|
||||||
|
|
||||||
@ -45,6 +49,12 @@ export function MakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
|||||||
...orderConfig,
|
...orderConfig,
|
||||||
};
|
};
|
||||||
this.orderFactory = new OrderFactory(this.actor.privateKey, defaultOrderParams);
|
this.orderFactory = new OrderFactory(this.actor.privateKey, defaultOrderParams);
|
||||||
|
|
||||||
|
// Register this mixin's assertion generators
|
||||||
|
this.actor.simulationActions = {
|
||||||
|
...this.actor.simulationActions,
|
||||||
|
validJoinStakingPool: this._validJoinStakingPool(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,6 +83,19 @@ export function MakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
|||||||
from: this.actor.address,
|
from: this.actor.address,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async *_validJoinStakingPool(): AsyncIterableIterator<AssertionResult | void> {
|
||||||
|
const { stakingPools } = this.actor.simulationEnvironment!;
|
||||||
|
const assertion = validJoinStakingPoolAssertion(this.actor.deployment);
|
||||||
|
while (true) {
|
||||||
|
const poolId = _.sample(Object.keys(stakingPools));
|
||||||
|
if (poolId === undefined) {
|
||||||
|
yield undefined;
|
||||||
|
} else {
|
||||||
|
yield assertion.executeAsync([poolId], { from: this.actor.address });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,98 +0,0 @@
|
|||||||
import { constants, getRandomInteger } from '@0x/contracts-test-utils';
|
|
||||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
|
||||||
import * as _ from 'lodash';
|
|
||||||
|
|
||||||
import { validFillOrderCompleteFillAssertion } from '../assertions/fillOrder';
|
|
||||||
import { AssertionResult } from '../assertions/function_assertion';
|
|
||||||
import { validJoinStakingPoolAssertion } from '../assertions/joinStakingPool';
|
|
||||||
|
|
||||||
import { Actor, Constructor } from './base';
|
|
||||||
|
|
||||||
interface PoolMemberInterface {
|
|
||||||
joinStakingPoolAsync: (poolId: string) => 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 PoolMemberMixin<TBase extends Constructor>(Base: TBase): TBase & Constructor<PoolMemberInterface> {
|
|
||||||
return class extends Base {
|
|
||||||
public readonly actor: Actor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The mixin pattern requires that this constructor uses `...args: any[]`, but this class
|
|
||||||
* really expects a single `ActorConfig` parameter (assuming `Actor` is used as the
|
|
||||||
* base class).
|
|
||||||
*/
|
|
||||||
constructor(...args: any[]) {
|
|
||||||
// tslint:disable-next-line:no-inferred-empty-object-type
|
|
||||||
super(...args);
|
|
||||||
this.actor = (this as any) as Actor;
|
|
||||||
|
|
||||||
// Register this mixin's assertion generators
|
|
||||||
this.actor.simulationActions = {
|
|
||||||
...this.actor.simulationActions,
|
|
||||||
validJoinStakingPool: this._validJoinStakingPool(),
|
|
||||||
validFillOrderCompleteFill: this._validFillOrderCompleteFill(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Joins a new staking pool.
|
|
||||||
*/
|
|
||||||
public async joinStakingPoolAsync(poolId: string): Promise<TransactionReceiptWithDecodedLogs> {
|
|
||||||
const stakingContract = this.actor.deployment.staking.stakingWrapper;
|
|
||||||
return stakingContract
|
|
||||||
.joinStakingPoolAsMaker(poolId)
|
|
||||||
.awaitTransactionSuccessAsync({ from: this.actor.address });
|
|
||||||
}
|
|
||||||
|
|
||||||
private async *_validJoinStakingPool(): AsyncIterableIterator<AssertionResult | void> {
|
|
||||||
const { stakingPools } = this.actor.simulationEnvironment!;
|
|
||||||
const assertion = validJoinStakingPoolAssertion(this.actor.deployment);
|
|
||||||
while (true) {
|
|
||||||
const poolId = _.sample(Object.keys(stakingPools));
|
|
||||||
if (poolId === undefined) {
|
|
||||||
yield undefined;
|
|
||||||
} else {
|
|
||||||
yield assertion.executeAsync({ args: [poolId], txData: { from: this.actor.address } });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async *_validFillOrderCompleteFill(): AsyncIterableIterator<AssertionResult | void> {
|
|
||||||
const { marketMakers } = this.actor.simulationEnvironment!;
|
|
||||||
const assertion = validFillOrderCompleteFillAssertion(this.actor.deployment);
|
|
||||||
while (true) {
|
|
||||||
const maker = _.sample(marketMakers);
|
|
||||||
if (maker === undefined) {
|
|
||||||
yield undefined;
|
|
||||||
} else {
|
|
||||||
// Configure the maker's token balances so that the order will definitely be fillable.
|
|
||||||
await Promise.all([
|
|
||||||
...this.actor.deployment.tokens.erc20.map(async token => maker.configureERC20TokenAsync(token)),
|
|
||||||
...this.actor.deployment.tokens.erc20.map(async token =>
|
|
||||||
this.actor.configureERC20TokenAsync(token),
|
|
||||||
),
|
|
||||||
this.actor.configureERC20TokenAsync(
|
|
||||||
this.actor.deployment.tokens.weth,
|
|
||||||
this.actor.deployment.staking.stakingProxy.address,
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const order = await maker.signOrderAsync({
|
|
||||||
makerAssetAmount: getRandomInteger(constants.ZERO_AMOUNT, constants.INITIAL_ERC20_BALANCE),
|
|
||||||
takerAssetAmount: getRandomInteger(constants.ZERO_AMOUNT, constants.INITIAL_ERC20_BALANCE),
|
|
||||||
});
|
|
||||||
yield assertion.executeAsync({
|
|
||||||
args: [order, order.takerAssetAmount, order.signature],
|
|
||||||
txData: { from: this.actor.address },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PoolMember extends PoolMemberMixin(Actor) {}
|
|
@ -84,7 +84,7 @@ export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase): TBase
|
|||||||
const assertion = validCreateStakingPoolAssertion(this.actor.deployment, stakingPools);
|
const assertion = validCreateStakingPoolAssertion(this.actor.deployment, stakingPools);
|
||||||
while (true) {
|
while (true) {
|
||||||
const operatorShare = getRandomInteger(0, constants.PPM).toNumber();
|
const operatorShare = getRandomInteger(0, constants.PPM).toNumber();
|
||||||
yield assertion.executeAsync({ args: [operatorShare, false], txData: { from: this.actor.address } });
|
yield assertion.executeAsync([operatorShare, false], { from: this.actor.address });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +97,7 @@ export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase): TBase
|
|||||||
yield undefined;
|
yield undefined;
|
||||||
} else {
|
} else {
|
||||||
const operatorShare = getRandomInteger(0, stakingPools[poolId].operatorShare).toNumber();
|
const operatorShare = getRandomInteger(0, stakingPools[poolId].operatorShare).toNumber();
|
||||||
yield assertion.executeAsync({
|
yield assertion.executeAsync([poolId, operatorShare], { from: this.actor.address });
|
||||||
args: [poolId, operatorShare],
|
|
||||||
txData: { from: this.actor.address },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ export function StakerMixin<TBase extends Constructor>(Base: TBase): TBase & Con
|
|||||||
await balanceStore.updateErc20BalancesAsync();
|
await balanceStore.updateErc20BalancesAsync();
|
||||||
const zrxBalance = balanceStore.balances.erc20[this.actor.address][zrx.address];
|
const zrxBalance = balanceStore.balances.erc20[this.actor.address][zrx.address];
|
||||||
const amount = getRandomInteger(0, zrxBalance);
|
const amount = getRandomInteger(0, zrxBalance);
|
||||||
yield assertion.executeAsync({ args: [amount], txData: { from: this.actor.address } });
|
yield assertion.executeAsync([amount], { from: this.actor.address });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ export function StakerMixin<TBase extends Constructor>(Base: TBase): TBase & Con
|
|||||||
undelegatedStake.nextEpochBalance,
|
undelegatedStake.nextEpochBalance,
|
||||||
);
|
);
|
||||||
const amount = getRandomInteger(0, withdrawableStake);
|
const amount = getRandomInteger(0, withdrawableStake);
|
||||||
yield assertion.executeAsync({ args: [amount], txData: { from: this.actor.address } });
|
yield assertion.executeAsync([amount], { from: this.actor.address });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ export function StakerMixin<TBase extends Constructor>(Base: TBase): TBase & Con
|
|||||||
: this.stake[StakeStatus.Delegated][from.poolId].nextEpochBalance;
|
: this.stake[StakeStatus.Delegated][from.poolId].nextEpochBalance;
|
||||||
const amount = getRandomInteger(0, moveableStake);
|
const amount = getRandomInteger(0, moveableStake);
|
||||||
|
|
||||||
yield assertion.executeAsync({ args: [from, to, amount], txData: { from: this.actor.address } });
|
yield assertion.executeAsync([from, to, amount], { from: this.actor.address });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
|
import { constants, getRandomInteger } from '@0x/contracts-test-utils';
|
||||||
import { SignedOrder } from '@0x/types';
|
import { SignedOrder } from '@0x/types';
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
||||||
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
|
import { validFillOrderCompleteFillAssertion } from '../assertions/fillOrder';
|
||||||
|
import { AssertionResult } from '../assertions/function_assertion';
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
|
|
||||||
import { Actor, Constructor } from './base';
|
import { Actor, Constructor } from './base';
|
||||||
@ -31,6 +35,12 @@ export function TakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
|||||||
// tslint:disable-next-line:no-inferred-empty-object-type
|
// tslint:disable-next-line:no-inferred-empty-object-type
|
||||||
super(...args);
|
super(...args);
|
||||||
this.actor = (this as any) as Actor;
|
this.actor = (this as any) as Actor;
|
||||||
|
|
||||||
|
// Register this mixin's assertion generators
|
||||||
|
this.actor.simulationActions = {
|
||||||
|
...this.actor.simulationActions,
|
||||||
|
validFillOrderCompleteFill: this._validFillOrderCompleteFill(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,6 +60,37 @@ export function TakerMixin<TBase extends Constructor>(Base: TBase): TBase & Cons
|
|||||||
...txData,
|
...txData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async *_validFillOrderCompleteFill(): AsyncIterableIterator<AssertionResult | void> {
|
||||||
|
const { marketMakers } = this.actor.simulationEnvironment!;
|
||||||
|
const assertion = validFillOrderCompleteFillAssertion(this.actor.deployment);
|
||||||
|
while (true) {
|
||||||
|
const maker = _.sample(marketMakers);
|
||||||
|
if (maker === undefined) {
|
||||||
|
yield undefined;
|
||||||
|
} else {
|
||||||
|
// Configure the maker's token balances so that the order will definitely be fillable.
|
||||||
|
await Promise.all([
|
||||||
|
...this.actor.deployment.tokens.erc20.map(async token => maker.configureERC20TokenAsync(token)),
|
||||||
|
...this.actor.deployment.tokens.erc20.map(async token =>
|
||||||
|
this.actor.configureERC20TokenAsync(token),
|
||||||
|
),
|
||||||
|
this.actor.configureERC20TokenAsync(
|
||||||
|
this.actor.deployment.tokens.weth,
|
||||||
|
this.actor.deployment.staking.stakingProxy.address,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const order = await maker.signOrderAsync({
|
||||||
|
makerAssetAmount: getRandomInteger(constants.ZERO_AMOUNT, constants.INITIAL_ERC20_BALANCE),
|
||||||
|
takerAssetAmount: getRandomInteger(constants.ZERO_AMOUNT, constants.INITIAL_ERC20_BALANCE),
|
||||||
|
});
|
||||||
|
yield assertion.executeAsync([order, order.takerAssetAmount, order.signature], {
|
||||||
|
from: this.actor.address,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import { FunctionAssertion, FunctionResult } from './function_assertion';
|
|||||||
* Returns a FunctionAssertion for `createStakingPool` which assumes valid input is provided. The
|
* Returns a FunctionAssertion for `createStakingPool` which assumes valid input is provided. The
|
||||||
* FunctionAssertion checks that the new poolId is one more than the last poolId.
|
* FunctionAssertion checks that the new poolId is one more than the last poolId.
|
||||||
*/
|
*/
|
||||||
|
/* tslint:disable:no-non-null-assertion */
|
||||||
export function validCreateStakingPoolAssertion(
|
export function validCreateStakingPoolAssertion(
|
||||||
deployment: DeploymentManager,
|
deployment: DeploymentManager,
|
||||||
pools: StakingPoolById,
|
pools: StakingPoolById,
|
||||||
@ -34,25 +35,26 @@ export function validCreateStakingPoolAssertion(
|
|||||||
after: async (
|
after: async (
|
||||||
expectedPoolId: string,
|
expectedPoolId: string,
|
||||||
result: FunctionResult,
|
result: FunctionResult,
|
||||||
args: {
|
args: [number, boolean],
|
||||||
args: [number, boolean];
|
txData: Partial<TxData>,
|
||||||
txData: Partial<TxData>;
|
|
||||||
},
|
|
||||||
) => {
|
) => {
|
||||||
logUtils.log(`createStakingPool(${args.args[0]}, ${args.args[1]}) => ${expectedPoolId}`);
|
const [operatorShare, shouldAddMakerAsOperator] = args;
|
||||||
|
|
||||||
|
logUtils.log(`createStakingPool(${operatorShare}, ${shouldAddMakerAsOperator}) => ${expectedPoolId}`);
|
||||||
|
|
||||||
// Checks the logs for the new poolId, verifies that it is as expected
|
// Checks the logs for the new poolId, verifies that it is as expected
|
||||||
const log = result.receipt!.logs[0]; // tslint:disable-line:no-non-null-assertion
|
const log = result.receipt!.logs[0];
|
||||||
const actualPoolId = (log as any).args.poolId;
|
const actualPoolId = (log as any).args.poolId;
|
||||||
expect(actualPoolId).to.equal(expectedPoolId);
|
expect(actualPoolId).to.equal(expectedPoolId);
|
||||||
|
|
||||||
// Adds the new pool to local state
|
// Adds the new pool to local state
|
||||||
pools[actualPoolId] = {
|
pools[actualPoolId] = {
|
||||||
operator: args.txData.from as string,
|
operator: txData.from!,
|
||||||
operatorShare: args.args[0],
|
operatorShare,
|
||||||
delegatedStake: new StoredBalance(),
|
delegatedStake: new StoredBalance(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/* tslint:enable:no-non-null-assertion*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { StakingPoolById } from '@0x/contracts-staking';
|
import { StakingPoolById } from '@0x/contracts-staking';
|
||||||
import { expect } from '@0x/contracts-test-utils';
|
import { expect } from '@0x/contracts-test-utils';
|
||||||
import { logUtils } from '@0x/utils';
|
import { logUtils } from '@0x/utils';
|
||||||
|
import { TxData } from 'ethereum-types';
|
||||||
|
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
|
|
||||||
@ -19,15 +20,15 @@ export function validDecreaseStakingPoolOperatorShareAssertion(
|
|||||||
return new FunctionAssertion<[string, number], {}, void>(
|
return new FunctionAssertion<[string, number], {}, void>(
|
||||||
stakingWrapper.decreaseStakingPoolOperatorShare.bind(stakingWrapper),
|
stakingWrapper.decreaseStakingPoolOperatorShare.bind(stakingWrapper),
|
||||||
{
|
{
|
||||||
after: async (_beforeInfo, _result: FunctionResult, args: { args: [string, number] }) => {
|
after: async (_beforeInfo, _result: FunctionResult, args: [string, number], txData: Partial<TxData>) => {
|
||||||
const poolId = args.args[0];
|
const [poolId, expectedOperatorShare] = args;
|
||||||
const expectedOperatorShare = args.args[1];
|
|
||||||
|
|
||||||
logUtils.log(`decreaseStakingPoolOperatorShare(${poolId}, ${expectedOperatorShare})`);
|
logUtils.log(`decreaseStakingPoolOperatorShare(${poolId}, ${expectedOperatorShare})`);
|
||||||
|
|
||||||
// Checks that the on-chain pool's operator share has been updated.
|
// Checks that the on-chain pool's operator share has been updated.
|
||||||
const { operatorShare } = await stakingWrapper.getStakingPool(poolId).callAsync();
|
const { operatorShare } = await stakingWrapper.getStakingPool(poolId).callAsync();
|
||||||
expect(operatorShare).to.bignumber.equal(expectedOperatorShare);
|
expect(operatorShare).to.bignumber.equal(expectedOperatorShare);
|
||||||
|
|
||||||
// Updates the pool in local state.
|
// Updates the pool in local state.
|
||||||
pools[poolId].operatorShare = operatorShare;
|
pools[poolId].operatorShare = operatorShare;
|
||||||
},
|
},
|
||||||
|
@ -3,12 +3,12 @@ import { ExchangeEvents, ExchangeFillEventArgs } from '@0x/contracts-exchange';
|
|||||||
import { constants, expect, orderHashUtils, verifyEvents } from '@0x/contracts-test-utils';
|
import { constants, expect, orderHashUtils, verifyEvents } from '@0x/contracts-test-utils';
|
||||||
import { FillResults, Order } from '@0x/types';
|
import { FillResults, Order } from '@0x/types';
|
||||||
import { BigNumber, logUtils } from '@0x/utils';
|
import { BigNumber, logUtils } from '@0x/utils';
|
||||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
|
|
||||||
import { FunctionArguments, FunctionAssertion, FunctionResult } from './function_assertion';
|
import { FunctionAssertion, FunctionResult } from './function_assertion';
|
||||||
|
|
||||||
function verifyFillEvents(
|
function verifyFillEvents(
|
||||||
takerAddress: string,
|
takerAddress: string,
|
||||||
@ -68,23 +68,30 @@ function verifyFillEvents(
|
|||||||
* A function assertion that verifies that a complete and valid fill succeeded and emitted the correct logs.
|
* A function assertion that verifies that a complete and valid fill succeeded and emitted the correct logs.
|
||||||
*/
|
*/
|
||||||
/* tslint:disable:no-unnecessary-type-assertion */
|
/* tslint:disable:no-unnecessary-type-assertion */
|
||||||
|
/* tslint:disable:no-non-null-assertion */
|
||||||
export function validFillOrderCompleteFillAssertion(
|
export function validFillOrderCompleteFillAssertion(
|
||||||
deployment: DeploymentManager,
|
deployment: DeploymentManager,
|
||||||
): FunctionAssertion<[Order, BigNumber, string], {}, FillResults> {
|
): FunctionAssertion<[Order, BigNumber, string], {}, FillResults> {
|
||||||
const exchange = deployment.exchange;
|
const exchange = deployment.exchange;
|
||||||
|
|
||||||
return new FunctionAssertion<[Order, BigNumber, string], {}, FillResults>(exchange.fillOrder.bind(exchange), {
|
return new FunctionAssertion<[Order, BigNumber, string], {}, FillResults>(exchange.fillOrder.bind(exchange), {
|
||||||
after: async (_beforeInfo, result: FunctionResult, args: FunctionArguments<[Order, BigNumber, string]>) => {
|
after: async (
|
||||||
const [order] = args.args;
|
_beforeInfo,
|
||||||
|
result: FunctionResult,
|
||||||
|
args: [Order, BigNumber, string],
|
||||||
|
txData: Partial<TxData>,
|
||||||
|
) => {
|
||||||
|
const [order] = args;
|
||||||
|
|
||||||
// Ensure that the tx succeeded.
|
// Ensure that the tx succeeded.
|
||||||
expect(result.success).to.be.true();
|
expect(result.success).to.be.true();
|
||||||
|
|
||||||
// Ensure that the correct events were emitted.
|
// Ensure that the correct events were emitted.
|
||||||
verifyFillEvents(args.txData.from!, order, result.receipt!, deployment); // tslint:disable-line:no-non-null-assertion
|
verifyFillEvents(txData.from!, order, result.receipt!, deployment);
|
||||||
|
|
||||||
logUtils.log(`Order filled by ${args.txData.from}`);
|
logUtils.log(`Order filled by ${txData.from}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/* tslint:enable:no-non-null-assertion */
|
||||||
/* tslint:enable:no-unnecessary-type-assertion */
|
/* tslint:enable:no-unnecessary-type-assertion */
|
||||||
|
@ -5,11 +5,6 @@ import * as _ from 'lodash';
|
|||||||
// tslint:disable:max-classes-per-file
|
// tslint:disable:max-classes-per-file
|
||||||
export type GenericContractFunction<T> = (...args: any[]) => ContractFunctionObj<T>;
|
export type GenericContractFunction<T> = (...args: any[]) => ContractFunctionObj<T>;
|
||||||
|
|
||||||
export interface FunctionArguments<TArgs extends any[]> {
|
|
||||||
args: TArgs;
|
|
||||||
txData: Partial<TxData>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FunctionResult {
|
export interface FunctionResult {
|
||||||
data?: any;
|
data?: any;
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@ -27,8 +22,8 @@ export interface FunctionResult {
|
|||||||
* function.
|
* function.
|
||||||
*/
|
*/
|
||||||
export interface Condition<TArgs extends any[], TBefore> {
|
export interface Condition<TArgs extends any[], TBefore> {
|
||||||
before: (args: FunctionArguments<TArgs>) => Promise<TBefore>;
|
before: (args: TArgs, txData: Partial<TxData>) => Promise<TBefore>;
|
||||||
after: (beforeInfo: TBefore, result: FunctionResult, args: FunctionArguments<TArgs>) => Promise<any>;
|
after: (beforeInfo: TBefore, result: FunctionResult, args: TArgs, txData: Partial<TxData>) => Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +34,7 @@ export interface Condition<TArgs extends any[], TBefore> {
|
|||||||
* @param runAsync The function to execute for the assertion.
|
* @param runAsync The function to execute for the assertion.
|
||||||
*/
|
*/
|
||||||
export interface Assertion<TArgs extends any[]> {
|
export interface Assertion<TArgs extends any[]> {
|
||||||
executeAsync: (args: FunctionArguments<TArgs>) => Promise<any>;
|
executeAsync: (args: TArgs, txData: TxData) => Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AssertionResult<TBefore = unknown> {
|
export interface AssertionResult<TBefore = unknown> {
|
||||||
@ -67,10 +62,10 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
|||||||
condition: Partial<Condition<TArgs, TBefore>> = {},
|
condition: Partial<Condition<TArgs, TBefore>> = {},
|
||||||
) {
|
) {
|
||||||
this.condition = {
|
this.condition = {
|
||||||
before: async (args: FunctionArguments<TArgs>) => {
|
before: async (args: TArgs, txData: Partial<TxData>) => {
|
||||||
return ({} as any) as TBefore;
|
return ({} as any) as TBefore;
|
||||||
},
|
},
|
||||||
after: async (beforeInfo: TBefore, result: FunctionResult, args: FunctionArguments<TArgs>) => {
|
after: async (beforeInfo: TBefore, result: FunctionResult, args: TArgs, txData: Partial<TxData>) => {
|
||||||
return ({} as any) as TBefore;
|
return ({} as any) as TBefore;
|
||||||
},
|
},
|
||||||
...condition,
|
...condition,
|
||||||
@ -82,9 +77,9 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
|||||||
* Runs the wrapped function and fails if the before or after assertions fail.
|
* Runs the wrapped function and fails if the before or after assertions fail.
|
||||||
* @param ...args The args to the contract wrapper function.
|
* @param ...args The args to the contract wrapper function.
|
||||||
*/
|
*/
|
||||||
public async executeAsync(args: FunctionArguments<TArgs>): Promise<AssertionResult<TBefore>> {
|
public async executeAsync(args: TArgs, txData: Partial<TxData>): Promise<AssertionResult<TBefore>> {
|
||||||
// Call the before condition.
|
// Call the before condition.
|
||||||
const beforeInfo = await this.condition.before(args);
|
const beforeInfo = await this.condition.before(args, txData);
|
||||||
|
|
||||||
// Initialize the callResult so that the default success value is true.
|
// Initialize the callResult so that the default success value is true.
|
||||||
const callResult: FunctionResult = { success: true };
|
const callResult: FunctionResult = { success: true };
|
||||||
@ -92,11 +87,11 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
|||||||
// Try to make the call to the function. If it is successful, pass the
|
// Try to make the call to the function. If it is successful, pass the
|
||||||
// result and receipt to the after condition.
|
// result and receipt to the after condition.
|
||||||
try {
|
try {
|
||||||
const functionWithArgs = this.wrapperFunction(...args.args) as ContractTxFunctionObj<ReturnDataType>;
|
const functionWithArgs = this.wrapperFunction(...args) as ContractTxFunctionObj<ReturnDataType>;
|
||||||
callResult.data = await functionWithArgs.callAsync(args.txData);
|
callResult.data = await functionWithArgs.callAsync(txData);
|
||||||
callResult.receipt =
|
callResult.receipt =
|
||||||
functionWithArgs.awaitTransactionSuccessAsync !== undefined
|
functionWithArgs.awaitTransactionSuccessAsync !== undefined
|
||||||
? await functionWithArgs.awaitTransactionSuccessAsync(args.txData) // tslint:disable-line:await-promise
|
? await functionWithArgs.awaitTransactionSuccessAsync(txData) // tslint:disable-line:await-promise
|
||||||
: undefined;
|
: undefined;
|
||||||
// tslint:enable:await-promise
|
// tslint:enable:await-promise
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -106,7 +101,7 @@ export class FunctionAssertion<TArgs extends any[], TBefore, ReturnDataType> imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call the after condition.
|
// Call the after condition.
|
||||||
const afterInfo = await this.condition.after(beforeInfo, callResult, args);
|
const afterInfo = await this.condition.after(beforeInfo, callResult, args, txData);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
beforeInfo,
|
beforeInfo,
|
||||||
|
@ -1,50 +1,43 @@
|
|||||||
import { StakingEvents, StakingMakerStakingPoolSetEventArgs } from '@0x/contracts-staking';
|
import { StakingEvents, StakingMakerStakingPoolSetEventArgs } from '@0x/contracts-staking';
|
||||||
import { expect, filterLogsToArguments } from '@0x/contracts-test-utils';
|
import { expect, filterLogsToArguments } from '@0x/contracts-test-utils';
|
||||||
import { logUtils } from '@0x/utils';
|
import { logUtils } from '@0x/utils';
|
||||||
|
import { TxData } from 'ethereum-types';
|
||||||
|
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
|
|
||||||
import { FunctionArguments, FunctionAssertion, FunctionResult } from './function_assertion';
|
import { FunctionAssertion, FunctionResult } from './function_assertion';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a function assertion that verifies valid pool joining.
|
* Returns a function assertion that verifies valid pool joining.
|
||||||
*/
|
*/
|
||||||
|
/* tslint:disable:no-unnecessary-type-assertion */
|
||||||
|
/* tslint:disable:no-non-null-assertion */
|
||||||
export function validJoinStakingPoolAssertion(deployment: DeploymentManager): FunctionAssertion<[string], {}, void> {
|
export function validJoinStakingPoolAssertion(deployment: DeploymentManager): FunctionAssertion<[string], {}, void> {
|
||||||
const { stakingWrapper } = deployment.staking;
|
const { stakingWrapper } = deployment.staking;
|
||||||
|
|
||||||
return new FunctionAssertion<[string], {}, void>(stakingWrapper.joinStakingPoolAsMaker.bind(stakingWrapper), {
|
return new FunctionAssertion<[string], {}, void>(stakingWrapper.joinStakingPoolAsMaker.bind(stakingWrapper), {
|
||||||
after: async (_beforeInfo, _result: FunctionResult, args: FunctionArguments<[string]>) => {
|
after: async (_beforeInfo, _result: FunctionResult, args: [string], txData: Partial<TxData>) => {
|
||||||
const poolId = args.args[0];
|
const [poolId] = args;
|
||||||
|
|
||||||
if (args.txData === undefined) {
|
|
||||||
throw new Error('Undefined transaction data');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.txData.from === undefined) {
|
|
||||||
throw new Error('Undefined from address');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_result.receipt === undefined) {
|
|
||||||
throw new Error('Undefined transaction receipt');
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(_result.success).to.be.true();
|
expect(_result.success).to.be.true();
|
||||||
|
|
||||||
const logs = _result.receipt.logs;
|
const logs = _result.receipt!.logs;
|
||||||
const logArgs = filterLogsToArguments<StakingMakerStakingPoolSetEventArgs>(
|
const logArgs = filterLogsToArguments<StakingMakerStakingPoolSetEventArgs>(
|
||||||
logs,
|
logs,
|
||||||
StakingEvents.MakerStakingPoolSet,
|
StakingEvents.MakerStakingPoolSet,
|
||||||
);
|
);
|
||||||
expect(logArgs).to.be.deep.eq([
|
expect(logArgs).to.be.deep.eq([
|
||||||
{
|
{
|
||||||
makerAddress: args.txData.from,
|
makerAddress: txData.from!,
|
||||||
poolId,
|
poolId,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
const joinedPoolId = await deployment.staking.stakingWrapper.poolIdByMaker(args.txData.from).callAsync();
|
const joinedPoolId = await deployment.staking.stakingWrapper.poolIdByMaker(txData.from!).callAsync();
|
||||||
expect(joinedPoolId).to.be.eq(poolId);
|
expect(joinedPoolId).to.be.eq(poolId);
|
||||||
|
|
||||||
logUtils.log(`Pool ${poolId} joined by ${args.txData.from}`); /* tslint:disable-line:no-console */
|
logUtils.log(`Pool ${poolId} joined by ${txData.from}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/* tslint:enable:no-non-null-assertion */
|
||||||
|
/* tslint:enable:no-unnecessary-type-assertion */
|
||||||
|
@ -8,11 +8,12 @@ import {
|
|||||||
} from '@0x/contracts-staking';
|
} from '@0x/contracts-staking';
|
||||||
import { constants, expect } from '@0x/contracts-test-utils';
|
import { constants, expect } from '@0x/contracts-test-utils';
|
||||||
import { BigNumber, logUtils } from '@0x/utils';
|
import { BigNumber, logUtils } from '@0x/utils';
|
||||||
|
import { TxData } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
|
|
||||||
import { FunctionArguments, FunctionAssertion, FunctionResult } from './function_assertion';
|
import { FunctionAssertion, FunctionResult } from './function_assertion';
|
||||||
|
|
||||||
function incrementNextEpochBalance(stakeBalance: StoredBalance, amount: BigNumber): void {
|
function incrementNextEpochBalance(stakeBalance: StoredBalance, amount: BigNumber): void {
|
||||||
_.update(stakeBalance, ['nextEpochBalance'], balance => (balance || constants.ZERO_AMOUNT).plus(amount));
|
_.update(stakeBalance, ['nextEpochBalance'], balance => (balance || constants.ZERO_AMOUNT).plus(amount));
|
||||||
@ -76,6 +77,7 @@ function updateNextEpochBalances(
|
|||||||
* Returns a FunctionAssertion for `moveStake` which assumes valid input is provided. The
|
* Returns a FunctionAssertion for `moveStake` which assumes valid input is provided. The
|
||||||
* FunctionAssertion checks that the staker's
|
* FunctionAssertion checks that the staker's
|
||||||
*/
|
*/
|
||||||
|
/* tslint:disable:no-unnecessary-type-assertion */
|
||||||
export function validMoveStakeAssertion(
|
export function validMoveStakeAssertion(
|
||||||
deployment: DeploymentManager,
|
deployment: DeploymentManager,
|
||||||
globalStake: GlobalStakeByStatus,
|
globalStake: GlobalStakeByStatus,
|
||||||
@ -90,9 +92,10 @@ export function validMoveStakeAssertion(
|
|||||||
after: async (
|
after: async (
|
||||||
_beforeInfo: {},
|
_beforeInfo: {},
|
||||||
_result: FunctionResult,
|
_result: FunctionResult,
|
||||||
args: FunctionArguments<[StakeInfo, StakeInfo, BigNumber]>,
|
args: [StakeInfo, StakeInfo, BigNumber],
|
||||||
|
txData: Partial<TxData>,
|
||||||
) => {
|
) => {
|
||||||
const [from, to, amount] = args.args;
|
const [from, to, amount] = args;
|
||||||
|
|
||||||
logUtils.log(
|
logUtils.log(
|
||||||
`moveStake({status: ${StakeStatus[from.status]}, poolId: ${from.poolId} }, { status: ${
|
`moveStake({status: ${StakeStatus[from.status]}, poolId: ${from.poolId} }, { status: ${
|
||||||
@ -100,7 +103,7 @@ export function validMoveStakeAssertion(
|
|||||||
}, poolId: ${to.poolId} }, ${amount})`,
|
}, poolId: ${to.poolId} }, ${amount})`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const owner = args.txData.from as string;
|
const owner = txData.from!; // tslint:disable-line:no-non-null-assertion
|
||||||
|
|
||||||
// Update local balances to match the expected result of this `moveStake` operation
|
// Update local balances to match the expected result of this `moveStake` operation
|
||||||
const updatedPools = updateNextEpochBalances(globalStake, ownerStake, pools, from, to, amount);
|
const updatedPools = updateNextEpochBalances(globalStake, ownerStake, pools, from, to, amount);
|
||||||
@ -140,3 +143,4 @@ export function validMoveStakeAssertion(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/* tslint:enable:no-unnecessary-type-assertion */
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import { GlobalStakeByStatus, OwnerStakeByStatus, StakeStatus, StoredBalance } from '@0x/contracts-staking';
|
import { GlobalStakeByStatus, OwnerStakeByStatus, StakeStatus, StoredBalance } from '@0x/contracts-staking';
|
||||||
import { expect } from '@0x/contracts-test-utils';
|
import { expect } from '@0x/contracts-test-utils';
|
||||||
import { BigNumber, logUtils } from '@0x/utils';
|
import { BigNumber, logUtils } from '@0x/utils';
|
||||||
|
import { TxData } from 'ethereum-types';
|
||||||
|
|
||||||
import { BlockchainBalanceStore } from '../balances/blockchain_balance_store';
|
import { BlockchainBalanceStore } from '../balances/blockchain_balance_store';
|
||||||
import { LocalBalanceStore } from '../balances/local_balance_store';
|
import { LocalBalanceStore } from '../balances/local_balance_store';
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
|
|
||||||
import { FunctionArguments, FunctionAssertion, FunctionResult } from './function_assertion';
|
import { FunctionAssertion, FunctionResult } from './function_assertion';
|
||||||
|
|
||||||
function expectedUndelegatedStake(
|
function expectedUndelegatedStake(
|
||||||
initStake: OwnerStakeByStatus | GlobalStakeByStatus,
|
initStake: OwnerStakeByStatus | GlobalStakeByStatus,
|
||||||
@ -24,6 +25,7 @@ function expectedUndelegatedStake(
|
|||||||
* FunctionAssertion checks that the staker and zrxVault's balances of ZRX decrease and increase,
|
* FunctionAssertion checks that the staker and zrxVault's balances of ZRX decrease and increase,
|
||||||
* respectively, by the input amount.
|
* respectively, by the input amount.
|
||||||
*/
|
*/
|
||||||
|
/* tslint:disable:no-unnecessary-type-assertion */
|
||||||
export function validStakeAssertion(
|
export function validStakeAssertion(
|
||||||
deployment: DeploymentManager,
|
deployment: DeploymentManager,
|
||||||
balanceStore: BlockchainBalanceStore,
|
balanceStore: BlockchainBalanceStore,
|
||||||
@ -33,13 +35,13 @@ export function validStakeAssertion(
|
|||||||
const { stakingWrapper, zrxVault } = deployment.staking;
|
const { stakingWrapper, zrxVault } = deployment.staking;
|
||||||
|
|
||||||
return new FunctionAssertion(stakingWrapper.stake.bind(stakingWrapper), {
|
return new FunctionAssertion(stakingWrapper.stake.bind(stakingWrapper), {
|
||||||
before: async (args: FunctionArguments<[BigNumber]>) => {
|
before: async (args: [BigNumber], txData: Partial<TxData>) => {
|
||||||
const [amount] = args.args;
|
const [amount] = args;
|
||||||
|
|
||||||
// Simulates the transfer of ZRX from staker to vault
|
// Simulates the transfer of ZRX from staker to vault
|
||||||
const expectedBalances = LocalBalanceStore.create(balanceStore);
|
const expectedBalances = LocalBalanceStore.create(balanceStore);
|
||||||
expectedBalances.transferAsset(
|
expectedBalances.transferAsset(
|
||||||
args.txData.from as string,
|
txData.from!, // tslint:disable-line:no-non-null-assertion
|
||||||
zrxVault.address,
|
zrxVault.address,
|
||||||
amount,
|
amount,
|
||||||
deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
|
deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
|
||||||
@ -49,9 +51,10 @@ export function validStakeAssertion(
|
|||||||
after: async (
|
after: async (
|
||||||
expectedBalances: LocalBalanceStore,
|
expectedBalances: LocalBalanceStore,
|
||||||
_result: FunctionResult,
|
_result: FunctionResult,
|
||||||
args: FunctionArguments<[BigNumber]>,
|
args: [BigNumber],
|
||||||
|
txData: Partial<TxData>,
|
||||||
) => {
|
) => {
|
||||||
const [amount] = args.args;
|
const [amount] = args;
|
||||||
|
|
||||||
logUtils.log(`stake(${amount})`);
|
logUtils.log(`stake(${amount})`);
|
||||||
|
|
||||||
@ -61,7 +64,7 @@ export function validStakeAssertion(
|
|||||||
|
|
||||||
// Checks that the owner's undelegated stake has increased by the stake amount
|
// Checks that the owner's undelegated stake has increased by the stake amount
|
||||||
const ownerUndelegatedStake = await stakingWrapper
|
const ownerUndelegatedStake = await stakingWrapper
|
||||||
.getOwnerStakeByStatus(args.txData.from as string, StakeStatus.Undelegated)
|
.getOwnerStakeByStatus(txData.from!, StakeStatus.Undelegated) // tslint:disable-line:no-non-null-assertion
|
||||||
.callAsync();
|
.callAsync();
|
||||||
const expectedOwnerUndelegatedStake = expectedUndelegatedStake(ownerStake, amount);
|
const expectedOwnerUndelegatedStake = expectedUndelegatedStake(ownerStake, amount);
|
||||||
expect(ownerUndelegatedStake, 'Owner undelegated stake').to.deep.equal(expectedOwnerUndelegatedStake);
|
expect(ownerUndelegatedStake, 'Owner undelegated stake').to.deep.equal(expectedOwnerUndelegatedStake);
|
||||||
@ -79,3 +82,4 @@ export function validStakeAssertion(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/* tslint:enable:no-unnecessary-type-assertion */
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import { GlobalStakeByStatus, OwnerStakeByStatus, StakeStatus, StoredBalance } from '@0x/contracts-staking';
|
import { GlobalStakeByStatus, OwnerStakeByStatus, StakeStatus, StoredBalance } from '@0x/contracts-staking';
|
||||||
import { expect } from '@0x/contracts-test-utils';
|
import { expect } from '@0x/contracts-test-utils';
|
||||||
import { BigNumber, logUtils } from '@0x/utils';
|
import { BigNumber, logUtils } from '@0x/utils';
|
||||||
|
import { TxData } from 'ethereum-types';
|
||||||
|
|
||||||
import { BlockchainBalanceStore } from '../balances/blockchain_balance_store';
|
import { BlockchainBalanceStore } from '../balances/blockchain_balance_store';
|
||||||
import { LocalBalanceStore } from '../balances/local_balance_store';
|
import { LocalBalanceStore } from '../balances/local_balance_store';
|
||||||
import { DeploymentManager } from '../deployment_manager';
|
import { DeploymentManager } from '../deployment_manager';
|
||||||
|
|
||||||
import { FunctionArguments, FunctionAssertion, FunctionResult } from './function_assertion';
|
import { FunctionAssertion, FunctionResult } from './function_assertion';
|
||||||
|
|
||||||
function expectedUndelegatedStake(
|
function expectedUndelegatedStake(
|
||||||
initStake: OwnerStakeByStatus | GlobalStakeByStatus,
|
initStake: OwnerStakeByStatus | GlobalStakeByStatus,
|
||||||
@ -24,6 +25,8 @@ function expectedUndelegatedStake(
|
|||||||
* FunctionAssertion checks that the staker and zrxVault's balances of ZRX increase and decrease,
|
* FunctionAssertion checks that the staker and zrxVault's balances of ZRX increase and decrease,
|
||||||
* respectively, by the input amount.
|
* respectively, by the input amount.
|
||||||
*/
|
*/
|
||||||
|
/* tslint:disable:no-unnecessary-type-assertion */
|
||||||
|
/* tslint:disable:no-non-null-assertion */
|
||||||
export function validUnstakeAssertion(
|
export function validUnstakeAssertion(
|
||||||
deployment: DeploymentManager,
|
deployment: DeploymentManager,
|
||||||
balanceStore: BlockchainBalanceStore,
|
balanceStore: BlockchainBalanceStore,
|
||||||
@ -33,14 +36,14 @@ export function validUnstakeAssertion(
|
|||||||
const { stakingWrapper, zrxVault } = deployment.staking;
|
const { stakingWrapper, zrxVault } = deployment.staking;
|
||||||
|
|
||||||
return new FunctionAssertion(stakingWrapper.unstake.bind(stakingWrapper), {
|
return new FunctionAssertion(stakingWrapper.unstake.bind(stakingWrapper), {
|
||||||
before: async (args: FunctionArguments<[BigNumber]>) => {
|
before: async (args: [BigNumber], txData: Partial<TxData>) => {
|
||||||
const [amount] = args.args;
|
const [amount] = args;
|
||||||
|
|
||||||
// Simulates the transfer of ZRX from vault to staker
|
// Simulates the transfer of ZRX from vault to staker
|
||||||
const expectedBalances = LocalBalanceStore.create(balanceStore);
|
const expectedBalances = LocalBalanceStore.create(balanceStore);
|
||||||
expectedBalances.transferAsset(
|
expectedBalances.transferAsset(
|
||||||
zrxVault.address,
|
zrxVault.address,
|
||||||
args.txData.from as string,
|
txData.from!,
|
||||||
amount,
|
amount,
|
||||||
deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
|
deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
|
||||||
);
|
);
|
||||||
@ -49,9 +52,10 @@ export function validUnstakeAssertion(
|
|||||||
after: async (
|
after: async (
|
||||||
expectedBalances: LocalBalanceStore,
|
expectedBalances: LocalBalanceStore,
|
||||||
_result: FunctionResult,
|
_result: FunctionResult,
|
||||||
args: FunctionArguments<[BigNumber]>,
|
args: [BigNumber],
|
||||||
|
txData: Partial<TxData>,
|
||||||
) => {
|
) => {
|
||||||
const [amount] = args.args;
|
const [amount] = args;
|
||||||
|
|
||||||
logUtils.log(`unstake(${amount})`);
|
logUtils.log(`unstake(${amount})`);
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ export function validUnstakeAssertion(
|
|||||||
|
|
||||||
// Checks that the owner's undelegated stake has decreased by the stake amount
|
// Checks that the owner's undelegated stake has decreased by the stake amount
|
||||||
const ownerUndelegatedStake = await stakingWrapper
|
const ownerUndelegatedStake = await stakingWrapper
|
||||||
.getOwnerStakeByStatus(args.txData.from as string, StakeStatus.Undelegated)
|
.getOwnerStakeByStatus(txData.from!, StakeStatus.Undelegated)
|
||||||
.callAsync();
|
.callAsync();
|
||||||
const expectedOwnerUndelegatedStake = expectedUndelegatedStake(ownerStake, amount);
|
const expectedOwnerUndelegatedStake = expectedUndelegatedStake(ownerStake, amount);
|
||||||
expect(ownerUndelegatedStake, 'Owner undelegated stake').to.deep.equal(expectedOwnerUndelegatedStake);
|
expect(ownerUndelegatedStake, 'Owner undelegated stake').to.deep.equal(expectedOwnerUndelegatedStake);
|
||||||
@ -79,3 +83,5 @@ export function validUnstakeAssertion(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/* tslint:enable:no-non-null-assertion */
|
||||||
|
/* tslint:enable:no-unnecessary-type-assertion */
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { blockchainTests, constants, expect, filterLogsToArguments, getRandomInteger } from '@0x/contracts-test-utils';
|
import { blockchainTests, constants, expect, filterLogsToArguments, getRandomInteger } from '@0x/contracts-test-utils';
|
||||||
import { BigNumber, StringRevertError } from '@0x/utils';
|
import { BigNumber, StringRevertError } from '@0x/utils';
|
||||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types';
|
||||||
|
|
||||||
import { artifacts } from '../../artifacts';
|
import { artifacts } from '../../artifacts';
|
||||||
import { TestFrameworkContract, TestFrameworkEventEventArgs, TestFrameworkEvents } from '../../wrappers';
|
import { TestFrameworkContract, TestFrameworkEventEventArgs, TestFrameworkEvents } from '../../wrappers';
|
||||||
import { FunctionArguments, FunctionAssertion, FunctionResult } from '../assertions/function_assertion';
|
import { FunctionAssertion, FunctionResult } from '../assertions/function_assertion';
|
||||||
|
|
||||||
const { ZERO_AMOUNT, MAX_UINT256 } = constants;
|
const { ZERO_AMOUNT, MAX_UINT256 } = constants;
|
||||||
|
|
||||||
@ -26,13 +26,13 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
|||||||
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
|
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
|
||||||
exampleContract.returnInteger.bind(exampleContract),
|
exampleContract.returnInteger.bind(exampleContract),
|
||||||
{
|
{
|
||||||
before: async (args: { args: [BigNumber] }) => {
|
before: async (args: [BigNumber], txData: Partial<TxData>) => {
|
||||||
sideEffectTarget = randomInput;
|
sideEffectTarget = randomInput;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
|
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
|
||||||
await assertion.executeAsync({ args: [randomInput], txData: {} });
|
await assertion.executeAsync([randomInput], {});
|
||||||
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -41,19 +41,24 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
|||||||
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
|
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
|
||||||
exampleContract.returnInteger.bind(exampleContract),
|
exampleContract.returnInteger.bind(exampleContract),
|
||||||
{
|
{
|
||||||
after: async (_beforeInfo: any, _result: FunctionResult, args: FunctionArguments<[BigNumber]>) => {
|
after: async (
|
||||||
sideEffectTarget = args.args[0];
|
_beforeInfo: any,
|
||||||
|
_result: FunctionResult,
|
||||||
|
args: [BigNumber],
|
||||||
|
txData: Partial<TxData>,
|
||||||
|
) => {
|
||||||
|
[sideEffectTarget] = args;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
|
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
|
||||||
await assertion.executeAsync({ args: [randomInput], txData: {} });
|
await assertion.executeAsync([randomInput], {});
|
||||||
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not fail immediately if the wrapped function fails', async () => {
|
it('should not fail immediately if the wrapped function fails', async () => {
|
||||||
const assertion = new FunctionAssertion<[], {}, void>(exampleContract.emptyRevert.bind(exampleContract));
|
const assertion = new FunctionAssertion<[], {}, void>(exampleContract.emptyRevert.bind(exampleContract));
|
||||||
await assertion.executeAsync({ args: [], txData: {} });
|
await assertion.executeAsync([], {});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pass the return value of "before" to "after"', async () => {
|
it('should pass the return value of "before" to "after"', async () => {
|
||||||
@ -62,15 +67,20 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
|||||||
const assertion = new FunctionAssertion<[BigNumber], BigNumber, BigNumber>(
|
const assertion = new FunctionAssertion<[BigNumber], BigNumber, BigNumber>(
|
||||||
exampleContract.returnInteger.bind(exampleContract),
|
exampleContract.returnInteger.bind(exampleContract),
|
||||||
{
|
{
|
||||||
before: async (_args: FunctionArguments<[BigNumber]>) => {
|
before: async (_args: [BigNumber], _txData: Partial<TxData>) => {
|
||||||
return randomInput;
|
return randomInput;
|
||||||
},
|
},
|
||||||
after: async (beforeInfo: any, _result: FunctionResult, _args: FunctionArguments<[BigNumber]>) => {
|
after: async (
|
||||||
|
beforeInfo: any,
|
||||||
|
_result: FunctionResult,
|
||||||
|
_args: [BigNumber],
|
||||||
|
_txData: Partial<TxData>,
|
||||||
|
) => {
|
||||||
sideEffectTarget = beforeInfo;
|
sideEffectTarget = beforeInfo;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await assertion.executeAsync({ args: [randomInput], txData: {} });
|
await assertion.executeAsync([randomInput], {});
|
||||||
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -79,13 +89,18 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
|||||||
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
|
const assertion = new FunctionAssertion<[BigNumber], void, BigNumber>(
|
||||||
exampleContract.returnInteger.bind(exampleContract),
|
exampleContract.returnInteger.bind(exampleContract),
|
||||||
{
|
{
|
||||||
after: async (_beforeInfo: any, result: FunctionResult, _args: FunctionArguments<[BigNumber]>) => {
|
after: async (
|
||||||
|
_beforeInfo: any,
|
||||||
|
result: FunctionResult,
|
||||||
|
_args: [BigNumber],
|
||||||
|
_txData: Partial<TxData>,
|
||||||
|
) => {
|
||||||
sideEffectTarget = result.data;
|
sideEffectTarget = result.data;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
|
const randomInput = getRandomInteger(ZERO_AMOUNT, MAX_UINT256);
|
||||||
await assertion.executeAsync({ args: [randomInput], txData: {} });
|
await assertion.executeAsync([randomInput], {});
|
||||||
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
expect(sideEffectTarget).bignumber.to.be.eq(randomInput);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -94,7 +109,12 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
|||||||
const assertion = new FunctionAssertion<[string], void, void>(
|
const assertion = new FunctionAssertion<[string], void, void>(
|
||||||
exampleContract.emitEvent.bind(exampleContract),
|
exampleContract.emitEvent.bind(exampleContract),
|
||||||
{
|
{
|
||||||
after: async (_beforeInfo: any, result: FunctionResult, _args: FunctionArguments<[string]>) => {
|
after: async (
|
||||||
|
_beforeInfo: any,
|
||||||
|
result: FunctionResult,
|
||||||
|
_args: [string],
|
||||||
|
_txData: Partial<TxData>,
|
||||||
|
) => {
|
||||||
if (result.receipt) {
|
if (result.receipt) {
|
||||||
sideEffectTarget = result.receipt;
|
sideEffectTarget = result.receipt;
|
||||||
}
|
}
|
||||||
@ -103,7 +123,7 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const input = 'emitted data';
|
const input = 'emitted data';
|
||||||
await assertion.executeAsync({ args: [input], txData: {} });
|
await assertion.executeAsync([input], {});
|
||||||
|
|
||||||
// Ensure that the correct events were emitted.
|
// Ensure that the correct events were emitted.
|
||||||
const [event] = filterLogsToArguments<TestFrameworkEventEventArgs>(
|
const [event] = filterLogsToArguments<TestFrameworkEventEventArgs>(
|
||||||
@ -118,13 +138,18 @@ blockchainTests.resets('FunctionAssertion Unit Tests', env => {
|
|||||||
const assertion = new FunctionAssertion<[string], void, void>(
|
const assertion = new FunctionAssertion<[string], void, void>(
|
||||||
exampleContract.stringRevert.bind(exampleContract),
|
exampleContract.stringRevert.bind(exampleContract),
|
||||||
{
|
{
|
||||||
after: async (_beforeInfo: any, result: FunctionResult, _args: FunctionArguments<[string]>) => {
|
after: async (
|
||||||
|
_beforeInfo: any,
|
||||||
|
result: FunctionResult,
|
||||||
|
_args: [string],
|
||||||
|
_txData: Partial<TxData>,
|
||||||
|
) => {
|
||||||
sideEffectTarget = result.data;
|
sideEffectTarget = result.data;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const message = 'error message';
|
const message = 'error message';
|
||||||
await assertion.executeAsync({ args: [message], txData: {} });
|
await assertion.executeAsync([message], {});
|
||||||
|
|
||||||
const expectedError = new StringRevertError(message);
|
const expectedError = new StringRevertError(message);
|
||||||
return expect(Promise.reject(sideEffectTarget!)).to.revertWith(expectedError); // tslint:disable-line
|
return expect(Promise.reject(sideEffectTarget!)).to.revertWith(expectedError); // tslint:disable-line
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
import { blockchainTests, constants } from '@0x/contracts-test-utils';
|
import { blockchainTests, constants } from '@0x/contracts-test-utils';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
|
import { MakerTaker } from '../framework/actors/hybrids';
|
||||||
import { Maker } from '../framework/actors/maker';
|
import { Maker } from '../framework/actors/maker';
|
||||||
import { PoolMember } from '../framework/actors/pool_member';
|
|
||||||
import { AssertionResult } from '../framework/assertions/function_assertion';
|
import { AssertionResult } from '../framework/assertions/function_assertion';
|
||||||
import { BlockchainBalanceStore } from '../framework/balances/blockchain_balance_store';
|
import { BlockchainBalanceStore } from '../framework/balances/blockchain_balance_store';
|
||||||
import { DeploymentManager } from '../framework/deployment_manager';
|
import { DeploymentManager } from '../framework/deployment_manager';
|
||||||
import { Simulation, SimulationEnvironment } from '../framework/simulation';
|
import { Simulation, SimulationEnvironment } from '../framework/simulation';
|
||||||
|
|
||||||
import { PoolManagementSimulation } from './pool_management_test';
|
import { PoolManagementSimulation } from './pool_management_test';
|
||||||
import { StakeManagementSimulation } from './stake_management_test';
|
|
||||||
|
|
||||||
class PoolMembershipSimulation extends Simulation {
|
class PoolMembershipSimulation extends Simulation {
|
||||||
protected async *_assertionGenerator(): AsyncIterableIterator<AssertionResult | void> {
|
protected async *_assertionGenerator(): AsyncIterableIterator<AssertionResult | void> {
|
||||||
const { deployment } = this.environment;
|
const { deployment } = this.environment;
|
||||||
|
|
||||||
const poolManagement = new PoolManagementSimulation(this.environment);
|
const poolManagement = new PoolManagementSimulation(this.environment);
|
||||||
const stakeManagement = new StakeManagementSimulation(this.environment);
|
|
||||||
|
|
||||||
const member = new PoolMember({
|
const member = new MakerTaker({
|
||||||
name: 'member',
|
name: 'member',
|
||||||
deployment,
|
deployment,
|
||||||
simulationEnvironment: this.environment,
|
simulationEnvironment: this.environment,
|
||||||
@ -28,7 +26,6 @@ class PoolMembershipSimulation extends Simulation {
|
|||||||
member.simulationActions.validJoinStakingPool,
|
member.simulationActions.validJoinStakingPool,
|
||||||
member.simulationActions.validFillOrderCompleteFill,
|
member.simulationActions.validFillOrderCompleteFill,
|
||||||
poolManagement.generator,
|
poolManagement.generator,
|
||||||
stakeManagement.generator,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -38,7 +35,7 @@ class PoolMembershipSimulation extends Simulation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blockchainTests.only('pool membership fuzz test', env => {
|
blockchainTests.skip('pool membership fuzz test', env => {
|
||||||
let deployment: DeploymentManager;
|
let deployment: DeploymentManager;
|
||||||
let maker: Maker;
|
let maker: Maker;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user