@acala-network/chopsticks-utils 1.0.1 → 1.0.2-2

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.
@@ -7,76 +7,150 @@ import { Keyring } from '@polkadot/keyring';
7
7
  import { NewBlockParams } from '@acala-network/chopsticks-core/rpc/dev/new-block.js';
8
8
  import { SubmittableExtrinsic } from '@polkadot/api-base/types';
9
9
  export * from './signFake.js';
10
+ /**
11
+ * Configuration options for setting up a blockchain network instance
12
+ */
10
13
  export type SetupOption = {
14
+ /** WebSocket endpoint(s) for connecting to the network */
11
15
  endpoint: string | string[];
16
+ /** Specific block number to start from */
12
17
  blockNumber?: number;
18
+ /** Specific block hash to start from */
13
19
  blockHash?: HexString;
20
+ /** Path to override WASM runtime */
14
21
  wasmOverride?: string;
22
+ /** Path to database file */
15
23
  db?: string;
24
+ /** Connection timeout in milliseconds */
16
25
  timeout?: number;
26
+ /** Host address to bind the server to */
17
27
  host?: string;
28
+ /** Port number to bind the server to */
18
29
  port?: number;
30
+ /** Maximum number of blocks to keep in memory */
19
31
  maxMemoryBlockCount?: number;
32
+ /** Resume from a previous state (block hash or number) */
20
33
  resume?: boolean | HexString | number;
34
+ /** Runtime log level (0-5) */
21
35
  runtimeLogLevel?: number;
36
+ /** Allow unresolved imports in runtime */
22
37
  allowUnresolvedImports?: boolean;
38
+ /** Process queued XCM messages */
23
39
  processQueuedMessages?: boolean;
24
40
  };
41
+ /**
42
+ * Extended configuration type that includes timeout
43
+ */
25
44
  export type SetupConfig = Config & {
45
+ /** Connection timeout in milliseconds */
26
46
  timeout?: number;
27
47
  };
48
+ /**
49
+ * Creates a configuration object from setup options
50
+ * @param options - Setup options for the network
51
+ * @returns Configuration object compatible with chopsticks
52
+ */
28
53
  export declare const createConfig: ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, host, port, maxMemoryBlockCount, resume, runtimeLogLevel, allowUnresolvedImports, processQueuedMessages, }: SetupOption) => SetupConfig;
54
+ /**
55
+ * Sets up a blockchain network context using provided options
56
+ * @param option - Setup options for the network
57
+ * @returns Network context including API, WebSocket provider, and utility functions
58
+ */
29
59
  export declare const setupContext: (option: SetupOption) => Promise<{
30
60
  url: string;
31
61
  chain: import("@acala-network/chopsticks").Blockchain;
32
62
  ws: WsProvider;
33
63
  api: ApiPromise;
34
64
  dev: {
65
+ /** Creates a new block with optional parameters */
35
66
  newBlock: (param?: Partial<NewBlockParams>) => Promise<string>;
67
+ /** Sets storage values at a specific block */
36
68
  setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
69
+ /** Moves blockchain time to a specific timestamp */
37
70
  timeTravel: (date: string | number) => Promise<number>;
71
+ /** Sets the chain head to a specific block */
38
72
  setHead: (hashOrNumber: string | number) => Promise<any>;
39
73
  };
74
+ /** Cleans up resources and closes connections */
40
75
  teardown(): Promise<void>;
76
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */
41
77
  pause(): Promise<unknown>;
42
78
  }>;
