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