Skip to content

Commit

Permalink
Merge pull request #672 from bvotteler/chore-upgrade-polkadot-js
Browse files Browse the repository at this point in the history
Chore: Change lib to esnext module, upgrade to polkadot/api 10.9.1
  • Loading branch information
bvotteler authored Aug 24, 2023
2 parents 2da53cd + df31904 commit 89374d4
Show file tree
Hide file tree
Showing 48 changed files with 3,067 additions and 3,167 deletions.
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

0 comments on commit 89374d4

Please sign in to comment.