-
Notifications
You must be signed in to change notification settings - Fork 972
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93be84b
commit 82bfe61
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,108 @@ | ||
import { expect } from "chai"; | ||
import { suite, test } from "mocha"; | ||
import { OpenSeaAPI } from "../../src/api/api"; | ||
import { Chain, OrderSide } from "../../src/types"; | ||
import { OrderAPIOptions } from "../../src/orders/types"; | ||
|
||
suite("API: postOrder validation", () => { | ||
const api = new OpenSeaAPI({ chain: Chain.Mainnet }); | ||
const mockOrder = { | ||
parameters: { | ||
offerer: "0x1234567890123456789012345678901234567890", | ||
zone: "0x1234567890123456789012345678901234567890", | ||
orderType: 0, | ||
startTime: "1234567890", | ||
endTime: "9876543210", | ||
zoneHash: "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
salt: "1234567890", | ||
offer: [], | ||
consideration: [], | ||
totalOriginalConsiderationItems: 0, | ||
conduitKey: "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
}, | ||
signature: "0x", | ||
}; | ||
|
||
test("should throw error when side is missing", async () => { | ||
const apiOptions = { | ||
protocolAddress: "0x1234567890123456789012345678901234567890", | ||
}; | ||
|
||
try { | ||
await api.postOrder(mockOrder, apiOptions as OrderAPIOptions); | ||
expect.fail("Should have thrown an error"); | ||
} catch (error: any) { | ||
expect(error.message).to.equal("apiOptions.side is required"); | ||
} | ||
}); | ||
|
||
test("should throw error when protocolAddress is missing", async () => { | ||
const apiOptions = { | ||
side: OrderSide.LISTING, | ||
}; | ||
|
||
try { | ||
await api.postOrder(mockOrder, apiOptions as OrderAPIOptions); | ||
expect.fail("Should have thrown an error"); | ||
} catch (error: any) { | ||
expect(error.message).to.equal("apiOptions.protocolAddress is required"); | ||
} | ||
}); | ||
|
||
test("should throw error when order is missing", async () => { | ||
const apiOptions = { | ||
side: OrderSide.LISTING, | ||
protocolAddress: "0x1234567890123456789012345678901234567890", | ||
} as OrderAPIOptions; | ||
|
||
try { | ||
await api.postOrder(null as any, apiOptions); | ||
expect.fail("Should have thrown an error"); | ||
} catch (error: any) { | ||
expect(error.message).to.equal("order data is required"); | ||
} | ||
}); | ||
|
||
test("should throw error for unsupported protocol", async () => { | ||
const apiOptions = { | ||
protocol: "unsupported" as "seaport", | ||
side: OrderSide.LISTING, | ||
protocolAddress: "0x1234567890123456789012345678901234567890", | ||
}; | ||
|
||
try { | ||
await api.postOrder(mockOrder, apiOptions); | ||
expect.fail("Should have thrown an error"); | ||
} catch (error: any) { | ||
expect(error.message).to.equal("Currently only 'seaport' protocol is supported"); | ||
} | ||
}); | ||
|
||
test("should throw error for invalid side value", async () => { | ||
const apiOptions = { | ||
side: "invalid_side" as OrderSide, | ||
protocolAddress: "0x1234567890123456789012345678901234567890", | ||
}; | ||
|
||
try { | ||
await api.postOrder(mockOrder, apiOptions); | ||
expect.fail("Should have thrown an error"); | ||
} catch (error: any) { | ||
expect(error.message).to.equal("side must be either 'ask' or 'bid'"); | ||
} | ||
}); | ||
|
||
test("should throw error for invalid protocol address format", async () => { | ||
const apiOptions = { | ||
side: OrderSide.LISTING, | ||
protocolAddress: "invalid_address", | ||
} as OrderAPIOptions; | ||
|
||
try { | ||
await api.postOrder(mockOrder, apiOptions); | ||
expect.fail("Should have thrown an error"); | ||
} catch (error: any) { | ||
expect(error.message).to.equal("Invalid protocol address format"); | ||
} | ||
}); | ||
}); |