register actors in the SimulationEnvironment constructor
This commit is contained in:
@@ -15,7 +15,6 @@ export type Constructor<T = {}> = new (...args: any[]) => T;
|
||||
export interface ActorConfig {
|
||||
name?: string;
|
||||
deployment: DeploymentManager;
|
||||
simulationEnvironment?: SimulationEnvironment;
|
||||
[mixinProperty: string]: any;
|
||||
}
|
||||
|
||||
@@ -25,7 +24,7 @@ export class Actor {
|
||||
public readonly name: string;
|
||||
public readonly privateKey: Buffer;
|
||||
public readonly deployment: DeploymentManager;
|
||||
public readonly simulationEnvironment?: SimulationEnvironment;
|
||||
public simulationEnvironment?: SimulationEnvironment;
|
||||
public simulationActions: {
|
||||
[action: string]: AsyncIterableIterator<AssertionResult | void>;
|
||||
} = {};
|
||||
@@ -48,10 +47,6 @@ 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)];
|
||||
if (config.simulationEnvironment !== undefined) {
|
||||
this.simulationEnvironment = config.simulationEnvironment;
|
||||
this.simulationEnvironment.actors.push(this);
|
||||
}
|
||||
this._transactionFactory = new TransactionFactory(
|
||||
this.privateKey,
|
||||
config.deployment.exchange.address,
|
||||
|
||||
@@ -77,7 +77,7 @@ function verifyFillEvents(
|
||||
_to: order.feeRecipientAddress,
|
||||
_value: fillResults.makerFeePaid,
|
||||
},
|
||||
];
|
||||
].filter(event => event._value.isGreaterThan(0));
|
||||
|
||||
// If not enough wei is sent to cover the protocol fee, there will be an additional WETH transfer event
|
||||
if (value.isLessThan(DeploymentManager.protocolFee)) {
|
||||
|
||||
@@ -26,8 +26,15 @@ export class SimulationEnvironment {
|
||||
public constructor(
|
||||
public readonly deployment: DeploymentManager,
|
||||
public balanceStore: BlockchainBalanceStore,
|
||||
public actors: Actor[] = [],
|
||||
) {}
|
||||
public readonly actors: Actor[] = [],
|
||||
) {
|
||||
for (const actor of actors) {
|
||||
// Set the actor's simulation environment
|
||||
actor.simulationEnvironment = this;
|
||||
// Register each actor in the balance store
|
||||
this.balanceStore.registerTokenOwner(actor.address, actor.name);
|
||||
}
|
||||
}
|
||||
|
||||
public state(): any {
|
||||
return {
|
||||
|
||||
@@ -43,11 +43,10 @@ blockchainTests('Pool management fuzz test', env => {
|
||||
});
|
||||
const balanceStore = new BlockchainBalanceStore({}, {});
|
||||
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore);
|
||||
// tslint:disable:no-unused-expression
|
||||
new PoolOperator({ deployment, simulationEnvironment, name: 'Operator 1' });
|
||||
new PoolOperator({ deployment, simulationEnvironment, name: 'Operator 2' });
|
||||
// tslint:enable:no-unused-expression
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore, [
|
||||
new PoolOperator({ deployment, name: 'Operator 1' }),
|
||||
new PoolOperator({ deployment, name: 'Operator 2' }),
|
||||
]);
|
||||
|
||||
const simulation = new PoolManagementSimulation(simulationEnvironment);
|
||||
return simulation.fuzzAsync();
|
||||
|
||||
@@ -60,25 +60,23 @@ blockchainTests('pool membership fuzz test', env => {
|
||||
},
|
||||
{ erc20: { ZRX: deployment.tokens.zrx } },
|
||||
);
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore);
|
||||
|
||||
const actors = [
|
||||
new Maker({ deployment, simulationEnvironment, name: 'Maker 1' }),
|
||||
new Maker({ deployment, simulationEnvironment, name: 'Maker 2' }),
|
||||
new Taker({ deployment, simulationEnvironment, name: 'Taker 1' }),
|
||||
new Taker({ deployment, simulationEnvironment, name: 'Taker 2' }),
|
||||
new MakerTaker({ deployment, simulationEnvironment, name: 'Maker/Taker' }),
|
||||
new PoolOperator({ deployment, simulationEnvironment, name: 'Operator 1' }),
|
||||
new PoolOperator({ deployment, simulationEnvironment, name: 'Operator 2' }),
|
||||
new Maker({ deployment, name: 'Maker 1' }),
|
||||
new Maker({ deployment, name: 'Maker 2' }),
|
||||
new Taker({ deployment, name: 'Taker 1' }),
|
||||
new Taker({ deployment, name: 'Taker 2' }),
|
||||
new MakerTaker({ deployment, name: 'Maker/Taker' }),
|
||||
new PoolOperator({ deployment, name: 'Operator 1' }),
|
||||
new PoolOperator({ deployment, name: 'Operator 2' }),
|
||||
];
|
||||
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore, actors);
|
||||
|
||||
const takers = filterActorsByRole(actors, Taker);
|
||||
for (const taker of takers) {
|
||||
await taker.configureERC20TokenAsync(deployment.tokens.weth, deployment.staking.stakingProxy.address);
|
||||
}
|
||||
for (const actor of actors) {
|
||||
balanceStore.registerTokenOwner(actor.address, actor.name);
|
||||
}
|
||||
|
||||
const simulation = new PoolMembershipSimulation(simulationEnvironment);
|
||||
return simulation.fuzzAsync();
|
||||
|
||||
@@ -58,21 +58,19 @@ blockchainTests('Stake management fuzz test', env => {
|
||||
{ erc20: { ZRX: deployment.tokens.zrx } },
|
||||
);
|
||||
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore);
|
||||
const actors = [
|
||||
new Staker({ name: 'Staker 1', deployment, simulationEnvironment }),
|
||||
new Staker({ name: 'Staker 2', deployment, simulationEnvironment }),
|
||||
new StakerOperator({ name: 'Staker/Operator', deployment, simulationEnvironment }),
|
||||
new PoolOperator({ deployment, simulationEnvironment, name: 'Operator' }),
|
||||
new Staker({ name: 'Staker 1', deployment }),
|
||||
new Staker({ name: 'Staker 2', deployment }),
|
||||
new StakerOperator({ name: 'Staker/Operator', deployment }),
|
||||
new PoolOperator({ name: 'Operator', deployment }),
|
||||
];
|
||||
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore, actors);
|
||||
|
||||
const stakers = filterActorsByRole(actors, Staker);
|
||||
for (const staker of stakers) {
|
||||
await staker.configureERC20TokenAsync(deployment.tokens.zrx);
|
||||
}
|
||||
for (const actor of actors) {
|
||||
balanceStore.registerTokenOwner(actor.address, actor.name);
|
||||
}
|
||||
|
||||
const simulation = new StakeManagementSimulation(simulationEnvironment);
|
||||
return simulation.fuzzAsync();
|
||||
|
||||
@@ -84,26 +84,26 @@ blockchainTests('Staking rewards fuzz test', env => {
|
||||
},
|
||||
);
|
||||
|
||||
// Set up simulation environment
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore);
|
||||
|
||||
// Spin up actors
|
||||
const actors = [
|
||||
new Maker({ deployment, simulationEnvironment, name: 'Maker 1' }),
|
||||
new Maker({ deployment, simulationEnvironment, name: 'Maker 2' }),
|
||||
new Taker({ deployment, simulationEnvironment, name: 'Taker 1' }),
|
||||
new Taker({ deployment, simulationEnvironment, name: 'Taker 2' }),
|
||||
new MakerTaker({ deployment, simulationEnvironment, name: 'Maker/Taker' }),
|
||||
new Staker({ deployment, simulationEnvironment, name: 'Staker 1' }),
|
||||
new Staker({ deployment, simulationEnvironment, name: 'Staker 2' }),
|
||||
new Keeper({ deployment, simulationEnvironment, name: 'Keeper' }),
|
||||
new StakerKeeper({ deployment, simulationEnvironment, name: 'Staker/Keeper' }),
|
||||
new StakerMaker({ deployment, simulationEnvironment, name: 'Staker/Maker' }),
|
||||
new PoolOperator({ deployment, simulationEnvironment, name: 'Pool Operator' }),
|
||||
new StakerOperator({ deployment, simulationEnvironment, name: 'Staker/Operator' }),
|
||||
new OperatorStakerMaker({ deployment, simulationEnvironment, name: 'Operator/Staker/Maker' }),
|
||||
new Maker({ deployment, name: 'Maker 1' }),
|
||||
new Maker({ deployment, name: 'Maker 2' }),
|
||||
new Taker({ deployment, name: 'Taker 1' }),
|
||||
new Taker({ deployment, name: 'Taker 2' }),
|
||||
new MakerTaker({ deployment, name: 'Maker/Taker' }),
|
||||
new Staker({ deployment, name: 'Staker 1' }),
|
||||
new Staker({ deployment, name: 'Staker 2' }),
|
||||
new Keeper({ deployment, name: 'Keeper' }),
|
||||
new StakerKeeper({ deployment, name: 'Staker/Keeper' }),
|
||||
new StakerMaker({ deployment, name: 'Staker/Maker' }),
|
||||
new PoolOperator({ deployment, name: 'Pool Operator' }),
|
||||
new StakerOperator({ deployment, name: 'Staker/Operator' }),
|
||||
new OperatorStakerMaker({ deployment, name: 'Operator/Staker/Maker' }),
|
||||
];
|
||||
|
||||
// Set up simulation environment
|
||||
const simulationEnvironment = new SimulationEnvironment(deployment, balanceStore, actors);
|
||||
|
||||
// Takers need to set a WETH allowance for the staking proxy in case they pay the protocol fee in WETH
|
||||
const takers = filterActorsByRole(actors, Taker);
|
||||
for (const taker of takers) {
|
||||
@@ -114,11 +114,6 @@ blockchainTests('Staking rewards fuzz test', env => {
|
||||
for (const staker of stakers) {
|
||||
await staker.configureERC20TokenAsync(deployment.tokens.zrx);
|
||||
}
|
||||
// Register each actor in the balance store
|
||||
for (const actor of actors) {
|
||||
balanceStore.registerTokenOwner(actor.address, actor.name);
|
||||
}
|
||||
|
||||
const simulation = new StakingRewardsSimulation(simulationEnvironment);
|
||||
return simulation.fuzzAsync();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user