Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Oct 4, 2023
1 parent bc22fc8 commit 78e403a
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 30 deletions.
116 changes: 87 additions & 29 deletions test/PrizePool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,7 @@ contract PrizePoolTest is Test {
function testAwardDraw_notElapsed_atStart() public {
vm.warp(firstDrawOpensAt);
vm.expectRevert(
abi.encodeWithSelector(
AwardingDrawNotClosed.selector,
firstDrawOpensAt + drawPeriodSeconds
)
abi.encodeWithSelector(AwardingDrawNotClosed.selector, firstDrawOpensAt + drawPeriodSeconds)
);
prizePool.awardDraw(winningRandomNumber);
}
Expand Down Expand Up @@ -521,10 +518,7 @@ contract PrizePoolTest is Test {
function testAwardDraw_notElapsed_partway() public {
vm.warp(firstDrawOpensAt + drawPeriodSeconds / 2);
vm.expectRevert(
abi.encodeWithSelector(
AwardingDrawNotClosed.selector,
firstDrawOpensAt + drawPeriodSeconds
)
abi.encodeWithSelector(AwardingDrawNotClosed.selector, firstDrawOpensAt + drawPeriodSeconds)
);
prizePool.awardDraw(winningRandomNumber);
}
Expand All @@ -541,7 +535,10 @@ contract PrizePoolTest is Test {
assertEq(prizePool.getLastAwardedDrawId(), 1);
assertEq(prizePool.getOpenDrawId(), 2);
assertEq(prizePool.drawOpensAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt);
assertEq(prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt + drawPeriodSeconds);
assertEq(
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()),
firstDrawOpensAt + drawPeriodSeconds
);
assertEq(prizePool.lastAwardedDrawAwardedAt(), block.timestamp);
}

Expand Down Expand Up @@ -1096,7 +1093,10 @@ contract PrizePoolTest is Test {
awardDraw(winningRandomNumber);

assertEq(prizePool.drawOpensAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt);
assertEq(prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt + drawPeriodSeconds);
assertEq(
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()),
firstDrawOpensAt + drawPeriodSeconds
);
assertEq(prizePool.lastAwardedDrawAwardedAt(), block.timestamp);
}

Expand All @@ -1105,20 +1105,32 @@ contract PrizePoolTest is Test {
awardDraw(winningRandomNumber);

assertEq(prizePool.drawOpensAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt);
assertEq(prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt + drawPeriodSeconds);
assertEq(
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()),
firstDrawOpensAt + drawPeriodSeconds
);
assertEq(prizePool.lastAwardedDrawAwardedAt(), block.timestamp);
}

function testOpenDrawStartMatchesLastDrawAwarded() public {
vm.warp(prizePool.drawClosesAt(prizePool.getOpenDrawId()) + 1 hours);
prizePool.awardDraw(winningRandomNumber);
assertEq(prizePool.drawOpensAt(prizePool.getOpenDrawId()), prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()));
assertEq(
prizePool.drawOpensAt(prizePool.getOpenDrawId()),
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId())
);
vm.warp(prizePool.drawClosesAt(prizePool.getOpenDrawId()) + 1 hours);
prizePool.awardDraw(winningRandomNumber);
assertEq(prizePool.drawOpensAt(prizePool.getOpenDrawId()), prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()));
assertEq(
prizePool.drawOpensAt(prizePool.getOpenDrawId()),
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId())
);
vm.warp(prizePool.drawClosesAt(prizePool.getOpenDrawId()) + 1 hours);
prizePool.awardDraw(winningRandomNumber);
assertEq(prizePool.drawOpensAt(prizePool.getOpenDrawId()), prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()));
assertEq(
prizePool.drawOpensAt(prizePool.getOpenDrawId()),
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId())
);
}

function testLastAwardedDrawAwardedAt() public {
Expand All @@ -1130,7 +1142,10 @@ contract PrizePoolTest is Test {
prizePool.awardDraw(winningRandomNumber);

assertEq(prizePool.drawOpensAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt);
assertEq(prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()), firstDrawOpensAt + drawPeriodSeconds);
assertEq(
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()),
firstDrawOpensAt + drawPeriodSeconds
);
assertEq(prizePool.lastAwardedDrawAwardedAt(), targetTimestamp);
}

