invalidDecreaseStakingPoolOperatorShareAssertion
This commit is contained in:
@@ -5,7 +5,10 @@ import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { invalidCreateStakingPoolAssertion, validCreateStakingPoolAssertion } from '../assertions/createStakingPool';
|
||||
import { validDecreaseStakingPoolOperatorShareAssertion } from '../assertions/decreaseStakingPoolOperatorShare';
|
||||
import {
|
||||
invalidDecreaseStakingPoolOperatorShareAssertion,
|
||||
validDecreaseStakingPoolOperatorShareAssertion,
|
||||
} from '../assertions/decreaseStakingPoolOperatorShare';
|
||||
import { AssertionResult } from '../assertions/function_assertion';
|
||||
import { Distributions, Pseudorandom } from '../utils/pseudorandom';
|
||||
|
||||
@@ -44,6 +47,7 @@ export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase): TBase
|
||||
validCreateStakingPool: this._validCreateStakingPool(),
|
||||
invalidCreateStakingPool: this._invalidCreateStakingPool(),
|
||||
validDecreaseStakingPoolOperatorShare: this._validDecreaseStakingPoolOperatorShare(),
|
||||
invalidDecreaseStakingPoolOperatorShare: this._invalidDecreaseStakingPoolOperatorShare(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -123,6 +127,24 @@ export function PoolOperatorMixin<TBase extends Constructor>(Base: TBase): TBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async *_invalidDecreaseStakingPoolOperatorShare(): AsyncIterableIterator<AssertionResult | void> {
|
||||
const { stakingPools } = this.actor.simulationEnvironment!;
|
||||
const assertion = invalidDecreaseStakingPoolOperatorShareAssertion(this.actor.deployment);
|
||||
while (true) {
|
||||
const poolId = Pseudorandom.sample(this._getOperatorPoolIds(stakingPools));
|
||||
if (poolId === undefined) {
|
||||
yield undefined;
|
||||
} else {
|
||||
const operatorShare = Pseudorandom.integer(
|
||||
stakingPools[poolId].operatorShare + 1,
|
||||
constants.MAX_UINT32,
|
||||
Distributions.Kumaraswamy(0.2, 0.2),
|
||||
).toNumber();
|
||||
yield assertion.executeAsync([poolId, operatorShare], { from: this.actor.address });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { StakingPoolById } from '@0x/contracts-staking';
|
||||
import { constants, StakingPoolById, StakingRevertErrors } from '@0x/contracts-staking';
|
||||
import { expect } from '@0x/contracts-test-utils';
|
||||
import { TxData } from 'ethereum-types';
|
||||
|
||||
@@ -32,3 +32,37 @@ export function validDecreaseStakingPoolOperatorShareAssertion(
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a FunctionAssertion for `decreaseStakingPoolOperatorShare` which assumes the given
|
||||
* operator share is larger than the current operator share for the pool. The FunctionAssertion
|
||||
* checks that the transaction reverts with the correct error in this scenario.
|
||||
*/
|
||||
export function invalidDecreaseStakingPoolOperatorShareAssertion(
|
||||
deployment: DeploymentManager,
|
||||
): FunctionAssertion<[string, number], void, void> {
|
||||
const { stakingWrapper } = deployment.staking;
|
||||
|
||||
return new FunctionAssertion<[string, number], void, void>(stakingWrapper, 'decreaseStakingPoolOperatorShare', {
|
||||
after: async (_beforeInfo: void, result: FunctionResult, args: [string, number], _txData: Partial<TxData>) => {
|
||||
// Ensure that the tx reverted.
|
||||
expect(result.success).to.be.false();
|
||||
|
||||
// Check revert error
|
||||
const [poolId, operatorShare] = args;
|
||||
const expectedError =
|
||||
operatorShare > constants.PPM
|
||||
? new StakingRevertErrors.OperatorShareError(
|
||||
StakingRevertErrors.OperatorShareErrorCodes.OperatorShareTooLarge,
|
||||
poolId,
|
||||
operatorShare,
|
||||
)
|
||||
: new StakingRevertErrors.OperatorShareError(
|
||||
StakingRevertErrors.OperatorShareErrorCodes.CanOnlyDecreaseOperatorShare,
|
||||
poolId,
|
||||
operatorShare,
|
||||
);
|
||||
expect(result.data).to.equal(expectedError);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user