Skip to content

Commit 8db884b

Browse files
authored
separate file for cancel tests (#72)
1 parent e7eb2af commit 8db884b

File tree

2 files changed

+108
-93
lines changed

2 files changed

+108
-93
lines changed

src/__tests__/basic-fulfill.spec.ts

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -783,98 +783,5 @@ describeWithFixture(
783783
});
784784
});
785785
});
786-
787-
describe("cancel order", function () {
788-
beforeEach(async () => {
789-
const { testErc721 } = fixture;
790-
791-
await testErc721.mint(offerer.address, nftId);
792-
793-
standardCreateOrderInput = {
794-
startTime: "0",
795-
offer: [
796-
{
797-
itemType: ItemType.ERC721,
798-
token: testErc721.address,
799-
identifier: nftId,
800-
},
801-
],
802-
consideration: [
803-
{
804-
amount: parseEther("10").toString(),
805-
recipient: offerer.address,
806-
},
807-
],
808-
// 2.5% fee
809-
fees: [{ recipient: zone.address, basisPoints: 250 }],
810-
};
811-
});
812-
813-
it("validate then bulk cancel orders", async () => {
814-
const { seaport } = fixture;
815-
816-
const { executeAllActions } = await seaport.createOrder(
817-
standardCreateOrderInput
818-
);
819-
const executeAllActionsOnChainOrder = (
820-
await seaport.createOrder(standardCreateOrderInput)
821-
).executeAllActions;
822-
823-
const offChainOrder = await executeAllActions();
824-
const onChainOrder = await executeAllActionsOnChainOrder();
825-
826-
// Remove signature
827-
onChainOrder.signature = "0x";
828-
829-
await seaport.validate([onChainOrder], offerer.address).transact();
830-
await seaport.bulkCancelOrders(offerer.address).transact();
831-
832-
const { executeAllActions: executeAllFulfillActionsOffChainOrder } =
833-
await seaport.fulfillOrder({
834-
order: offChainOrder,
835-
accountAddress: fulfiller.address,
836-
});
837-
838-
const { executeAllActions: executeAllFulfillActionsOnChainOrder } =
839-
await seaport.fulfillOrder({
840-
order: onChainOrder,
841-
accountAddress: fulfiller.address,
842-
});
843-
844-
await expect(executeAllFulfillActionsOffChainOrder()).to.be.reverted;
845-
await expect(executeAllFulfillActionsOnChainOrder()).to.be.reverted;
846-
847-
expect(await seaport.getCounter(offerer.address)).to.equal(
848-
offChainOrder.parameters.counter + 1
849-
);
850-
});
851-
852-
it("validate then cancel single order", async () => {
853-
const { seaport } = fixture;
854-
855-
const { executeAllActions } = await seaport.createOrder(
856-
standardCreateOrderInput
857-
);
858-
const order = await executeAllActions();
859-
860-
// Remove signature
861-
order.signature = "0x";
862-
863-
await seaport.validate([order], offerer.address).transact();
864-
const orderHash = seaport.getOrderHash(order.parameters);
865-
expect(await seaport.getOrderStatus(orderHash)).to.have.property(
866-
"isValidated",
867-
true
868-
);
869-
870-
await seaport
871-
.cancelOrders([order.parameters], offerer.address)
872-
.transact();
873-
expect(await seaport.getOrderStatus(orderHash)).to.have.property(
874-
"isCancelled",
875-
true
876-
);
877-
});
878-
});
879786
}
880787
);

src/__tests__/cancel.spec.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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

Comments
 (0)