invalidWithdrawDelegatorRewardsAssertion
This commit is contained in:
@@ -9,7 +9,10 @@ import { assetProxyTransferFailedAssertion } from '../assertions/generic_asserti
|
||||
import { validMoveStakeAssertion } from '../assertions/moveStake';
|
||||
import { validStakeAssertion } from '../assertions/stake';
|
||||
import { invalidUnstakeAssertion, validUnstakeAssertion } from '../assertions/unstake';
|
||||
import { validWithdrawDelegatorRewardsAssertion } from '../assertions/withdrawDelegatorRewards';
|
||||
import {
|
||||
invalidWithdrawDelegatorRewardsAssertion,
|
||||
validWithdrawDelegatorRewardsAssertion,
|
||||
} from '../assertions/withdrawDelegatorRewards';
|
||||
import { Pseudorandom } from '../utils/pseudorandom';
|
||||
|
||||
import { Actor, Constructor } from './base';
|
||||
@@ -52,6 +55,7 @@ export function StakerMixin<TBase extends Constructor>(Base: TBase): TBase & Con
|
||||
invalidUnstake: this._invalidUnstake(),
|
||||
validMoveStake: this._validMoveStake(),
|
||||
validWithdrawDelegatorRewards: this._validWithdrawDelegatorRewards(),
|
||||
invalidWithdrawDelegatorRewards: this._invalidWithdrawDelegatorRewards(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -205,6 +209,26 @@ export function StakerMixin<TBase extends Constructor>(Base: TBase): TBase & Con
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async *_invalidWithdrawDelegatorRewards(): AsyncIterableIterator<AssertionResult | void> {
|
||||
const { stakingPools } = this.actor.simulationEnvironment!;
|
||||
const assertion = invalidWithdrawDelegatorRewardsAssertion(
|
||||
this.actor.deployment,
|
||||
this.actor.simulationEnvironment!,
|
||||
);
|
||||
while (true) {
|
||||
const prevEpoch = this.actor.simulationEnvironment!.currentEpoch.minus(1);
|
||||
// Pick an unfinalized pool
|
||||
const poolId = Pseudorandom.sample(
|
||||
Object.keys(stakingPools).filter(id => stakingPools[id].lastFinalized.isLessThan(prevEpoch)),
|
||||
);
|
||||
if (poolId === undefined) {
|
||||
yield;
|
||||
} else {
|
||||
yield assertion.executeAsync([poolId], { from: this.actor.address });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { WETH9Events, WETH9TransferEventArgs } from '@0x/contracts-erc20';
|
||||
import { loadCurrentBalance, StoredBalance } from '@0x/contracts-staking';
|
||||
import { loadCurrentBalance, StakingRevertErrors, StoredBalance } from '@0x/contracts-staking';
|
||||
import { expect, filterLogsToArguments } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TxData } from 'ethereum-types';
|
||||
@@ -73,4 +73,25 @@ export function validWithdrawDelegatorRewardsAssertion(
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a FunctionAssertion for `withdrawDelegatorRewards` which assumes the given pool hasn't
|
||||
* been finalized for the previous epoch. It checks that the call reverts with a PoolNotFinalizedError.
|
||||
*/
|
||||
export function invalidWithdrawDelegatorRewardsAssertion(
|
||||
deployment: DeploymentManager,
|
||||
simulationEnvironment: SimulationEnvironment,
|
||||
): FunctionAssertion<[string], void, void> {
|
||||
return new FunctionAssertion(deployment.staking.stakingWrapper, 'withdrawDelegatorRewards', {
|
||||
after: async (_beforeInfo: void, result: FunctionResult, args: [string]) => {
|
||||
// Ensure that the tx reverted.
|
||||
expect(result.success).to.be.false();
|
||||
|
||||
// Check revert error
|
||||
const [poolId] = args;
|
||||
const { currentEpoch } = simulationEnvironment;
|
||||
expect(result.data).to.equal(new StakingRevertErrors.PoolNotFinalizedError(poolId, currentEpoch.minus(1)));
|
||||
},
|
||||
});
|
||||
}
|
||||
/* tslint:enable:no-unnecessary-type-assertion */
|
||||
|
Reference in New Issue
Block a user