Skip to content

Commit b3baeb4

Browse files
refactor: move getRandomExpiration to setup.ts as requested
- Move getRandomExpiration function from test/utils/utils.ts to test/integration/setup.ts - Update imports in postOrder.spec.ts and privateListing.spec.ts - Addresses GitHub comment from @ryanio to consolidate test utilities in setup.ts Co-Authored-By: Ryan Ghods <ralxzryan@gmail.com>
1 parent c485ca3 commit b3baeb4

4 files changed

Lines changed: 20 additions & 18 deletions

File tree

test/integration/postOrder.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
sdk,
1010
sdkPolygon,
1111
walletAddress,
12+
getRandomExpiration,
1213
} from "./setup";
1314
import { ENGLISH_AUCTION_ZONE_MAINNETS } from "../../src/constants";
1415
import { getWETHAddress } from "../../src/utils";
1516
import { OFFER_AMOUNT } from "../utils/constants";
16-
import { expectValidOrder, getRandomExpiration } from "../utils/utils";
17+
import { expectValidOrder } from "../utils/utils";
1718

1819
suite("SDK: order posting", () => {
1920
test("Post Offer - Mainnet", async () => {

test/integration/privateListing.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { expect } from "chai";
22
import { suite, test } from "mocha";
3-
import { OPENSEA_FEE_RECIPIENT } from "../../src/constants";
43
import {
4+
getRandomExpiration,
55
LISTING_AMOUNT,
66
TOKEN_ADDRESS_MAINNET,
77
TOKEN_ID_MAINNET,
88
sdk,
99
walletAddress,
10-
} from "../integration/setup";
11-
import { expectValidOrder, getRandomExpiration } from "../utils/utils";
10+
} from "./setup";
11+
import { OPENSEA_FEE_RECIPIENT } from "../../src/constants";
12+
import { expectValidOrder } from "../utils/utils";
1213

1314
suite("SDK: Private Listings Integration", () => {
1415
test("Post Private Listing - Mainnet", async function () {

test/integration/setup.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,17 @@ export const sdkPolygon = new OpenSeaSDK(
5050
},
5151
(line) => console.info(`POLYGON: ${line}`),
5252
);
53+
54+
export const getRandomExpiration = (): number => {
55+
const now = Math.floor(Date.now() / 1000);
56+
const fifteenMinutes = 15 * 60;
57+
const oneHour = 60 * 60;
58+
const range = oneHour - fifteenMinutes + 1;
59+
60+
const crypto = require("crypto");
61+
const randomBuffer = crypto.randomBytes(4);
62+
const randomValue = randomBuffer.readUInt32BE(0);
63+
const randomSeconds = (randomValue % range) + fifteenMinutes;
64+
65+
return now + randomSeconds;
66+
};

test/utils/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,3 @@ export const expectValidOrder = (order: OrderV2) => {
2626
expect(field in order).to.be.true;
2727
}
2828
};
29-
30-
export const getRandomExpiration = (): number => {
31-
const now = Math.floor(Date.now() / 1000);
32-
const fifteenMinutes = 15 * 60;
33-
const oneHour = 60 * 60;
34-
const range = oneHour - fifteenMinutes + 1;
35-
36-
const crypto = require("crypto");
37-
const randomBuffer = crypto.randomBytes(4);
38-
const randomValue = randomBuffer.readUInt32BE(0);
39-
const randomSeconds = (randomValue % range) + fifteenMinutes;
40-
41-
return now + randomSeconds;
42-
};

0 commit comments

Comments
 (0)