Skip to content

Commit

Permalink
feat(billboard): return cleared auctions instead of empty
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Jul 22, 2024
1 parent b9dcf1d commit 0a39ceb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 40 deletions.
79 changes: 40 additions & 39 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,51 @@ ACLManagerTest:testGrantRole() (gas: 23547)
ACLManagerTest:testRenounceRole() (gas: 27841)
ACLManagerTest:testRoles() (gas: 15393)
ACLManagerTest:testTransferRole() (gas: 21528)
BillboardTest:testApproveAndTransfer() (gas: 258021)
BillboardTest:testCalculateTax() (gas: 539866)
BillboardTest:testApproveAndTransfer() (gas: 258043)
BillboardTest:testCalculateTax() (gas: 539888)
BillboardTest:testCannnotWithdrawTaxIfZero() (gas: 20184)
BillboardTest:testCannotApproveByAttacker() (gas: 224303)
BillboardTest:testCannotCalculateTax() (gas: 218949)
BillboardTest:testCannotClearAuctionIfAuctionNotEnded() (gas: 255688)
BillboardTest:testCannotClearAuctionIfClosed() (gas: 252814)
BillboardTest:testCannotClearAuctionIfNoBid() (gas: 260854)
BillboardTest:testCannotClearAuctionIfClosed() (gas: 252836)
BillboardTest:testCannotClearAuctionIfNoBid() (gas: 260876)
BillboardTest:testCannotGetBlockFromEpoch() (gas: 8622)
BillboardTest:testCannotGetEpochFromBlock() (gas: 18458)
BillboardTest:testCannotPlaceBidIfAuctionEnded() (gas: 278692)
BillboardTest:testCannotPlaceBidIfClosed() (gas: 252690)
BillboardTest:testCannotPlaceBidIfClosed() (gas: 252735)
BillboardTest:testCannotPlaceBidIfNotWhitelisted() (gas: 463932)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 221525)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 221547)
BillboardTest:testCannotSetBoardByAttacker() (gas: 229522)
BillboardTest:testCannotSetBoardByOwner() (gas: 361740)
BillboardTest:testCannotSetClosedByAttacker() (gas: 228476)
BillboardTest:testCannotSetClosedByAttacker() (gas: 228498)
BillboardTest:testCannotSetWhitelistByAttacker() (gas: 228686)
BillboardTest:testCannotTransferByOperator() (gas: 226659)
BillboardTest:testCannotTransferToZeroAddress() (gas: 222169)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9105)
BillboardTest:testCannotTransferByOperator() (gas: 226704)
BillboardTest:testCannotTransferToZeroAddress() (gas: 222191)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9127)
BillboardTest:testCannotWithdrawBidIfAuctionNotEndedOrCleared(uint96) (runs: 256, μ: 606433, ~: 606433)
BillboardTest:testCannotWithdrawBidIfNotFound(uint96) (runs: 256, μ: 723940, ~: 723940)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 975407, ~: 975407)
BillboardTest:testCannotWithdrawBidIfWon(uint96) (runs: 256, μ: 975429, ~: 975429)
BillboardTest:testCannotWithdrawBidTwice(uint96) (runs: 256, μ: 1059869, ~: 1059869)
BillboardTest:testClearAuction(uint96) (runs: 256, μ: 705310, ~: 705310)
BillboardTest:testClearAuctions() (gas: 1262174)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 7743197, ~: 5910727)
BillboardTest:testClearAuctionIfAlreadyCleared() (gas: 712435)
BillboardTest:testClearAuctions() (gas: 1262152)
BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 7753801, ~: 5910727)
BillboardTest:testGetBlockFromEpoch() (gas: 17135)
BillboardTest:testGetEpochFromBlock() (gas: 18232)
BillboardTest:testGetTokenURI() (gas: 391474)
BillboardTest:testMintBoard() (gas: 585732)
BillboardTest:testPlaceBid(uint96) (runs: 257, μ: 788829, ~: 789449)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 257, μ: 970451, ~: 970458)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 257, μ: 857638, ~: 858568)
BillboardTest:testGetEpochFromBlock() (gas: 18167)
BillboardTest:testGetTokenURI() (gas: 391429)
BillboardTest:testMintBoard() (gas: 585710)
BillboardTest:testPlaceBid(uint96) (runs: 256, μ: 788827, ~: 789449)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 970451, ~: 970458)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 857635, ~: 858568)
BillboardTest:testPlaceBidZeroPrice() (gas: 406133)
BillboardTest:testSafeTransferByOperator() (gas: 235323)
BillboardTest:testSetBidURIs() (gas: 633218)
BillboardTest:testSetBoardByCreator() (gas: 342194)
BillboardTest:testSafeTransferByOperator() (gas: 235236)
BillboardTest:testSetBidURIs() (gas: 633240)
BillboardTest:testSetBoardByCreator() (gas: 342216)
BillboardTest:testSetClosed() (gas: 240886)
BillboardTest:testSetWhitelist() (gas: 245315)
BillboardTest:testUpgradeRegistry() (gas: 3494596)
BillboardTest:testUpgradeRegistry() (gas: 3495108)
BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1047812, ~: 1047812)
BillboardTest:testWithdrawBidIfClosed(uint96) (runs: 256, μ: 670375, ~: 670375)
BillboardTest:testWithdrawBidIfClosed(uint96) (runs: 256, μ: 670397, ~: 670397)
BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 710598, ~: 710598)
CurationTest:testCannotCurateERC20CurateZeroAmount() (gas: 12194)
CurationTest:testCannotCurateERC20EmptyURI() (gas: 15797)
Expand All @@ -71,8 +72,8 @@ DistributionTest:testCannotClaimIfAlreadyClaimed() (gas: 284835)
DistributionTest:testCannotClaimIfInsufficientBalance() (gas: 394264)
DistributionTest:testCannotClaimIfInvalidProof() (gas: 245236)
DistributionTest:testCannotClaimIfInvalidTreeId() (gas: 243332)
DistributionTest:testCannotDropIfInsufficientAllowance(uint256) (runs: 257, μ: 212269, ~: 212285)
DistributionTest:testCannotDropIfInsufficientBalance(uint256) (runs: 257, μ: 214708, ~: 214740)
DistributionTest:testCannotDropIfInsufficientAllowance(uint256) (runs: 256, μ: 212269, ~: 212284)
DistributionTest:testCannotDropIfInsufficientBalance(uint256) (runs: 256, μ: 214708, ~: 214740)
DistributionTest:testCannotDropIfZeroAmount() (gas: 148793)
DistributionTest:testCannotDropTwiceWithSameTreeId() (gas: 307260)
DistributionTest:testCannotSetAdminByAdmin() (gas: 17334)
Expand All @@ -85,14 +86,14 @@ DistributionTest:testSetAdmin() (gas: 20239)
DistributionTest:testSweep() (gas: 253087)
LogbookNFTSVGTest:testTokenURI(uint8,uint8,uint16) (runs: 256, μ: 2613180, ~: 1746428)
LogbookTest:testClaim() (gas: 135608)
LogbookTest:testDonate(uint96) (runs: 257, μ: 156550, ~: 156936)
LogbookTest:testDonateWithCommission(uint96,uint96) (runs: 257, μ: 146620, ~: 140444)
LogbookTest:testFork(uint96,string) (runs: 257, μ: 452543, ~: 453928)
LogbookTest:testForkRecursively(uint8,uint96) (runs: 257, μ: 5363774, ~: 1801537)
LogbookTest:testForkWithCommission(uint96,string,uint256) (runs: 257, μ: 342132, ~: 257636)
LogbookTest:testDonate(uint96) (runs: 256, μ: 156549, ~: 156936)
LogbookTest:testDonateWithCommission(uint96,uint96) (runs: 256, μ: 146644, ~: 140444)
LogbookTest:testFork(uint96,string) (runs: 256, μ: 452537, ~: 453928)
LogbookTest:testForkRecursively(uint8,uint96) (runs: 256, μ: 5351224, ~: 1801537)
LogbookTest:testForkWithCommission(uint96,string,uint256) (runs: 256, μ: 342465, ~: 257636)
LogbookTest:testMulticall() (gas: 284999)
LogbookTest:testPublicSale() (gas: 207337)
LogbookTest:testPublish(string) (runs: 257, μ: 264063, ~: 263590)
LogbookTest:testPublish(string) (runs: 256, μ: 264065, ~: 263590)
LogbookTest:testPublishEn1000() (gas: 243477)
LogbookTest:testPublishEn140() (gas: 221241)
LogbookTest:testPublishEn200() (gas: 222826)
Expand All @@ -111,18 +112,18 @@ LogbookTest:testPublishZh5000() (gas: 607690)
LogbookTest:testSetDescription() (gas: 140760)
LogbookTest:testSetForkPrice() (gas: 153925)
LogbookTest:testSetTitle() (gas: 168680)
LogbookTest:testSplitRoyalty(uint8,uint8,uint96) (runs: 257, μ: 1963734, ~: 965338)
LogbookTest:testSplitRoyalty(uint8,uint8,uint96) (runs: 256, μ: 1959072, ~: 965338)
LogbookTest:testWithdraw() (gas: 7284400)
SnapperTest:testCannotInitRegionByNotOwner() (gas: 11365)
SnapperTest:testCannotReInitRegion() (gas: 14373)
SnapperTest:testCannotTakeSnapshotBeforeInit() (gas: 15717)
SnapperTest:testCannotTakeSnapshotByNotOwner() (gas: 12478)
SnapperTest:testCannotTakeSnapshotWrongLastBlock() (gas: 49242)
SnapperTest:testCannotTakeSnapshotWrongSnapshotBlock() (gas: 23899)
SnapperTest:testInitRegion(uint256) (runs: 257, μ: 114408, ~: 114408)
SnapperTest:testInitRegion(uint256) (runs: 256, μ: 114408, ~: 114408)
SnapperTest:testTakeSnapshot() (gas: 47831)
TheSpaceTest:testBatchBid() (gas: 695308)
TheSpaceTest:testBatchSetPixels(uint16,uint8) (runs: 257, μ: 371405, ~: 372904)
TheSpaceTest:testBatchSetPixels(uint16,uint8) (runs: 256, μ: 371399, ~: 372904)
TheSpaceTest:testBidDefaultedToken() (gas: 413399)
TheSpaceTest:testBidExistingToken() (gas: 360023)
TheSpaceTest:testBidNewToken() (gas: 303729)
Expand All @@ -134,7 +135,7 @@ TheSpaceTest:testCannotGetTaxWithNonExistingToken() (gas: 16379)
TheSpaceTest:testCannotGetTokenURIInLogicContract() (gas: 300973)
TheSpaceTest:testCannotSetColorByAttacker() (gas: 305326)
TheSpaceTest:testCannotSetConfigByAttacker() (gas: 12031)
TheSpaceTest:testCannotSetPixel(uint256) (runs: 257, μ: 314857, ~: 314857)
TheSpaceTest:testCannotSetPixel(uint256) (runs: 256, μ: 314857, ~: 314857)
TheSpaceTest:testCannotSetPriceByNonOwner() (gas: 305424)
TheSpaceTest:testCannotSetTokenImageURIByNonACLManager() (gas: 11862)
TheSpaceTest:testCannotSetTotalSupplyByAttacker() (gas: 11836)
Expand All @@ -158,12 +159,12 @@ TheSpaceTest:testGetTokenURI() (gas: 333462)
TheSpaceTest:testSetColor() (gas: 331348)
TheSpaceTest:testSetMintTax() (gas: 271715)
TheSpaceTest:testSetPixel(uint256) (runs: 256, μ: 403816, ~: 403816)
TheSpaceTest:testSetPrice(uint256) (runs: 257, μ: 304652, ~: 304652)
TheSpaceTest:testSetPriceByOperator(uint96) (runs: 257, μ: 354785, ~: 354785)
TheSpaceTest:testSetPrice(uint256) (runs: 256, μ: 304652, ~: 304652)
TheSpaceTest:testSetPriceByOperator(uint96) (runs: 256, μ: 354785, ~: 354785)
TheSpaceTest:testSetPriceTooHigh() (gas: 314504)
TheSpaceTest:testSetTaxRate() (gas: 347951)
TheSpaceTest:testSetTokenImageURI() (gas: 355813)
TheSpaceTest:testSetTotalSupply(uint256) (runs: 257, μ: 352202, ~: 352208)
TheSpaceTest:testSetTotalSupply(uint256) (runs: 256, μ: 352202, ~: 352208)
TheSpaceTest:testSetTreasuryShare() (gas: 384288)
TheSpaceTest:testSettleTax() (gas: 339465)
TheSpaceTest:testTaxCalculation() (gas: 402405)
Expand Down
2 changes: 1 addition & 1 deletion src/Billboard/Billboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ contract Billboard is IBillboard {

// skip if auction is already cleared
if (_highestBid.isWon) {
return (address(0), 0, 0);
return (_highestBidder, _highestBid.price, _highestBid.tax);
}

address _prevOwner = registry.ownerOf(tokenId_);
Expand Down
24 changes: 24 additions & 0 deletions src/test/Billboard/BillboardTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,30 @@ contract BillboardTest is BillboardTestBase {
assertEq(usdt.balanceOf(USER_A), 0);
}

function testClearAuctionIfAlreadyCleared() public {
(uint256 _tokenId, IBillboardRegistry.Board memory _board) = _mintBoard();
uint256 _epoch = operator.getEpochFromBlock(_board.startedAt, block.number, _board.epochInterval);
uint256 _clearedAt = operator.getBlockFromEpoch(_board.startedAt, _epoch + 1, _board.epochInterval);
uint256 _price = 1 ether;
uint256 _tax = operator.calculateTax(_tokenId, _price);

// place bid
_placeBid(_tokenId, _epoch, USER_A, 1 ether);

// clear auction
vm.roll(_clearedAt);
(address _highestBidder1, uint256 _price1, uint256 _tax1) = operator.clearAuction(_tokenId, _epoch);
assertEq(_highestBidder1, USER_A);
assertEq(_price1, _price);
assertEq(_tax1, _tax);

// clear auction again
(address _highestBidder2, uint256 _price2, uint256 _tax2) = operator.clearAuction(_tokenId, _epoch);
assertEq(_highestBidder2, USER_A);
assertEq(_price2, _price);
assertEq(_tax2, _tax);
}

function testClearAuctions() public {
(uint256 _tokenId1, IBillboardRegistry.Board memory _board1) = _mintBoard();
(uint256 _tokenId2, IBillboardRegistry.Board memory _board2) = _mintBoard();
Expand Down

0 comments on commit 0a39ceb

Please sign in to comment.