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