Skip to content

Commit

Permalink
test(billboard): revise tests for auction & bids
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Jul 2, 2024
1 parent 380ba7c commit f84f906
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 332 deletions.
38 changes: 22 additions & 16 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ ACLManagerTest:testGrantRole() (gas: 23547)
ACLManagerTest:testRenounceRole() (gas: 27841)
ACLManagerTest:testRoles() (gas: 15393)
ACLManagerTest:testTransferRole() (gas: 21528)
BillboardTest:testAddToWhitelist() (gas: 220255)
BillboardTest:testApproveAndTransfer() (gas: 222603)
BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 193898)
BillboardTest:testCannotApproveByAttacker() (gas: 191753)
BillboardTest:testCannotRemoveToWhitelistByAttacker() (gas: 193983)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 189023)
BillboardTest:testCannotSetBoardByAttacker() (gas: 195085)
BillboardTest:testCannotSetBoardByOwner() (gas: 329033)
BillboardTest:testCannotTransferByOperator() (gas: 194267)
BillboardTest:testCannotTransferToZeroAddress() (gas: 189754)
BillboardTest:testAddToWhitelist() (gas: 252070)
BillboardTest:testApproveAndTransfer() (gas: 252645)
BillboardTest:testCannotAddToWhitelistByAttacker() (gas: 225643)
BillboardTest:testCannotApproveByAttacker() (gas: 221634)
BillboardTest:testCannotPlaceBidByAttacker() (gas: 459506)
BillboardTest:testCannotPlaceBidIfAuctionEnded() (gas: 598942)
BillboardTest:testCannotRemoveToWhitelistByAttacker() (gas: 225773)
BillboardTest:testCannotSafeTransferByAttacker() (gas: 218748)
BillboardTest:testCannotSetBoardByAttacker() (gas: 226787)
BillboardTest:testCannotSetBoardByOwner() (gas: 358929)
BillboardTest:testCannotTransferByOperator() (gas: 224012)
BillboardTest:testCannotTransferToZeroAddress() (gas: 219434)
BillboardTest:testCannotUpgradeRegistryByAttacker() (gas: 9016)
BillboardTest:testGetTokenURI() (gas: 358637)
BillboardTest:testMintBoard() (gas: 372377)
BillboardTest:testRemoveToWhitelist() (gas: 206806)
BillboardTest:testSafeTransferByOperator() (gas: 202755)
BillboardTest:testSetBoardByCreator() (gas: 307453)
BillboardTest:testUpgradeRegistry() (gas: 3311256)
BillboardTest:testGetTokenURI() (gas: 388561)
BillboardTest:testMintBoard() (gas: 417198)
BillboardTest:testPlaceBid(uint96) (runs: 256, μ: 599051, ~: 601384)
BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 953951, ~: 953956)
BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 846964, ~: 850463)
BillboardTest:testPlaceBidZeroPrice() (gas: 416316)
BillboardTest:testRemoveToWhitelist() (gas: 238710)
BillboardTest:testSafeTransferByOperator() (gas: 232457)
BillboardTest:testSetBoardByCreator() (gas: 339338)
BillboardTest:testUpgradeRegistry() (gas: 3319574)
CurationTest:testCannotCurateERC20CurateZeroAmount() (gas: 12194)
CurationTest:testCannotCurateERC20EmptyURI() (gas: 15797)
CurationTest:testCannotCurateERC20IfNotApproval() (gas: 21624)
Expand Down
6 changes: 3 additions & 3 deletions src/Billboard/Billboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ contract Billboard is IBillboard {
/// @inheritdoc IBillboard
function mintBoard(uint256 taxRate_, uint256 epochInterval_) external returns (uint256 tokenId) {
require(epochInterval_ > 0, "Zero epoch interval");

tokenId = registry.newBoard(msg.sender, taxRate_, epochInterval_);
whitelist[tokenId][msg.sender] = true;
}

/// @inheritdoc IBillboard
Expand Down Expand Up @@ -216,7 +216,7 @@ contract Billboard is IBillboard {
address boardCreator_,
uint256 epoch_
) private returns (address highestBidder, uint256 price, uint256 tax) {
address _highestBidder = registry.higgestBidder(tokenId_, epoch_);
address _highestBidder = registry.highestBidder(tokenId_, epoch_);
IBillboardRegistry.Bid memory _highestBid = registry.getBid(tokenId_, epoch_, _highestBidder);

// skip if auction is already cleared
Expand Down Expand Up @@ -297,7 +297,7 @@ contract Billboard is IBillboard {
require(block.number < _endedAt, "Auction not ended");

// revert if auction is not cleared
address _highestBidder = registry.higgestBidder(tokenId_, epoch_);
address _highestBidder = registry.highestBidder(tokenId_, epoch_);
IBillboardRegistry.Bid memory _highestBid = registry.getBid(tokenId_, epoch_, _highestBidder);
require(!_highestBid.isWon, "Auction not cleared");

Expand Down
16 changes: 8 additions & 8 deletions src/Billboard/BillboardRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
mapping(uint256 => Board) public boards;

// tokenId => epoch => bidder
mapping(uint256 => mapping(uint256 => address)) public higgestBidder;
mapping(uint256 => mapping(uint256 => address)) public highestBidder;

// tokenId => epoch => bidders
mapping(uint256 => mapping(uint256 => address[])) public bidders;
Expand Down Expand Up @@ -157,7 +157,7 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
// add to auction bidders if new bid
bidders[tokenId_][epoch_].push(bidder_);

_setHiggestBidder(tokenId_, epoch_, price_, bidder_);
_sethighestBidder(tokenId_, epoch_, price_, bidder_);

emit BidUpdated(tokenId_, epoch_, bidder_, price_, tax_, contentURI_, redirectURI_);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
_bid.redirectURI = redirectURI_;
}

_setHiggestBidder(tokenId_, epoch_, price_, bidder_);
_sethighestBidder(tokenId_, epoch_, price_, bidder_);

emit BidUpdated(tokenId_, epoch_, bidder_, price_, tax_, contentURI_, redirectURI_);
}
Expand All @@ -194,11 +194,11 @@ contract BillboardRegistry is IBillboardRegistry, ERC721 {
//
// Note: for same price, the first bidder will always be
// the highest bidder since the block.number is always greater.
function _setHiggestBidder(uint256 tokenId_, uint256 epoch_, uint256 price_, address bidder_) internal {
address highestBidder = higgestBidder[tokenId_][epoch_];
Bid memory highestBid = bids[tokenId_][epoch_][highestBidder];
if (highestBidder == address(0) || price_ > highestBid.price) {
higgestBidder[tokenId_][epoch_] = bidder_;
function _sethighestBidder(uint256 tokenId_, uint256 epoch_, uint256 price_, address bidder_) internal {
address _highestBidder = highestBidder[tokenId_][epoch_];
Bid memory highestBid = bids[tokenId_][epoch_][_highestBidder];
if (_highestBidder == address(0) || price_ > highestBid.price) {
highestBidder[tokenId_][epoch_] = bidder_;
}
}

Expand Down
Loading

0 comments on commit f84f906

Please sign in to comment.