Expand Down Expand Up @@ -1186,26 +1201,44 @@ contract PrizePoolTest is Test {
function testDrawToAwardSkipsMissedDraws() public {
assertEq(prizePool.getDrawIdToAward(), 1);
vm.warp(firstDrawOpensAt + drawPeriodSeconds * 2);
assertEq(prizePool.drawOpensAt(prizePool.getDrawIdToAward()), firstDrawOpensAt + drawPeriodSeconds);
assertEq(prizePool.drawClosesAt(prizePool.getDrawIdToAward()), firstDrawOpensAt + drawPeriodSeconds * 2);
assertEq(
prizePool.drawOpensAt(prizePool.getDrawIdToAward()),
firstDrawOpensAt + drawPeriodSeconds
);
assertEq(
prizePool.drawClosesAt(prizePool.getDrawIdToAward()),
firstDrawOpensAt + drawPeriodSeconds * 2
);
awardDraw(winningRandomNumber);
assertEq(prizePool.getDrawIdToAward(), 3);
}

function testDrawToAwardSkipsMissedDraws_middleOfDraw() public {
assertEq(prizePool.getDrawIdToAward(), 1);
vm.warp(firstDrawOpensAt + (drawPeriodSeconds * 5) / 2);
assertEq(prizePool.drawOpensAt(prizePool.getDrawIdToAward()), firstDrawOpensAt + drawPeriodSeconds);
assertEq(prizePool.drawClosesAt(prizePool.getDrawIdToAward()), firstDrawOpensAt + drawPeriodSeconds * 2);
assertEq(
prizePool.drawOpensAt(prizePool.getDrawIdToAward()),
firstDrawOpensAt + drawPeriodSeconds
);
assertEq(
prizePool.drawClosesAt(prizePool.getDrawIdToAward()),
firstDrawOpensAt + drawPeriodSeconds * 2
);
awardDraw(winningRandomNumber);
assertEq(prizePool.getDrawIdToAward(), 3);
}

function testDrawToAwardSkipsMissedDraws_2Draws() public {
assertEq(prizePool.getDrawIdToAward(), 1);
vm.warp(firstDrawOpensAt + drawPeriodSeconds * 3);
assertEq(prizePool.drawOpensAt(prizePool.getDrawIdToAward()), firstDrawOpensAt + drawPeriodSeconds * 2);
assertEq(prizePool.drawClosesAt(prizePool.getDrawIdToAward()), firstDrawOpensAt + drawPeriodSeconds * 3);
assertEq(
prizePool.drawOpensAt(prizePool.getDrawIdToAward()),
firstDrawOpensAt + drawPeriodSeconds * 2
);
assertEq(
prizePool.drawClosesAt(prizePool.getDrawIdToAward()),
firstDrawOpensAt + drawPeriodSeconds * 3
);
awardDraw(winningRandomNumber);
assertEq(prizePool.getDrawIdToAward(), 4);
}
Expand All @@ -1215,8 +1248,14 @@ contract PrizePoolTest is Test {
uint48 _lastDrawClosedAt = prizePool.drawClosesAt(prizePool.getLastAwardedDrawId());
assertEq(prizePool.getDrawIdToAward(), 2);
vm.warp(_lastDrawClosedAt + drawPeriodSeconds * 2);
assertEq(prizePool.drawOpensAt(prizePool.getDrawIdToAward()), _lastDrawClosedAt + drawPeriodSeconds);
assertEq(prizePool.drawClosesAt(prizePool.getDrawIdToAward()), _lastDrawClosedAt + drawPeriodSeconds * 2);
assertEq(
prizePool.drawOpensAt(prizePool.getDrawIdToAward()),
_lastDrawClosedAt + drawPeriodSeconds
);
assertEq(
prizePool.drawClosesAt(prizePool.getDrawIdToAward()),
_lastDrawClosedAt + drawPeriodSeconds * 2
);
awardDraw(winningRandomNumber);
assertEq(prizePool.getDrawIdToAward(), 4);
}
Expand All @@ -1229,8 +1268,14 @@ contract PrizePoolTest is Test {
uint48 _lastDrawClosedAt = prizePool.drawClosesAt(prizePool.getLastAwardedDrawId());
assertEq(prizePool.getDrawIdToAward(), 5);
vm.warp(_lastDrawClosedAt + drawPeriodSeconds * 5);
assertEq(prizePool.drawOpensAt(prizePool.getDrawIdToAward()), _lastDrawClosedAt + drawPeriodSeconds * 4);
assertEq(prizePool.drawClosesAt(prizePool.getDrawIdToAward()), _lastDrawClosedAt + drawPeriodSeconds * 5);
assertEq(
prizePool.drawOpensAt(prizePool.getDrawIdToAward()),
_lastDrawClosedAt + drawPeriodSeconds * 4
);
assertEq(
prizePool.drawClosesAt(prizePool.getDrawIdToAward()),
_lastDrawClosedAt + drawPeriodSeconds * 5
);
awardDraw(winningRandomNumber);
assertEq(prizePool.getDrawIdToAward(), 10);
}
Expand All @@ -1241,8 +1286,14 @@ contract PrizePoolTest is Test {
assertEq(prizePool.getDrawIdToAward(), 2);
vm.warp(_lastDrawClosedAt + (drawPeriodSeconds * 5) / 2); // warp 2.5 draws in the future
assertEq(prizePool.getDrawIdToAward(), 3);
assertEq(prizePool.drawOpensAt(prizePool.getDrawIdToAward()), _lastDrawClosedAt + drawPeriodSeconds);
assertEq(prizePool.drawClosesAt(prizePool.getDrawIdToAward()), _lastDrawClosedAt + drawPeriodSeconds * 2);
assertEq(
prizePool.drawOpensAt(prizePool.getDrawIdToAward()),
_lastDrawClosedAt + drawPeriodSeconds
);
assertEq(
prizePool.drawClosesAt(prizePool.getDrawIdToAward()),
_lastDrawClosedAt + drawPeriodSeconds * 2
);
awardDraw(winningRandomNumber);
assertEq(prizePool.getDrawIdToAward(), 4);
}
Expand All @@ -1252,7 +1303,9 @@ contract PrizePoolTest is Test {
mockTwab(
address(this),
msg.sender,
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()) - grandPrizePeriodDraws * drawPeriodSeconds,
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()) -
grandPrizePeriodDraws *
drawPeriodSeconds,
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId())
);
(uint256 twab, uint256 twabTotalSupply) = prizePool.getVaultUserBalanceAndTotalSupplyTwab(
Expand All @@ -1275,7 +1328,12 @@ contract PrizePoolTest is Test {
prizePool = new PrizePool(params);
prizePool.setDrawManager(address(this));
awardDraw(winningRandomNumber);
mockTwab(address(this), msg.sender, 0, prizePool.drawClosesAt(prizePool.getLastAwardedDrawId()));
mockTwab(
address(this),
msg.sender,
0,
prizePool.drawClosesAt(prizePool.getLastAwardedDrawId())
);
(uint256 twab, uint256 twabTotalSupply) = prizePool.getVaultUserBalanceAndTotalSupplyTwab(
address(this),
msg.sender,
Expand Down
5 changes: 4 additions & 1 deletion test/invariants/helpers/PrizePoolFuzzHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ contract PrizePoolFuzzHarness is CommonBase, StdCheats {
SD1x18 smoothing = SD1x18.wrap(0.9e18);

token = new ERC20Mintable("name", "SYMBOL");
TwabController twabController = new TwabController(drawPeriodSeconds, uint32(awardDrawStartsAt));
TwabController twabController = new TwabController(
drawPeriodSeconds,
uint32(awardDrawStartsAt)
);
// arbitrary mint
twabController.mint(address(this), 100e18);

Expand Down

0 comments on commit 78e403a

Please sign in to comment.