@acala-network/chopsticks-testing 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +42 -1
- package/lib/index.js +42 -4
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
2
2
|
import { Codec } from '@polkadot/types/types';
|
|
3
|
+
import { Config } from '@acala-network/chopsticks/schema';
|
|
3
4
|
import { HexString } from '@polkadot/util/types';
|
|
4
5
|
import { Keyring } from '@polkadot/keyring';
|
|
5
6
|
import { StorageValues } from '@acala-network/chopsticks/utils/set-storage';
|
|
@@ -12,8 +13,13 @@ export type SetupOption = {
|
|
|
12
13
|
wasmOverride?: string;
|
|
13
14
|
db?: string;
|
|
14
15
|
timeout?: number;
|
|
16
|
+
port?: number;
|
|
15
17
|
};
|
|
16
|
-
export
|
|
18
|
+
export type SetupConfig = Config & {
|
|
19
|
+
timeout?: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const createConfig: ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, port, }: SetupOption) => SetupConfig;
|
|
22
|
+
export declare const setupContext: (option: SetupOption) => Promise<{
|
|
17
23
|
url: string;
|
|
18
24
|
chain: import("@acala-network/chopsticks").Blockchain;
|
|
19
25
|
ws: WsProvider;
|
|
@@ -30,6 +36,41 @@ export declare const setupContext: ({ endpoint, blockNumber, blockHash, wasmOver
|
|
|
30
36
|
teardown(): Promise<void>;
|
|
31
37
|
pause(): Promise<unknown>;
|
|
32
38
|
}>;
|
|
39
|
+
export declare const setupContextWithConfig: ({ timeout, ...config }: SetupConfig) => Promise<{
|
|
40
|
+
url: string;
|
|
41
|
+
chain: import("@acala-network/chopsticks").Blockchain;
|
|
42
|
+
ws: WsProvider;
|
|
43
|
+
api: ApiPromise;
|
|
44
|
+
dev: {
|
|
45
|
+
newBlock: (param?: {
|
|
46
|
+
count?: number;
|
|
47
|
+
to?: number;
|
|
48
|
+
}) => Promise<string>;
|
|
49
|
+
setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
|
|
50
|
+
timeTravel: (date: string | number) => Promise<number>;
|
|
51
|
+
setHead: (hashOrNumber: string | number) => Promise<any>;
|
|
52
|
+
};
|
|
53
|
+
teardown(): Promise<void>;
|
|
54
|
+
pause(): Promise<unknown>;
|
|
55
|
+
}>;
|
|
56
|
+
export type NetworkContext = Awaited<ReturnType<typeof setupContext>>;
|
|
57
|
+
export declare const setupNetworks: (networkOptions: Partial<Record<string, Config | string | undefined>>) => Promise<Record<string, {
|
|
58
|
+
url: string;
|
|
59
|
+
chain: import("@acala-network/chopsticks").Blockchain;
|
|
60
|
+
ws: WsProvider;
|
|
61
|
+
api: ApiPromise;
|
|
62
|
+
dev: {
|
|
63
|
+
newBlock: (param?: {
|
|
64
|
+
count?: number;
|
|
65
|
+
to?: number;
|
|
66
|
+
}) => Promise<string>;
|
|
67
|
+
setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
|
|
68
|
+
timeTravel: (date: string | number) => Promise<number>;
|
|
69
|
+
setHead: (hashOrNumber: string | number) => Promise<any>;
|
|
70
|
+
};
|
|
71
|
+
teardown(): Promise<void>;
|
|
72
|
+
pause(): Promise<unknown>;
|
|
73
|
+
}>>;
|
|
33
74
|
type CodecOrArray = Codec | Codec[];
|
|
34
75
|
export declare const expectJson: (codec: CodecOrArray) => import("@vitest/expect").Assertion<any>;
|
|
35
76
|
export declare const expectHex: (codec: CodecOrArray) => import("@vitest/expect").Assertion<any>;
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
2
|
-
import { BuildBlockMode, setupWithServer } from '@acala-network/chopsticks';
|
|
2
|
+
import { BuildBlockMode, connectParachains, connectVertical, fetchConfig, setupWithServer, } from '@acala-network/chopsticks';
|
|
3
3
|
import { Keyring, createTestKeyring } from '@polkadot/keyring';
|
|
4
4
|
import { expect } from 'vitest';
|
|
5
5
|
export * from './check';
|
|
6
|
-
export const
|
|
7
|
-
// random port
|
|
8
|
-
|
|
6
|
+
export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, port, }) => {
|
|
7
|
+
// random port if not specified
|
|
8
|
+
port = port ?? Math.floor(Math.random() * 10000) + 10000;
|
|
9
9
|
const config = {
|
|
10
10
|
endpoint,
|
|
11
11
|
port,
|
|
@@ -14,7 +14,14 @@ export const setupContext = async ({ endpoint, blockNumber, blockHash, wasmOverr
|
|
|
14
14
|
'build-block-mode': BuildBlockMode.Manual,
|
|
15
15
|
db,
|
|
16
16
|
'wasm-override': wasmOverride,
|
|
17
|
+
timeout,
|
|
17
18
|
};
|
|
19
|
+
return config;
|
|
20
|
+
};
|
|
21
|
+
export const setupContext = async (option) => {
|
|
22
|
+
return setupContextWithConfig(createConfig(option));
|
|
23
|
+
};
|
|
24
|
+
export const setupContextWithConfig = async ({ timeout, ...config }) => {
|
|
18
25
|
const { chain, listenPort, close } = await setupWithServer(config);
|
|
19
26
|
const url = `ws://localhost:${listenPort}`;
|
|
20
27
|
const ws = new WsProvider(url, undefined, undefined, timeout);
|
|
@@ -59,6 +66,37 @@ export const setupContext = async ({ endpoint, blockNumber, blockHash, wasmOverr
|
|
|
59
66
|
},
|
|
60
67
|
};
|
|
61
68
|
};
|
|
69
|
+
export const setupNetworks = async (networkOptions) => {
|
|
70
|
+
const ret = {};
|
|
71
|
+
let wasmOverriden = false;
|
|
72
|
+
for (const [name, options] of Object.entries(networkOptions)) {
|
|
73
|
+
const config = typeof options === 'string' ? await fetchConfig(options) : options ?? (await fetchConfig(name));
|
|
74
|
+
ret[name] = await setupContextWithConfig(config);
|
|
75
|
+
wasmOverriden ||= config['wasm-override'] != null;
|
|
76
|
+
}
|
|
77
|
+
const relaychainName = Object.keys(ret).filter((x) => ['polkadot', 'kusama'].includes(x.toLocaleLowerCase()))[0];
|
|
78
|
+
const { [relaychainName]: relaychain, ...parachains } = ret;
|
|
79
|
+
if (relaychain) {
|
|
80
|
+
for (const parachain of Object.values(parachains)) {
|
|
81
|
+
await connectVertical(relaychain.chain, parachain.chain);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const parachainList = Object.values(parachains).map((i) => i.chain);
|
|
85
|
+
if (parachainList.length > 0) {
|
|
86
|
+
await connectParachains(parachainList);
|
|
87
|
+
}
|
|
88
|
+
if (wasmOverriden) {
|
|
89
|
+
// trigger runtime upgrade if needed (due to wasm override)
|
|
90
|
+
for (const chain of Object.values(ret)) {
|
|
91
|
+
await chain.dev.newBlock();
|
|
92
|
+
}
|
|
93
|
+
// handle xcm version message if needed (due to wasm override triggered xcm version upgrade)
|
|
94
|
+
for (const chain of Object.values(ret)) {
|
|
95
|
+
await chain.dev.newBlock();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return ret;
|
|
99
|
+
};
|
|
62
100
|
const processCodecOrArray = (codec, fn) => Array.isArray(codec) ? codec.map(fn) : fn(codec);
|
|
63
101
|
const toHuman = (codec) => processCodecOrArray(codec, (c) => c?.toHuman?.() ?? c);
|
|
64
102
|
const toJson = (codec) => processCodecOrArray(codec, (c) => c?.toJSON?.() ?? c);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-testing",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"build": "tsc -p ./tsconfig.json"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@acala-network/chopsticks": "0.7.
|
|
11
|
+
"@acala-network/chopsticks": "0.7.1"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"vitest": "^0.33.0"
|