@acala-network/chopsticks-utils 1.0.2-1 → 1.0.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.
- package/dist/cjs/index.d.ts +94 -6
- package/dist/cjs/index.js +32 -7
- package/dist/cjs/signFake.d.ts +3 -3
- package/dist/esm/index.d.ts +94 -6
- package/dist/esm/index.js +68 -14
- package/dist/esm/signFake.d.ts +3 -3
- package/package.json +17 -11
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,82 +1,156 @@
|
|
|
1
|
+
import { type StorageValues } from '@acala-network/chopsticks';
|
|
2
|
+
import type { NewBlockParams } from '@acala-network/chopsticks-core/rpc/dev/new-block.js';
|
|
3
|
+
import type { Config } from '@acala-network/chopsticks/schema/index.js';
|
|
1
4
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
2
|
-
import {
|
|
3
|
-
import { Codec } from '@polkadot/types/types';
|
|
4
|
-
import { Config } from '@acala-network/chopsticks/schema/index.js';
|
|
5
|
-
import { HexString } from '@polkadot/util/types';
|
|
5
|
+
import type { SubmittableExtrinsic } from '@polkadot/api-base/types';
|
|
6
6
|
import { Keyring } from '@polkadot/keyring';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import type { Codec } from '@polkadot/types/types';
|
|
8
|
+
import type { HexString } from '@polkadot/util/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;
|
|
@@ -91,3 +165,17 @@ export declare const testingPairs: (keyringType?: "ed25519" | "sr25519", ss58For
|
|
|
91
165
|
keyring: Keyring;
|
|
92
166
|
keyringEth: import("@polkadot/keyring/types").KeyringInstance;
|
|
93
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Creates a set of test signers for either Ed25519 or Sr25519.
|
|
170
|
+
* @param keyringType Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
|
|
171
|
+
* @returns Object containing various test signers, and a `polkadotSignerBuilder` function to create more.
|
|
172
|
+
*/
|
|
173
|
+
export declare const testingSigners: (keyringType?: "Ed25519" | "Sr25519") => {
|
|
174
|
+
alice: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
175
|
+
bob: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
176
|
+
charlie: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
177
|
+
dave: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
178
|
+
eve: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
179
|
+
ferdie: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
180
|
+
polkadotSignerBuilder: (path: string, keyringType?: "Ed25519" | "Sr25519") => import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
181
|
+
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -29,11 +29,17 @@ _export(exports, {
|
|
|
29
29
|
},
|
|
30
30
|
testingPairs: function() {
|
|
31
31
|
return testingPairs;
|
|
32
|
+
},
|
|
33
|
+
testingSigners: function() {
|
|
34
|
+
return testingSigners;
|
|
32
35
|
}
|
|
33
36
|
});
|
|
34
|
-
const _api = require("@polkadot/api");
|
|
35
37
|
const _chopsticks = require("@acala-network/chopsticks");
|
|
38
|
+
const _hdkd = require("@polkadot-labs/hdkd");
|
|
39
|
+
const _hdkdhelpers = require("@polkadot-labs/hdkd-helpers");
|
|
40
|
+
const _api = require("@polkadot/api");
|
|
36
41
|
const _keyring = require("@polkadot/keyring");
|
|
42
|
+
const _signer = require("polkadot-api/signer");
|
|
37
43
|
_export_star(require("./signFake.js"), exports);
|
|
38
44
|
function _export_star(from, to) {
|
|
39
45
|
Object.keys(from).forEach(function(k) {
|
|
@@ -89,33 +95,33 @@ const setupContextWithConfig = async ({ timeout, ...config })=>{
|
|
|
89
95
|
ws,
|
|
90
96
|
api,
|
|
91
97
|
dev: {
|
|
92
|
-
newBlock: (param)=>{
|
|
98
|
+
/** Creates a new block with optional parameters */ newBlock: (param)=>{
|
|
93
99
|
return ws.send('dev_newBlock', [
|
|
94
100
|
param
|
|
95
101
|
]);
|
|
96
102
|
},
|
|
97
|
-
setStorage: (values, blockHash)=>{
|
|
103
|
+
/** Sets storage values at a specific block */ setStorage: (values, blockHash)=>{
|
|
98
104
|
return ws.send('dev_setStorage', [
|
|
99
105
|
values,
|
|
100
106
|
blockHash
|
|
101
107
|
]);
|
|
102
108
|
},
|
|
103
|
-
timeTravel: (date)=>{
|
|
109
|
+
/** Moves blockchain time to a specific timestamp */ timeTravel: (date)=>{
|
|
104
110
|
return ws.send('dev_timeTravel', [
|
|
105
111
|
date
|
|
106
112
|
]);
|
|
107
113
|
},
|
|
108
|
-
setHead: (hashOrNumber)=>{
|
|
114
|
+
/** Sets the chain head to a specific block */ setHead: (hashOrNumber)=>{
|
|
109
115
|
return ws.send('dev_setHead', [
|
|
110
116
|
hashOrNumber
|
|
111
117
|
]);
|
|
112
118
|
}
|
|
113
119
|
},
|
|
114
|
-
async teardown () {
|
|
120
|
+
/** Cleans up resources and closes connections */ async teardown () {
|
|
115
121
|
await api.disconnect();
|
|
116
122
|
await close();
|
|
117
123
|
},
|
|
118
|
-
async pause () {
|
|
124
|
+
/** Pauses execution and enables manual interaction through Polkadot.js apps */ async pause () {
|
|
119
125
|
await ws.send('dev_setBlockBuildMode', [
|
|
120
126
|
_chopsticks.BuildBlockMode.Instant
|
|
121
127
|
]);
|
|
@@ -210,3 +216,22 @@ const testingPairs = (keyringType = 'ed25519', ss58Format)=>{
|
|
|
210
216
|
keyringEth
|
|
211
217
|
};
|
|
212
218
|
};
|
|
219
|
+
const testingSigners = (keyringType = 'Ed25519')=>{
|
|
220
|
+
const entropy = (0, _hdkdhelpers.mnemonicToEntropy)(_hdkdhelpers.DEV_PHRASE);
|
|
221
|
+
const miniSecret = (0, _hdkdhelpers.entropyToMiniSecret)(entropy);
|
|
222
|
+
const derive = keyringType === 'Ed25519' ? (0, _hdkd.ed25519CreateDerive)(miniSecret) : (0, _hdkd.sr25519CreateDerive)(miniSecret);
|
|
223
|
+
// Create a PAPI polkadot signer given a derivation path e.g. "//Alice" or "//Bob".
|
|
224
|
+
const polkadotSignerBuilder = (path, keyringType = 'Ed25519')=>{
|
|
225
|
+
const hdkdKeyPair = derive(path);
|
|
226
|
+
return (0, _signer.getPolkadotSigner)(hdkdKeyPair.publicKey, keyringType, hdkdKeyPair.sign);
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
alice: polkadotSignerBuilder('//Alice', keyringType),
|
|
230
|
+
bob: polkadotSignerBuilder('//Bob', keyringType),
|
|
231
|
+
charlie: polkadotSignerBuilder('//Charlie', keyringType),
|
|
232
|
+
dave: polkadotSignerBuilder('//Dave', keyringType),
|
|
233
|
+
eve: polkadotSignerBuilder('//Eve', keyringType),
|
|
234
|
+
ferdie: polkadotSignerBuilder('//Ferdie', keyringType),
|
|
235
|
+
polkadotSignerBuilder
|
|
236
|
+
};
|
|
237
|
+
};
|
package/dist/cjs/signFake.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { GenericExtrinsic } from '@polkadot/types';
|
|
3
|
-
import { SignatureOptions } from '@polkadot/types/types';
|
|
1
|
+
import type { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import type { GenericExtrinsic } from '@polkadot/types';
|
|
3
|
+
import type { SignatureOptions } from '@polkadot/types/types';
|
|
4
4
|
export type SignFakeOptions = Partial<SignatureOptions>;
|
|
5
5
|
export declare const signFakeWithApi: (api: ApiPromise, tx: GenericExtrinsic, addr: string, options?: SignFakeOptions) => Promise<void>;
|
|
6
6
|
export declare const signFake: (tx: GenericExtrinsic, addr: string, options: SignatureOptions) => void;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,82 +1,156 @@
|
|
|
1
|
+
import { type StorageValues } from '@acala-network/chopsticks';
|
|
2
|
+
import type { NewBlockParams } from '@acala-network/chopsticks-core/rpc/dev/new-block.js';
|
|
3
|
+
import type { Config } from '@acala-network/chopsticks/schema/index.js';
|
|
1
4
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
2
|
-
import {
|
|
3
|
-
import { Codec } from '@polkadot/types/types';
|
|
4
|
-
import { Config } from '@acala-network/chopsticks/schema/index.js';
|
|
5
|
-
import { HexString } from '@polkadot/util/types';
|
|
5
|
+
import type { SubmittableExtrinsic } from '@polkadot/api-base/types';
|
|
6
6
|
import { Keyring } from '@polkadot/keyring';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import type { Codec } from '@polkadot/types/types';
|
|
8
|
+
import type { HexString } from '@polkadot/util/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;
|
|
@@ -91,3 +165,17 @@ export declare const testingPairs: (keyringType?: "ed25519" | "sr25519", ss58For
|
|
|
91
165
|
keyring: Keyring;
|
|
92
166
|
keyringEth: import("@polkadot/keyring/types").KeyringInstance;
|
|
93
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Creates a set of test signers for either Ed25519 or Sr25519.
|
|
170
|
+
* @param keyringType Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
|
|
171
|
+
* @returns Object containing various test signers, and a `polkadotSignerBuilder` function to create more.
|
|
172
|
+
*/
|
|
173
|
+
export declare const testingSigners: (keyringType?: "Ed25519" | "Sr25519") => {
|
|
174
|
+
alice: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
175
|
+
bob: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
176
|
+
charlie: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
177
|
+
dave: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
178
|
+
eve: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
179
|
+
ferdie: import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
180
|
+
polkadotSignerBuilder: (path: string, keyringType?: "Ed25519" | "Sr25519") => import("@polkadot-api/polkadot-signer").PolkadotSigner;
|
|
181
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
2
1
|
import { BuildBlockMode, connectParachains, connectVertical, defaultLogger, environment, fetchConfig, setupWithServer } from '@acala-network/chopsticks';
|
|
2
|
+
import { ed25519CreateDerive, sr25519CreateDerive } from '@polkadot-labs/hdkd';
|
|
3
|
+
import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from '@polkadot-labs/hdkd-helpers';
|
|
4
|
+
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
3
5
|
import { Keyring, createTestKeyring } from '@polkadot/keyring';
|
|
6
|
+
import { getPolkadotSigner } from 'polkadot-api/signer';
|
|
4
7
|
const logger = defaultLogger.child({
|
|
5
8
|
name: 'utils'
|
|
6
9
|
});
|
|
7
10
|
export * from './signFake.js';
|
|
8
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates a configuration object from setup options
|
|
13
|
+
* @param options - Setup options for the network
|
|
14
|
+
* @returns Configuration object compatible with chopsticks
|
|
15
|
+
*/ export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, host, port, maxMemoryBlockCount, resume, runtimeLogLevel, allowUnresolvedImports, processQueuedMessages })=>{
|
|
9
16
|
// random port if not specified
|
|
10
17
|
port = port ?? Math.floor(Math.random() * 10000) + 10000;
|
|
11
18
|
const config = {
|
|
@@ -26,10 +33,18 @@ export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, d
|
|
|
26
33
|
};
|
|
27
34
|
return config;
|
|
28
35
|
};
|
|
29
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Sets up a blockchain network context using provided options
|
|
38
|
+
* @param option - Setup options for the network
|
|
39
|
+
* @returns Network context including API, WebSocket provider, and utility functions
|
|
40
|
+
*/ export const setupContext = async (option)=>{
|
|
30
41
|
return setupContextWithConfig(createConfig(option));
|
|
31
42
|
};
|
|
32
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Sets up a blockchain network context using a configuration object
|
|
45
|
+
* @param config - Configuration object for the network
|
|
46
|
+
* @returns Network context including API, WebSocket provider, and utility functions
|
|
47
|
+
*/ export const setupContextWithConfig = async ({ timeout, ...config })=>{
|
|
33
48
|
const { chain, addr, close } = await setupWithServer(config);
|
|
34
49
|
const url = `ws://${addr}`;
|
|
35
50
|
const ws = new WsProvider(url, 3_000, undefined, timeout);
|
|
@@ -43,33 +58,33 @@ export const setupContextWithConfig = async ({ timeout, ...config })=>{
|
|
|
43
58
|
ws,
|
|
44
59
|
api,
|
|
45
60
|
dev: {
|
|
46
|
-
newBlock: (param)=>{
|
|
61
|
+
/** Creates a new block with optional parameters */ newBlock: (param)=>{
|
|
47
62
|
return ws.send('dev_newBlock', [
|
|
48
63
|
param
|
|
49
64
|
]);
|
|
50
65
|
},
|
|
51
|
-
setStorage: (values, blockHash)=>{
|
|
66
|
+
/** Sets storage values at a specific block */ setStorage: (values, blockHash)=>{
|
|
52
67
|
return ws.send('dev_setStorage', [
|
|
53
68
|
values,
|
|
54
69
|
blockHash
|
|
55
70
|
]);
|
|
56
71
|
},
|
|
57
|
-
timeTravel: (date)=>{
|
|
72
|
+
/** Moves blockchain time to a specific timestamp */ timeTravel: (date)=>{
|
|
58
73
|
return ws.send('dev_timeTravel', [
|
|
59
74
|
date
|
|
60
75
|
]);
|
|
61
76
|
},
|
|
62
|
-
setHead: (hashOrNumber)=>{
|
|
77
|
+
/** Sets the chain head to a specific block */ setHead: (hashOrNumber)=>{
|
|
63
78
|
return ws.send('dev_setHead', [
|
|
64
79
|
hashOrNumber
|
|
65
80
|
]);
|
|
66
81
|
}
|
|
67
82
|
},
|
|
68
|
-
async teardown () {
|
|
83
|
+
/** Cleans up resources and closes connections */ async teardown () {
|
|
69
84
|
await api.disconnect();
|
|
70
85
|
await close();
|
|
71
86
|
},
|
|
72
|
-
async pause () {
|
|
87
|
+
/** Pauses execution and enables manual interaction through Polkadot.js apps */ async pause () {
|
|
73
88
|
await ws.send('dev_setBlockBuildMode', [
|
|
74
89
|
BuildBlockMode.Instant
|
|
75
90
|
]);
|
|
@@ -80,7 +95,11 @@ export const setupContextWithConfig = async ({ timeout, ...config })=>{
|
|
|
80
95
|
}
|
|
81
96
|
};
|
|
82
97
|
};
|
|
83
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Sets up multiple blockchain networks and establishes connections between them
|
|
100
|
+
* @param networkOptions - Configuration options for each network
|
|
101
|
+
* @returns Record of network contexts indexed by network name
|
|
102
|
+
*/ export const setupNetworks = async (networkOptions)=>{
|
|
84
103
|
const ret = {};
|
|
85
104
|
let wasmOverriden = false;
|
|
86
105
|
for (const [name, options] of Object.entries(networkOptions)){
|
|
@@ -114,7 +133,10 @@ export const setupNetworks = async (networkOptions)=>{
|
|
|
114
133
|
}
|
|
115
134
|
return ret;
|
|
116
135
|
};
|
|
117
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Creates a deferred promise that can be resolved or rejected from outside
|
|
138
|
+
* @returns Object containing promise, resolve function, and reject function
|
|
139
|
+
*/ export function defer() {
|
|
118
140
|
const deferred = {};
|
|
119
141
|
deferred.promise = new Promise((resolve, reject)=>{
|
|
120
142
|
deferred.resolve = resolve;
|
|
@@ -122,7 +144,11 @@ export function defer() {
|
|
|
122
144
|
});
|
|
123
145
|
return deferred;
|
|
124
146
|
}
|
|
125
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Sends a transaction and waits for it to be included in a block
|
|
149
|
+
* @param tx - Promise of a submittable extrinsic
|
|
150
|
+
* @returns Promise that resolves with transaction events
|
|
151
|
+
*/ export const sendTransaction = async (tx)=>{
|
|
126
152
|
const signed = await tx;
|
|
127
153
|
const deferred = defer();
|
|
128
154
|
await signed.send((status)=>{
|
|
@@ -140,7 +166,12 @@ export const sendTransaction = async (tx)=>{
|
|
|
140
166
|
events: deferred.promise
|
|
141
167
|
};
|
|
142
168
|
};
|
|
143
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Creates a set of test keypairs for both ed25519/sr25519 and ethereum addresses
|
|
171
|
+
* @param keyringType - Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
|
|
172
|
+
* @param ss58Format - SS58 address format to use
|
|
173
|
+
* @returns Object containing various test keypairs and keyring instances
|
|
174
|
+
*/ export const testingPairs = (keyringType = 'ed25519', ss58Format)=>{
|
|
144
175
|
const keyringEth = createTestKeyring({
|
|
145
176
|
type: 'ethereum'
|
|
146
177
|
});
|
|
@@ -164,3 +195,26 @@ export const testingPairs = (keyringType = 'ed25519', ss58Format)=>{
|
|
|
164
195
|
keyringEth
|
|
165
196
|
};
|
|
166
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Creates a set of test signers for either Ed25519 or Sr25519.
|
|
200
|
+
* @param keyringType Type of keyring to use for substrate addresses ('ed25519' or 'sr25519')
|
|
201
|
+
* @returns Object containing various test signers, and a `polkadotSignerBuilder` function to create more.
|
|
202
|
+
*/ export const testingSigners = (keyringType = 'Ed25519')=>{
|
|
203
|
+
const entropy = mnemonicToEntropy(DEV_PHRASE);
|
|
204
|
+
const miniSecret = entropyToMiniSecret(entropy);
|
|
205
|
+
const derive = keyringType === 'Ed25519' ? ed25519CreateDerive(miniSecret) : sr25519CreateDerive(miniSecret);
|
|
206
|
+
// Create a PAPI polkadot signer given a derivation path e.g. "//Alice" or "//Bob".
|
|
207
|
+
const polkadotSignerBuilder = (path, keyringType = 'Ed25519')=>{
|
|
208
|
+
const hdkdKeyPair = derive(path);
|
|
209
|
+
return getPolkadotSigner(hdkdKeyPair.publicKey, keyringType, hdkdKeyPair.sign);
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
alice: polkadotSignerBuilder('//Alice', keyringType),
|
|
213
|
+
bob: polkadotSignerBuilder('//Bob', keyringType),
|
|
214
|
+
charlie: polkadotSignerBuilder('//Charlie', keyringType),
|
|
215
|
+
dave: polkadotSignerBuilder('//Dave', keyringType),
|
|
216
|
+
eve: polkadotSignerBuilder('//Eve', keyringType),
|
|
217
|
+
ferdie: polkadotSignerBuilder('//Ferdie', keyringType),
|
|
218
|
+
polkadotSignerBuilder
|
|
219
|
+
};
|
|
220
|
+
};
|
package/dist/esm/signFake.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { GenericExtrinsic } from '@polkadot/types';
|
|
3
|
-
import { SignatureOptions } from '@polkadot/types/types';
|
|
1
|
+
import type { ApiPromise } from '@polkadot/api';
|
|
2
|
+
import type { GenericExtrinsic } from '@polkadot/types';
|
|
3
|
+
import type { SignatureOptions } from '@polkadot/types/types';
|
|
4
4
|
export type SignFakeOptions = Partial<SignatureOptions>;
|
|
5
5
|
export declare const signFakeWithApi: (api: ApiPromise, tx: GenericExtrinsic, addr: string, options?: SignFakeOptions) => Promise<void>;
|
|
6
6
|
export declare const signFake: (tx: GenericExtrinsic, addr: string, options: SignatureOptions) => void;
|
package/package.json
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-utils",
|
|
3
|
-
"version": "1.0.2
|
|
3
|
+
"version": "1.0.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.2
|
|
14
|
-
"@acala-network/chopsticks-core": "1.0.2
|
|
15
|
-
"@polkadot/
|
|
16
|
-
"@polkadot/
|
|
17
|
-
"@polkadot/
|
|
18
|
-
"@polkadot/
|
|
19
|
-
"@polkadot/
|
|
16
|
+
"@acala-network/chopsticks": "1.0.2",
|
|
17
|
+
"@acala-network/chopsticks-core": "1.0.2",
|
|
18
|
+
"@polkadot-labs/hdkd": "^0.0.10",
|
|
19
|
+
"@polkadot-labs/hdkd-helpers": "^0.0.10",
|
|
20
|
+
"@polkadot/api": "^15.0",
|
|
21
|
+
"@polkadot/api-base": "^15.0",
|
|
22
|
+
"@polkadot/keyring": "^13.2",
|
|
23
|
+
"@polkadot/types": "^15.0",
|
|
24
|
+
"@polkadot/util": "^13.2",
|
|
25
|
+
"polkadot-api": "^1.8.2"
|
|
20
26
|
},
|
|
21
27
|
"devDependencies": {
|
|
22
|
-
"@swc/cli": "0.5.
|
|
23
|
-
"@swc/core": "^1.
|
|
24
|
-
"typescript": "^5.
|
|
28
|
+
"@swc/cli": "0.5.2",
|
|
29
|
+
"@swc/core": "^1.10.1",
|
|
30
|
+
"typescript": "^5.7.2"
|
|
25
31
|
},
|
|
26
32
|
"files": [
|
|
27
33
|
"dist/esm/**",
|