Skip to content

Commit

Permalink
test(rewards-manager): add unit test for registerRewardsForEpoch() wi…
Browse files Browse the repository at this point in the history
…th non-voting users
  • Loading branch information
oliviera9 committed Mar 1, 2024
1 parent 40fa6f0 commit 32901e3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/RewardsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ describe('RewardsManager', () => {
await assertDaoPntBalances(['220000', '440000', '55000', '10000'])
expect(await rewardsManager.unclaimableAmountByEpoch(0)).to.be.eq(ethers.parseUnits('1000'))

await expect(rewardsManager.connect(randomGuy).registerRewardsForEpoch(0, [pntHolder4.address])).to.not.be.reverted
await assertLockedRewardForEpoch(0, ['20000', '40000', '5000', '0'])
await assertDaoPntBalances(['220000', '440000', '55000', '10000'])
expect(await rewardsManager.unclaimableAmountByEpoch(0)).to.be.eq(ethers.parseUnits('1000'))

await expect(rewardsManager.connect(pntHolder1).claimRewardByEpoch(0)).to.be.revertedWithCustomError(
rewardsManager,
'TooEarly'
Expand Down Expand Up @@ -237,6 +242,32 @@ describe('RewardsManager', () => {
)
})

it('should not count twice unclaimableRewards when registering the same user', async () => {
const amount = (ethers.parseUnits('660000') * 10n) / 100n
await setPermission(owner.address, tokenManager.target, MINT_ROLE)

await assertDaoPntBalances(['0', '0', '0', '0'])
// mint daoPNT to simulate staking
await mintDaoPnt(['200000', '400000', '50000', '10000'])
await assertDaoPntBalances(['200000', '400000', '50000', '10000'])
await assertPntBalances(['400000', '400000', '400000', '400000'])

expect(await epochsManager.currentEpoch()).to.be.eq(0)
await depositRewardsForEpoch(amount, 0)

await time.increase(ONE_DAY)
await dandelionVoting.newVote()
await setStakersVoteState(1, [VOTE_STATUS.YES, VOTE_STATUS.YES, VOTE_STATUS.ABSENT, VOTE_STATUS.ABSENT])
await time.increase(ONE_MONTH + ONE_DAY)
await expect(rewardsManager.connect(randomGuy).registerRewardsForEpoch(0, [pntHolder4.address])).to.not.be.reverted
expect(await rewardsManager.unclaimableAmountByEpoch(0)).to.be.eq(ethers.parseUnits('1000'))
// try to register again the same non-voting user
await expect(rewardsManager.connect(randomGuy).registerRewardsForEpoch(0, [pntHolder4.address])).to.not.be.reverted
expect(await rewardsManager.unclaimableAmountByEpoch(0)).to.be.eq(ethers.parseUnits('1000'))
await assertLockedRewardForEpoch(0, ['0', '0', '0', '0'])
await assertDaoPntBalances(['200000', '400000', '50000', '10000'])
})

it('should not register anything if there is no vote in the epoch', async () => {
const amount = (ethers.parseUnits('660000') * 10n) / 100n
await setPermission(owner.address, tokenManager.target, MINT_ROLE)
Expand Down

0 comments on commit 32901e3

Please sign in to comment.