Skip to content

Commit

Permalink
return correct draw Id on closeDraw
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Sep 15, 2023
1 parent 9c950bc commit d6427b3
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 d6427b3

Please sign in to comment.