@acala-network/chopsticks-testing 1.5.1 → 1.6.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 CHANGED
@@ -25,15 +25,12 @@ function _check_private_redeclaration(obj, privateCollection) {
25
25
  }
26
26
  }
27
27
  function _class_apply_descriptor_get(receiver, descriptor) {
28
- if (descriptor.get) {
29
- return descriptor.get.call(receiver);
30
- }
28
+ if (descriptor.get) return descriptor.get.call(receiver);
31
29
  return descriptor.value;
32
30
  }
33
31
  function _class_apply_descriptor_set(receiver, descriptor, value) {
34
- if (descriptor.set) {
35
- descriptor.set.call(receiver, value);
36
- } else {
32
+ if (descriptor.set) descriptor.set.call(receiver, value);
33
+ else {
37
34
  if (!descriptor.writable) {
38
35
  throw new TypeError("attempted to set read only private field");
39
36
  }
@@ -41,9 +38,7 @@ function _class_apply_descriptor_set(receiver, descriptor, value) {
41
38
  }
42
39
  }
43
40
  function _class_extract_field_descriptor(receiver, privateMap, action) {
44
- if (!privateMap.has(receiver)) {
45
- throw new TypeError("attempted to " + action + " private field on non-instance");
46
- }
41
+ if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
47
42
  return privateMap.get(receiver);
48
43
  }
49
44
  function _class_private_field_get(receiver, privateMap) {
@@ -60,15 +55,64 @@ function _class_private_field_set(receiver, privateMap, value) {
60
55
  return value;
61
56
  }
62
57
  function _class_private_method_get(receiver, privateSet, fn) {
63
- if (!privateSet.has(receiver)) {
64
- throw new TypeError("attempted to get private field on non-instance");
65
- }
58
+ if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
66
59
  return fn;
67
60
  }
68
61
  function _class_private_method_init(obj, privateSet) {
69
62
  _check_private_redeclaration(obj, privateSet);
70
63
  privateSet.add(obj);
71
64
  }
65
+ /**
66
+ * `XcmpMessageFormat` index of the `ConcatenatedOpaqueVersionedXcm` variant.
67
+ *
68
+ * The variant is matched by index, not by name, because older versions of
69
+ * `@polkadot/types` do not declare it and cannot decode it.
70
+ */ const CONCATENATED_OPAQUE_VERSIONED_XCM = 3;
71
+ /**
72
+ * Decode one XCMP message.
73
+ *
74
+ * A message starts with an `XcmpMessageFormat` byte. In the
75
+ * `ConcatenatedOpaqueVersionedXcm` format, each XCM that follows has a compact
76
+ * length prefix. Such a payload is not a single `XcmVersionedXcm`, so it must be
77
+ * read one item at a time. All other formats keep the previous behaviour.
78
+ *
79
+ * @param api - Polkadot API instance
80
+ * @param data - Message bytes, or their hex string, with the format byte first
81
+ */ /**
82
+ * Convert a hex string to bytes. Storage gives the message as a hex string.
83
+ * Bytes are also accepted.
84
+ *
85
+ * @param data - Hex string or bytes
86
+ */ const toBytes = (data)=>{
87
+ if (typeof data !== 'string') {
88
+ return data;
89
+ }
90
+ const digits = data.startsWith('0x') ? data.slice(2) : data;
91
+ const bytes = new Uint8Array(digits.length / 2);
92
+ for(let index = 0; index < bytes.length; index++){
93
+ bytes[index] = Number.parseInt(digits.slice(index * 2, index * 2 + 2), 16);
94
+ }
95
+ return bytes;
96
+ };
97
+ const decodeXcmpMessage = (api, data)=>{
98
+ const bytes = toBytes(data);
99
+ if (bytes[0] !== CONCATENATED_OPAQUE_VERSIONED_XCM) {
100
+ return api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data).toJSON();
101
+ }
102
+ const messages = [];
103
+ let offset = 1;
104
+ while(offset < bytes.length){
105
+ const length = api.createType('Compact<u32>', bytes.subarray(offset));
106
+ offset += length.encodedLength;
107
+ const end = offset + length.toNumber();
108
+ messages.push(api.createType('XcmVersionedXcm', bytes.subarray(offset, end)).toJSON());
109
+ offset = end;
110
+ }
111
+ return [
112
+ 'ConcatenatedOpaqueVersionedXcm',
113
+ messages
114
+ ];
115
+ };
72
116
  /**
73
117
  * Processes a Codec or array of Codecs with a given transformation function
74
118
  * @param codec - Single Codec or array of Codecs to process
@@ -389,7 +433,7 @@ const setupCheck = (options)=>{
389
433
  * Check HRMP (Horizontal Relay-routed Message Passing) messages
390
434
  * @param api - Polkadot API instance
391
435
  */ const checkHrmp = ({ api })=>check(api.query.parachainSystem.hrmpOutboundMessages(), 'hrmp').map((value)=>value.map(({ recipient, data })=>({
392
- data: api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data).toJSON(),
436
+ data: decodeXcmpMessage(api, data),
393
437
  recipient
394
438
  })));
395
439
  /**
package/dist/esm/check.js CHANGED
@@ -1,3 +1,54 @@
1
+ /**
2
+ * `XcmpMessageFormat` index of the `ConcatenatedOpaqueVersionedXcm` variant.
3
+ *
4
+ * The variant is matched by index, not by name, because older versions of
5
+ * `@polkadot/types` do not declare it and cannot decode it.
6
+ */ const CONCATENATED_OPAQUE_VERSIONED_XCM = 3;
7
+ /**
8
+ * Decode one XCMP message.
9
+ *
10
+ * A message starts with an `XcmpMessageFormat` byte. In the
11
+ * `ConcatenatedOpaqueVersionedXcm` format, each XCM that follows has a compact
12
+ * length prefix. Such a payload is not a single `XcmVersionedXcm`, so it must be
13
+ * read one item at a time. All other formats keep the previous behaviour.
14
+ *
15
+ * @param api - Polkadot API instance
16
+ * @param data - Message bytes, or their hex string, with the format byte first
17
+ */ /**
18
+ * Convert a hex string to bytes. Storage gives the message as a hex string.
19
+ * Bytes are also accepted.
20
+ *
21
+ * @param data - Hex string or bytes
22
+ */ const toBytes = (data)=>{
23
+ if (typeof data !== 'string') {
24
+ return data;
25
+ }
26
+ const digits = data.startsWith('0x') ? data.slice(2) : data;
27
+ const bytes = new Uint8Array(digits.length / 2);
28
+ for(let index = 0; index < bytes.length; index++){
29
+ bytes[index] = Number.parseInt(digits.slice(index * 2, index * 2 + 2), 16);
30
+ }
31
+ return bytes;
32
+ };
33
+ const decodeXcmpMessage = (api, data)=>{
34
+ const bytes = toBytes(data);
35
+ if (bytes[0] !== CONCATENATED_OPAQUE_VERSIONED_XCM) {
36
+ return api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data).toJSON();
37
+ }
38
+ const messages = [];
39
+ let offset = 1;
40
+ while(offset < bytes.length){
41
+ const length = api.createType('Compact<u32>', bytes.subarray(offset));
42
+ offset += length.encodedLength;
43
+ const end = offset + length.toNumber();
44
+ messages.push(api.createType('XcmVersionedXcm', bytes.subarray(offset, end)).toJSON());
45
+ offset = end;
46
+ }
47
+ return [
48
+ 'ConcatenatedOpaqueVersionedXcm',
49
+ messages
50
+ ];
51
+ };
1
52
  /**
2
53
  * Processes a Codec or array of Codecs with a given transformation function
3
54
  * @param codec - Single Codec or array of Codecs to process
@@ -301,7 +352,7 @@
301
352
  * Check HRMP (Horizontal Relay-routed Message Passing) messages
302
353
  * @param api - Polkadot API instance
303
354
  */ const checkHrmp = ({ api })=>check(api.query.parachainSystem.hrmpOutboundMessages(), 'hrmp').map((value)=>value.map(({ recipient, data })=>({
304
- data: api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data).toJSON(),
355
+ data: decodeXcmpMessage(api, data),
305
356
  recipient
306
357
  })));