79
+ /**
80
+ * Sets up a blockchain network context using a configuration object
81
+ * @param config - Configuration object for the network
82
+ * @returns Network context including API, WebSocket provider, and utility functions
83
+ */
43
84
  export declare const setupContextWithConfig: ({ timeout, ...config }: SetupConfig) => Promise<{
44
85
  url: string;
45
86
  chain: import("@acala-network/chopsticks").Blockchain;
46
87
  ws: WsProvider;
47
88
  api: ApiPromise;
48
89
  dev: {
90
+ /** Creates a new block with optional parameters */
49
91
  newBlock: (param?: Partial<NewBlockParams>) => Promise<string>;
92
+ /** Sets storage values at a specific block */
50
93
  setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
94
+ /** Moves blockchain time to a specific timestamp */
51
95
  timeTravel: (date: string | number) => Promise<number>;
96
+ /** Sets the chain head to a specific block */
52
97
  setHead: (hashOrNumber: string | number) => Promise<any>;
53
98
  };
99
+ /** Cleans up resources and closes connections */
54
100
  teardown(): Promise<void>;
101
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */
55
102
  pause(): Promise<unknown>;
56
103
  }>;
104
+ /** Type alias for the network context returned by setupContext */
57
105
  export type NetworkContext = Awaited<ReturnType<typeof setupContext>>;
106
+ /**
107
+ * Sets up multiple blockchain networks and establishes connections between them
108
+ * @param networkOptions - Configuration options for each network
109
+ * @returns Record of network contexts indexed by network name
110
+ */
58
111
  export declare const setupNetworks: (networkOptions: Partial<Record<string, Config | string | undefined>>) => Promise<Record<string, {
59
112
  url: string;
60
113
  chain: import("@acala-network/chopsticks").Blockchain;
61
114
  ws: WsProvider;
62
115
  api: ApiPromise;
63
116
  dev: {
117
+ /** Creates a new block with optional parameters */
64
118
  newBlock: (param?: Partial<NewBlockParams>) => Promise<string>;
119
+ /** Sets storage values at a specific block */
65
120
  setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
121
+ /** Moves blockchain time to a specific timestamp */
66
122
  timeTravel: (date: string | number) => Promise<number>;
123
+ /** Sets the chain head to a specific block */
67
124
  setHead: (hashOrNumber: string | number) => Promise<any>;
68
125
  };
126
+ /** Cleans up resources and closes connections */
69
127
  teardown(): Promise<void>;
128
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */
70
129
  pause(): Promise<unknown>;
71
130
  }>>;
131
+ /**
132
+ * Creates a deferred promise that can be resolved or rejected from outside
133
+ * @returns Object containing promise, resolve function, and reject function
134
+ */
72
135
  export declare function defer<T>(): {
73
136
  resolve: (value: any) => void;
74
137
  reject: (reason: any) => void;
75
138
  promise: Promise<T>;
76
139
  };
140
+ /**
141
+ * Sends a transaction and waits for it to be included in a block
142
+ * @param tx - Promise of a submittable extrinsic
143
+ * @returns Promise that resolves with transaction events
144
+ */
77
145
  export declare const sendTransaction: (tx: Promise<SubmittableExtrinsic<"promise">>) => Promise<{
78
146
  events: Promise<Codec[]>;
79
147
  }>;
