Skip to content

Commit 89374d4

Browse files
authored
Merge pull request #672 from bvotteler/chore-upgrade-polkadot-js
Chore: Change lib to esnext module, upgrade to polkadot/api 10.9.1
2 parents 2da53cd + df31904 commit 89374d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3067
-3167
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ src/**.js
88
yarn.lock
99
src/interfaces/*
1010
!src/interfaces/definitions.ts
11+
!src/interfaces/interbtc-types.ts
1112
!src/interfaces/default
1213
src/interfaces/default/*
1314
!src/interfaces/default/.keep

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ yarn test:unit
159159
Note that the parachain needs to be running for all tests to run.
160160

161161
```bash
162-
docker-compose up
162+
docker-compose up -d
163163
```
164164

165165
The default parachain runtime is Kintsugi.
@@ -178,9 +178,18 @@ yarn test
178178
yarn test:integration
179179
```
180180

181-
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.
181+
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.
182182

183-
Another option is to check the logs, i.e. for `vault_1` you can use this:
183+
##### Dealing with timeouts during local testing
184+
185+
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:
186+
187+
```bash
188+
yarn test:integration --testTimeout=900000
189+
```
190+
191+
##### Check service logs in detached mode
192+
To check the logs or the services (for example, `vault_1`) you can use this:
184193

185194
```bash
186195
docker-compose logs -f vault_1

package.json

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "@interlay/interbtc-api",
3-
"version": "2.4.3",
3+
"version": "2.5.0",
44
"description": "JavaScript library to interact with interBTC",
55
"main": "build/src/index.js",
6+
"type": "module",
67
"typings": "build/src/index.d.ts",
78
"repository": "https://github.com/interlay/interbtc-api",
89
"license": "Apache-2.0",
@@ -26,8 +27,8 @@
2627
"ci:test:release": "run-s build test:integration:release",
2728
"ci:test-with-coverage": "nyc -r lcov -e .ts -x \"*.test.ts\" yarn ci:test",
2829
"docs": "./generate_docs",
29-
"generate:defs": "ts-node node_modules/.bin/polkadot-types-from-defs --package @interlay/interbtc-api/interfaces --input ./src/interfaces --endpoint ./src/json/parachain.json",
30-
"generate:meta": "ts-node node_modules/.bin/polkadot-types-from-chain --package @interlay/interbtc-api/interfaces --endpoint ./src/json/parachain.json --output ./src/interfaces",
30+
"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",
31+
"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",
3132
"hrmp-setup": "ts-node scripts/hrmp-setup",
3233
"runtime-upgrade": "ts-node scripts/runtime-upgrade",
3334
"xcm-cross-chain-transfer": "ts-node scripts/xcm-cross-chain-transfer",
@@ -37,15 +38,16 @@
3738
"undercollateralized-borrowers": "ts-node scripts/get-undercollateralized-borrowers",
3839
"test": "run-s build test:*",
3940
"test:lint": "eslint src --ext .ts",
40-
"test:unit": "mocha test/unit/*.test.ts test/unit/**/*.test.ts",
41+
"test:unit": "jest test/unit/*.test.ts test/unit/**/*.test.ts",
4142
"test:integration": "run-s test:integration:staging",
4243
"test:integration:staging": "run-s test:integration:setup test:integration:parallel test:integration:sequential",
43-
"test:integration:setup": "mocha test/integration/**/staging/setup/initialize.test.ts",
44-
"test:integration:parallel": "mocha test/integration/**/staging/*.test.ts --parallel",
45-
"test:integration:sequential": "mocha test/integration/**/staging/sequential/*.test.ts",
44+
"test:integration:setup": "jest test/integration/**/staging/setup/initialize.test.ts",
45+
"test:integration:parallel": "jest test/integration/**/staging/*.test.ts",
46+
"test:integration:sequential": "jest --runInBand test/integration/**/staging/sequential/*.test.ts",
4647
"watch:build": "tsc -p tsconfig.json -w",
47-
"watch:test": "mocha --watch test/**/*.test.ts",
48-
"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"
48+
"watch:test": "jest --watch test/**/*.test.ts",
49+
"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",
50+
"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"
4951
},
5052
"engines": {
5153
"node": ">=11"
@@ -55,7 +57,7 @@
5557
"@interlay/esplora-btc-api": "0.4.0",
5658
"@interlay/interbtc-types": "1.13.0",
5759
"@interlay/monetary-js": "0.7.3",
58-
"@polkadot/api": "9.14.2",
60+
"@polkadot/api": "10.9.1",
5961
"big.js": "6.1.1",
6062
"bitcoin-core": "^3.0.0",
6163
"bitcoinjs-lib": "^5.2.0",
@@ -65,36 +67,29 @@
6567
"regtest-client": "^0.2.0"
6668
},
6769
"devDependencies": {
68-
"@polkadot/typegen": "9.14.2",
70+
"@polkadot/typegen": "10.9.1",
6971
"@types/big.js": "6.1.2",
70-
"@types/chai": "^4.2.12",
71-
"@types/chai-as-promised": "^7.1.3",
72-
"@types/mocha": "^10.0.1",
72+
"@types/jest": "^29.5.3",
7373
"@types/node": "^18.11.9",
7474
"@types/shelljs": "0.8.12",
75-
"@types/sinon": "^10.0.15",
7675
"@types/yargs": "^17.0.10",
7776
"@typescript-eslint/eslint-plugin": "^5.59.7",
7877
"@typescript-eslint/parser": "^5.59.7",
79-
"chai": "^4.2.0",
80-
"chai-as-promised": "^7.1.1",
8178
"cli-table3": "0.6.3",
8279
"eslint": "^8.41.0",
8380
"eslint-config-prettier": "^8.8.0",
8481
"eslint-plugin-unused-imports": "^2.0.0",
8582
"husky": "^8.0.3",
86-
"mocha": "10.2.0",
87-
"nock": "^13.0.4",
83+
"jest": "^29.6.2",
8884
"npm-run-all": "^4.1.5",
8985
"nyc": "^15.1.0",
9086
"prettier": "^3.0.1",
9187
"shelljs": "0.8.5",
92-
"sinon": "^15.1.0",
93-
"ts-mock-imports": "^1.3.0",
88+
"ts-jest": "^29.1.1",
9489
"ts-node": "10.9.1",
9590
"typedoc": "^0.24.7",
9691
"typedoc-plugin-markdown": "^3.15.3",
97-
"typescript": "5.0.4",
92+
"typescript": "4.9.5",
9893
"yargs": "^17.5.1"
9994
},
10095
"resolutions": {
@@ -113,13 +108,29 @@
113108
"singleQuote": false,
114109
"tabWidth": 4
115110
},
116-
"mocha": {
117-
"reporter": "spec",
118-
"require": "ts-node/register",
119-
"watch-files": [
120-
"src/**/*.ts",
121-
"test/**/*.ts"
111+
"jest": {
112+
"moduleNameMapper": {
113+
"^(\\.\\.?\\/.+)\\.js$": "$1"
114+
},
115+
"testPathIgnorePatterns": [
116+
"<rootDir>/src"
122117
],
123-
"recursive": true
118+
"preset": "ts-jest",
119+
"testEnvironment": "node",
120+
"modulePathIgnorePatterns": [
121+
"<rootDir>/build/"
122+
],
123+
"collectCoverageFrom": [
124+
"<rootDir>/src/**/*.ts*"
125+
],
126+
"coveragePathIgnorePatterns": [
127+
"<rootDir>/node_modules/",
128+
"<rootDir>/build/",
129+
"<rootDir>/src/interfaces/"
130+
],
131+
"setupFilesAfterEnv": [
132+
"<rootDir>/test/utils/jestSetupFileAfterEnv.ts"
133+
],
134+
"testTimeout": 30000
124135
}
125-
}
136+
}

