Skip to content

Commit

Permalink
test(billboard): add tests for getBlockFromEpoch and getEpochFromBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Jul 3, 2024
1 parent db48341 commit 0ab131e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 28 deletions.
60 changes: 32 additions & 28 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,43 @@ ACLManagerTest:testGrantRole() (gas: 23547)
ACLManagerTest:testRenounceRole() (gas: 27841)
ACLManagerTest:testRoles() (gas: 15393)
ACLManagerTest:testTransferRole() (gas: 21528)
BillboardTest:testAddToWhitelist() (gas: 252168)
BillboardTest:testApproveAndTransfer() (gas: 252840)
BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 225852)
BillboardTest:testCannotApproveByAttacker() (gas: 221710)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 247677)
BillboardTest:testCannotClearAuctionIfNoBid() (gas: 255428)
BillboardTest:testCannotPlaceBidByAttacker() (gas: 459880)
BillboardTest:testCannotPlaceBidIfAuctionEnded() (gas: 270378)
BillboardTest:testCannotRemoveToWhitelistByAttacker() (gas: 225871)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 218890)
BillboardTest:testCannotSetBoardByAttacker() (gas: 226951)
BillboardTest:testCannotSetBoardByOwner() (gas: 359191)
BillboardTest:testCannotTransferByOperator() (gas: 224110)
BillboardTest:testCannotTransferToZeroAddress() (gas: 219576)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9038)
BillboardTest:testCannotWithdrawBidIfAuctionNotEndedOrCleared(uint96) (runs: 256, μ: 614753, ~: 614753)
BillboardTest:testAddToWhitelist() (gas: 252190)
BillboardTest:testApproveAndTransfer() (gas: 252884)
BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 225763)
BillboardTest:testCannotApproveByAttacker() (gas: 221754)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 247699)
BillboardTest:testCannotClearAuctionIfNoBid() (gas: 255361)
BillboardTest:testCannotGetBlockFromEpoch() (gas: 8580)
BillboardTest:testCannotGetEpochFromBlock() (gas: 15189)
BillboardTest:testCannotPlaceBidByAttacker() (gas: 459810)
BillboardTest:testCannotPlaceBidIfAuctionEnded() (gas: 270400)
BillboardTest:testCannotRemoveToWhitelistByAttacker() (gas: 225893)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 218912)
BillboardTest:testCannotSetBoardByAttacker() (gas: 226995)
BillboardTest:testCannotSetBoardByOwner() (gas: 359213)
BillboardTest:testCannotTransferByOperator() (gas: 224154)
BillboardTest:testCannotTransferToZeroAddress() (gas: 219598)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9082)
BillboardTest:testCannotWithdrawBidIfAuctionNotEndedOrCleared(uint96) (runs: 256, μ: 614797, ~: 614797)
BillboardTest:testCannotWithdrawBidIfNotFound(uint96) (runs: 256, μ: 730039, ~: 730039)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 982286, ~: 982286)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 982308, ~: 982308)
BillboardTest:testCannotWithdrawBidTwice(uint96) (runs: 256, μ: 1065867, ~: 1065867)
BillboardTest:testClearAuction(uint96) (runs: 256, μ: 712172, ~: 712172)
BillboardTest:testClearAuctions() (gas: 1278587)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 4721233, ~: 1988178)
BillboardTest:testGetTokenURI() (gas: 388799)
BillboardTest:testMintBoard() (gas: 417504)
BillboardTest:testPlaceBid(uint96) (runs: 256, μ: 798110, ~: 800443)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 975879, ~: 975884)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 865740, ~: 869472)
BillboardTest:testClearAuctions() (gas: 1278609)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 4979403, ~: 2145243)
BillboardTest:testGetBlockFromEpoch() (gas: 13412)
BillboardTest:testGetEpochFromBlock() (gas: 14160)
BillboardTest:testGetTokenURI() (gas: 388821)
BillboardTest:testMintBoard() (gas: 417427)
BillboardTest:testPlaceBid(uint96) (runs: 256, μ: 797955, ~: 800443)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 975808, ~: 975813)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 865906, ~: 869405)
BillboardTest:testPlaceBidZeroPrice() (gas: 416644)
BillboardTest:testRemoveToWhitelist() (gas: 238874)
BillboardTest:testSafeTransferByOperator() (gas: 232599)
BillboardTest:testSetBoardByCreator() (gas: 339600)
BillboardTest:testUpgradeRegistry() (gas: 3326686)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1054698, ~: 1054698)
BillboardTest:testSafeTransferByOperator() (gas: 232643)
BillboardTest:testSetBoardByCreator() (gas: 339644)
BillboardTest:testUpgradeRegistry() (gas: 3326599)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1054720, ~: 1054720)
CurationTest:testCannotCurateERC20CurateZeroAmount() (gas: 12194)
CurationTest:testCannotCurateERC20EmptyURI() (gas: 15797)
CurationTest:testCannotCurateERC20IfNotApproval() (gas: 21624)
Expand Down
59 changes: 59 additions & 0 deletions src/test/Billboard/BillboardTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,65 @@ contract BillboardTest is BillboardTestBase {
operator.withdrawBid(_tokenId, _epoch);
}

