diff --git a/.gas-snapshot b/.gas-snapshot index b3c2aec..8f28159 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -37,22 +37,22 @@ BillboardTest:testCannotWithdrawBidTwice(uint96) (runs: 256, μ: 1108455, ~: 110 BillboardTest:testClearAuction(uint96) (runs: 256, μ: 729526, ~: 729526) BillboardTest:testClearAuctionIfAlreadyCleared() (gas: 736674) BillboardTest:testClearAuctions() (gas: 1310672) -BillboardTest:testGetBidderBids(uint8,uint8,uint8) (runs: 256, μ: 1503234, ~: 1134296) -BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 257, μ: 8185787, ~: 6273841) +BillboardTest:testGetBidderBids(uint8,uint8,uint8) (runs: 256, μ: 1505979, ~: 1138329) +BillboardTest:testGetBids(uint8,uint8,uint8) (runs: 256, μ: 8242518, ~: 6452578) BillboardTest:testGetBlockFromEpoch() (gas: 16849) BillboardTest:testGetEpochFromBlock() (gas: 17968) BillboardTest:testGetTokenURI() (gas: 391497) BillboardTest:testMintBoard() (gas: 585644) -BillboardTest:testPlaceBid(uint96) (runs: 257, μ: 837566, ~: 838186) -BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 257, μ: 1009249, ~: 1009253) -BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 257, μ: 906266, ~: 907196) +BillboardTest:testPlaceBid(uint96) (runs: 256, μ: 837564, ~: 838186) +BillboardTest:testPlaceBidWithHigherPrice(uint96) (runs: 256, μ: 1009249, ~: 1009253) +BillboardTest:testPlaceBidWithSamePrices(uint96) (runs: 256, μ: 906263, ~: 907196) BillboardTest:testPlaceBidZeroPrice() (gas: 430502) BillboardTest:testSafeTransferByOperator() (gas: 235301) BillboardTest:testSetBidURIs() (gas: 657544) BillboardTest:testSetBoardByCreator() (gas: 342349) BillboardTest:testSetClosed() (gas: 240866) BillboardTest:testSetWhitelist() (gas: 245316) -BillboardTest:testUpgradeRegistry() (gas: 3655978) +BillboardTest:testUpgradeRegistry() (gas: 3708725) BillboardTest:testWithdrawBid(uint96) (runs: 256, μ: 1096420, ~: 1096420) BillboardTest:testWithdrawBidIfClosed(uint96) (runs: 256, μ: 694679, ~: 694679) BillboardTest:testWithdrawTax(uint96) (runs: 256, μ: 734859, ~: 734859) @@ -73,8 +73,8 @@ DistributionTest:testCannotClaimIfAlreadyClaimed() (gas: 284835) DistributionTest:testCannotClaimIfInsufficientBalance() (gas: 394264) DistributionTest:testCannotClaimIfInvalidProof() (gas: 245236) DistributionTest:testCannotClaimIfInvalidTreeId() (gas: 243332) -DistributionTest:testCannotDropIfInsufficientAllowance(uint256) (runs: 257, μ: 212269, ~: 212283) -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) @@ -87,14 +87,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, μ: 5348891, ~: 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) @@ -113,7 +113,7 @@ LogbookTest:testPublishZh5000() (gas: 607690) LogbookTest:testSetDescription() (gas: 140760) LogbookTest:testSetForkPrice() (gas: 153925) LogbookTest:testSetTitle() (gas: 168680) -LogbookTest:testSplitRoyalty(uint8,uint8,uint96) (runs: 257, μ: 1963054, ~: 965338) +LogbookTest:testSplitRoyalty(uint8,uint8,uint96) (runs: 256, μ: 1959072, ~: 965338) LogbookTest:testWithdraw() (gas: 7284400) SnapperTest:testCannotInitRegionByNotOwner() (gas: 11365) SnapperTest:testCannotReInitRegion() (gas: 14373) @@ -121,10 +121,10 @@ 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) @@ -161,11 +161,11 @@ TheSpaceTest:testSetColor() (gas: 331348) TheSpaceTest:testSetMintTax() (gas: 271715) TheSpaceTest:testSetPixel(uint256) (runs: 256, μ: 403816, ~: 403816) TheSpaceTest:testSetPrice(uint256) (runs: 256, μ: 304652, ~: 304652) -TheSpaceTest:testSetPriceByOperator(uint96) (runs: 257, μ: 354785, ~: 354785) +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) diff --git a/src/Billboard/Billboard.sol b/src/Billboard/Billboard.sol index 6a719fb..0102c93 100644 --- a/src/Billboard/Billboard.sol +++ b/src/Billboard/Billboard.sol @@ -312,24 +312,45 @@ contract Billboard is IBillboard { address bidder_, uint256 limit_, uint256 offset_ - ) external view returns (uint256 total, uint256 limit, uint256 offset, IBillboardRegistry.Bid[] memory bids) { + ) + external + view + returns ( + uint256 total, + uint256 limit, + uint256 offset, + IBillboardRegistry.Bid[] memory bids, + uint256[] memory epochs + ) + { uint256 _total = registry.getBidderBidCount(tokenId_, bidder_); if (limit_ == 0 || offset_ >= _total) { - return (_total, limit_, offset_, new IBillboardRegistry.Bid[](0)); + return (_total, limit_, offset_, new IBillboardRegistry.Bid[](0), new uint256[](0)); } uint256 _left = _total - offset_; uint256 _size = _left > limit_ ? limit_ : _left; - bids = new IBillboardRegistry.Bid[](_size); + (bids, epochs) = _getBidsAndEpochs(tokenId_, bidder_, offset_, _size); - for (uint256 i = 0; i < _size; i++) { + return (_total, limit_, offset_, bids, epochs); + } + + function _getBidsAndEpochs( + uint256 tokenId_, + address bidder_, + uint256 offset_, + uint256 size_ + ) internal view returns (IBillboardRegistry.Bid[] memory bids, uint256[] memory epochs) { + bids = new IBillboardRegistry.Bid[](size_); + epochs = new uint256[](size_); + + for (uint256 i = 0; i < size_; i++) { uint256 _epoch = registry.bidderBids(tokenId_, bidder_, offset_ + i); bids[i] = registry.getBid(tokenId_, _epoch, bidder_); + epochs[i] = _epoch; } - - return (_total, limit_, offset_, bids); } /// @inheritdoc IBillboard diff --git a/src/Billboard/IBillboard.sol b/src/Billboard/IBillboard.sol index ef00f6d..09cf895 100644 --- a/src/Billboard/IBillboard.sol +++ b/src/Billboard/IBillboard.sol @@ -232,13 +232,23 @@ interface IBillboard { * @return limit Limit of returned bids. * @return offset Offset of returned bids. * @return bids Bids. + * @return epoches Epoches of bids. */ function getBidderBids( uint256 tokenId_, address bidder_, uint256 limit_, uint256 offset_ - ) external view returns (uint256 total, uint256 limit, uint256 offset, IBillboardRegistry.Bid[] memory bids); + ) + external + view + returns ( + uint256 total, + uint256 limit, + uint256 offset, + IBillboardRegistry.Bid[] memory bids, + uint256[] memory epoches + ); /** * @notice Withdraw bid that were not won by auction id; diff --git a/src/test/Billboard/BillboardTest.t.sol b/src/test/Billboard/BillboardTest.t.sol index f569e0a..ae95514 100644 --- a/src/test/Billboard/BillboardTest.t.sol +++ b/src/test/Billboard/BillboardTest.t.sol @@ -574,6 +574,7 @@ contract BillboardTest is BillboardTestBase { } } + // Main function to test getting bidder bids function testGetBidderBids(uint8 _bidCount, uint8 _limit, uint8 _offset) public { vm.assume(_bidCount > 0); vm.assume(_bidCount <= 10); @@ -582,6 +583,22 @@ contract BillboardTest is BillboardTestBase { (uint256 _tokenId, IBillboardRegistry.Board memory _board) = _mintBoard(); + _placeBids(_bidCount, _tokenId, _board); + + // Get bidder bids + ( + uint256 totalBids, + uint256 limit, + uint256 offset, + IBillboardRegistry.Bid[] memory bids, + uint256[] memory epoches + ) = operator.getBidderBids(_tokenId, USER_A, _limit, _offset); + + _assertBidderBids(_bidCount, _limit, _offset, totalBids, limit, offset, bids, epoches, _board); + } + + // Helper function to place bids + function _placeBids(uint8 _bidCount, uint256 _tokenId, IBillboardRegistry.Board memory _board) internal { for (uint8 i = 0; i < _bidCount; i++) { uint256 _epoch = operator.getEpochFromBlock(_board.startedAt, block.number, _board.epochInterval) + i; @@ -598,23 +615,36 @@ contract BillboardTest is BillboardTestBase { operator.placeBid(_tokenId, _epoch, _price); vm.stopPrank(); } + } - // get bidder bids - (uint256 _t, uint256 _l, uint256 _o, IBillboardRegistry.Bid[] memory _bids) = operator.getBidderBids( - _tokenId, - USER_A, - _limit, - _offset - ); - uint256 _left = _t - _offset; - uint256 _size = _left > _limit ? _limit : _left; - assertEq(_t, _bidCount); - assertEq(_l, _limit); - assertEq(_bids.length, _size); - assertEq(_o, _offset); - for (uint256 i = 0; i < _size; i++) { - uint256 _price = 1 ether + _offset + i; - assertEq(_bids[i].price, _price); + // Helper function to assert bidder bids + function _assertBidderBids( + uint8 _bidCount, + uint8 _limit, + uint8 _offset, + uint256 totalBids, + uint256 limit, + uint256 offset, + IBillboardRegistry.Bid[] memory bids, + uint256[] memory epoches, + IBillboardRegistry.Board memory _board + ) internal { + uint256 remainingBids = totalBids - offset; + uint256 size = remainingBids > limit ? limit : remainingBids; + + assertEq(totalBids, _bidCount); + assertEq(limit, _limit); + assertEq(bids.length, size); + assertEq(offset, _offset); + + for (uint256 i = 0; i < size; i++) { + uint256 expectedPrice = 1 ether + _offset + i; + uint256 expectedEpoch = operator.getEpochFromBlock(_board.startedAt, block.number, _board.epochInterval) + + _offset + + i; + + assertEq(bids[i].price, expectedPrice); + assertEq(epoches[i], expectedEpoch); } }