Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit fc58f80

Browse files
author
Denis Ermolin
committed
new
1 parent 48f2288 commit fc58f80

File tree

1 file changed

+58
-14
lines changed

1 file changed

+58
-14
lines changed

test/units/staking/stakeManager/StakeManager.test.js

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,28 +2417,72 @@ contract('StakeManager', async function(accounts) {
24172417
const aliceId = '2'
24182418
const bobId = '8'
24192419
const delegator = wallets[9].getChecksumAddressString()
2420+
24202421
let aliceContract
2422+
let totalStakeAfterUnstake
24212423

2422-
before(prepareForTest)
2423-
before(async function() {
2424-
await this.stakeManager.updateDynastyValue(1)
2425-
await this.stakeToken.mint(delegator, delegationAmount)
2426-
await this.stakeToken.approve(this.stakeManager.address, delegationAmount, {
2427-
from: delegator
2424+
function testMigration() {
2425+
it('Should migrate', async function() {
2426+
await this.stakeManager.migrateDelegation(aliceId, bobId, delegationAmount, { from: delegator })
24282427
})
24292428

2430-
const aliceValidator = await this.stakeManager.validators(aliceId)
2431-
aliceContract = await ValidatorShare.at(aliceValidator.contractAddress)
2429+
it('total stake must be correct', async function() {
2430+
assertBigNumberEquality(await this.stakeManager.currentValidatorSetTotalStake(), totalStakeAfterUnstake.add(delegationAmountBN))
2431+
})
2432+
}
24322433

2433-
await buyVoucher(aliceContract, delegationAmount, delegator)
2434+
function prepare() {
2435+
before(prepareForTest)
2436+
before(async function() {
2437+
await this.stakeManager.updateDynastyValue(1)
2438+
await this.stakeToken.mint(delegator, delegationAmount)
2439+
await this.stakeToken.approve(this.stakeManager.address, delegationAmount, {
2440+
from: delegator
2441+
})
2442+
2443+
const aliceValidator = await this.stakeManager.validators(aliceId)
2444+
aliceContract = await ValidatorShare.at(aliceValidator.contractAddress)
2445+
2446+
await buyVoucher(aliceContract, delegationAmount, delegator)
2447+
2448+
await this.stakeManager.unstake(aliceId, { from: initialStakers[1].getChecksumAddressString() })
2449+
2450+
})
2451+
}
2452+
2453+
describe('when migrating after validator claimed his stake', function() {
2454+
prepare()
2455+
2456+
before(async function() {
2457+
await this.stakeManager.advanceEpoch(10)
2458+
await this.stakeManager.unstakeClaim(aliceId, { from: initialStakers[1].getChecksumAddressString() })
24342459

2435-
await this.stakeManager.unstake(aliceId, { from: initialStakers[1].getChecksumAddressString() })
2436-
await this.stakeManager.advanceEpoch(100)
2437-
await this.stakeManager.unstakeClaim(aliceId, { from: initialStakers[1].getChecksumAddressString() })
2460+
totalStakeAfterUnstake = await this.stakeManager.currentValidatorSetTotalStake()
2461+
})
2462+
2463+
testMigration()
24382464
})
24392465

2440-
it('Should migrate', async function() {
2441-
await this.stakeManager.migrateDelegation(aliceId, bobId, migrationAmount, { from: delegator })
2466+
describe('when migrating after 1 epoch', function() {
2467+
prepare()
2468+
2469+
before(async function() {
2470+
await this.stakeManager.advanceEpoch(10)
2471+
2472+
totalStakeAfterUnstake = await this.stakeManager.currentValidatorSetTotalStake()
2473+
})
2474+
2475+
testMigration()
2476+
})
2477+
2478+
describe('when migrating within unstake epoch', function() {
2479+
prepare()
2480+
2481+
before(async function() {
2482+
totalStakeAfterUnstake = await this.stakeManager.currentValidatorSetTotalStake()
2483+
})
2484+
2485+
testMigration()
24422486
})
24432487
})
24442488

0 commit comments

Comments
 (0)