@acala-network/chopsticks-testing 0.9.1-1 → 0.9.1-3
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/check.js +155 -83
- package/dist/cjs/index.js +157 -100
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/signFake.js +27 -9
- package/dist/esm/check.js +103 -119
- package/dist/esm/index.js +80 -55
- package/dist/esm/signFake.js +9 -4
- package/package.json +11 -4
package/dist/esm/check.js
CHANGED
|
@@ -1,58 +1,44 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Checker_instances, _Checker_value, _Checker_pipeline, _Checker_format, _Checker_message, _Checker_redactOptions, _Checker_redact;
|
|
13
1
|
import { expect } from 'vitest';
|
|
14
|
-
const processCodecOrArray = (codec, fn)
|
|
15
|
-
const toHuman = (codec)
|
|
16
|
-
const toHex = (codec)
|
|
17
|
-
const toJson = (codec)
|
|
2
|
+
const processCodecOrArray = (codec, fn)=>Array.isArray(codec) ? codec.map(fn) : fn(codec);
|
|
3
|
+
const toHuman = (codec)=>processCodecOrArray(codec, (c)=>c?.toHuman?.() ?? c);
|
|
4
|
+
const toHex = (codec)=>processCodecOrArray(codec, (c)=>c?.toHex?.() ?? c);
|
|
5
|
+
const toJson = (codec)=>processCodecOrArray(codec, (c)=>c?.toJSON?.() ?? c);
|
|
18
6
|
export class Checker {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
__classPrivateFieldSet(this, _Checker_message, message, "f");
|
|
7
|
+
#value;
|
|
8
|
+
#pipeline = [];
|
|
9
|
+
#format = 'json';
|
|
10
|
+
#message;
|
|
11
|
+
#redactOptions;
|
|
12
|
+
constructor(value, message){
|
|
13
|
+
this.#value = value;
|
|
14
|
+
this.#message = message;
|
|
28
15
|
}
|
|
29
16
|
toHuman() {
|
|
30
|
-
|
|
17
|
+
this.#format = 'human';
|
|
31
18
|
return this;
|
|
32
19
|
}
|
|
33
20
|
toHex() {
|
|
34
|
-
|
|
21
|
+
this.#format = 'hex';
|
|
35
22
|
return this;
|
|
36
23
|
}
|
|
37
24
|
toJson() {
|
|
38
|
-
|
|
25
|
+
this.#format = 'json';
|
|
39
26
|
return this;
|
|
40
27
|
}
|
|
41
28
|
message(message) {
|
|
42
|
-
|
|
29
|
+
this.#message = message;
|
|
43
30
|
return this;
|
|
44
31
|
}
|
|
45
32
|
filterEvents(...filters) {
|
|
46
33
|
this.toHuman();
|
|
47
|
-
|
|
48
|
-
let data = value.map(({ event: { index: _, ...event } })
|
|
34
|
+
this.#pipeline.push((value)=>{
|
|
35
|
+
let data = value.map(({ event: { index: _, ...event } })=>event);
|
|
49
36
|
if (filters.length > 0) {
|
|
50
|
-
data = data.filter((evt)
|
|
51
|
-
return filters.some((filter)
|
|
37
|
+
data = data.filter((evt)=>{
|
|
38
|
+
return filters.some((filter)=>{
|
|
52
39
|
if (typeof filter === 'string') {
|
|
53
40
|
return evt.section === filter;
|
|
54
|
-
}
|
|
55
|
-
else if ('method' in filter) {
|
|
41
|
+
} else if ('method' in filter) {
|
|
56
42
|
const { section, method } = filter;
|
|
57
43
|
return evt.section === section && evt.method === method;
|
|
58
44
|
}
|
|
@@ -63,23 +49,86 @@ export class Checker {
|
|
|
63
49
|
});
|
|
64
50
|
return this;
|
|
65
51
|
}
|
|
66
|
-
redact(options = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
redact(options = {
|
|
53
|
+
number: 2,
|
|
54
|
+
hash: true
|
|
55
|
+
}) {
|
|
56
|
+
this.#redactOptions = {
|
|
57
|
+
...this.#redactOptions,
|
|
58
|
+
...options
|
|
59
|
+
};
|
|
71
60
|
return this;
|
|
72
61
|
}
|
|
62
|
+
#redact(value) {
|
|
63
|
+
if (!this.#redactOptions) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
const redactNumber = this.#redactOptions.number === true || typeof this.#redactOptions.number === 'number';
|
|
67
|
+
const precision = redactNumber ? typeof this.#redactOptions.number === 'number' ? this.#redactOptions.number : 0 : 0;
|
|
68
|
+
const redactHash = this.#redactOptions.hash === true;
|
|
69
|
+
const redactHex = this.#redactOptions.hex === true;
|
|
70
|
+
const redactAddress = this.#redactOptions.address === true;
|
|
71
|
+
const processNumber = (value)=>{
|
|
72
|
+
if (precision > 0) {
|
|
73
|
+
const rounded = parseFloat(value.toPrecision(precision));
|
|
74
|
+
if (rounded === value) {
|
|
75
|
+
return rounded;
|
|
76
|
+
}
|
|
77
|
+
return `(rounded ${rounded})`;
|
|
78
|
+
}
|
|
79
|
+
return '(number)';
|
|
80
|
+
};
|
|
81
|
+
const process = (obj)=>{
|
|
82
|
+
if (obj == null) {
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(obj)) {
|
|
86
|
+
return obj.map(process);
|
|
87
|
+
}
|
|
88
|
+
if (redactNumber && typeof obj === 'number') {
|
|
89
|
+
return processNumber(obj);
|
|
90
|
+
}
|
|
91
|
+
if (typeof obj === 'string') {
|
|
92
|
+
if (redactNumber && obj.match(/0x000000[0-9a-f]{26}/)) {
|
|
93
|
+
// this is very likely u128 encoded in hex
|
|
94
|
+
const num = parseInt(obj);
|
|
95
|
+
return processNumber(num);
|
|
96
|
+
}
|
|
97
|
+
if (redactHash && obj.match(/0x[0-9a-f]{64}/)) {
|
|
98
|
+
return '(hash)';
|
|
99
|
+
}
|
|
100
|
+
if (redactHex && obj.match(/0x[0-9a-f]+/)) {
|
|
101
|
+
return '(hex)';
|
|
102
|
+
}
|
|
103
|
+
if (redactAddress && obj.match(/^[1-9A-HJ-NP-Za-km-z]{46,48}$/)) {
|
|
104
|
+
return '(address)';
|
|
105
|
+
}
|
|
106
|
+
if (redactNumber && obj.match(/^-?[\d,]+$/)) {
|
|
107
|
+
const num = parseInt(obj.replace(/,/g, ''));
|
|
108
|
+
return processNumber(num);
|
|
109
|
+
}
|
|
110
|
+
return obj;
|
|
111
|
+
}
|
|
112
|
+
if (typeof obj === 'object') {
|
|
113
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v])=>[
|
|
114
|
+
k,
|
|
115
|
+
process(v)
|
|
116
|
+
]));
|
|
117
|
+
}
|
|
118
|
+
return obj;
|
|
119
|
+
};
|
|
120
|
+
return process(value);
|
|
121
|
+
}
|
|
73
122
|
map(fn) {
|
|
74
|
-
|
|
123
|
+
this.#pipeline.push(fn);
|
|
75
124
|
return this;
|
|
76
125
|
}
|
|
77
126
|
pipe(fn) {
|
|
78
127
|
return fn ? fn(this) : this;
|
|
79
128
|
}
|
|
80
129
|
async value() {
|
|
81
|
-
let value = await
|
|
82
|
-
switch
|
|
130
|
+
let value = await this.#value;
|
|
131
|
+
switch(this.#format){
|
|
83
132
|
case 'human':
|
|
84
133
|
value = toHuman(value);
|
|
85
134
|
break;
|
|
@@ -90,78 +139,17 @@ export class Checker {
|
|
|
90
139
|
value = toJson(value);
|
|
91
140
|
break;
|
|
92
141
|
}
|
|
93
|
-
for (const fn of
|
|
142
|
+
for (const fn of this.#pipeline){
|
|
94
143
|
value = await fn(value);
|
|
95
144
|
}
|
|
96
|
-
value =
|
|
145
|
+
value = this.#redact(value);
|
|
97
146
|
return value;
|
|
98
147
|
}
|
|
99
148
|
async toMatchSnapshot(msg) {
|
|
100
|
-
return expect(await this.value()).toMatchSnapshot(msg ??
|
|
149
|
+
return expect(await this.value()).toMatchSnapshot(msg ?? this.#message);
|
|
101
150
|
}
|
|
102
151
|
}
|
|
103
|
-
|
|
104
|
-
if (!__classPrivateFieldGet(this, _Checker_redactOptions, "f")) {
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
const redactNumber = __classPrivateFieldGet(this, _Checker_redactOptions, "f").number === true || typeof __classPrivateFieldGet(this, _Checker_redactOptions, "f").number === 'number';
|
|
108
|
-
const precision = redactNumber
|
|
109
|
-
? typeof __classPrivateFieldGet(this, _Checker_redactOptions, "f").number === 'number'
|
|
110
|
-
? __classPrivateFieldGet(this, _Checker_redactOptions, "f").number
|
|
111
|
-
: 0
|
|
112
|
-
: 0;
|
|
113
|
-
const redactHash = __classPrivateFieldGet(this, _Checker_redactOptions, "f").hash === true;
|
|
114
|
-
const redactHex = __classPrivateFieldGet(this, _Checker_redactOptions, "f").hex === true;
|
|
115
|
-
const redactAddress = __classPrivateFieldGet(this, _Checker_redactOptions, "f").address === true;
|
|
116
|
-
const processNumber = (value) => {
|
|
117
|
-
if (precision > 0) {
|
|
118
|
-
const rounded = parseFloat(value.toPrecision(precision));
|
|
119
|
-
if (rounded === value) {
|
|
120
|
-
return rounded;
|
|
121
|
-
}
|
|
122
|
-
return `(rounded ${rounded})`;
|
|
123
|
-
}
|
|
124
|
-
return '(number)';
|
|
125
|
-
};
|
|
126
|
-
const process = (obj) => {
|
|
127
|
-
if (obj == null) {
|
|
128
|
-
return obj;
|
|
129
|
-
}
|
|
130
|
-
if (Array.isArray(obj)) {
|
|
131
|
-
return obj.map(process);
|
|
132
|
-
}
|
|
133
|
-
if (redactNumber && typeof obj === 'number') {
|
|
134
|
-
return processNumber(obj);
|
|
135
|
-
}
|
|
136
|
-
if (typeof obj === 'string') {
|
|
137
|
-
if (redactNumber && obj.match(/0x000000[0-9a-f]{26}/)) {
|
|
138
|
-
// this is very likely u128 encoded in hex
|
|
139
|
-
const num = parseInt(obj);
|
|
140
|
-
return processNumber(num);
|
|
141
|
-
}
|
|
142
|
-
if (redactHash && obj.match(/0x[0-9a-f]{64}/)) {
|
|
143
|
-
return '(hash)';
|
|
144
|
-
}
|
|
145
|
-
if (redactHex && obj.match(/0x[0-9a-f]+/)) {
|
|
146
|
-
return '(hex)';
|
|
147
|
-
}
|
|
148
|
-
if (redactAddress && obj.match(/^[1-9A-HJ-NP-Za-km-z]{46,48}$/)) {
|
|
149
|
-
return '(address)';
|
|
150
|
-
}
|
|
151
|
-
if (redactNumber && obj.match(/^-?[\d,]+$/)) {
|
|
152
|
-
const num = parseInt(obj.replace(/,/g, ''));
|
|
153
|
-
return processNumber(num);
|
|
154
|
-
}
|
|
155
|
-
return obj;
|
|
156
|
-
}
|
|
157
|
-
if (typeof obj === 'object') {
|
|
158
|
-
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, process(v)]));
|
|
159
|
-
}
|
|
160
|
-
return obj;
|
|
161
|
-
};
|
|
162
|
-
return process(value);
|
|
163
|
-
};
|
|
164
|
-
export const check = (value, msg) => {
|
|
152
|
+
export const check = (value, msg)=>{
|
|
165
153
|
if (value instanceof Checker) {
|
|
166
154
|
if (msg) {
|
|
167
155
|
return value.message(msg);
|
|
@@ -170,14 +158,10 @@ export const check = (value, msg) => {
|
|
|
170
158
|
}
|
|
171
159
|
return new Checker(value, msg);
|
|
172
160
|
};
|
|
173
|
-
export const checkEvents = ({ events }, ...filters)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
export const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
export const checkHrmp = ({ api }) => check(api.query.parachainSystem.hrmpOutboundMessages(), 'hrmp').map((value) => value.map(({ recipient, data }) => ({
|
|
181
|
-
data: api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data),
|
|
182
|
-
recipient,
|
|
183
|
-
})));
|
|
161
|
+
export const checkEvents = ({ events }, ...filters)=>check(events, 'events').filterEvents(...filters).redact();
|
|
162
|
+
export const checkSystemEvents = ({ api }, ...filters)=>check(api.query.system.events(), 'system events').filterEvents(...filters).redact();
|
|
163
|
+
export const checkUmp = ({ api })=>check(api.query.parachainSystem.upwardMessages(), 'ump').map((value)=>api.createType('Vec<XcmVersionedXcm>', value).toJSON());
|
|
164
|
+
export const checkHrmp = ({ api })=>check(api.query.parachainSystem.hrmpOutboundMessages(), 'hrmp').map((value)=>value.map(({ recipient, data })=>({
|
|
165
|
+
data: api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data),
|
|
166
|
+
recipient
|
|
167
|
+
})));
|
package/dist/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
2
|
-
import { BuildBlockMode, connectParachains, connectVertical, fetchConfig, setupWithServer
|
|
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
6
|
export * from './signFake';
|
|
7
|
-
export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, port, maxMemoryBlockCount, resume
|
|
7
|
+
export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, db, timeout, port, maxMemoryBlockCount, resume })=>{
|
|
8
8
|
// random port if not specified
|
|
9
9
|
port = port ?? Math.floor(Math.random() * 10000) + 10000;
|
|
10
10
|
const config = {
|
|
@@ -17,14 +17,14 @@ export const createConfig = ({ endpoint, blockNumber, blockHash, wasmOverride, d
|
|
|
17
17
|
db,
|
|
18
18
|
'wasm-override': wasmOverride,
|
|
19
19
|
timeout,
|
|
20
|
-
resume: resume ?? false
|
|
20
|
+
resume: resume ?? false
|
|
21
21
|
};
|
|
22
22
|
return config;
|
|
23
23
|
};
|
|
24
|
-
export const setupContext = async (option)
|
|
24
|
+
export const setupContext = async (option)=>{
|
|
25
25
|
return setupContextWithConfig(createConfig(option));
|
|
26
26
|
};
|
|
27
|
-
export const setupContextWithConfig = async ({ timeout, ...config })
|
|
27
|
+
export const setupContextWithConfig = async ({ timeout, ...config })=>{
|
|
28
28
|
const { chain, listenPort, close } = await setupWithServer(config);
|
|
29
29
|
const url = `ws://localhost:${listenPort}`;
|
|
30
30
|
const ws = new WsProvider(url, undefined, undefined, timeout);
|
|
@@ -33,9 +33,9 @@ export const setupContextWithConfig = async ({ timeout, ...config }) => {
|
|
|
33
33
|
signedExtensions: {
|
|
34
34
|
SetEvmOrigin: {
|
|
35
35
|
extrinsic: {},
|
|
36
|
-
payload: {}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
36
|
+
payload: {}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
39
|
});
|
|
40
40
|
await api.isReady;
|
|
41
41
|
return {
|
|
@@ -44,78 +44,95 @@ export const setupContextWithConfig = async ({ timeout, ...config }) => {
|
|
|
44
44
|
ws,
|
|
45
45
|
api,
|
|
46
46
|
dev: {
|
|
47
|
-
newBlock: (param)
|
|
48
|
-
return ws.send('dev_newBlock', [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return ws.send('dev_setStorage', [values, blockHash]);
|
|
47
|
+
newBlock: (param)=>{
|
|
48
|
+
return ws.send('dev_newBlock', [
|
|
49
|
+
param
|
|
50
|
+
]);
|
|
52
51
|
},
|
|
53
|
-
|
|
54
|
-
return ws.send('
|
|
52
|
+
setStorage: (values, blockHash)=>{
|
|
53
|
+
return ws.send('dev_setStorage', [
|
|
54
|
+
values,
|
|
55
|
+
blockHash
|
|
56
|
+
]);
|
|
55
57
|
},
|
|
56
|
-
|
|
57
|
-
return ws.send('
|
|
58
|
+
timeTravel: (date)=>{
|
|
59
|
+
return ws.send('dev_timeTravel', [
|
|
60
|
+
date
|
|
61
|
+
]);
|
|
58
62
|
},
|
|
63
|
+
setHead: (hashOrNumber)=>{
|
|
64
|
+
return ws.send('dev_setHead', [
|
|
65
|
+
hashOrNumber
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
59
68
|
},
|
|
60
|
-
async teardown() {
|
|
69
|
+
async teardown () {
|
|
61
70
|
await api.disconnect();
|
|
62
71
|
await close();
|
|
63
72
|
},
|
|
64
|
-
async pause() {
|
|
65
|
-
await ws.send('dev_setBlockBuildMode', [
|
|
73
|
+
async pause () {
|
|
74
|
+
await ws.send('dev_setBlockBuildMode', [
|
|
75
|
+
BuildBlockMode.Instant
|
|
76
|
+
]);
|
|
66
77
|
// log a bit later to ensure the message is visible
|
|
67
|
-
setTimeout(()
|
|
68
|
-
return new Promise((_resolve)
|
|
69
|
-
|
|
78
|
+
setTimeout(()=>console.log(`Test paused. Polkadot.js apps URL: https://polkadot.js.org/apps/?rpc=${url}`), 100);
|
|
79
|
+
return new Promise((_resolve)=>{}) // wait forever
|
|
80
|
+
;
|
|
81
|
+
}
|
|
70
82
|
};
|
|
71
83
|
};
|
|
72
|
-
export const setupNetworks = async (networkOptions)
|
|
84
|
+
export const setupNetworks = async (networkOptions)=>{
|
|
73
85
|
const ret = {};
|
|
74
86
|
let wasmOverriden = false;
|
|
75
|
-
for (const [name, options] of Object.entries(networkOptions))
|
|
76
|
-
const config = typeof options === 'string' ? await fetchConfig(options) : options ??
|
|
87
|
+
for (const [name, options] of Object.entries(networkOptions)){
|
|
88
|
+
const config = typeof options === 'string' ? await fetchConfig(options) : options ?? await fetchConfig(name);
|
|
77
89
|
ret[name] = await setupContextWithConfig(config);
|
|
78
90
|
wasmOverriden ||= config['wasm-override'] != null;
|
|
79
91
|
}
|
|
80
|
-
const relaychainName = Object.keys(ret).filter((x)
|
|
92
|
+
const relaychainName = Object.keys(ret).filter((x)=>[
|
|
93
|
+
'polkadot',
|
|
94
|
+
'kusama'
|
|
95
|
+
].includes(x.toLocaleLowerCase()))[0];
|
|
81
96
|
const { [relaychainName]: relaychain, ...parachains } = ret;
|
|
82
97
|
if (relaychain) {
|
|
83
|
-
for (const parachain of Object.values(parachains))
|
|
98
|
+
for (const parachain of Object.values(parachains)){
|
|
84
99
|
await connectVertical(relaychain.chain, parachain.chain);
|
|
85
100
|
}
|
|
86
101
|
}
|
|
87
|
-
const parachainList = Object.values(parachains).map((i)
|
|
102
|
+
const parachainList = Object.values(parachains).map((i)=>i.chain);
|
|
88
103
|
if (parachainList.length > 0) {
|
|
89
104
|
await connectParachains(parachainList);
|
|
90
105
|
}
|
|
91
106
|
if (wasmOverriden) {
|
|
92
107
|
// trigger runtime upgrade if needed (due to wasm override)
|
|
93
|
-
for (const chain of Object.values(ret))
|
|
108
|
+
for (const chain of Object.values(ret)){
|
|
94
109
|
await chain.dev.newBlock();
|
|
95
110
|
}
|
|
96
111
|
// handle xcm version message if needed (due to wasm override triggered xcm version upgrade)
|
|
97
|
-
for (const chain of Object.values(ret))
|
|
112
|
+
for (const chain of Object.values(ret)){
|
|
98
113
|
await chain.dev.newBlock();
|
|
99
114
|
}
|
|
100
115
|
}
|
|
101
116
|
return ret;
|
|
102
117
|
};
|
|
103
|
-
const processCodecOrArray = (codec, fn)
|
|
104
|
-
const toHuman = (codec)
|
|
105
|
-
const toJson = (codec)
|
|
106
|
-
const toHex = (codec)
|
|
107
|
-
export const expectJson = (codec)
|
|
118
|
+
const processCodecOrArray = (codec, fn)=>Array.isArray(codec) ? codec.map(fn) : fn(codec);
|
|
119
|
+
const toHuman = (codec)=>processCodecOrArray(codec, (c)=>c?.toHuman?.() ?? c);
|
|
120
|
+
const toJson = (codec)=>processCodecOrArray(codec, (c)=>c?.toJSON?.() ?? c);
|
|
121
|
+
const toHex = (codec)=>processCodecOrArray(codec, (c)=>c?.toHex?.() ?? c);
|
|
122
|
+
export const expectJson = (codec)=>{
|
|
108
123
|
return expect(toJson(codec));
|
|
109
124
|
};
|
|
110
|
-
export const expectHex = (codec)
|
|
125
|
+
export const expectHex = (codec)=>{
|
|
111
126
|
return expect(toHex(codec));
|
|
112
127
|
};
|
|
113
|
-
const _matchEvents = async (msg, events, ...filters)
|
|
114
|
-
let data = toHuman(await events).map(({ event: { index: _, ...event } })
|
|
128
|
+
const _matchEvents = async (msg, events, ...filters)=>{
|
|
129
|
+
let data = toHuman(await events).map(({ event: { index: _, ...event } })=>event);
|
|
115
130
|
if (filters.length > 0) {
|
|
116
|
-
const filtersArr = Array.isArray(filters) ? filters : [
|
|
117
|
-
|
|
118
|
-
|
|
131
|
+
const filtersArr = Array.isArray(filters) ? filters : [
|
|
132
|
+
filters
|
|
133
|
+
];
|
|
134
|
+
data = data.filter((evt)=>{
|
|
135
|
+
return filtersArr.some((filter)=>{
|
|
119
136
|
if (typeof filter === 'string') {
|
|
120
137
|
return evt.section === filter;
|
|
121
138
|
}
|
|
@@ -126,15 +143,15 @@ const _matchEvents = async (msg, events, ...filters) => {
|
|
|
126
143
|
}
|
|
127
144
|
return expect(data).toMatchSnapshot(msg);
|
|
128
145
|
};
|
|
129
|
-
export const matchEvents = async (events, ...filters)
|
|
146
|
+
export const matchEvents = async (events, ...filters)=>{
|
|
130
147
|
return _matchEvents('events', redact(events), ...filters);
|
|
131
148
|
};
|
|
132
|
-
export const matchSystemEvents = async ({ api }, ...filters)
|
|
149
|
+
export const matchSystemEvents = async ({ api }, ...filters)=>{
|
|
133
150
|
await _matchEvents('system events', redact(api.query.system.events()), ...filters);
|
|
134
151
|
};
|
|
135
|
-
export const redact = async (data)
|
|
152
|
+
export const redact = async (data)=>{
|
|
136
153
|
const json = toHuman(await data);
|
|
137
|
-
const process = (obj)
|
|
154
|
+
const process = (obj)=>{
|
|
138
155
|
if (obj == null) {
|
|
139
156
|
return obj;
|
|
140
157
|
}
|
|
@@ -163,7 +180,10 @@ export const redact = async (data) => {
|
|
|
163
180
|
return obj;
|
|
164
181
|
}
|
|
165
182
|
if (typeof obj === 'object') {
|
|
166
|
-
return Object.fromEntries(Object.entries(obj).map(([k, v])
|
|
183
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v])=>[
|
|
184
|
+
k,
|
|
185
|
+
process(v)
|
|
186
|
+
]));
|
|
167
187
|
}
|
|
168
188
|
return obj;
|
|
169
189
|
};
|
|
@@ -171,16 +191,16 @@ export const redact = async (data) => {
|
|
|
171
191
|
};
|
|
172
192
|
export function defer() {
|
|
173
193
|
const deferred = {};
|
|
174
|
-
deferred.promise = new Promise((resolve, reject)
|
|
194
|
+
deferred.promise = new Promise((resolve, reject)=>{
|
|
175
195
|
deferred.resolve = resolve;
|
|
176
196
|
deferred.reject = reject;
|
|
177
197
|
});
|
|
178
198
|
return deferred;
|
|
179
199
|
}
|
|
180
|
-
export const sendTransaction = async (tx)
|
|
200
|
+
export const sendTransaction = async (tx)=>{
|
|
181
201
|
const signed = await tx;
|
|
182
202
|
const deferred = defer();
|
|
183
|
-
await signed.send((status)
|
|
203
|
+
await signed.send((status)=>{
|
|
184
204
|
console.log('tranaction status: ', status.status.toHuman());
|
|
185
205
|
if (status.isInBlock || status.isFinalized) {
|
|
186
206
|
deferred.resolve(status.events);
|
|
@@ -190,13 +210,18 @@ export const sendTransaction = async (tx) => {
|
|
|
190
210
|
}
|
|
191
211
|
});
|
|
192
212
|
return {
|
|
193
|
-
events: deferred.promise
|
|
213
|
+
events: deferred.promise
|
|
194
214
|
};
|
|
195
215
|
};
|
|
196
|
-
export const testingPairs = (keyringType = 'ed25519', ss58Format)
|
|
197
|
-
const keyringEth = createTestKeyring({
|
|
216
|
+
export const testingPairs = (keyringType = 'ed25519', ss58Format)=>{
|
|
217
|
+
const keyringEth = createTestKeyring({
|
|
218
|
+
type: 'ethereum'
|
|
219
|
+
});
|
|
198
220
|
// default to ed25519 because sr25519 signature is non-deterministic
|
|
199
|
-
const keyring = new Keyring({
|
|
221
|
+
const keyring = new Keyring({
|
|
222
|
+
type: keyringType,
|
|
223
|
+
ss58Format
|
|
224
|
+
});
|
|
200
225
|
return {
|
|
201
226
|
alice: keyring.addFromUri('//Alice'),
|
|
202
227
|
bob: keyring.addFromUri('//Bob'),
|
|
@@ -209,6 +234,6 @@ export const testingPairs = (keyringType = 'ed25519', ss58Format) => {
|
|
|
209
234
|
dorothy: keyringEth.getPair('0x773539d4Ac0e786233D90A233654ccEE26a613D9'),
|
|
210
235
|
ethan: keyringEth.getPair('0xFf64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB'),
|
|
211
236
|
keyring,
|
|
212
|
-
keyringEth
|
|
237
|
+
keyringEth
|
|
213
238
|
};
|
|
214
239
|
};
|
package/dist/esm/signFake.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
export const signFakeWithApi = async (api, tx, addr, options = {})
|
|
1
|
+
export const signFakeWithApi = async (api, tx, addr, options = {})=>{
|
|
2
2
|
const nonce = options.nonce ?? (await api.query.system.account(addr)).nonce;
|
|
3
3
|
signFake(tx, addr, {
|
|
4
4
|
nonce,
|
|
5
5
|
genesisHash: api.genesisHash,
|
|
6
6
|
runtimeVersion: api.runtimeVersion,
|
|
7
7
|
blockHash: api.genesisHash,
|
|
8
|
-
...options
|
|
8
|
+
...options
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
export const signFake = (tx, addr, options)
|
|
11
|
+
export const signFake = (tx, addr, options)=>{
|
|
12
12
|
const mockSignature = new Uint8Array(64);
|
|
13
13
|
mockSignature.fill(0xcd);
|
|
14
|
-
mockSignature.set([
|
|
14
|
+
mockSignature.set([
|
|
15
|
+
0xde,
|
|
16
|
+
0xad,
|
|
17
|
+
0xbe,
|
|
18
|
+
0xef
|
|
19
|
+
]);
|
|
15
20
|
tx.signFake(addr, options);
|
|
16
21
|
tx.signature.set(mockSignature);
|
|
17
22
|
};
|
package/package.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-testing",
|
|
3
|
-
"version": "0.9.1-
|
|
3
|
+
"version": "0.9.1-3",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"clean": "rm -rf dist",
|
|
8
|
-
"build": "yarn clean &&
|
|
9
|
+
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
|
|
10
|
+
"build:cjs": "swc ./src --config-file ../../.cjsswcrc -d dist/cjs && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
|
|
11
|
+
"build:esm": "swc ./src --config-file ../../.esmswcrc -d dist/esm",
|
|
12
|
+
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly --outDir dist/types"
|
|
9
13
|
},
|
|
10
14
|
"dependencies": {
|
|
11
|
-
"@acala-network/chopsticks": "0.9.1-
|
|
15
|
+
"@acala-network/chopsticks": "0.9.1-3"
|
|
12
16
|
},
|
|
13
17
|
"peerDependencies": {
|
|
14
18
|
"vitest": "^0.34.0"
|
|
15
19
|
},
|
|
16
20
|
"devDependencies": {
|
|
21
|
+
"@swc/cli": "0.1.62",
|
|
22
|
+
"@swc/core": "^1.3.96",
|
|
17
23
|
"@types/chai": "^4.3.5",
|
|
18
24
|
"typescript": "^5.1.6"
|
|
19
25
|
},
|
|
@@ -38,6 +44,7 @@
|
|
|
38
44
|
"import": "./dist/esm/index.js",
|
|
39
45
|
"default": "./dist/esm/index.js"
|
|
40
46
|
},
|
|
41
|
-
"./package.json": "./package.json"
|
|
47
|
+
"./package.json": "./package.json",
|
|
48
|
+
"./package.cjs.json": "./dist/cjs/package.json"
|
|
42
49
|
}
|
|
43
50
|
}
|