Skip to content

Commit 7540bb2

Browse files
authored
epochs: reintroduce test to check if we stay on the same epoch after moving fwd one block without passing epoch length (#182)
1 parent a5165d8 commit 7540bb2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

contracts/EpochManager.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ contract EpochManager is Governed {
124124
return lastLengthUpdateBlock.add(epochsSinceUpdate().mul(epochLength));
125125
}
126126

127+
/**
128+
* @dev Return the number of blocks that passed since current epoch started
129+
* @return Blocks that passed since start of epoch
130+
*/
131+
function currentEpochBlockSinceStart() public view returns (uint256) {
132+
return blockNum() - currentEpochBlock();
133+
}
134+
127135
/**
128136
* @dev Return the number of epoch that passed since another epoch
129137
* @param _epoch Epoch to use as since epoch value

test/epochs.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ contract('EpochManager', ([me, other, governor]) => {
6868
expect(await this.epochManager.blockNum()).to.be.bignumber.eq(currentBlock)
6969
})
7070

71+
it('should return same starting block if we stay on the same epoch', async function() {
72+
// Move right to the start of a new epoch
73+
const blocksSinceEpochStart = await this.epochManager.currentEpochBlockSinceStart()
74+
const blocksToNextEpoch = this.epochLength.sub(blocksSinceEpochStart)
75+
await time.advanceBlockTo((await this.epochManager.blockNum()).add(blocksToNextEpoch))
76+
77+
const currentEpochBlockBefore = await this.epochManager.currentEpochBlock()
78+
79+
// Advance block - will not jump to next epoch
80+
await time.advanceBlock()
81+
82+
const currentEpochBlockAfter = await this.epochManager.currentEpochBlock()
83+
expect(currentEpochBlockAfter).to.be.bignumber.equal(currentEpochBlockBefore)
84+
})
85+
7186
it('should return next starting block if we move to the next epoch', async function() {
7287
const currentEpochBlockBefore = await this.epochManager.currentEpochBlock()
7388

0 commit comments

Comments
 (0)