|
| 1 | +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; |
| 2 | +import { expect } from "chai"; |
| 3 | +import { parseEther } from "ethers/lib/utils"; |
| 4 | +import { ethers } from "hardhat"; |
| 5 | +import { ItemType } from "../constants"; |
| 6 | +import { CreateOrderInput } from "../types"; |
| 7 | +import { describeWithFixture } from "./utils/setup"; |
| 8 | + |
| 9 | +describeWithFixture("As a user I want to cancel an order", (fixture) => { |
| 10 | + let offerer: SignerWithAddress; |
| 11 | + let zone: SignerWithAddress; |
| 12 | + let fulfiller: SignerWithAddress; |
| 13 | + let standardCreateOrderInput: CreateOrderInput; |
| 14 | + const nftId = "1"; |
| 15 | + |
| 16 | + before(async () => { |
| 17 | + [offerer, zone, fulfiller] = await ethers.getSigners(); |
| 18 | + }); |
| 19 | + |
| 20 | + beforeEach(async () => { |
| 21 | + const { testErc721 } = fixture; |
| 22 | + |
| 23 | + await testErc721.mint(offerer.address, nftId); |
| 24 | + |
| 25 | + standardCreateOrderInput = { |
| 26 | + startTime: "0", |
| 27 | + offer: [ |
| 28 | + { |
| 29 | + itemType: ItemType.ERC721, |
| 30 | + token: testErc721.address, |
| 31 | + identifier: nftId, |
| 32 | + }, |
| 33 | + ], |
| 34 | + consideration: [ |
| 35 | + { |
| 36 | + amount: parseEther("10").toString(), |
| 37 | + recipient: offerer.address, |
| 38 | + }, |
| 39 | + ], |
| 40 | + // 2.5% fee |
| 41 | + fees: [{ recipient: zone.address, basisPoints: 250 }], |
| 42 | + }; |
| 43 | + }); |
| 44 | + |
| 45 | + it("validate then bulk cancel orders", async () => { |
| 46 | + const { seaport } = fixture; |
| 47 | + |
| 48 | + const { executeAllActions } = await seaport.createOrder( |
| 49 | + standardCreateOrderInput |
| 50 | + ); |
| 51 | + const executeAllActionsOnChainOrder = ( |
| 52 | + await seaport.createOrder(standardCreateOrderInput) |
| 53 | + ).executeAllActions; |
| 54 | + |
| 55 | + const offChainOrder = await executeAllActions(); |
| 56 | + const onChainOrder = await executeAllActionsOnChainOrder(); |
| 57 | + |
| 58 | + // Remove signature |
| 59 | + onChainOrder.signature = "0x"; |
| 60 | + |
| 61 | + await seaport.validate([onChainOrder], offerer.address).transact(); |
| 62 | + await seaport.bulkCancelOrders(offerer.address).transact(); |
| 63 | + |
| 64 | + const { executeAllActions: executeAllFulfillActionsOffChainOrder } = |
| 65 | + await seaport.fulfillOrder({ |
| 66 | + order: offChainOrder, |
| 67 | + accountAddress: fulfiller.address, |
| 68 | + }); |
| 69 | + |
| 70 | + const { executeAllActions: executeAllFulfillActionsOnChainOrder } = |
| 71 | + await seaport.fulfillOrder({ |
| 72 | + order: onChainOrder, |
| 73 | + accountAddress: fulfiller.address, |
| 74 | + }); |
| 75 | + |
| 76 | + await expect(executeAllFulfillActionsOffChainOrder()).to.be.reverted; |
| 77 | + await expect(executeAllFulfillActionsOnChainOrder()).to.be.reverted; |
| 78 | + |
| 79 | + expect(await seaport.getCounter(offerer.address)).to.equal( |
| 80 | + offChainOrder.parameters.counter + 1 |
| 81 | + ); |
| 82 | + }); |
| 83 | + |
| 84 | + it("validate then cancel single order", async () => { |
| 85 | + const { seaport } = fixture; |
| 86 | + |
| 87 | + const { executeAllActions } = await seaport.createOrder( |
| 88 | + standardCreateOrderInput |
| 89 | + ); |
| 90 | + const order = await executeAllActions(); |
| 91 | + |
| 92 | + // Remove signature |
| 93 | + order.signature = "0x"; |
| 94 | + |
| 95 | + await seaport.validate([order], offerer.address).transact(); |
| 96 | + const orderHash = seaport.getOrderHash(order.parameters); |
| 97 | + expect(await seaport.getOrderStatus(orderHash)).to.have.property( |
| 98 | + "isValidated", |
| 99 | + true |
| 100 | + ); |
| 101 | + |
| 102 | + await seaport.cancelOrders([order.parameters], offerer.address).transact(); |
| 103 | + expect(await seaport.getOrderStatus(orderHash)).to.have.property( |
| 104 | + "isCancelled", |
| 105 | + true |
| 106 | + ); |
| 107 | + }); |
| 108 | +}); |
0 commit comments