Skip to content

Commit 2ae2aea

Browse files
committed
tests: offer expiration
1 parent 38133d5 commit 2ae2aea

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/test/Marketplace.t.sol

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,51 @@ contract MarketplaceTest is BaseTest {
236236
assertEq(weth.balanceOf(getActor(1)), 0);
237237
}
238238

239+
function test_acceptOffer_expiration() public {
240+
vm.deal(getActor(0), 100 ether);
241+
vm.deal(getActor(1), 100 ether);
242+
243+
// Actor-0 creates a direct listing with NATIVE_TOKEN as accepted currency.
244+
vm.prank(getActor(0));
245+
(uint256 listingId, ) = createERC721Listing(
246+
getActor(0),
247+
NATIVE_TOKEN,
248+
5 ether,
249+
IMarketplace.ListingType.Direct
250+
);
251+
252+
vm.warp(1);
253+
vm.startPrank(getActor(1));
254+
255+
// Actor-1 mints 4 ether worth of WETH
256+
assertEq(weth.balanceOf(getActor(1)), 0);
257+
weth.deposit{ value: 4 ether }();
258+
assertEq(weth.balanceOf(getActor(1)), 4 ether);
259+
260+
// Actor-1 makes an offer to the direct listing for 4 WETH.
261+
weth.approve(address(marketplace), 4 ether);
262+
marketplace.offer(listingId, 1, NATIVE_TOKEN, 4 ether, 0);
263+
264+
vm.stopPrank();
265+
266+
// Actor-0 successfully accepts the offer.
267+
vm.warp(2);
268+
Marketplace.Listing memory listing = getListing(listingId);
269+
assertEq(erc721.ownerOf(listing.tokenId), getActor(0));
270+
assertEq(weth.balanceOf(getActor(0)), 0);
271+
assertEq(weth.balanceOf(getActor(1)), 4 ether);
272+
273+
vm.prank(getActor(0));
274+
vm.expectRevert(bytes("EXPIRED"));
275+
marketplace.acceptOffer(listingId, getActor(1), address(weth), 4 ether);
276+
277+
vm.prank(getActor(1));
278+
marketplace.offer(listingId, 1, NATIVE_TOKEN, 4 ether, 3);
279+
280+
vm.prank(getActor(0));
281+
marketplace.acceptOffer(listingId, getActor(1), address(weth), 4 ether);
282+
}
283+
239284
function test_createListing_startTime_past() public {
240285
address to = getActor(0);
241286
uint256 tokenId = erc721.nextTokenIdToMint();

0 commit comments

Comments
 (0)