148
+ /**
149
+ * Creates a set of test keypairs for both ed25519/sr25519 and ethereum addresses
150
+ * @param keyringType - Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
151
+ * @param ss58Format - SS58 address format to use
152
+ * @returns Object containing various test keypairs and keyring instances
153
+ */
80
154
  export declare const testingPairs: (keyringType?: "ed25519" | "sr25519", ss58Format?: number) => {
81
155
  alice: import("@polkadot/keyring/types").KeyringPair;
82
156
  bob: import("@polkadot/keyring/types").KeyringPair;
package/dist/cjs/index.js CHANGED
@@ -89,33 +89,33 @@ const setupContextWithConfig = async ({ timeout, ...config })=>{
89
89
  ws,
90
90
  api,
91
91
  dev: {
92
- newBlock: (param)=>{
92
+ /** Creates a new block with optional parameters */ newBlock: (param)=>{
93
93
  return ws.send('dev_newBlock', [
94
94
  param
95
95
  ]);
96
96
  },
97
- setStorage: (values, blockHash)=>{
97
+ /** Sets storage values at a specific block */ setStorage: (values, blockHash)=>{
98
98
  return ws.send('dev_setStorage', [
99
99
  values,
100
100
  blockHash
101
101
  ]);
102
102
  },
103
- timeTravel: (date)=>{
103
+ /** Moves blockchain time to a specific timestamp */ timeTravel: (date)=>{
104
104
  return ws.send('dev_timeTravel', [
105
105
  date
106
106
  ]);
107
107
  },
108
- setHead: (hashOrNumber)=>{
108
+ /** Sets the chain head to a specific block */ setHead: (hashOrNumber)=>{
109
109
  return ws.send('dev_setHead', [
110
110
  hashOrNumber
111
111
  ]);
112
112
  }
113
113
  },
114
- async teardown () {
114
+ /** Cleans up resources and closes connections */ async teardown () {
115
115
  await api.disconnect();
116
116
  await close();
117
117
  },
118
- async pause () {
118
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */ async pause () {
119
119
  await ws.send('dev_setBlockBuildMode', [
120
120
  _chopsticks.BuildBlockMode.Instant
121
121
  ]);
@@ -7,76 +7,150 @@ import { Keyring } from '@polkadot/keyring';
7
7
  import { NewBlockParams } from '@acala-network/chopsticks-core/rpc/dev/new-block.js';
8
8
  import { SubmittableExtrinsic } from '@polkadot/api-base/types';
9
9
  export * from './signFake.js';
10
+ /**
11
+ * Configuration options for setting up a blockchain network instance
12
+ */
10
13
  export type SetupOption = {
14
+ /** WebSocket endpoint(s) for connecting to the network */
11
15
  endpoint: string | string[];
16
+ /** Specific block number to start from */
12
17
  blockNumber?: number;
18
+ /** Specific block hash to start from */
13
19
  blockHash?: HexString;
20
+ /** Path to override WASM runtime */
14
21
  wasmOverride?: string;
22
+ /** Path to database file */
15
23
  db?: string;
24
+ /** Connection timeout in milliseconds */
16
25
  timeout?: number;
26
+ /** Host address to bind the server to */
17
27
  host?: string;
28
+ /** Port number to bind the server to */
18
29
  port?: number;
30
+ /** Maximum number of blocks to keep in memory */
19
31
  maxMemoryBlockCount?: number;
32
+ /** Resume from a previous state (block hash or number) */
20
33
  resume?: boolean | HexString | number;
34
+ /** Runtime log level (0-5) */
21
35
  runtimeLogLevel?: number;
36
+ /** Allow unresolved imports in runtime */
22
37
  allowUnresolvedImports?: boolean;
38
+ /** Process queued XCM messages */
23
39
  processQueuedMessages?: boolean;
24
40
  };
41
+ /**
42
+ * Extended configuration type that includes timeout
43
+ */
25
44
  export type SetupConfig = Config & {
45
+ /** Connection timeout in milliseconds */
26
46
  timeout?: number;
27
47
  };
48
+ /**
49
+ * Creates a configuration object from setup options
50
+ * @param options - Setup options for the network
51
+ * @returns Configuration object compatible with chopsticks
52
+ */
28
53
  export declare const createConfig: ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, host, port, maxMemoryBlockCount, resume, runtimeLogLevel, allowUnresolvedImports, processQueuedMessages, }: SetupOption) => SetupConfig;
54
+ /**
55
+ * Sets up a blockchain network context using provided options
56
+ * @param option - Setup options for the network
57
+ * @returns Network context including API, WebSocket provider, and utility functions
58
+ */
29
59
  export declare const setupContext: (option: SetupOption) => Promise<{
30
60
  url: string;
31
61
  chain: import("@acala-network/chopsticks").Blockchain;
32
62
  ws: WsProvider;
33
63
  api: ApiPromise;
34
64
  dev: {
65
+ /** Creates a new block with optional parameters */
35
66
  newBlock: (param?: Partial<NewBlockParams>) => Promise<string>;
67
+ /** Sets storage values at a specific block */
36
68
  setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
69
+ /** Moves blockchain time to a specific timestamp */
37
70
  timeTravel: (date: string | number) => Promise<number>;
71
+ /** Sets the chain head to a specific block */
38
72
  setHead: (hashOrNumber: string | number) => Promise<any>;
39
73
  };
74
+ /** Cleans up resources and closes connections */
40
75
  teardown(): Promise<void>;
76
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */
41
77
  pause(): Promise<unknown>;
42
78
  }>;
79
+ /**
80
+ * Sets up a blockchain network context using a configuration object
81
+ * @param config - Configuration object for the network
82
+ * @returns Network context including API, WebSocket provider, and utility functions
83
+ */
43
84
  export declare const setupContextWithConfig: ({ timeout, ...config }: SetupConfig) => Promise<{
44
85
  url: string;
45
86
  chain: import("@acala-network/chopsticks").Blockchain;
46
87
  ws: WsProvider;
47
88
  api: ApiPromise;
48
89
  dev: {
90
+ /** Creates a new block with optional parameters */
49
91
  newBlock: (param?: Partial<NewBlockParams>) => Promise<string>;
92
+ /** Sets storage values at a specific block */
50
93
  setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
94
+ /** Moves blockchain time to a specific timestamp */
51
95
  timeTravel: (date: string | number) => Promise<number>;
96
+ /** Sets the chain head to a specific block */
52
97
  setHead: (hashOrNumber: string | number) => Promise<any>;
53
98
  };
99
+ /** Cleans up resources and closes connections */
54
100
  teardown(): Promise<void>;
101
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */
55
102
  pause(): Promise<unknown>;
56
103
  }>;
104
+ /** Type alias for the network context returned by setupContext */
57
105
  export type NetworkContext = Awaited<ReturnType<typeof setupContext>>;
106
+ /**
107
+ * Sets up multiple blockchain networks and establishes connections between them
108
+ * @param networkOptions - Configuration options for each network
109
+ * @returns Record of network contexts indexed by network name
110
+ */
58
111
  export declare const setupNetworks: (networkOptions: Partial<Record<string, Config | string | undefined>>) => Promise<Record<string, {
59
112
  url: string;
60
113
  chain: import("@acala-network/chopsticks").Blockchain;
61
114
  ws: WsProvider;
62
115
  api: ApiPromise;
63
116
  dev: {
117
+ /** Creates a new block with optional parameters */
64
118
  newBlock: (param?: Partial<NewBlockParams>) => Promise<string>;
119
+ /** Sets storage values at a specific block */
65
120
  setStorage: (values: StorageValues, blockHash?: string) => Promise<any>;
121
+ /** Moves blockchain time to a specific timestamp */
66
122
  timeTravel: (date: string | number) => Promise<number>;
123
+ /** Sets the chain head to a specific block */
67
124
  setHead: (hashOrNumber: string | number) => Promise<any>;
68
125
  };
126
+ /** Cleans up resources and closes connections */
69
127
  teardown(): Promise<void>;
128
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */
70
129
  pause(): Promise<unknown>;
71
130
  }>>;
131
+ /**
132
+ * Creates a deferred promise that can be resolved or rejected from outside
133
+ * @returns Object containing promise, resolve function, and reject function
134
+ */
72
135
  export declare function defer<T>(): {
73
136
  resolve: (value: any) => void;
74
137
  reject: (reason: any) => void;
75
138
  promise: Promise<T>;
76
139
  };
140
+ /**
141
+ * Sends a transaction and waits for it to be included in a block
142
+ * @param tx - Promise of a submittable extrinsic
143
+ * @returns Promise that resolves with transaction events
144
+ */
77
145
  export declare const sendTransaction: (tx: Promise<SubmittableExtrinsic<"promise">>) => Promise<{
78
146
  events: Promise<Codec[]>;
79
147
  }>;
148
+ /**
149
+ * Creates a set of test keypairs for both ed25519/sr25519 and ethereum addresses
150
+ * @param keyringType - Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
151
+ * @param ss58Format - SS58 address format to use
152
+ * @returns Object containing various test keypairs and keyring instances
153
+ */
80
154
  export declare const testingPairs: (keyringType?: "ed25519" | "sr25519", ss58Format?: number) => {
81
155
  alice: import("@polkadot/keyring/types").KeyringPair;
82
156
  bob: import("@polkadot/keyring/types").KeyringPair;
package/dist/esm/index.js CHANGED
@@ -5,7 +5,11 @@ const logger = defaultLogger.child({
5
5
  name: 'utils'
6
6
  });
7
7
  export * from './signFake.js';
8
- export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, host, port, maxMemoryBlockCount, resume, runtimeLogLevel, allowUnresolvedImports, processQueuedMessages })=>{
8
+ /**
9
+ * Creates a configuration object from setup options
10
+ * @param options - Setup options for the network
11
+ * @returns Configuration object compatible with chopsticks
12
+ */ export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, host, port, maxMemoryBlockCount, resume, runtimeLogLevel, allowUnresolvedImports, processQueuedMessages })=>{
9
13
  // random port if not specified
10
14
  port = port ?? Math.floor(Math.random() * 10000) + 10000;
11
15
  const config = {
@@ -26,10 +30,18 @@ export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, d
26
30
  };
27
31
  return config;
28
32
  };
29
- export const setupContext = async (option)=>{
33
+ /**
34
+ * Sets up a blockchain network context using provided options
35
+ * @param option - Setup options for the network
36
+ * @returns Network context including API, WebSocket provider, and utility functions
37
+ */ export const setupContext = async (option)=>{
30
38
  return setupContextWithConfig(createConfig(option));
31
39
  };
32
- export const setupContextWithConfig = async ({ timeout, ...config })=>{
40
+ /**
41
+ * Sets up a blockchain network context using a configuration object
42
+ * @param config - Configuration object for the network
43
+ * @returns Network context including API, WebSocket provider, and utility functions
44
+ */ export const setupContextWithConfig = async ({ timeout, ...config })=>{
33
45
  const { chain, addr, close } = await setupWithServer(config);
34
46
  const url = `ws://${addr}`;
35
47
  const ws = new WsProvider(url, 3_000, undefined, timeout);
@@ -43,33 +55,33 @@ export const setupContextWithConfig = async ({ timeout, ...config })=>{
43
55
  ws,
44
56
  api,
45
57
  dev: {
46
- newBlock: (param)=>{
58
+ /** Creates a new block with optional parameters */ newBlock: (param)=>{
47
59
  return ws.send('dev_newBlock', [
48
60
  param
49
61
  ]);
50
62
  },
51
- setStorage: (values, blockHash)=>{
63
+ /** Sets storage values at a specific block */ setStorage: (values, blockHash)=>{
52
64
  return ws.send('dev_setStorage', [
53
65
  values,
54
66
  blockHash
55
67
  ]);
56
68
  },
57
- timeTravel: (date)=>{
69
+ /** Moves blockchain time to a specific timestamp */ timeTravel: (date)=>{
58
70
  return ws.send('dev_timeTravel', [
59
71
  date
60
72
  ]);
61
73
  },
62
- setHead: (hashOrNumber)=>{
74
+ /** Sets the chain head to a specific block */ setHead: (hashOrNumber)=>{
63
75
  return ws.send('dev_setHead', [
64
76
  hashOrNumber
65
77
  ]);
66
78
  }
67
79
  },
68
- async teardown () {
80
+ /** Cleans up resources and closes connections */ async teardown () {
69
81
  await api.disconnect();
70
82
  await close();
71
83
  },
72
- async pause () {
84
+ /** Pauses execution and enables manual interaction through Polkadot.js apps */ async pause () {
73
85
  await ws.send('dev_setBlockBuildMode', [
74
86
  BuildBlockMode.Instant
75
87
  ]);
@@ -80,7 +92,11 @@ export const setupContextWithConfig = async ({ timeout, ...config })=>{
80
92
  }
81
93
  };
82
94
  };
83
- export const setupNetworks = async (networkOptions)=>{
95
+ /**
96
+ * Sets up multiple blockchain networks and establishes connections between them
97
+ * @param networkOptions - Configuration options for each network
98
+ * @returns Record of network contexts indexed by network name
99
+ */ export const setupNetworks = async (networkOptions)=>{
84
100
  const ret = {};
85
101
  let wasmOverriden = false;
86
102
  for (const [name, options] of Object.entries(networkOptions)){
@@ -114,7 +130,10 @@ export const setupNetworks = async (networkOptions)=>{
114
130
  }
115
131
  return ret;
116
132
  };
117
- export function defer() {
133
+ /**
134
+ * Creates a deferred promise that can be resolved or rejected from outside
135
+ * @returns Object containing promise, resolve function, and reject function
136
+ */ export function defer() {
118
137
  const deferred = {};
119
138
  deferred.promise = new Promise((resolve, reject)=>{
120
139
  deferred.resolve = resolve;
@@ -122,7 +141,11 @@ export function defer() {
122
141
  });
123
142
  return deferred;
124
143
  }
125
- export const sendTransaction = async (tx)=>{
144
+ /**
145
+ * Sends a transaction and waits for it to be included in a block
146
+ * @param tx - Promise of a submittable extrinsic
147
+ * @returns Promise that resolves with transaction events
148
+ */ export const sendTransaction = async (tx)=>{
126
149
  const signed = await tx;
127
150
  const deferred = defer();
128
151
  await signed.send((status)=>{
@@ -140,7 +163,12 @@ export const sendTransaction = async (tx)=>{
140
163
  events: deferred.promise
141
164
  };
142
165
  };
143
- export const testingPairs = (keyringType = 'ed25519', ss58Format)=>{
166
+ /**
167
+ * Creates a set of test keypairs for both ed25519/sr25519 and ethereum addresses
168
+ * @param keyringType - Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
169
+ * @param ss58Format - SS58 address format to use
170
+ * @returns Object containing various test keypairs and keyring instances
171
+ */ export const testingPairs = (keyringType = 'ed25519', ss58Format)=>{
144
172
  const keyringEth = createTestKeyring({
145
173
  type: 'ethereum'
146
174
  });
package/package.json CHANGED
@@ -1,27 +1,30 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks-utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-2",
4
4
  "author": "Acala Developers <hello@acala.network>",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
+ "engines": {
8
+ "node": ">=v20"
9
+ },
7
10
  "scripts": {
8
11
  "clean": "rm -rf dist tsconfig.tsbuildinfo",
9
12
  "build": "yarn clean && ../../package-build.sh",
10
13
  "depcheck": "npx depcheck"
11
14
  },
12
15
  "dependencies": {
13
- "@acala-network/chopsticks": "1.0.1",
14
- "@acala-network/chopsticks-core": "1.0.1",
15
- "@polkadot/api": "^14.0.1",
16
- "@polkadot/api-base": "^14.0.1",
17
- "@polkadot/keyring": "^13.2.2",
18
- "@polkadot/types": "^14.0.1",
19
- "@polkadot/util": "^13.2.2"
16
+ "@acala-network/chopsticks": "1.0.2-2",
17
+ "@acala-network/chopsticks-core": "1.0.2-2",
18
+ "@polkadot/api": "^15.0",
19
+ "@polkadot/api-base": "^15.0",
20
+ "@polkadot/keyring": "^13.2",
21
+ "@polkadot/types": "^15.0",
22
+ "@polkadot/util": "^13.2"
20
23
  },
21
24
  "devDependencies": {
22
- "@swc/cli": "0.5.0",
23
- "@swc/core": "^1.7.40",
24
- "typescript": "^5.6.3"
25
+ "@swc/cli": "0.5.2",
26
+ "@swc/core": "^1.10.1",
27
+ "typescript": "^5.7.2"
25
28
  },
26
29
  "files": [
27
30
  "dist/esm/**",