Skip to content

Commit

Permalink
Merge pull request #68 from GenerationSoftware/gen-699-prize-pool-clo…
Browse files Browse the repository at this point in the history
…sedraw-returns-the-wrong-draw-id

return correct draw Id on closeDraw
  • Loading branch information
trmid authored Sep 21, 2023
2 parents 9c950bc + d6427b3 commit 713c300
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/PrizePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ contract PrizePool is TieredLiquidityDistributor, Ownable {
}

uint24 lastClosedDrawId_ = _lastClosedDrawId;
uint24 nextDrawId = lastClosedDrawId_ + 1;
uint24 closingDrawId = lastClosedDrawId_ + 1;
uint32 _claimCount = claimCount;
uint8 _numTiers = numberOfTiers;
uint8 _nextNumberOfTiers = _numTiers;
Expand All @@ -376,7 +376,7 @@ contract PrizePool is TieredLiquidityDistributor, Ownable {

uint48 openDrawStartedAt_ = _openDrawStartedAt();

_nextDraw(_nextNumberOfTiers, _contributionsForDraw(nextDrawId));
_nextDraw(_nextNumberOfTiers, _contributionsForDraw(closingDrawId));

_winningRandomNumber = winningRandomNumber_;
if (_claimCount != 0) {
Expand All @@ -386,7 +386,7 @@ contract PrizePool is TieredLiquidityDistributor, Ownable {
_lastClosedDrawAwardedAt = uint48(block.timestamp);

emit DrawClosed(
nextDrawId,
closingDrawId,
winningRandomNumber_,
_numTiers,
_nextNumberOfTiers,
Expand All @@ -395,7 +395,7 @@ contract PrizePool is TieredLiquidityDistributor, Ownable {
openDrawStartedAt_
);

return lastClosedDrawId_;
return closingDrawId;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/PrizePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,18 @@ contract PrizePoolTest is Test {
prizePool.closeDraw(winningRandomNumber);
}

function testCloseAndOpenNextDraw_emittedDrawIdSameAsReturnedDrawId() public {
contribute(510e18);
uint24 expectedDrawId = 1;

vm.expectEmit(true, true, true, false);
emit DrawClosed(expectedDrawId, 12345, 3, 3, 0, UD34x4.wrap(0), firstDrawStartsAt);
vm.warp(prizePool.openDrawEndsAt());
uint24 closedDrawId = prizePool.closeDraw(12345);

assertEq(closedDrawId, expectedDrawId, "closed draw ID matches expected");
}

function testCloseAndOpenNextDraw_notElapsed_openDrawPartway() public {
vm.warp(firstDrawStartsAt + drawPeriodSeconds);
prizePool.closeDraw(winningRandomNumber);
Expand Down

0 comments on commit 713c300

Please sign in to comment.