Skip to content

Commit

Permalink
fix(TwabRewards): test claimRewards epochs limit
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Dec 15, 2021
1 parent e6081b9 commit 1444409
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/TwabRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract TwabRewards is ITwabRewards {

/// @notice Keeps track of claimed rewards per user.
/// @dev _claimedEpochs[promotionId][user] => claimedEpochs
/// @dev We pack epochs claimed by a user into a uint256. So we can't store more than 255 epochs.
/// @dev We pack epochs claimed by a user into a uint256. So we can't store more than 256 epochs.
mapping(uint256 => mapping(address => uint256)) internal _claimedEpochs;

/* ============ Events ============ */
Expand Down
28 changes: 27 additions & 1 deletion test/TwabRewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('TwabRewards', () => {
const tokensPerEpoch = toWei('10000');
const epochDuration = 604800; // 1 week in seconds
const numberOfEpochs = 12; // 3 months since 1 epoch runs for 1 week
const promotionAmount = tokensPerEpoch.mul(numberOfEpochs);
let promotionAmount: BigNumber;

const createPromotion = async (
ticketAddress: string = ticket.address,
Expand All @@ -64,6 +64,8 @@ describe('TwabRewards', () => {
epochsNumber: number = numberOfEpochs,
startTimestamp?: number,
) => {
promotionAmount = epochTokens.mul(epochsNumber);

if (token.mock) {
await token.mock.transferFrom
.withArgs(wallet1.address, twabRewards.address, promotionAmount)
Expand Down Expand Up @@ -810,6 +812,30 @@ describe('TwabRewards', () => {
twabRewards.claimRewards(wallet2.address, promotionId, ['2', '3', '4']),
).to.be.revertedWith('TwabRewards/rewards-claimed');
});

it('should fail to claim rewards past 255', async () => {
const promotionId = 1;

const wallet2Amount = toWei('750');
const wallet3Amount = toWei('250');

await ticket.mint(wallet2.address, wallet2Amount);
await ticket.mint(wallet3.address, wallet3Amount);

await createPromotion(
ticket.address,
rewardToken,
tokensPerEpoch,
epochDuration,
255
);

await increaseTime(epochDuration * 256);

await expect(
twabRewards.claimRewards(wallet2.address, promotionId, ['256']),
).to.be.reverted;
});
});

describe('_requireTicket()', () => {
Expand Down

0 comments on commit 1444409

Please sign in to comment.