307
358
  /**
package/package.json CHANGED
@@ -1,43 +1,47 @@
1
1
  {
2
- "name": "@acala-network/chopsticks-testing",
3
- "version": "1.5.1",
4
- "author": "Acala Developers <hello@acala.network>",
5
- "license": "Apache-2.0",
6
- "type": "module",
7
- "engines": {
8
- "node": ">=v22"
9
- },
10
- "scripts": {
11
- "clean": "rm -rf dist tsconfig.tsbuildinfo",
12
- "build": "yarn clean && ../../package-build.sh",
13
- "depcheck": "npx depcheck"
14
- },
15
- "dependencies": {
16
- "@acala-network/chopsticks-utils": "1.5.1",
17
- "@polkadot/api": "^16.4.1",
18
- "@polkadot/types": "^16.4.1"
19
- },
20
- "devDependencies": {
21
- "@swc/cli": "0.7.10",
22
- "@swc/core": "^1.12.14",
23
- "typescript": "^5.8.3"
24
- },
25
- "files": [
26
- "dist/esm/**",
27
- "dist/cjs/**"
28
- ],
29
- "main": "./dist/cjs/index.js",
30
- "module": "./dist/esm/index.js",
31
- "exports": {
32
- ".": {
33
- "require": "./dist/cjs/index.js",
34
- "import": "./dist/esm/index.js",
35
- "default": "./dist/esm/index.js"
36
- },
37
- "./*": {
38
- "require": "./dist/cjs/*.js",
39
- "import": "./dist/esm/*.js",
40
- "default": "./dist/esm/*.js"
41
- }
42
- }
43
- }
2
+ "name": "@acala-network/chopsticks-testing",
3
+ "version": "1.6.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/AcalaNetwork/chopsticks"
7
+ },
8
+ "author": "Acala Developers <hello@acala.network>",
9
+ "license": "Apache-2.0",
10
+ "type": "module",
11
+ "engines": {
12
+ "node": ">=v24"
13
+ },
14
+ "scripts": {
15
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
16
+ "build": "bun run clean && ../../package-build.sh",
17
+ "depcheck": "bunx depcheck"
18
+ },
19
+ "dependencies": {
20
+ "@acala-network/chopsticks-utils": "workspace:*",
21
+ "@polkadot/api": "^17.0.2",
22
+ "@polkadot/types": "^17.0.2"
23
+ },
24
+ "devDependencies": {
25
+ "@swc/cli": "0.8.2",
26
+ "@swc/core": "^1.16.22",
27
+ "typescript": "^6.0.3"
28
+ },
29
+ "files": [
30
+ "dist/esm/**",
31
+ "dist/cjs/**"
32
+ ],
33
+ "main": "./dist/cjs/index.js",
34
+ "module": "./dist/esm/index.js",
35
+ "exports": {
36
+ ".": {
37
+ "require": "./dist/cjs/index.js",
38
+ "import": "./dist/esm/index.js",
39
+ "default": "./dist/esm/index.js"
40
+ },
41
+ "./*": {
42
+ "require": "./dist/cjs/*.js",
43
+ "import": "./dist/esm/*.js",
44
+ "default": "./dist/esm/*.js"
45
+ }
46
+ }
47
+ }