Skip to content

Commit

Permalink
ci: run tests (ProjectOpenSea#288)
Browse files Browse the repository at this point in the history
* ci: run tests
  • Loading branch information
Meemaw authored Dec 15, 2021
1 parent 6ac99e8 commit 9a1f50b
Show file tree
Hide file tree
Showing 13 changed files with 1,032 additions and 365 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ env:
CI: true

jobs:
linting:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand All @@ -24,3 +23,23 @@ jobs:

- name: Run linters
run: yarn lint:check

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14.17.0"
cache: yarn

- name: Install dependencies
run: yarn install --immutable --ignore-scripts

- name: Run tests
env:
API_KEY: ${{ secrets.API_KEY }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
yarn test
yarn coverage-report
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# OpenSea.js <!-- omit in toc -->

[![https://badges.frapsoft.com/os/mit/mit.svg?v=102](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://opensource.org/licenses/MIT)
[![Coverage Status](https://coveralls.io/repos/github/ProjectOpenSea/opensea-js/badge.svg?branch=master)](https://coveralls.io/github/ProjectOpenSea/opensea-js?branch=master)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)

<!-- [![npm](https://img.shields.io/npm/v/wyvern-js.svg)](https://www.npmjs.com/package/wyvern-js) [![npm](https://img.shields.io/npm/dt/wyvern-js.svg)](https://www.npmjs.com/package/wyvern-js) -->

Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"scripts": {
"build": "tsc",
"check-types": "tsc --noEmit --project tsconfig.json",
"coverage-report": "nyc report --reporter=text-lcov | coveralls",
"docs": "npm run docsHtml",
"docsHtml": "./node_modules/.bin/typedoc --target ES5 --exclude src/abi --excludePrivate --out ./docs --ignoreCompilerErrors --mode file",
"docsMarkdown": "./node_modules/.bin/typedoc --theme markdown --target ES5 --exclude src/abi --excludePrivate --out ./docs_markdown --ignoreCompilerErrors --mode file",
"eslint:check": "eslint . --max-warnings 0 --ext .js,.ts",
"lint:check": "concurrently \"yarn check-types\" \"yarn prettier:check\" \"yarn eslint:check\"",
"prepare": "husky install",
"test": "./node_modules/.bin/mocha test/**/*.ts --require ts-node/register --timeout 15000",
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' TS_NODE_TRANSPILE_ONLY=true nyc mocha -r ts-node/register src/__tests__/**/*.ts --timeout 15000",
"prettier:check": "prettier --check .",
"prettier:check:package.json": "yarn prettier-package-json --list-different",
"prettier:fix": "prettier --write ."
Expand All @@ -35,38 +36,39 @@
"bignumber.js": "^4.1.0",
"ethereumjs-abi": "git+https://github.com/ProjectWyvern/ethereumjs-abi.git",
"ethereumjs-util": "^5.2.0",
"fbemitter": "^2.1.1",
"fbemitter": "2.1.1",
"isomorphic-unfetch": "^2.1.1",
"lodash": "^4.17.4",
"lodash": "^4.17.21",
"query-string": "^6.11.1",
"web3": "0.20.7",
"wyvern-js": "git+https://github.com/ProjectOpenSea/wyvern-js.git#v3.2.1",
"wyvern-schemas": "git+https://github.com/ProjectOpenSea/wyvern-schemas.git#v0.13.1"
},
"devDependencies": {
"@types/chai": "4.2.9",
"@types/chai": "4.3.0",
"@types/fbemitter": "^2.0.32",
"@types/lodash": "^4.14.92",
"@types/lodash": "^4.14.178",
"@types/mocha": "^9.0.0",
"@types/node": "^9.3.0",
"@types/node-fetch": "2.5.5",
"@types/query-string": "^6.1.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"chai": "^4.1.2",
"chai": "4.3.4",
"concurrently": "6.4.0",
"confusing-browser-globals": "^1.0.11",
"coveralls": "^3.1.1",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "7.0.4",
"lint-staged": "12.1.2",
"mocha": "^5.2.0",
"mocha-typescript": "^1.1.15",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier": "2.5.1",
"prettier-package-json": "2.6.0",
"ts-node": "^6.1.0",
"ts-node": "10.4.0",
"typedoc": "^0.11.1",
"types-bn": "^0.0.1",
"types-ethereumjs-util": "0.0.8",
Expand Down
18 changes: 9 additions & 9 deletions test/api/api.ts → src/__tests__/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { assert } from "chai";
import { suite, test } from "mocha-typescript";
import { suite, test } from "mocha";
import * as Web3 from "web3";
import { WyvernProtocol } from "wyvern-js";
import { orderToJSON, OpenSeaPort } from "../../src";
import {
MAINNET_PROVIDER_URL,
NULL_ADDRESS,
ORDERBOOK_VERSION,
ORDER_MATCHING_LATENCY_SECONDS,
} from "../../src/constants";
import { Network, OrderSide } from "../../src/types";
import { getOrderHash, makeBigNumber } from "../../src/utils/utils";
} from "../../constants";
import { orderToJSON, OpenSeaPort } from "../../index";
import { Network, OrderSide } from "../../types";
import { getOrderHash, makeBigNumber } from "../../utils/utils";
import {
ALEX_ADDRESS,
apiToTest,
Expand Down Expand Up @@ -226,13 +226,13 @@ suite("api", () => {

test("API fetches buy orders for maker", async () => {
const forMaker = await apiToTest.getOrders({
maker: ALEX_ADDRESS,
maker: "0x5a237d6ce6d1fa3766fc15256cbfb8bdcf5a5b8a",
side: OrderSide.Buy,
});
assert.isAbove(forMaker.orders.length, 0);
assert.isAbove(forMaker.count, 0);
forMaker.orders.forEach((order) => {
assert.equal(ALEX_ADDRESS, order.maker);
assert.equal("0x5a237d6ce6d1fa3766fc15256cbfb8bdcf5a5b8a", order.maker);
assert.equal(OrderSide.Buy, order.side);
});
});
Expand Down Expand Up @@ -275,14 +275,14 @@ suite("api", () => {
try {
await apiToTest.get("/user");
} catch (error) {
assert.include(error.message, "Unauthorized");
assert.include((error as Error).message, "Unauthorized");
}

// 404 Not found
try {
await apiToTest.get(`/asset/${CK_RINKEBY_ADDRESS}/0`);
} catch (error) {
assert.include(error.message, "Not found");
assert.include((error as Error).message, "Not found");
}

// 400 malformed
Expand Down
6 changes: 3 additions & 3 deletions test/constants.ts → src/__tests__/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenSeaAPI } from "../src/api";
import { CK_ADDRESS, CK_RINKEBY_ADDRESS } from "../src/constants";
import { Network } from "../src/types";
import { OpenSeaAPI } from "../api";
import { CK_ADDRESS, CK_RINKEBY_ADDRESS } from "../constants";
import { Network } from "../types";

export const MAINNET_API_KEY = process.env.API_KEY;
export const RINKEBY_API_KEY = process.env.API_KEY;
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions test/seaport/bundles.ts → src/__tests__/seaport/bundles.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { assert } from "chai";
import { before } from "mocha";
import { suite, test } from "mocha-typescript";
import { before, suite, test } from "mocha";
import * as Web3 from "web3";
import {
ENJIN_ADDRESS,
MAINNET_PROVIDER_URL,
NULL_ADDRESS,
} from "../../src/constants";
import { OpenSeaPort } from "../../src/index";
import { Network, UnhashedOrder, WyvernSchemaName } from "../../src/types";
} from "../../constants";
import { OpenSeaPort } from "../../index";
import { Network, UnhashedOrder, WyvernSchemaName } from "../../types";
import {
AGE_OF_RUST_TOKEN_ID,
ALEX_ADDRESS,
Expand Down
14 changes: 7 additions & 7 deletions test/seaport/fees.ts → src/__tests__/seaport/fees.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BigNumber from "bignumber.js";
import { assert } from "chai";
import { before } from "mocha";
import { suite, test } from "mocha-typescript";
import { before, suite, test } from "mocha";
import * as Web3 from "web3";
import {
DEFAULT_BUYER_FEE_BASIS_POINTS,
Expand All @@ -13,8 +12,8 @@ import {
NULL_ADDRESS,
OPENSEA_FEE_RECIPIENT,
OPENSEA_SELLER_BOUNTY_BASIS_POINTS,
} from "../../src/constants";
import { OpenSeaPort } from "../../src/index";
} from "../../constants";
import { OpenSeaPort } from "../../index";
import {
FeeMethod,
Network,
Expand All @@ -23,8 +22,8 @@ import {
Order,
OrderSide,
UnhashedOrder,
} from "../../src/types";
import { getOrderHash } from "../../src/utils/utils";
} from "../../types";
import { getOrderHash } from "../../utils/utils";
import {
ALEX_ADDRESS,
CATS_IN_MECHS_ID,
Expand Down Expand Up @@ -193,7 +192,8 @@ suite("seaport: fees", () => {
side: OrderSide.Sell,
});
assert.fail();
} catch (error) {
} catch (err) {
const error = err as Error;
if (
!error.message.includes("bounty exceeds the maximum") ||
!error.message.includes("OpenSea will add")
Expand Down
18 changes: 11 additions & 7 deletions test/seaport/misc.ts → src/__tests__/seaport/misc.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { assert } from "chai";
import { suite, test } from "mocha-typescript";
import { suite, test } from "mocha";
import * as Web3 from "web3";
import {
CK_ADDRESS,
MAINNET_PROVIDER_URL,
MAX_UINT_256,
} from "../../src/constants";
import { ERC721 } from "../../src/contracts";
import { OpenSeaPort } from "../../src/index";
import { Network } from "../../src/types";
} from "../../constants";
import { ERC721 } from "../../contracts";
import { OpenSeaPort } from "../../index";
import { Network } from "../../types";
import {
getNonCompliantApprovalAddress,
isContractAddress,
} from "../../src/utils/utils";
} from "../../utils/utils";
import {
ALEX_ADDRESS,
ALEX_ADDRESS_2,
Expand Down Expand Up @@ -74,10 +74,14 @@ suite("seaport: misc", () => {

test("Single-approval tokens are approved for tester address", async () => {
const accountAddress = ALEX_ADDRESS_2;
// @ts-expect-error unused
const _proxyAddress = await client._getProxy(accountAddress);
const tokenId = CK_TOKEN_ID.toString();
const tokenAddress = CK_ADDRESS;
const erc721 = await client.web3.eth.contract(ERC721).at(tokenAddress);
const erc721 = await client.web3.eth
.contract(ERC721 as Web3.AbiDefinition[])
.at(tokenAddress);
// @ts-expect-error unused
const _approvedAddress = await getNonCompliantApprovalAddress(
erc721,
tokenId,
Expand Down
Loading

0 comments on commit 9a1f50b

Please sign in to comment.