Skip to content

Commit

Permalink
Add createSellOrder integration test (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaSchmidt-OpenSea authored May 16, 2023
1 parent df17e6c commit 48bc6d6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"docs-build": "typedoc --out docs src/index.ts",
"eslint:check": "eslint . --max-warnings 0 --ext .js,.ts",
"eslint:fix": "eslint . --fix --max-warnings 0 --ext .js,.ts",
"integration_tests": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' TS_NODE_TRANSPILE_ONLY=true nyc mocha -r ts-node/register src/__integration_tests__/**/*.ts --timeout 15000",
"integration_tests": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' TS_NODE_TRANSPILE_ONLY=true nyc mocha -r ts-node/register -r dotenv/config src/__integration_tests__/**/*.ts --timeout 15000",
"lint:check": "concurrently \"yarn check-types\" \"yarn prettier:check\" \"yarn eslint:check\"",
"prepare": "husky install && npm run build",
"prettier:check": "prettier --check .",
Expand Down Expand Up @@ -65,6 +65,7 @@
"concurrently": "8.0.1",
"confusing-browser-globals": "^1.0.11",
"coveralls": "^3.1.1",
"dotenv": "^16.0.3",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^3.0.0",
Expand Down
27 changes: 22 additions & 5 deletions src/__integration_tests__/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@ These tests were built to test the order posting functionality of the SDK. Signi

### Environment variables:

- `API_KEY`: your OpenSea mainnet API key.
- `WALLET_ADDRESS`: the wallet address to send your offer from.
- `WALLET_PRIV_KEY`: the private key to your wallet. This is required to sign the order.
- `ALCHEMY_API_KEY`: your Alchemy API key.
Environment variables for integration tests are set using `.env`. This file is not in the source code for the repository so you will need to create a file with the following fields:

```
API_KEY = "" # OpenSea API Key
WALLET_ADDRESS = ""
WALLET_PRIV_KEY = ""
ALCHEMY_API_KEY = ""
# The following needs to be an NFT owned by the WALLET_ADDRESS
SELL_ORDER_CONTRACT_ADDRESS = "" # If not set, postSellOrder test will fail
SELL_ORDER_TOKEN_ID = "" # If not set, postSellOrder test will fail
```

Optional:

```
OFFER_AMOUNT = "" # Defaults to 0.004
LISTING_AMOUNT = "" # Defaults to 40
### How to run:
```
API_KEY="..." WALLET_ADDRESS="..." WALLET_PRIV_KEY="..." ALCHEMY_API_KEY="..." npm run integration_tests

npm run integration_tests

```
```
38 changes: 28 additions & 10 deletions src/__integration_tests__/postOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { expectValidOrder } from "../__tests__/utils";
import { OpenSeaSDK } from "../index";
import { Network } from "../types";

const TOKEN_ADDRESS = process.env.SELL_ORDER_CONTRACT_ADDRESS;
const TOKEN_ID = process.env.SELL_ORDER_TOKEN_ID;
const LISTING_AMOUNT = process.env.LISTING_AMOUNT;

const walletAddress = WALLET_ADDRESS ?? "";

const webProvider = new Web3.providers.HttpProvider(
`https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`
);
Expand All @@ -22,10 +28,7 @@ const rpcProvider = new ethers.providers.JsonRpcProvider(
`https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`
);

const wallet = new ethers.Wallet(
WALLET_PRIV_KEY ? WALLET_PRIV_KEY : "",
rpcProvider
);
const wallet = new ethers.Wallet(WALLET_PRIV_KEY ?? "", rpcProvider);

const sdk = new OpenSeaSDK(
webProvider,
Expand All @@ -39,16 +42,31 @@ const sdk = new OpenSeaSDK(

suite("SDK: order posting", () => {
test("Post Buy Order", async () => {
const postBuyOrder = {
accountAddress: WALLET_ADDRESS ? WALLET_ADDRESS : "",
startAmount: OFFER_AMOUNT ? OFFER_AMOUNT : "0.004",
const buyOrder = {
accountAddress: walletAddress,
startAmount: OFFER_AMOUNT ?? "0.004",
asset: {
tokenAddress: "0x1a92f7381b9f03921564a437210bb9396471050c",
tokenId: "2288",
},
};

const order = await sdk.createBuyOrder(postBuyOrder);
const order = await sdk.createBuyOrder(buyOrder);

expectValidOrder(order);
});

test("Post Sell Order", async () => {
const sellOrder = {
accountAddress: walletAddress,
startAmount: LISTING_AMOUNT ?? "40",
asset: {
tokenAddress: TOKEN_ADDRESS ?? "",
tokenId: TOKEN_ID ?? "",
},
};

const order = await sdk.createSellOrder(sellOrder);

expectValidOrder(order);
});
Expand All @@ -58,8 +76,8 @@ suite("SDK: order posting", () => {

const postOrderRequest = {
collectionSlug: collection.slug,
accountAddress: WALLET_ADDRESS ? WALLET_ADDRESS : "",
amount: "0.004",
accountAddress: walletAddress,
amount: OFFER_AMOUNT ?? "0.004",
quantity: 1,
paymentTokenAddress: WETH_ADDRESS,
};
Expand Down

0 comments on commit 48bc6d6

Please sign in to comment.