Skip to content

Commit

Permalink
feat(billboard): add more tests for withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Nov 17, 2023
1 parent 882b9ba commit 14fa055
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 44 deletions.
67 changes: 37 additions & 30 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,52 @@ ACLManagerTest:testGrantRole() (gas: 23547)
ACLManagerTest:testRenounceRole() (gas: 27841)
ACLManagerTest:testRoles() (gas: 15393)
ACLManagerTest:testTransferRole() (gas: 21528)
BillboardTest:testAddToWhitelist() (gas: 37314)
BillboardTest:testAddToWhitelist() (gas: 37249)
BillboardTest:testApproveAndTransfer() (gas: 157829)
BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 11772)
BillboardTest:testCannotApproveByAttacker() (gas: 131382)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 679059)
BillboardTest:testCannotClearAuctionOnNewBoard() (gas: 139133)
BillboardTest:testCalculateTax() (gas: 210)
BillboardTest:testCannnotWithdrawTaxIfSmallAmount(uint8) (runs: 256, μ: 483874, ~: 497559)
BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 449939)
BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 11839)
BillboardTest:testCannotApproveByAttacker() (gas: 131427)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 679282)
BillboardTest:testCannotClearAuctionOnNewBoard() (gas: 139178)
BillboardTest:testCannotMintBoardByAttacker() (gas: 13960)
BillboardTest:testCannotPlaceBidByAttacker() (gas: 145191)
BillboardTest:testCannotPlaceBidTwice(uint96) (runs: 256, μ: 709756, ~: 712100)
BillboardTest:testCannotPlaceBidByAttacker() (gas: 145247)
BillboardTest:testCannotPlaceBidTwice(uint96) (runs: 256, μ: 725916, ~: 732147)
BillboardTest:testCannotRemoveToWhitelistByAttacker() (gas: 11883)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 129339)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 129251)
BillboardTest:testCannotSetBoardProprtiesByAttacker() (gas: 162160)
BillboardTest:testCannotSetIsOpenedByAttacker() (gas: 11751)
BillboardTest:testCannotSetIsOpenedByAttacker() (gas: 11796)
BillboardTest:testCannotSetTaxRateByAttacker() (gas: 11763)
BillboardTest:testCannotTransferByOperator() (gas: 133860)
BillboardTest:testCannotTransferToZeroAddress() (gas: 129414)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 11971)
BillboardTest:testCannotWithdrawBidByAttacker() (gas: 188)
BillboardTest:testCannotWithdrawTaxByAttacker() (gas: 252)
BillboardTest:testClearAuctionIfAuctionEnded() (gas: 752876)
BillboardTest:testGetTokenURI() (gas: 154193)
BillboardTest:testCannotTransferByOperator() (gas: 133927)
BillboardTest:testCannotTransferToZeroAddress() (gas: 129436)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 11949)
BillboardTest:testCannotWithBidTwice(uint96) (runs: 256, μ: 1035780, ~: 1035780)
BillboardTest:testCannotWithdrawBidIfAuctionNotCleared(uint96) (runs: 256, μ: 842804, ~: 842804)
BillboardTest:testCannotWithdrawBidIfAuctionNotEnded(uint96) (runs: 256, μ: 721017, ~: 721017)
BillboardTest:testCannotWithdrawBidIfNotFound() (gas: 480313)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 849293, ~: 849293)
BillboardTest:testCannotWithdrawTaxByAttacker() (gas: 21732)
BillboardTest:testClearAuctionIfAuctionEnded() (gas: 752944)
BillboardTest:testGetTokenURI() (gas: 154215)
BillboardTest:testMintBoard() (gas: 220013)
BillboardTest:testMintBoardByWhitelist() (gas: 157589)
BillboardTest:testMintBoardIfOpened() (gas: 130603)
BillboardTest:testPlaceBidByWhitelist() (gas: 493304)
BillboardTest:testPlaceBidIfAuctionEnded() (gas: 1005279)
BillboardTest:testPlaceBidOnNewBoard(uint96) (runs: 256, μ: 500763, ~: 503713)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 802701, ~: 802701)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 803985, ~: 807888)
BillboardTest:testPlaceBidZeroPrice() (gas: 418787)
BillboardTest:testMintBoardByWhitelist() (gas: 157567)
BillboardTest:testMintBoardIfOpened() (gas: 130581)
BillboardTest:testPlaceBidByWhitelist() (gas: 533304)
BillboardTest:testPlaceBidIfAuctionEnded() (gas: 1065336)
BillboardTest:testPlaceBidOnNewBoard(uint96) (runs: 256, μ: 532879, ~: 543603)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 838439, ~: 845513)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 836369, ~: 848045)
BillboardTest:testPlaceBidZeroPrice() (gas: 418865)
BillboardTest:testRemoveToWhitelist() (gas: 24992)
BillboardTest:testSafeTransferByOperator() (gas: 140039)
BillboardTest:testSetBoardProperties() (gas: 284970)
BillboardTest:testSetBoardPropertiesAfterTransfer() (gas: 328878)
BillboardTest:testSetBoardProperties() (gas: 285015)
BillboardTest:testSetBoardPropertiesAfterTransfer() (gas: 328856)
BillboardTest:testSetIsOpened() (gas: 15932)
BillboardTest:testSetTaxRate() (gas: 24803)
BillboardTest:testUpgradeRegistry() (gas: 2390816)
BillboardTest:testWithdrawBid() (gas: 274)
BillboardTest:testWithdrawTax() (gas: 232)
BillboardTest:testSetTaxRate() (gas: 24738)
BillboardTest:testUpgradeRegistry() (gas: 2471831)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1033494, ~: 1033494)
BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 566620, ~: 566620)
CurationTest:testCannotCurateERC20CurateZeroAmount() (gas: 12194)
CurationTest:testCannotCurateERC20EmptyURI() (gas: 15797)
CurationTest:testCannotCurateERC20IfNotApproval() (gas: 21624)
Expand Down
18 changes: 13 additions & 5 deletions src/Billboard/Billboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ contract Billboard is IBillboard {
}

