@agoric/kmarshal 0.1.1-other-dev-fbe72e7.0.fbe72e7 → 0.1.1-other-dev-d15096d.0.d15096d
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/package.json +4 -5
- package/src/kmarshal.js +4 -1
- package/test/basic.test.js +1 -0
- package/test/error-test-cases.js +62 -0
- package/test/error-unsafe-fast.test.js +14 -0
- package/test/error.test.js +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/kmarshal",
|
|
3
|
-
"version": "0.1.1-other-dev-
|
|
3
|
+
"version": "0.1.1-other-dev-d15096d.0.d15096d",
|
|
4
4
|
"description": "Token-only marshaller for kernel and tests",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/kmarshal.js",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"@endo/marshal": "^1.8.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
+
"@endo/init": "^1.1.12",
|
|
30
|
+
"@endo/ses-ava": "^1.3.2",
|
|
29
31
|
"ava": "^5.3.0"
|
|
30
32
|
},
|
|
31
33
|
"publishConfig": {
|
|
@@ -35,13 +37,10 @@
|
|
|
35
37
|
"files": [
|
|
36
38
|
"test/**/*.test.*"
|
|
37
39
|
],
|
|
38
|
-
"require": [
|
|
39
|
-
"@endo/init/debug.js"
|
|
40
|
-
],
|
|
41
40
|
"timeout": "2m"
|
|
42
41
|
},
|
|
43
42
|
"engines": {
|
|
44
43
|
"node": "^20.9 || ^22.11"
|
|
45
44
|
},
|
|
46
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "d15096dc4ff8b96e9b6cd11954c20d3a9efbb393"
|
|
47
46
|
}
|
package/src/kmarshal.js
CHANGED
|
@@ -4,6 +4,7 @@ import { makeMarshal } from '@endo/marshal';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @import {ConvertSlotToVal} from '@endo/marshal';
|
|
7
|
+
* @import {CapData} from '@endo/marshal';
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
// Simple wrapper for serializing and unserializing marshalled values inside the
|
|
@@ -96,12 +97,14 @@ const kmarshal = makeMarshal(krefOf, kslot, {
|
|
|
96
97
|
export const kser = value => kmarshal.serialize(harden(value));
|
|
97
98
|
|
|
98
99
|
/**
|
|
99
|
-
* @param {
|
|
100
|
+
* @param {CapData<string>} serializedValue
|
|
100
101
|
* @returns {any}
|
|
101
102
|
*/
|
|
102
103
|
export const kunser = serializedValue => kmarshal.unserialize(serializedValue);
|
|
103
104
|
|
|
104
105
|
export function makeError(message) {
|
|
105
106
|
assert.typeof(message, 'string');
|
|
107
|
+
// Marshal has a relaxation for an error at the root of the data
|
|
108
|
+
// so these will always serialize even if not passable
|
|
106
109
|
return kser(Error(message));
|
|
107
110
|
}
|
package/test/basic.test.js
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { passStyleOf, toPassableError } from '@endo/marshal';
|
|
2
|
+
|
|
3
|
+
import { kser, makeError } from '../src/kmarshal.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import {ExecutionContext} from 'ava';
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @type {Record<string, (t: ExecutionContext) => void>} */
|
|
10
|
+
export const cases = {
|
|
11
|
+
'kernel serialization of errors': t => {
|
|
12
|
+
// The kernel synthesizes e.g. `Error('vat terminated')`, so we
|
|
13
|
+
// need kmarshal to serialize those errors in a deterministic
|
|
14
|
+
// way. This test checks that we don't get surprising things like
|
|
15
|
+
// `errorId` or stack traces.
|
|
16
|
+
const e1 = kser(Error('fake error'));
|
|
17
|
+
const ref = {
|
|
18
|
+
body: '#{"#error":"fake error","name":"Error"}',
|
|
19
|
+
slots: [],
|
|
20
|
+
};
|
|
21
|
+
t.deepEqual(e1, ref);
|
|
22
|
+
|
|
23
|
+
const e2 = makeError('fake error');
|
|
24
|
+
t.deepEqual(e2, ref);
|
|
25
|
+
},
|
|
26
|
+
'kernel serialization of passable errors in deliveries': t => {
|
|
27
|
+
// The kernel synthesizes e.g. `Error('vat-upgrade failure')`, and includes
|
|
28
|
+
// it in arguments to deliveries, so we need kmarshal to serialize those
|
|
29
|
+
// nested errors reliably. This test checks that we don't get surprising
|
|
30
|
+
// behaviors like non-passable errors even when the kernel explicitly
|
|
31
|
+
// coerce those to passable.
|
|
32
|
+
const e1 = toPassableError(Error('fake nested error'));
|
|
33
|
+
const methargs = ['someMethod', [e1]];
|
|
34
|
+
const ref = {
|
|
35
|
+
body: '#["someMethod",[{"#error":"fake nested error","name":"Error"}]]',
|
|
36
|
+
slots: [],
|
|
37
|
+
};
|
|
38
|
+
t.deepEqual(kser(methargs), ref);
|
|
39
|
+
},
|
|
40
|
+
'kernel serialization of raw errors in deliveries': t => {
|
|
41
|
+
// The kernel synthesizes e.g. `Error('vat-upgrade failure')`, and includes
|
|
42
|
+
// it in arguments to deliveries, so we need kmarshal to serialize those
|
|
43
|
+
// nested errors reliably. While the kernel coerces errors it synthesizes to
|
|
44
|
+
// passable errors, here we check the behavior if it didn't.
|
|
45
|
+
const e1 = Error('fake nested error');
|
|
46
|
+
const methargs = ['someMethod', [e1]];
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
t.is(passStyleOf(harden({ error: Error('sentinel') })), 'copyRecord');
|
|
50
|
+
// If the above doesn't throw, raw errors are passable, or passStyle repairs them
|
|
51
|
+
const ref = {
|
|
52
|
+
body: '#["someMethod",[{"#error":"fake nested error","name":"Error"}]]',
|
|
53
|
+
slots: [],
|
|
54
|
+
};
|
|
55
|
+
t.deepEqual(kser(methargs), ref);
|
|
56
|
+
} catch {
|
|
57
|
+
// If we threw, raw errors are not passable. We expect kser to throw as well
|
|
58
|
+
|
|
59
|
+
t.throws(() => kser(methargs));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// We are explicitly testing unsafe-fast behavior in this test
|
|
2
|
+
// Unlike in error.test.js
|
|
3
|
+
import '@endo/init/unsafe-fast.js';
|
|
4
|
+
|
|
5
|
+
import { wrapTest } from '@endo/ses-ava';
|
|
6
|
+
import rawTest from 'ava';
|
|
7
|
+
|
|
8
|
+
import { cases } from './error-test-cases.js';
|
|
9
|
+
|
|
10
|
+
const test = wrapTest(rawTest);
|
|
11
|
+
|
|
12
|
+
for (const [title, impl] of Object.entries(cases)) {
|
|
13
|
+
test(title, impl);
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// We are testing normal lockdown behavior in this test
|
|
2
|
+
// Unlike in error-unsafe-fast.test.js
|
|
3
|
+
import '@endo/init/debug.js';
|
|
4
|
+
|
|
5
|
+
import { wrapTest } from '@endo/ses-ava';
|
|
6
|
+
import rawTest from 'ava';
|
|
7
|
+
|
|
8
|
+
import { cases } from './error-test-cases.js';
|
|
9
|
+
|
|
10
|
+
const test = wrapTest(rawTest);
|
|
11
|
+
|
|
12
|
+
for (const [title, impl] of Object.entries(cases)) {
|
|
13
|
+
test(title, impl);
|
|
14
|
+
}
|