Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
i-stam committed Apr 8, 2020
1 parent 4c536a4 commit c5927ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions contracts/base/BlockRewardHbbftBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,16 @@ contract BlockRewardHbbftBase is UpgradeableOwned, IBlockRewardHbbft {
uint256 nextStakingEpoch = stakingEpoch + 1;
address[] memory miningAddresses;

// Choose new validators
validatorSetContract.newValidatorSet();

// We need to remember the total staked amounts for the pending addresses
// for when these pending addresses are finalized by `ValidatorSetHbbft.finalizeChange()`.
miningAddresses = validatorSetContract.getPendingValidators();
for (i = 0; i < miningAddresses.length; i++) {
_snapshotPoolStakeAmounts(stakingContract, nextStakingEpoch, miningAddresses[i]);
}

// Choose new validators
validatorSetContract.newValidatorSet();

// We need to remember the total staked amounts for the current validators
// for the possible case when these validators continue to be validators
// throughout the upcoming staking epoch (if the new validator set is not finalized
Expand Down
24 changes: 14 additions & 10 deletions test/BlockRewardHbbft.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ contract('BlockRewardHbbft', async accounts => {
stakingEpochStartBlock.should.be.bignumber.equal(new BN(STAKING_EPOCH_START_BLOCK + STAKING_EPOCH_DURATION * 1));
await setCurrentBlockNumber(stakingEpochStartBlock);

const validators = await validatorSetHbbft.getValidators.call();

const pendingValidators = await validatorSetHbbft.getPendingValidators.call();
pendingValidators.should.be.deep.equal([]);
pendingValidators.length.should.be.equal(0);
(await validatorSetHbbft.forNewEpoch.call()).should.be.equal(false);

const validators = await validatorSetHbbft.getValidators.call();
validators.length.should.be.equal(3);
const currentBlock = stakingEpochStartBlock.add(new BN(Math.floor(validators.length / 2) + 1));
await setCurrentBlockNumber(currentBlock);
});
Expand Down Expand Up @@ -395,8 +395,10 @@ contract('BlockRewardHbbft', async accounts => {

const blockRewardBalanceBeforeReward = await erc677Token.balanceOf.call(blockRewardHbbft.address);

await callReward();
let pendingValidators = await validatorSetHbbft.getPendingValidators.call();
pendingValidators.length.should.be.equal(0);
await callReward();
pendingValidators = await validatorSetHbbft.getPendingValidators.call();
pendingValidators.sortedEqual([
accounts[1],
accounts[2],
Expand All @@ -405,7 +407,13 @@ contract('BlockRewardHbbft', async accounts => {
accounts[32],
accounts[33],
]);

const nextStakingEpoch = stakingEpoch.add(new BN(1)); // 4
(await validatorSetHbbft.validatorSetApplyBlock.call()).should.be.bignumber.equal(new BN(0));
await callFinalizeChange();
(await validatorSetHbbft.validatorSetApplyBlock.call()).should.be.bignumber.equal(stakingEpochEndBlock);
(await stakingHbbft.stakingEpoch.call()).should.be.bignumber.equal(nextStakingEpoch);

for (let i = 0; i < pendingValidators.length; i++) {
(await blockRewardHbbft.snapshotPoolValidatorStakeAmount.call(nextStakingEpoch, pendingValidators[i])).should.be.bignumber.equal(
candidateMinStake
Expand All @@ -414,10 +422,6 @@ contract('BlockRewardHbbft', async accounts => {
candidateMinStake.add(delegatorMinStake.mul(new BN(3)))
);
}
(await validatorSetHbbft.validatorSetApplyBlock.call()).should.be.bignumber.equal(new BN(0));
await callFinalizeChange();
(await validatorSetHbbft.validatorSetApplyBlock.call()).should.be.bignumber.equal(stakingEpochEndBlock);
(await stakingHbbft.stakingEpoch.call()).should.be.bignumber.equal(nextStakingEpoch);

let rewardDistributed = new BN(0);
for (let i = 0; i < validators.length; i++) {
Expand Down Expand Up @@ -608,12 +612,12 @@ contract('BlockRewardHbbft', async accounts => {

});

it.only(' bridge fee accumulated during the epoch #5', async () => {
it('bridge fee accumulated during the epoch #5', async () => {
const fee = await accrueBridgeFees();
tokenRewardUndistributed = tokenRewardUndistributed.add(fee);
});

it.only('current pending validators remove their pools during the epoch #5', async () => {
it('current pending validators remove their pools during the epoch #5', async () => {
const pendingValidators = await validatorSetHbbft.getPendingValidators.call();
for (let i = 0; i < pendingValidators.length; i++) {
const stakingAddress = await validatorSetHbbft.stakingByMiningAddress.call(pendingValidators[i]);
Expand Down
2 changes: 1 addition & 1 deletion test/StakingHbbft.js
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ contract('StakingHbbft', async accounts => {
initialValidatorsIpAddresses // _internetAddresses
).should.be.fulfilled;
new BN(120954).should.be.bignumber.equal(
await stakingHbbft.stakingEpochDuration.call()
await stakingHbbft.stakingFixedEpochDuration.call()
);
new BN(4320).should.be.bignumber.equal(
await stakingHbbft.stakeWithdrawDisallowPeriod.call()
Expand Down
2 changes: 1 addition & 1 deletion test/ValidatorSetHbbft.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ contract('ValidatorSetHbbft', async accounts => {

// Check the returned value of the pending validators; it should be an empty list
(await validatorSetHbbft.getPendingValidators.call()).length.should.be.equal(0);
(await validatorSetHbbft.isForNewEpoch.call()).should.be.equal(false);
(await validatorSetHbbft.forNewEpoch.call()).should.be.equal(false);

// Emulate calling `newValidatorSet()` at the last block of staking epoch
await stakingHbbft.setCurrentBlockNumber(120954).should.be.fulfilled;
Expand Down

0 comments on commit c5927ee

Please sign in to comment.