src/clients/faucet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FundAccountJsonRpcRequest } from "../interfaces/default";
22
import { getAPITypes } from "../factory";
33
import { TypeRegistry } from "@polkadot/types";
4-
import { Constructor } from "@polkadot/types/types";
4+
import { CodecClass } from "@polkadot/types/types";
55
import { AccountId } from "@polkadot/types/interfaces";
66
import { JsonRpcClient } from "./client";
77
import { newCurrencyId } from "../utils";
@@ -15,7 +15,7 @@ export class FaucetClient extends JsonRpcClient<void> {
1515
registry: TypeRegistry;
1616

1717
constr: {
18-
FundAccountJsonRpcRequest: Constructor<FundAccountJsonRpcRequest>;
18+
FundAccountJsonRpcRequest: CodecClass<FundAccountJsonRpcRequest>;
1919
};
2020

2121
constructor(private api: ApiPromise, url: string) {

src/factory.ts

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { DefinitionRpc, DefinitionRpcSub } from "@polkadot/types/types";
88
import * as definitions from "./interfaces/definitions";
99
import { InterBtcApi, DefaultInterBtcApi } from "./interbtc-api";
1010
import { BitcoinNetwork } from "./types";
11-
import { objectSpread } from "@polkadot/util";
12-
import { DefinitionCall, DefinitionsCall } from "@polkadot/types/types";
1311

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

@@ -64,86 +59,3 @@ export function createAPIRegistry(): TypeRegistry {
6459
registry.register(getAPITypes());
6560
return registry;
6661
}
67-
68-
const V1_TO_V4_SHARED_PAY: Record<string, DefinitionCall> = {
69-
query_fee_details: {
70-
description: "The transaction fee details",
71-
params: [
72-
{
73-
name: "uxt",
74-
type: "Extrinsic"
75-
},
76-
{
77-
name: "len",
78-
type: "u32"
79-
}
80-
],
81-
type: "FeeDetails"
82-
}
83-
};
84-
85-
const V2_TO_V4_SHARED_PAY: Record<string, DefinitionCall> = {
86-
query_info: {
87-
description: "The transaction info",
88-
params: [
89-
{
90-
name: "uxt",
91-
type: "Extrinsic"
92-
},
93-
{
94-
name: "len",
95-
type: "u32"
96-
}
97-
],
98-
type: "RuntimeDispatchInfo"
99-
}
100-
};
101-
102-
const V3_SHARED_PAY_CALL: Record<string, DefinitionCall> = {
103-
query_length_to_fee: {
104-
description: "Query the output of the current LengthToFee given some input",
105-
params: [
106-
{
107-
name: "length",
108-
type: "u32"
109-
}
110-
],
111-
type: "Balance"
112-
},
113-
query_weight_to_fee: {
114-
description: "Query the output of the current WeightToFee given some input",
115-
params: [
116-
{
117-
name: "weight",
118-
type: "Weight"
119-
}
120-
],
121-
type: "Balance"
122-
}
123-
};
124-
125-
export function getRuntimeDefs(): DefinitionsCall {
126-
return {
127-
TransactionPaymentApi: [
128-
{
129-
// V4 is equivalent to V3 (V4 just dropped all V1 references)
130-
methods: objectSpread(
131-
{},
132-
V3_SHARED_PAY_CALL,
133-
V2_TO_V4_SHARED_PAY,
134-
V1_TO_V4_SHARED_PAY
135-
),
136-
version: 4
137-
},
138-
{
139-
methods: objectSpread(
140-
{},
141-
V3_SHARED_PAY_CALL,
142-
V2_TO_V4_SHARED_PAY,
143-
V1_TO_V4_SHARED_PAY
144-
),
145-
version: 3
146-
},
147-
]
148-
};
149-
}

src/interfaces/definitions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import definitions, { RpcFunctionDefinition } from "@interlay/interbtc-types";
1+
import { RpcFunctionDefinition } from "@interlay/interbtc-types";
2+
import fs from "fs";
3+
4+
// hacky, but cannot import json "the old way" in esnext
5+
const definitionsString = fs.readFileSync("./node_modules/@interlay/interbtc-types/definitions.json", "utf-8");
6+
const definitions = JSON.parse(definitionsString);
7+
8+
interface DecoratedRpcFunctionDefinition extends RpcFunctionDefinition {
9+
aliasSection: string;
10+
}
11+
212
export default {
313
types: definitions.types[0].types,
414
rpc: parseProviderRpcDefinitions(definitions.rpc),
@@ -22,7 +32,3 @@ function parseProviderRpcDefinitions(
2232
}
2333
return parsedDefs;
2434
}
25-
26-
interface DecoratedRpcFunctionDefinition extends RpcFunctionDefinition {
27-
aliasSection: string;
28-
}

test/chai.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)