Skip to content

Commit b56fbc0

Browse files
lavidaloca26lavidaloca
andauthored
fix(sdk): throw when both orders and orderHashes are passed to cancelOrders (#1951)
Co-authored-by: lavidaloca <lavida@gm.com>
1 parent 444438b commit b56fbc0

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/sdk/cancellation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ export class CancellationManager {
149149
);
150150
}
151151

152+
if (orders && orderHashes) {
153+
throw new Error(
154+
"Cannot provide both orders and orderHashes. Please use one or the other.",
155+
);
156+
}
157+
152158
if (orders && orders.length === 0) {
153159
throw new Error("At least one order must be provided");
154160
}

test/sdk/cancelOrders.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,40 @@ suite("SDK: cancelOrders", () => {
5151
}
5252
});
5353

54+
test("Should throw an error when both orders and orderHashes are provided", async () => {
55+
const mockOrderComponents: OrderComponents = {
56+
offerer: "0x0000000000000000000000000000000000000001",
57+
zone: "0x0000000000000000000000000000000000000000",
58+
offer: [],
59+
consideration: [],
60+
orderType: 0,
61+
startTime: "0",
62+
endTime: "0",
63+
zoneHash:
64+
"0x0000000000000000000000000000000000000000000000000000000000000000",
65+
salt: "0",
66+
conduitKey:
67+
"0x0000000000000000000000000000000000000000000000000000000000000000",
68+
totalOriginalConsiderationItems: 0,
69+
counter: 0,
70+
};
71+
72+
try {
73+
await sdk.cancelOrders({
74+
orders: [mockOrderComponents],
75+
orderHashes: [
76+
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
77+
],
78+
accountAddress,
79+
});
80+
throw new Error("should have thrown");
81+
} catch (e) {
82+
expect((e as Error).message).to.include(
83+
"Cannot provide both orders and orderHashes",
84+
);
85+
}
86+
});
87+
5488
test("Should attempt to fetch orders from API when using orderHashes", async () => {
5589
try {
5690
await sdk.cancelOrders({

0 commit comments

Comments
 (0)