invalidCreateStakingPoolAssertion
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { constants, StakingPoolById } from '@0x/contracts-staking';
|
||||
import { constants as stakingConstants, StakingPoolById } from '@0x/contracts-staking';
|
||||
import { constants } from '@0x/contracts-test-utils';
|
||||
import '@azure/core-asynciterator-polyfill';
|
||||
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { validCreateStakingPoolAssertion } from '../assertions/createStakingPool';
|
||||
import { invalidCreateStakingPoolAssertion, validCreateStakingPoolAssertion } from '../assertions/createStakingPool';
|
||||
import { validDecreaseStakingPoolOperatorShareAssertion } from '../assertions/decreaseStakingPoolOperatorShare';
|
||||
import { AssertionResult } from '../assertions/function_assertion';
|
||||
import { Distributions, Pseudorandom } from '../utils/pseudorandom';
|
||||
@@ -41,6 +42,7 @@ export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase): TBase
|
||||
this.actor.simulationActions = {
|
||||
...this.actor.simulationActions,
|
||||
validCreateStakingPool: this._validCreateStakingPool(),
|
||||
invalidCreateStakingPool: this._invalidCreateStakingPool(),
|
||||
validDecreaseStakingPoolOperatorShare: this._validDecreaseStakingPoolOperatorShare(),
|
||||
};
|
||||
}
|
||||
@@ -85,7 +87,19 @@ export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase): TBase
|
||||
while (true) {
|
||||
const operatorShare = Pseudorandom.integer(
|
||||
0,
|
||||
constants.PPM,
|
||||
stakingConstants.PPM,
|
||||
Distributions.Kumaraswamy(0.2, 0.2),
|
||||
).toNumber();
|
||||
yield assertion.executeAsync([operatorShare, false], { from: this.actor.address });
|
||||
}
|
||||
}
|
||||
|
||||
private async *_invalidCreateStakingPool(): AsyncIterableIterator<AssertionResult> {
|
||||
const assertion = invalidCreateStakingPoolAssertion(this.actor.deployment);
|
||||
while (true) {
|
||||
const operatorShare = Pseudorandom.integer(
|
||||
stakingConstants.PPM + 1,
|
||||
constants.MAX_UINT32,
|
||||
Distributions.Kumaraswamy(0.2, 0.2),
|
||||
).toNumber();
|
||||
yield assertion.executeAsync([operatorShare, false], { from: this.actor.address });
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { StoredBalance } from '@0x/contracts-staking';
|
||||
import { StakingRevertErrors, StoredBalance } from '@0x/contracts-staking';
|
||||
import { expect } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TxData } from 'ethereum-types';
|
||||
@@ -22,7 +22,7 @@ export function validCreateStakingPoolAssertion(
|
||||
const { stakingWrapper } = deployment.staking;
|
||||
|
||||
return new FunctionAssertion<[number, boolean], string, string>(stakingWrapper, 'createStakingPool', {
|
||||
// Returns the expected ID of th created pool
|
||||
// Returns the expected ID of the created pool
|
||||
before: async () => {
|
||||
const lastPoolId = await stakingWrapper.lastPoolId().callAsync();
|
||||
// Effectively the last poolId + 1, but as a bytestring
|
||||
@@ -57,4 +57,41 @@ export function validCreateStakingPoolAssertion(
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a FunctionAssertion for `createStakingPool` which assumes an invalid operator share (i.e.
|
||||
* greater than 1,000,000) is provided. The FunctionAssertion checks that the transaction reverts
|
||||
* with the expected OperatorShareError.
|
||||
*/
|
||||
export function invalidCreateStakingPoolAssertion(
|
||||
deployment: DeploymentManager,
|
||||
): FunctionAssertion<[number, boolean], string, string> {
|
||||
const { stakingWrapper } = deployment.staking;
|
||||
|
||||
return new FunctionAssertion<[number, boolean], string, string>(stakingWrapper, 'createStakingPool', {
|
||||
// Returns the poolId we are expecting to revert with
|
||||
before: async () => {
|
||||
const lastPoolId = await stakingWrapper.lastPoolId().callAsync();
|
||||
// Effectively the last poolId + 1, but as a bytestring
|
||||
return `0x${new BigNumber(lastPoolId)
|
||||
.plus(1)
|
||||
.toString(16)
|
||||
.padStart(64, '0')}`;
|
||||
},
|
||||
after: async (expectedPoolId: string, result: FunctionResult, args: [number, boolean]) => {
|
||||
// Ensure that the tx reverted.
|
||||
expect(result.success).to.be.false();
|
||||
|
||||
// Check revert error
|
||||
const [operatorShare] = args;
|
||||
expect(result.data).to.equal(
|
||||
new StakingRevertErrors.OperatorShareError(
|
||||
StakingRevertErrors.OperatorShareErrorCodes.OperatorShareTooLarge,
|
||||
expectedPoolId,
|
||||
operatorShare,
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
/* tslint:enable:no-non-null-assertion*/
|
||||
|
Reference in New Issue
Block a user