Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Stake State -> Status in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hysz committed Sep 5, 2019
1 parent 369ffc5 commit f84df45
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 134 deletions.
20 changes: 10 additions & 10 deletions contracts/staking/test/actors/staker_actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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,
);
Expand All @@ -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,
);
Expand All @@ -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,
);
Expand Down
98 changes: 49 additions & 49 deletions contracts/staking/test/rewards_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -266,17 +266,17 @@ 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
await payProtocolFeeAndFinalize();
// 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
Expand All @@ -298,17 +298,17 @@ 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
await payProtocolFeeAndFinalize();
// 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
Expand Down Expand Up @@ -348,17 +348,17 @@ 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
await payProtocolFeeAndFinalize();
// 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -451,17 +451,17 @@ 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
await payProtocolFeeAndFinalize();
// 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
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -570,17 +570,17 @@ 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();
// this should not go do the delegator
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();
Expand Down
Loading

0 comments on commit f84df45

Please sign in to comment.