Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Change lib to esnext module, upgrade to polkadot/api 10.9.1 #672

Merged
merged 43 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fb510b9
chore: change lib to esnext module to be able to upgrade polkadot-js …
bvotteler Aug 15, 2023
a04bb1d
Merge branch 'master' into chore-upgrade-polkadot-js
bvotteler Aug 16, 2023
d4030d3
fix: replace bitcoin-core require method with createRequire's helper …
bvotteler Aug 16, 2023
910a476
chore: add jest
bvotteler Aug 16, 2023
f7bfb18
chore: intermittent commit after first pass of migrating mocha -> jest
bvotteler Aug 16, 2023
3346e13
chore: migrate mocha/sinon -> jest, part deux; incomplete
bvotteler Aug 16, 2023
1b4dcf2
chre: switch from mocha/sinon to jest, continued; fixed some unit tes…
bvotteler Aug 16, 2023
592a7d8
chore: load definitions from interbtc-types via json file load, rathe…
bvotteler Aug 18, 2023
352986a
tests: skip unimplemented tests
bvotteler Aug 18, 2023
6abb1f8
test: remove unnecessary ApiPromise creation which will throw/reject …
bvotteler Aug 18, 2023
ba0964b
test: replace ApiPromise use to create types with TypeRegistry which …
bvotteler Aug 18, 2023
f4e0161
chore: remove old scripts and mocha config from package.json
bvotteler Aug 18, 2023
97410cb
test: fix incorrect jest cli args for parallel/sequential tests, and …
bvotteler Aug 22, 2023
5083401
Merge branch 'master' into chore-upgrade-polkadot-js
bvotteler Aug 22, 2023
0ebb629
test: silence console.log in jest tests
bvotteler Aug 22, 2023
2e115ba
test: fix incorrect assertion in loans.test
bvotteler Aug 22, 2023
3cf28e8
test: fix fail statements that were incorrectly auto-converted
bvotteler Aug 22, 2023
2336392
test: improve fail messages, adjust expected promise failure
bvotteler Aug 22, 2023
784e3bd
test: enable logging again
bvotteler Aug 22, 2023
6d0a69f
test: add assertion failure messages
bvotteler Aug 22, 2023
7b0dfd2
test: await api.disconnect() in all tests
bvotteler Aug 22, 2023
44b4010
test: cannot use fail() in catch block, use throw instead
bvotteler Aug 22, 2023
87a7f76
test: adjust error message and rejection test condition
bvotteler Aug 22, 2023
6188474
test: suppress console logging during tests
bvotteler Aug 22, 2023
682a6c6
test: silence specific console methods: log and debug
bvotteler Aug 22, 2023
4ab5b15
test: fix fail is not defined error - throw instead
bvotteler Aug 22, 2023
b7e5381
test: change default timeout to 30 seconds (from 5) to avoid too eage…
bvotteler Aug 22, 2023
2d60acb
test: enforce alphabetic sorting for tests - particularly important f…
bvotteler Aug 22, 2023
d324cf3
test: remove sequencer which doesn't seem to work with esm modules an…
bvotteler Aug 22, 2023
8e9b247
test: fix incorrect assertion in amm test
bvotteler Aug 23, 2023
7e81a76
test: fix promise rejection assertion in redeem test
bvotteler Aug 23, 2023
62154d0
test: remove incorrect test; getVaultCollaterization does not reject …
bvotteler Aug 23, 2023
ea5545f
test: simplify cases, reset interBtcApi accountafter each test
bvotteler Aug 23, 2023
dc9bc63
test: in redeem tests, create separate instances for accounts instead…
bvotteler Aug 23, 2023
4a12d7c
test: recreate interbtcapi instances for different accounts rather th…
bvotteler Aug 23, 2023
40cabaf
test: create interbtcapi instance for vaults test (previously acciden…
bvotteler Aug 23, 2023
c720ffd
chore: update README with jest specific timout controls
bvotteler Aug 23, 2023
66586e6
test: use total issued amount times two to force failed replace request
bvotteler Aug 23, 2023
a0db635
test: fix rejections assertion for failed redeem request
bvotteler Aug 23, 2023
d74c3f8
test: disable flaky test, to be resolved at later stage (functionalit…
bvotteler Aug 23, 2023
43fb372
chore: revert manual runtime definitions added due to issue https://g…
bvotteler Aug 23, 2023
d7ea6fc
test: remove test case that is covered by parachain tests
bvotteler Aug 24, 2023
df31904
chore: remove commented code
bvotteler Aug 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ src/**.js
yarn.lock
src/interfaces/*
!src/interfaces/definitions.ts
!src/interfaces/interbtc-types.ts
!src/interfaces/default
src/interfaces/default/*
!src/interfaces/default/.keep
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ yarn test:unit
Note that the parachain needs to be running for all tests to run.

```bash
docker-compose up
docker-compose up -d
```

The default parachain runtime is Kintsugi.
Expand All @@ -178,9 +178,18 @@ yarn test
yarn test:integration
```

NOTE: While the parachain is starting up, there will be warnings from the integration tests until it can locate the locally running test vaults. Expect the startup to take around 2-3 minutes, and only start the integration tests after that time frame.
NOTE: While the parachain is starting up, there will be warnings from the integration tests until it can locate the locally running test vaults. Expect the startup to take a few seconds, before the integration tests start.

Another option is to check the logs, i.e. for `vault_1` you can use this:
##### Dealing with timeouts during local testing

At times, when running tests locally, the timeout set in `package.json`'s `jest.testTimeout` setting might not be enough. In that case, you can override the `testTimeout` value (in ms) on the command line:

```bash
yarn test:integration --testTimeout=900000
```

##### Check service logs in detached mode
To check the logs or the services (for example, `vault_1`) you can use this:

```bash
docker-compose logs -f vault_1
Expand Down
71 changes: 41 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "@interlay/interbtc-api",
"version": "2.4.3",
"version": "2.5.0",
"description": "JavaScript library to interact with interBTC",
"main": "build/src/index.js",
"type": "module",
"typings": "build/src/index.d.ts",
"repository": "https://github.com/interlay/interbtc-api",
"license": "Apache-2.0",
Expand All @@ -26,8 +27,8 @@
"ci:test:release": "run-s build test:integration:release",
"ci:test-with-coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" yarn ci:test",
"docs": "./generate_docs",
"generate:defs": "ts-node node_modules/.bin/polkadot-types-from-defs --package @interlay/interbtc-api/interfaces --input ./src/interfaces --endpoint ./src/json/parachain.json",
"generate:meta": "ts-node node_modules/.bin/polkadot-types-from-chain --package @interlay/interbtc-api/interfaces --endpoint ./src/json/parachain.json --output ./src/interfaces",
"generate:defs": "node --experimental-specifier-resolution=node --loader ts-node/esm node_modules/.bin/polkadot-types-from-defs --package @interlay/interbtc-api/interfaces --input ./src/interfaces --endpoint ./src/json/parachain.json",
"generate:meta": "node --experimental-specifier-resolution=node --loader ts-node/esm node_modules/.bin/polkadot-types-from-chain --package @interlay/interbtc-api/interfaces --endpoint ./src/json/parachain.json --output ./src/interfaces",
"hrmp-setup": "ts-node scripts/hrmp-setup",
"runtime-upgrade": "ts-node scripts/runtime-upgrade",
"xcm-cross-chain-transfer": "ts-node scripts/xcm-cross-chain-transfer",
Expand All @@ -37,15 +38,16 @@
"undercollateralized-borrowers": "ts-node scripts/get-undercollateralized-borrowers",
"test": "run-s build test:*",
"test:lint": "eslint src --ext .ts",
"test:unit": "mocha test/unit/*.test.ts test/unit/**/*.test.ts",
"test:unit": "jest test/unit/*.test.ts test/unit/**/*.test.ts",
"test:integration": "run-s test:integration:staging",
"test:integration:staging": "run-s test:integration:setup test:integration:parallel test:integration:sequential",
"test:integration:setup": "mocha test/integration/**/staging/setup/initialize.test.ts",
"test:integration:parallel": "mocha test/integration/**/staging/*.test.ts --parallel",
"test:integration:sequential": "mocha test/integration/**/staging/sequential/*.test.ts",
"test:integration:setup": "jest test/integration/**/staging/setup/initialize.test.ts",
"test:integration:parallel": "jest test/integration/**/staging/*.test.ts",
"test:integration:sequential": "jest --runInBand test/integration/**/staging/sequential/*.test.ts",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "mocha --watch test/**/*.test.ts",
"update-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/json/parachain.json"
"watch:test": "jest --watch test/**/*.test.ts",
"update-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/json/parachain.json",
"update-metadata-kintnet": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' https://api-dev-kintsugi.interlay.io/parachain > src/json/parachain.json"
},
"engines": {
"node": ">=11"
Expand All @@ -55,7 +57,7 @@
"@interlay/esplora-btc-api": "0.4.0",
"@interlay/interbtc-types": "1.13.0",
"@interlay/monetary-js": "0.7.3",
"@polkadot/api": "9.14.2",
"@polkadot/api": "10.9.1",
"big.js": "6.1.1",
"bitcoin-core": "^3.0.0",
"bitcoinjs-lib": "^5.2.0",
Expand All @@ -65,36 +67,29 @@
"regtest-client": "^0.2.0"
},
"devDependencies": {
"@polkadot/typegen": "9.14.2",
"@polkadot/typegen": "10.9.1",
"@types/big.js": "6.1.2",
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.3",
"@types/mocha": "^10.0.1",
"@types/jest": "^29.5.3",
"@types/node": "^18.11.9",
"@types/shelljs": "0.8.12",
"@types/sinon": "^10.0.15",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cli-table3": "0.6.3",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-unused-imports": "^2.0.0",
"husky": "^8.0.3",
"mocha": "10.2.0",
"nock": "^13.0.4",
"jest": "^29.6.2",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^3.0.1",
"shelljs": "0.8.5",
"sinon": "^15.1.0",
"ts-mock-imports": "^1.3.0",
"ts-jest": "^29.1.1",
"ts-node": "10.9.1",
"typedoc": "^0.24.7",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "5.0.4",
"typescript": "4.9.5",
"yargs": "^17.5.1"
},
"resolutions": {
Expand All @@ -113,13 +108,29 @@
"singleQuote": false,
"tabWidth": 4
},
"mocha": {
"reporter": "spec",
"require": "ts-node/register",
"watch-files": [
"src/**/*.ts",
"test/**/*.ts"
"jest": {
"moduleNameMapper": {
"^(\\.\\.?\\/.+)\\.js$": "$1"
},
"testPathIgnorePatterns": [
"<rootDir>/src"
],
"recursive": true
"preset": "ts-jest",
"testEnvironment": "node",
"modulePathIgnorePatterns": [
"<rootDir>/build/"
],
"collectCoverageFrom": [
"<rootDir>/src/**/*.ts*"
],
"coveragePathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/build/",
"<rootDir>/src/interfaces/"
],
"setupFilesAfterEnv": [
"<rootDir>/test/utils/jestSetupFileAfterEnv.ts"
],
"testTimeout": 30000
}
}
}
4 changes: 2 additions & 2 deletions src/clients/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FundAccountJsonRpcRequest } from "../interfaces/default";
import { getAPITypes } from "../factory";
import { TypeRegistry } from "@polkadot/types";
import { Constructor } from "@polkadot/types/types";
import { CodecClass } from "@polkadot/types/types";
import { AccountId } from "@polkadot/types/interfaces";
import { JsonRpcClient } from "./client";
import { newCurrencyId } from "../utils";
Expand All @@ -15,7 +15,7 @@ export class FaucetClient extends JsonRpcClient<void> {
registry: TypeRegistry;

constr: {
FundAccountJsonRpcRequest: Constructor<FundAccountJsonRpcRequest>;
FundAccountJsonRpcRequest: CodecClass<FundAccountJsonRpcRequest>;
};

constructor(private api: ApiPromise, url: string) {
Expand Down
88 changes: 0 additions & 88 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { DefinitionRpc, DefinitionRpcSub } from "@polkadot/types/types";
import * as definitions from "./interfaces/definitions";
import { InterBtcApi, DefaultInterBtcApi } from "./interbtc-api";
import { BitcoinNetwork } from "./types";
import { objectSpread } from "@polkadot/util";
import { DefinitionCall, DefinitionsCall } from "@polkadot/types/types";

export function createProvider(endpoint: string, autoConnect?: number | false | undefined): ProviderInterface {
if (/https?:\/\//.exec(endpoint)) {
Expand All @@ -35,9 +33,6 @@ export function createSubstrateAPI(
types,
rpc,
noInitWarn: noInitWarn || true,
// manual definition for transactionPaymentApi.queryInfo until polkadot-js/api can be upgraded
// TODO: revert when this work is merged: https://github.com/interlay/interbtc-api/pull/672
runtime: getRuntimeDefs(),
});
}

Expand All @@ -64,86 +59,3 @@ export function createAPIRegistry(): TypeRegistry {
registry.register(getAPITypes());
return registry;
}

const V1_TO_V4_SHARED_PAY: Record<string, DefinitionCall> = {
query_fee_details: {
description: "The transaction fee details",
params: [
{
name: "uxt",
type: "Extrinsic"
},
{
name: "len",
type: "u32"
}
],
type: "FeeDetails"
}
};

const V2_TO_V4_SHARED_PAY: Record<string, DefinitionCall> = {
query_info: {
description: "The transaction info",
params: [
{
name: "uxt",
type: "Extrinsic"
},
{
name: "len",
type: "u32"
}
],
type: "RuntimeDispatchInfo"
}
};

const V3_SHARED_PAY_CALL: Record<string, DefinitionCall> = {
query_length_to_fee: {
description: "Query the output of the current LengthToFee given some input",
params: [
{
name: "length",
type: "u32"
}
],
type: "Balance"
},
query_weight_to_fee: {
description: "Query the output of the current WeightToFee given some input",
params: [
{
name: "weight",
type: "Weight"
}
],
type: "Balance"
}
};

export function getRuntimeDefs(): DefinitionsCall {
return {
TransactionPaymentApi: [
{
// V4 is equivalent to V3 (V4 just dropped all V1 references)
methods: objectSpread(
{},
V3_SHARED_PAY_CALL,
V2_TO_V4_SHARED_PAY,
V1_TO_V4_SHARED_PAY
),
version: 4
},
{
methods: objectSpread(
{},
V3_SHARED_PAY_CALL,
V2_TO_V4_SHARED_PAY,
V1_TO_V4_SHARED_PAY
),
version: 3
},
]
};
}
16 changes: 11 additions & 5 deletions src/interfaces/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import definitions, { RpcFunctionDefinition } from "@interlay/interbtc-types";
import { RpcFunctionDefinition } from "@interlay/interbtc-types";
import fs from "fs";

// hacky, but cannot import json "the old way" in esnext
const definitionsString = fs.readFileSync("./node_modules/@interlay/interbtc-types/definitions.json", "utf-8");
const definitions = JSON.parse(definitionsString);

interface DecoratedRpcFunctionDefinition extends RpcFunctionDefinition {
aliasSection: string;
}

export default {
types: definitions.types[0].types,
rpc: parseProviderRpcDefinitions(definitions.rpc),
Expand All @@ -22,7 +32,3 @@ function parseProviderRpcDefinitions(
}
return parsedDefs;
}

interface DecoratedRpcFunctionDefinition extends RpcFunctionDefinition {
aliasSection: string;
}
6 changes: 0 additions & 6 deletions test/chai.ts

This file was deleted.

Loading