Skip to content

Commit 25d8eb7

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
fix marketplace tests
1 parent ce14ab5 commit 25d8eb7

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/forge-std

src/test/Marketplace.t.sol

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ contract MarketplaceTest is BaseTest {
8989
}
9090

9191
function test_createListing_auctionListing() public {
92+
vm.warp(0);
9293
(uint256 createdListingId, Marketplace.ListingParameters memory createdListing) = createERC721Listing(
9394
getActor(0),
9495
NATIVE_TOKEN,
@@ -114,6 +115,7 @@ contract MarketplaceTest is BaseTest {
114115
vm.deal(getActor(0), 100 ether);
115116

116117
Marketplace.Offer memory winningBid;
118+
vm.warp(0);
117119
(uint256 listingId, ) = createERC721Listing(
118120
getActor(0),
119121
NATIVE_TOKEN,
@@ -123,8 +125,8 @@ contract MarketplaceTest is BaseTest {
123125

124126
assertEq(getActor(0).balance, 100 ether);
125127

126-
vm.warp(1);
127128
vm.prank(getActor(0));
129+
vm.warp(1);
128130
marketplace.offer{ value: 1 ether }(listingId, 1, NATIVE_TOKEN, 1 ether, type(uint256).max);
129131
winningBid = getWinningBid(listingId);
130132
assertEq(getActor(0).balance, 99 ether);
@@ -134,8 +136,8 @@ contract MarketplaceTest is BaseTest {
134136
assertEq(winningBid.currency, NATIVE_TOKEN);
135137
assertEq(winningBid.pricePerToken, 1 ether);
136138

137-
vm.warp(2);
138139
vm.prank(getActor(0));
140+
vm.warp(2);
139141
marketplace.offer{ value: 2 ether }(listingId, 1, NATIVE_TOKEN, 2 ether, type(uint256).max);
140142
winningBid = getWinningBid(listingId);
141143
assertEq(getActor(0).balance, 98 ether);
@@ -152,6 +154,7 @@ contract MarketplaceTest is BaseTest {
152154

153155
// Actor-0 creates an auction listing.
154156
vm.prank(getActor(0));
157+
vm.warp(0);
155158
(uint256 listingId, ) = createERC721Listing(
156159
getActor(0),
157160
NATIVE_TOKEN,
@@ -168,8 +171,8 @@ contract MarketplaceTest is BaseTest {
168171
* - Actor-1 receives auctioned items escrowed in Marketplace.
169172
* - Winning bid amount is escrowed in the contract.
170173
*/
171-
vm.warp(1);
172174
vm.prank(getActor(1));
175+
vm.warp(1);
173176
marketplace.offer{ value: 5 ether }(listingId, 1, NATIVE_TOKEN, 5 ether, type(uint256).max);
174177

175178
assertEq(erc721.ownerOf(listing.tokenId), getActor(1));
@@ -199,14 +202,14 @@ contract MarketplaceTest is BaseTest {
199202

200203
// Actor-0 creates a direct listing with NATIVE_TOKEN as accepted currency.
201204
vm.prank(getActor(0));
205+
vm.warp(0);
202206
(uint256 listingId, ) = createERC721Listing(
203207
getActor(0),
204208
NATIVE_TOKEN,
205209
5 ether,
206210
IMarketplace.ListingType.Direct
207211
);
208212

209-
vm.warp(1);
210213
vm.startPrank(getActor(1));
211214

212215
// Actor-1 mints 4 ether worth of WETH
@@ -216,12 +219,13 @@ contract MarketplaceTest is BaseTest {
216219

217220
// Actor-1 makes an offer to the direct listing for 4 WETH.
218221
weth.approve(address(marketplace), 4 ether);
222+
223+
vm.warp(1);
219224
marketplace.offer(listingId, 1, NATIVE_TOKEN, 4 ether, type(uint256).max);
220225

221226
vm.stopPrank();
222227

223228
// Actor-0 successfully accepts the offer.
224-
vm.warp(2);
225229
Marketplace.Listing memory listing = getListing(listingId);
226230
assertEq(erc721.ownerOf(listing.tokenId), getActor(0));
227231
assertEq(weth.balanceOf(getActor(0)), 0);
@@ -230,6 +234,7 @@ contract MarketplaceTest is BaseTest {
230234
uint256 offerValuePostFee = (4 ether * (MAX_BPS - platformFeeBps)) / MAX_BPS;
231235

232236
vm.prank(getActor(0));
237+
vm.warp(2);
233238
marketplace.acceptOffer(listingId, getActor(1), address(weth), 4 ether);
234239
assertEq(erc721.ownerOf(listing.tokenId), getActor(1));
235240
assertEq(weth.balanceOf(getActor(0)), offerValuePostFee);
@@ -249,7 +254,6 @@ contract MarketplaceTest is BaseTest {
249254
IMarketplace.ListingType.Direct
250255
);
251256

252-
vm.warp(1);
253257
vm.startPrank(getActor(1));
254258

255259
// Actor-1 mints 4 ether worth of WETH
@@ -259,12 +263,13 @@ contract MarketplaceTest is BaseTest {
259263

260264
// Actor-1 makes an offer to the direct listing for 4 WETH.
261265
weth.approve(address(marketplace), 4 ether);
266+
267+
vm.warp(2);
262268
marketplace.offer(listingId, 1, NATIVE_TOKEN, 4 ether, 0);
263269

264270
vm.stopPrank();
265271

266272
// Actor-0 successfully accepts the offer.
267-
vm.warp(2);
268273
Marketplace.Listing memory listing = getListing(listingId);
269274
assertEq(erc721.ownerOf(listing.tokenId), getActor(0));
270275
assertEq(weth.balanceOf(getActor(0)), 0);
@@ -275,9 +280,11 @@ contract MarketplaceTest is BaseTest {
275280
marketplace.acceptOffer(listingId, getActor(1), address(weth), 4 ether);
276281

277282
vm.prank(getActor(1));
278-
marketplace.offer(listingId, 1, NATIVE_TOKEN, 4 ether, 3);
283+
vm.warp(3);
284+
marketplace.offer(listingId, 1, NATIVE_TOKEN, 4 ether, 5);
279285

280286
vm.prank(getActor(0));
287+
vm.warp(4);
281288
marketplace.acceptOffer(listingId, getActor(1), address(weth), 4 ether);
282289
}
283290

0 commit comments

Comments
 (0)