Stake State -> Status in tests
This commit is contained in:
parent
4bc84cd526
commit
deceed37f3
@ -3,7 +3,7 @@ import { BigNumber, RevertError } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { StakingWrapper } from '../utils/staking_wrapper';
|
||||
import { StakeBalances, StakeState, StakeStateInfo } from '../utils/types';
|
||||
import { StakeBalances, StakeStatus, StakeInfo } from '../utils/types';
|
||||
|
||||
import { BaseActor } from './base_actor';
|
||||
|
||||
@ -69,13 +69,13 @@ export class StakerActor extends BaseActor {
|
||||
}
|
||||
|
||||
public async moveStakeAsync(
|
||||
from: StakeStateInfo,
|
||||
to: StakeStateInfo,
|
||||
from: StakeInfo,
|
||||
to: StakeInfo,
|
||||
amount: BigNumber,
|
||||
revertError?: RevertError,
|
||||
): Promise<void> {
|
||||
// check if we're moving stake into a new pool
|
||||
if (to.state === StakeState.Delegated && to.poolId !== undefined && !_.includes(this._poolIds, to.poolId)) {
|
||||
if (to.status === StakeStatus.Delegated && to.poolId !== undefined && !_.includes(this._poolIds, to.poolId)) {
|
||||
this._poolIds.push(to.poolId);
|
||||
}
|
||||
// cache balances
|
||||
@ -85,9 +85,9 @@ export class StakerActor extends BaseActor {
|
||||
// check balances
|
||||
const expectedStakerBalances = initStakerBalances;
|
||||
// from
|
||||
if (from.state === StakeState.Active) {
|
||||
if (from.status === StakeStatus.Active) {
|
||||
expectedStakerBalances.activeStakeBalance.next = initStakerBalances.activeStakeBalance.next.minus(amount);
|
||||
} else if (from.state === StakeState.Inactive) {
|
||||
} else if (from.status === StakeStatus.Inactive) {
|
||||
expectedStakerBalances.inactiveStakeBalance.next = initStakerBalances.inactiveStakeBalance.next.minus(
|
||||
amount,
|
||||
);
|
||||
@ -98,7 +98,7 @@ export class StakerActor extends BaseActor {
|
||||
) {
|
||||
expectedStakerBalances.withdrawableStakeBalance = expectedStakerBalances.inactiveStakeBalance.next;
|
||||
}
|
||||
} else if (from.state === StakeState.Delegated && from.poolId !== undefined) {
|
||||
} else if (from.status === StakeStatus.Delegated && from.poolId !== undefined) {
|
||||
expectedStakerBalances.delegatedStakeBalance.next = initStakerBalances.delegatedStakeBalance.next.minus(
|
||||
amount,
|
||||
);
|
||||
@ -110,13 +110,13 @@ export class StakerActor extends BaseActor {
|
||||
].next = initStakerBalances.totalDelegatedStakeByPool[from.poolId].next.minus(amount);
|
||||
}
|
||||
// to
|
||||
if (to.state === StakeState.Active) {
|
||||
if (to.status === StakeStatus.Active) {
|
||||
expectedStakerBalances.activeStakeBalance.next = initStakerBalances.activeStakeBalance.next.plus(amount);
|
||||
} else if (to.state === StakeState.Inactive) {
|
||||
} else if (to.status === StakeStatus.Inactive) {
|
||||
expectedStakerBalances.inactiveStakeBalance.next = initStakerBalances.inactiveStakeBalance.next.plus(
|
||||
amount,
|
||||
);
|
||||
} else if (to.state === StakeState.Delegated && to.poolId !== undefined) {
|
||||
} else if (to.status === StakeStatus.Delegated && to.poolId !== undefined) {
|
||||
expectedStakerBalances.delegatedStakeBalance.next = initStakerBalances.delegatedStakeBalance.next.plus(
|
||||
amount,
|
||||
);
|
||||
|
@ -7,7 +7,7 @@ import * as _ from 'lodash';
|
||||
import { FinalizerActor } from './actors/finalizer_actor';
|
||||
import { StakerActor } from './actors/staker_actor';
|
||||
import { StakingWrapper } from './utils/staking_wrapper';
|
||||
import { MembersByPoolId, OperatorByPoolId, StakeState } from './utils/types';
|
||||
import { MembersByPoolId, OperatorByPoolId, StakeStatus } from './utils/types';
|
||||
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
// tslint:disable:max-file-line-count
|
||||
@ -174,8 +174,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(amount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
amount,
|
||||
);
|
||||
await payProtocolFeeAndFinalize();
|
||||
@ -196,8 +196,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(amount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
amount,
|
||||
);
|
||||
// finalize
|
||||
@ -214,8 +214,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(amount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
amount,
|
||||
);
|
||||
// skip epoch, so staker can start earning rewards
|
||||
@ -236,15 +236,15 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const totalStakeAmount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await stakers[0].stakeAsync(stakeAmounts[0]);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[0],
|
||||
);
|
||||
// second staker delegates
|
||||
await stakers[1].stakeAsync(stakeAmounts[1]);
|
||||
await stakers[1].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[1],
|
||||
);
|
||||
// skip epoch, so staker can start earning rewards
|
||||
@ -266,8 +266,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const totalStakeAmount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await stakers[0].stakeAsync(stakeAmounts[0]);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[0],
|
||||
);
|
||||
// skip epoch, so staker can start earning rewards
|
||||
@ -275,8 +275,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
// second staker delegates (epoch 1)
|
||||
await stakers[1].stakeAsync(stakeAmounts[1]);
|
||||
await stakers[1].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[1],
|
||||
);
|
||||
// skip epoch, so staker can start earning rewards
|
||||
@ -298,8 +298,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const totalStakeAmount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await stakers[0].stakeAsync(stakeAmounts[0]);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[0],
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -307,8 +307,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
// second staker delegates (epoch 1)
|
||||
await stakers[1].stakeAsync(stakeAmounts[1]);
|
||||
await stakers[1].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[1],
|
||||
);
|
||||
// only the first staker will get this reward
|
||||
@ -348,8 +348,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const totalStakeAmount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await stakers[0].stakeAsync(stakeAmounts[0]);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[0],
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -357,8 +357,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
// second staker delegates (epoch 1)
|
||||
await stakers[1].stakeAsync(stakeAmounts[1]);
|
||||
await stakers[1].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[1],
|
||||
);
|
||||
// only the first staker will get this reward
|
||||
@ -384,8 +384,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const stakeAmount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(stakeAmount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmount,
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -395,8 +395,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
await payProtocolFeeAndFinalize(reward);
|
||||
// undelegate (moves delegator's from the transient reward vault into the eth vault)
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
stakeAmount,
|
||||
);
|
||||
// sanity check final balances
|
||||
@ -410,8 +410,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const stakeAmount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(stakeAmount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmount,
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -422,8 +422,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
// add more stake
|
||||
await stakers[0].stakeAsync(stakeAmount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmount,
|
||||
);
|
||||
// sanity check final balances
|
||||
@ -451,8 +451,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const stakeAmounts = [StakingWrapper.toBaseUnitAmount(4), StakingWrapper.toBaseUnitAmount(6)];
|
||||
await stakers[0].stakeAsync(stakeAmounts[0]);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[0],
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -460,8 +460,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
// second staker delegates (epoch 1)
|
||||
await stakers[0].stakeAsync(stakeAmounts[1]);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmounts[1],
|
||||
);
|
||||
// only the first staker will get this reward
|
||||
@ -484,8 +484,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const stakeAmount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(stakeAmount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmount,
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -494,8 +494,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
await payProtocolFeeAndFinalize(rewardForDelegator);
|
||||
// undelegate stake and finalize epoch
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
stakeAmount,
|
||||
);
|
||||
await payProtocolFeeAndFinalize();
|
||||
@ -527,8 +527,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const stakeAmount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(stakeAmount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmount,
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -537,8 +537,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
await payProtocolFeeAndFinalize(rewardForDelegator);
|
||||
// undelegate stake and finalize epoch
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
stakeAmount,
|
||||
);
|
||||
await payProtocolFeeAndFinalize();
|
||||
@ -560,8 +560,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
const stakeAmount = StakingWrapper.toBaseUnitAmount(4);
|
||||
await stakers[0].stakeAsync(stakeAmount);
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmount,
|
||||
);
|
||||
// skip epoch, so first staker can start earning rewards
|
||||
@ -570,8 +570,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
await payProtocolFeeAndFinalize(rewardsForDelegator[0]);
|
||||
// undelegate stake and finalize epoch
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
stakeAmount,
|
||||
);
|
||||
await payProtocolFeeAndFinalize();
|
||||
@ -579,8 +579,8 @@ blockchainTests.resets('Testing Rewards', () => {
|
||||
await payProtocolFeeAndFinalize(rewardNotForDelegator);
|
||||
// delegate stake and go to next epoch
|
||||
await stakers[0].moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId },
|
||||
stakeAmount,
|
||||
);
|
||||
await payProtocolFeeAndFinalize();
|
||||
|
@ -7,10 +7,10 @@ import * as _ from 'lodash';
|
||||
|
||||
import { StakerActor } from './actors/staker_actor';
|
||||
import { StakingWrapper } from './utils/staking_wrapper';
|
||||
import { StakeState, StakeStateInfo } from './utils/types';
|
||||
import { StakeStatus, StakeInfo } from './utils/types';
|
||||
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
blockchainTests.resets('Stake States', () => {
|
||||
blockchainTests.resets('Stake Statuses', () => {
|
||||
// constants
|
||||
const ZRX_TOKEN_DECIMALS = new BigNumber(18);
|
||||
const ZERO = new BigNumber(0);
|
||||
@ -77,11 +77,11 @@ blockchainTests.resets('Stake States', () => {
|
||||
// epoch 1
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
// still epoch 1 ~ should be able to move stake again
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Inactive },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Inactive },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
amount,
|
||||
);
|
||||
});
|
||||
@ -89,11 +89,11 @@ blockchainTests.resets('Stake States', () => {
|
||||
// epoch 1
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
// stake is now inactive, should not be able to move it out of active state again
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
// stake is now inactive, should not be able to move it out of active status again
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Inactive },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Inactive },
|
||||
amount,
|
||||
new StakingRevertErrors.InsufficientBalanceError(amount, ZERO),
|
||||
);
|
||||
@ -102,17 +102,17 @@ blockchainTests.resets('Stake States', () => {
|
||||
// epoch 1
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
// still epoch 1 ~ should be able to move stake again
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Inactive },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Inactive },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
amount,
|
||||
);
|
||||
// stake is now delegated; should fail to re-assign it from inactive back to active
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Inactive },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Inactive },
|
||||
{ status: StakeStatus.Active },
|
||||
amount,
|
||||
new StakingRevertErrors.InsufficientBalanceError(amount, ZERO),
|
||||
);
|
||||
@ -120,67 +120,67 @@ blockchainTests.resets('Stake States', () => {
|
||||
});
|
||||
describe('Move Zero Stake', () => {
|
||||
it('active -> active', async () => {
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Active }, ZERO);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Active }, ZERO);
|
||||
});
|
||||
it('active -> inactive', async () => {
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, ZERO);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, ZERO);
|
||||
});
|
||||
it('active -> delegated', async () => {
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
ZERO,
|
||||
);
|
||||
});
|
||||
it('inactive -> active', async () => {
|
||||
await staker.moveStakeAsync({ state: StakeState.Inactive }, { state: StakeState.Active }, ZERO);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Inactive }, { status: StakeStatus.Active }, ZERO);
|
||||
});
|
||||
it('inactive -> inactive', async () => {
|
||||
await staker.moveStakeAsync({ state: StakeState.Inactive }, { state: StakeState.Inactive }, ZERO);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Inactive }, { status: StakeStatus.Inactive }, ZERO);
|
||||
});
|
||||
it('inactive -> delegated', async () => {
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Inactive },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Inactive },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
ZERO,
|
||||
);
|
||||
});
|
||||
it('delegated -> active', async () => {
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Active },
|
||||
ZERO,
|
||||
);
|
||||
});
|
||||
it('delegated -> inactive', async () => {
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Inactive },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Inactive },
|
||||
ZERO,
|
||||
);
|
||||
});
|
||||
it('delegated -> delegated (same pool)', async () => {
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
ZERO,
|
||||
);
|
||||
});
|
||||
it('delegated -> delegated (other pool)', async () => {
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[1] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[1] },
|
||||
ZERO,
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('Move Non-Zero Stake', () => {
|
||||
const testMovePartialStake = async (from: StakeStateInfo, to: StakeStateInfo) => {
|
||||
const testMovePartialStake = async (from: StakeInfo, to: StakeInfo) => {
|
||||
// setup
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
if (from.state !== StakeState.Active) {
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, from, amount);
|
||||
if (from.status !== StakeStatus.Active) {
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, from, amount);
|
||||
}
|
||||
// run test, checking balances in epochs [n .. n + 2]
|
||||
// in epoch `n` - `next` is set
|
||||
@ -191,51 +191,51 @@ blockchainTests.resets('Stake States', () => {
|
||||
await staker.goToNextEpochAsync();
|
||||
};
|
||||
it('active -> active', async () => {
|
||||
await testMovePartialStake({ state: StakeState.Active }, { state: StakeState.Active });
|
||||
await testMovePartialStake({ status: StakeStatus.Active }, { status: StakeStatus.Active });
|
||||
});
|
||||
it('active -> inactive', async () => {
|
||||
await testMovePartialStake({ state: StakeState.Active }, { state: StakeState.Inactive });
|
||||
await testMovePartialStake({ status: StakeStatus.Active }, { status: StakeStatus.Inactive });
|
||||
});
|
||||
it('active -> delegated', async () => {
|
||||
await testMovePartialStake(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
);
|
||||
});
|
||||
it('inactive -> active', async () => {
|
||||
await testMovePartialStake({ state: StakeState.Inactive }, { state: StakeState.Active });
|
||||
await testMovePartialStake({ status: StakeStatus.Inactive }, { status: StakeStatus.Active });
|
||||
});
|
||||
it('inactive -> inactive', async () => {
|
||||
await testMovePartialStake({ state: StakeState.Inactive }, { state: StakeState.Inactive });
|
||||
await testMovePartialStake({ status: StakeStatus.Inactive }, { status: StakeStatus.Inactive });
|
||||
});
|
||||
it('inactive -> delegated', async () => {
|
||||
await testMovePartialStake(
|
||||
{ state: StakeState.Inactive },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Inactive },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
);
|
||||
});
|
||||
it('delegated -> active', async () => {
|
||||
await testMovePartialStake(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Active },
|
||||
);
|
||||
});
|
||||
it('delegated -> inactive', async () => {
|
||||
await testMovePartialStake(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Inactive },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Inactive },
|
||||
);
|
||||
});
|
||||
it('delegated -> delegated (same pool)', async () => {
|
||||
await testMovePartialStake(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
);
|
||||
});
|
||||
it('delegated -> delegated (other pool)', async () => {
|
||||
await testMovePartialStake(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[1] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[1] },
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -247,7 +247,7 @@ blockchainTests.resets('Stake States', () => {
|
||||
it('should successfully unstake after being inactive for 1 epoch', async () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
await staker.goToNextEpochAsync(); // stake is now inactive
|
||||
await staker.goToNextEpochAsync(); // stake is now withdrawable
|
||||
await staker.unstakeAsync(amount);
|
||||
@ -260,42 +260,42 @@ blockchainTests.resets('Stake States', () => {
|
||||
it('should fail to unstake in the same epoch as stake was set to inactive', async () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
|
||||
});
|
||||
it('should fail to unstake after being inactive for <1 epoch', async () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
await staker.goToNextEpochAsync();
|
||||
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
|
||||
});
|
||||
it('should fail to unstake in same epoch that inactive/withdrawable stake has been reactivated', async () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
await staker.goToNextEpochAsync(); // stake is now inactive
|
||||
await staker.goToNextEpochAsync(); // stake is now withdrawable
|
||||
await staker.moveStakeAsync({ state: StakeState.Inactive }, { state: StakeState.Active }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Inactive }, { status: StakeStatus.Active }, amount);
|
||||
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
|
||||
});
|
||||
it('should fail to unstake one epoch after inactive/withdrawable stake has been reactivated', async () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
await staker.goToNextEpochAsync(); // stake is now inactive
|
||||
await staker.goToNextEpochAsync(); // stake is now withdrawable
|
||||
await staker.moveStakeAsync({ state: StakeState.Inactive }, { state: StakeState.Active }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Inactive }, { status: StakeStatus.Active }, amount);
|
||||
await staker.goToNextEpochAsync(); // stake is active and not withdrawable
|
||||
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
|
||||
});
|
||||
it('should fail to unstake >1 epoch after inactive/withdrawable stake has been reactivated', async () => {
|
||||
const amount = StakingWrapper.toBaseUnitAmount(10);
|
||||
await staker.stakeAsync(amount);
|
||||
await staker.moveStakeAsync({ state: StakeState.Active }, { state: StakeState.Inactive }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Active }, { status: StakeStatus.Inactive }, amount);
|
||||
await staker.goToNextEpochAsync(); // stake is now inactive
|
||||
await staker.goToNextEpochAsync(); // stake is now withdrawable
|
||||
await staker.moveStakeAsync({ state: StakeState.Inactive }, { state: StakeState.Active }, amount);
|
||||
await staker.moveStakeAsync({ status: StakeStatus.Inactive }, { status: StakeStatus.Active }, amount);
|
||||
await staker.goToNextEpochAsync(); // stake is active and not withdrawable
|
||||
await staker.goToNextEpochAsync(); // stake is active and not withdrawable
|
||||
await staker.unstakeAsync(amount, new StakingRevertErrors.InsufficientBalanceError(amount, ZERO));
|
||||
@ -307,50 +307,50 @@ blockchainTests.resets('Stake States', () => {
|
||||
await staker.stakeAsync(StakingWrapper.toBaseUnitAmount(4));
|
||||
// Later in Epoch 1: User delegates and deactivates some stake
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Inactive },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Inactive },
|
||||
StakingWrapper.toBaseUnitAmount(1),
|
||||
);
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
StakingWrapper.toBaseUnitAmount(2),
|
||||
);
|
||||
// Epoch 2: State updates (no user intervention required)
|
||||
// Epoch 2: Status updates (no user intervention required)
|
||||
await staker.goToNextEpochAsync();
|
||||
// Epoch 3: Stake that has been inactive for an epoch can be withdrawn (no user intervention required)
|
||||
await staker.goToNextEpochAsync();
|
||||
// Later in Epoch 3: User reactivates half of their inactive stake; this becomes Active next epoch
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Inactive },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Inactive },
|
||||
{ status: StakeStatus.Active },
|
||||
StakingWrapper.toBaseUnitAmount(0.5),
|
||||
);
|
||||
// Later in Epoch 3: User re-delegates half of their stake from Pool 1 to Pool 2
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Delegated, poolId: poolIds[0] },
|
||||
{ state: StakeState.Delegated, poolId: poolIds[1] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[0] },
|
||||
{ status: StakeStatus.Delegated, poolId: poolIds[1] },
|
||||
StakingWrapper.toBaseUnitAmount(1),
|
||||
);
|
||||
// Epoch 4: State updates (no user intervention required)
|
||||
// Epoch 4: Status updates (no user intervention required)
|
||||
await staker.goToNextEpochAsync();
|
||||
// Later in Epoch 4: User deactivates all active stake
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Active },
|
||||
{ state: StakeState.Inactive },
|
||||
{ status: StakeStatus.Active },
|
||||
{ status: StakeStatus.Inactive },
|
||||
StakingWrapper.toBaseUnitAmount(1.5),
|
||||
);
|
||||
// Later in Epoch 4: User withdraws all available inactive stake
|
||||
await staker.unstakeAsync(StakingWrapper.toBaseUnitAmount(0.5));
|
||||
// Epoch 5: State updates (no user intervention required)
|
||||
// Epoch 5: Status updates (no user intervention required)
|
||||
await staker.goToNextEpochAsync();
|
||||
// Later in Epoch 5: User reactivates a portion of their stake
|
||||
await staker.moveStakeAsync(
|
||||
{ state: StakeState.Inactive },
|
||||
{ state: StakeState.Active },
|
||||
{ status: StakeStatus.Inactive },
|
||||
{ status: StakeStatus.Active },
|
||||
StakingWrapper.toBaseUnitAmount(1),
|
||||
);
|
||||
// Epoch 6: State updates (no user intervention required)
|
||||
// Epoch 6: Status updates (no user intervention required)
|
||||
await staker.goToNextEpochAsync();
|
||||
});
|
||||
});
|
||||
|
@ -66,7 +66,7 @@ export enum StakeStatus {
|
||||
}
|
||||
|
||||
export interface StakeInfo {
|
||||
Status: StakeStatus;
|
||||
status: StakeStatus;
|
||||
poolId?: string;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user