function calculateTax(uint256 amount_) public view returns (uint256 tax) {
return amount_ * (registry.taxRate() / 100) * registry.leaseTerm();
tax = (amount_ * registry.taxRate() * registry.leaseTerm()) / 1 days / 100;
}

/// @inheritdoc IBillboard
Expand All @@ -318,7 +318,7 @@ contract Billboard is IBillboard {

uint256 amount = _taxAccumulated - _taxWithdrawn;

if (amount <= 0) revert WithdrawFailed();
if (amount <= 0) revert WithdrawFailed("zero amount");

// transfer tax to the owner
registry.transferAmount(msg.sender, amount);
Expand All @@ -329,12 +329,20 @@ contract Billboard is IBillboard {

/// @inheritdoc IBillboard
function withdrawBid(uint256 tokenId_, uint256 auctionId_) external {
// revert if auction is still running
IBillboardRegistry.Auction memory _auction = registry.getAuction(tokenId_, auctionId_);
if (block.timestamp < _auction.endAt) revert AuctionNotEnded();

// revert if auction is not cleared
if (_auction.leaseEndAt == 0) revert WithdrawFailed("auction not cleared");

IBillboardRegistry.Bid memory _bid = registry.getBid(tokenId_, auctionId_, msg.sender);
uint256 amount = _bid.price + _bid.tax;

if (_bid.isWithdrawn) revert WithdrawFailed();
if (_bid.isWon) revert WithdrawFailed();
if (amount <= 0) revert WithdrawFailed();
if (_bid.placedAt == 0) revert BidNotFound();
if (_bid.isWithdrawn) revert WithdrawFailed("withdrawn");
if (_bid.isWon) revert WithdrawFailed("won");
if (amount <= 0) revert WithdrawFailed("zero amount");

// transfer bid price and tax back to the bidder
registry.transferAmount(msg.sender, amount);
Expand Down
6 changes: 4 additions & 2 deletions src/Billboard/IBillboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ interface IBillboard {
/// Error
//////////////////////////////

error Unauthorized(string type_);
error Unauthorized(string reason_);

error BoardNotFound();

error AuctionNotFound();

error AuctionNotEnded();

error BidNotFound();

error BidAlreadyPlaced();

error WithdrawFailed();
error WithdrawFailed(string reason_);

error TransferFailed();

Expand Down
Loading

0 comments on commit 14fa055

Please sign in to comment.