function testGetEpochFromBlock() public {
// epoch interval = 1
assertEq(operator.getEpochFromBlock(0, 1), 0);
assertEq(operator.getEpochFromBlock(1, 1), 1);

// epoch interval = 101
assertEq(operator.getEpochFromBlock(0, 101), 0);
assertEq(operator.getEpochFromBlock(1, 101), 0);
assertEq(operator.getEpochFromBlock(100, 101), 0);
assertEq(operator.getEpochFromBlock(101, 101), 1);
assertEq(operator.getEpochFromBlock(203, 101), 2);

// epoch interval = MAX
assertEq(operator.getEpochFromBlock(0, type(uint256).max), 0);
assertEq(operator.getEpochFromBlock(1, type(uint256).max), 0);
assertEq(operator.getEpochFromBlock(type(uint256).max, type(uint256).max), 1);
}

function testCannotGetEpochFromBlock() public {
// panic: division or modulo by zero
vm.expectRevert();
assertEq(operator.getEpochFromBlock(0, 0), 0);
vm.expectRevert();
assertEq(operator.getEpochFromBlock(1, 0), 0);
vm.expectRevert();
assertEq(operator.getEpochFromBlock(0, type(uint256).min), 0);

// panic: arithmetic underflow or overflow
vm.expectRevert();
assertEq(operator.getEpochFromBlock(type(uint256).max + 1, type(uint256).max), 1);
vm.expectRevert();
assertEq(operator.getEpochFromBlock(type(uint256).min - 1, type(uint256).min), 1);
}

function testGetBlockFromEpoch() public {
// epoch interval = 1
assertEq(operator.getBlockFromEpoch(0, 1), 0);
assertEq(operator.getBlockFromEpoch(1, 1), 1);

// epoch interval = 101
assertEq(operator.getBlockFromEpoch(0, 101), 0);
assertEq(operator.getBlockFromEpoch(1, 101), 101);
assertEq(operator.getBlockFromEpoch(2, 101), 202);

// epoch interval = MAX
assertEq(operator.getBlockFromEpoch(0, type(uint256).max), 0);
assertEq(operator.getBlockFromEpoch(1, type(uint256).max), type(uint256).max);

// epoch interval = MIN
assertEq(operator.getBlockFromEpoch(0, type(uint256).min), 0);
assertEq(operator.getBlockFromEpoch(1, type(uint256).min), 0);
}

function testCannotGetBlockFromEpoch() public {
// panic: arithmetic underflow or overflow
vm.expectRevert();
assertEq(operator.getBlockFromEpoch(2, type(uint256).max), 0);
}

//////////////////////////////
/// Tax
//////////////////////////////
Expand Down

0 comments on commit 0ab131e

Please sign in to comment.