@agoric/vat-data 0.5.3-dev-4733782.0 → 0.5.3-dev-c774209.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/vat-data",
|
|
3
|
-
"version": "0.5.3-dev-
|
|
3
|
+
"version": "0.5.3-dev-c774209.0+c774209",
|
|
4
4
|
"description": "Safe access to VatData global",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/Agoric/agoric-sdk",
|
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
"author": "Agoric",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@agoric/assert": "0.6.1-dev-
|
|
23
|
-
"@agoric/base-zone": "0.1.1-dev-
|
|
24
|
-
"@agoric/internal": "0.3.3-dev-
|
|
25
|
-
"@agoric/store": "0.9.3-dev-
|
|
26
|
-
"@agoric/swingset-liveslots": "0.10.3-dev-
|
|
27
|
-
"@agoric/vow": "0.1.1-dev-
|
|
22
|
+
"@agoric/assert": "0.6.1-dev-c774209.0+c774209",
|
|
23
|
+
"@agoric/base-zone": "0.1.1-dev-c774209.0+c774209",
|
|
24
|
+
"@agoric/internal": "0.3.3-dev-c774209.0+c774209",
|
|
25
|
+
"@agoric/store": "0.9.3-dev-c774209.0+c774209",
|
|
26
|
+
"@agoric/swingset-liveslots": "0.10.3-dev-c774209.0+c774209",
|
|
27
|
+
"@agoric/vow": "0.1.1-dev-c774209.0+c774209",
|
|
28
|
+
"@endo/exo": "^1.3.0",
|
|
29
|
+
"@endo/patterns": "^1.3.0"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
32
|
"@endo/far": "^1.1.0",
|
|
@@ -50,5 +52,5 @@
|
|
|
50
52
|
"typeCoverage": {
|
|
51
53
|
"atLeast": 98.79
|
|
52
54
|
},
|
|
53
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c7742091b64886f933314ec3981c939504552d29"
|
|
54
56
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// modeled on test-amplify-heap-class-kits.js
|
|
2
|
+
import { test } from './prepare-test-env-ava.js';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line import/order
|
|
5
|
+
import { M } from '@endo/patterns';
|
|
6
|
+
import {
|
|
7
|
+
defineVirtualExoClass,
|
|
8
|
+
defineVirtualExoClassKit,
|
|
9
|
+
} from '../src/exo-utils.js';
|
|
10
|
+
|
|
11
|
+
const UpCounterI = M.interface('UpCounter', {
|
|
12
|
+
incr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const DownCounterI = M.interface('DownCounter', {
|
|
16
|
+
decr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('test amplify defineVirtualExoClass fails', t => {
|
|
20
|
+
t.throws(
|
|
21
|
+
() =>
|
|
22
|
+
defineVirtualExoClass(
|
|
23
|
+
'UpCounter',
|
|
24
|
+
UpCounterI,
|
|
25
|
+
/** @param {number} [x] */
|
|
26
|
+
(x = 0) => ({ x }),
|
|
27
|
+
{
|
|
28
|
+
incr(y = 1) {
|
|
29
|
+
const { state } = this;
|
|
30
|
+
state.x += y;
|
|
31
|
+
return state.x;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
receiveAmplifier(_) {},
|
|
36
|
+
},
|
|
37
|
+
),
|
|
38
|
+
{
|
|
39
|
+
message:
|
|
40
|
+
'Only facets of an exo class kit can be amplified, not "UpCounter"',
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('test amplify defineVirtualExoClassKit', t => {
|
|
46
|
+
/** @type {import('@endo/exo/src/exo-makers.js').Amplify} */
|
|
47
|
+
let amp;
|
|
48
|
+
const makeCounterKit = defineVirtualExoClassKit(
|
|
49
|
+
'Counter',
|
|
50
|
+
{ up: UpCounterI, down: DownCounterI },
|
|
51
|
+
/** @param {number} [x] */
|
|
52
|
+
(x = 0) => ({ x }),
|
|
53
|
+
{
|
|
54
|
+
up: {
|
|
55
|
+
incr(y = 1) {
|
|
56
|
+
const { state } = this;
|
|
57
|
+
state.x += y;
|
|
58
|
+
return state.x;
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
down: {
|
|
62
|
+
decr(y = 1) {
|
|
63
|
+
const { state } = this;
|
|
64
|
+
state.x -= y;
|
|
65
|
+
return state.x;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
receiveAmplifier(a) {
|
|
71
|
+
amp = a;
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
// @ts-expect-error TS thinks it is used before assigned, which is a hazard
|
|
76
|
+
// TS is correct to bring to our attention, since there is not enough static
|
|
77
|
+
// into to infer otherwise.
|
|
78
|
+
assert(amp !== undefined);
|
|
79
|
+
|
|
80
|
+
const counterKit = makeCounterKit(3);
|
|
81
|
+
const { up: upCounter, down: downCounter } = counterKit;
|
|
82
|
+
t.is(upCounter.incr(5), 8);
|
|
83
|
+
t.is(downCounter.decr(), 7);
|
|
84
|
+
|
|
85
|
+
t.throws(() => amp(harden({})), {
|
|
86
|
+
message: 'Must be a facet of "Counter": {}',
|
|
87
|
+
});
|
|
88
|
+
t.deepEqual(amp(upCounter), counterKit);
|
|
89
|
+
t.deepEqual(amp(downCounter), counterKit);
|
|
90
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// modeled on test-is-instance-heap-class-kits.js
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line import/order
|
|
4
|
+
import { test } from './prepare-test-env-ava.js';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line import/order
|
|
7
|
+
import { M } from '@endo/patterns';
|
|
8
|
+
import {
|
|
9
|
+
defineVirtualExoClass,
|
|
10
|
+
defineVirtualExoClassKit,
|
|
11
|
+
} from '../src/exo-utils.js';
|
|
12
|
+
|
|
13
|
+
const UpCounterI = M.interface('UpCounter', {
|
|
14
|
+
incr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const DownCounterI = M.interface('DownCounter', {
|
|
18
|
+
decr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('test isInstance defineVirtualExoClass', t => {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
23
|
+
// @ts-ignore IsInstance merged after last sync with endo
|
|
24
|
+
/** @type {import('@endo/exo/src/exo-makers.js').IsInstance} */
|
|
25
|
+
let isInstance;
|
|
26
|
+
const makeUpCounter = defineVirtualExoClass(
|
|
27
|
+
'UpCounter',
|
|
28
|
+
UpCounterI,
|
|
29
|
+
/** @param {number} x */
|
|
30
|
+
(x = 0) => ({ x }),
|
|
31
|
+
{
|
|
32
|
+
incr(y = 1) {
|
|
33
|
+
const { state } = this;
|
|
34
|
+
state.x += y;
|
|
35
|
+
return state.x;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
receiveInstanceTester(i) {
|
|
40
|
+
isInstance = i;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
// @ts-expect-error TS thinks it is used before assigned, which is a hazard
|
|
45
|
+
// TS is correct to bring to our attention, since there is not enough static
|
|
46
|
+
// into to infer otherwise.
|
|
47
|
+
assert(isInstance !== undefined);
|
|
48
|
+
|
|
49
|
+
t.is(isInstance(harden({})), false);
|
|
50
|
+
t.throws(() => isInstance(harden({}), 'up'), {
|
|
51
|
+
message:
|
|
52
|
+
'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const upCounter = makeUpCounter(3);
|
|
56
|
+
|
|
57
|
+
t.is(isInstance(upCounter), true);
|
|
58
|
+
t.throws(() => isInstance(upCounter, 'up'), {
|
|
59
|
+
message:
|
|
60
|
+
'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('test isInstance defineVirtualExoClassKit', t => {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
66
|
+
// @ts-ignore IsInstance merged after last sync with endo
|
|
67
|
+
/** @type {import('@endo/exo/src/exo-makers.js').IsInstance} */
|
|
68
|
+
let isInstance;
|
|
69
|
+
const makeCounterKit = defineVirtualExoClassKit(
|
|
70
|
+
'Counter',
|
|
71
|
+
{ up: UpCounterI, down: DownCounterI },
|
|
72
|
+
/** @param {number} x */
|
|
73
|
+
(x = 0) => ({ x }),
|
|
74
|
+
{
|
|
75
|
+
up: {
|
|
76
|
+
incr(y = 1) {
|
|
77
|
+
const { state } = this;
|
|
78
|
+
state.x += y;
|
|
79
|
+
return state.x;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
down: {
|
|
83
|
+
decr(y = 1) {
|
|
84
|
+
const { state } = this;
|
|
85
|
+
state.x -= y;
|
|
86
|
+
return state.x;
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
receiveInstanceTester(i) {
|
|
92
|
+
isInstance = i;
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
// @ts-expect-error TS thinks it is used before assigned, which is a hazard
|
|
97
|
+
// TS is correct to bring to our attention, since there is not enough static
|
|
98
|
+
// into to infer otherwise.
|
|
99
|
+
assert(isInstance !== undefined);
|
|
100
|
+
|
|
101
|
+
t.is(isInstance(harden({})), false);
|
|
102
|
+
t.is(isInstance(harden({}), 'up'), false);
|
|
103
|
+
t.throws(() => isInstance(harden({}), 'foo'), {
|
|
104
|
+
message: 'exo class kit "Counter" has no facet named "foo"',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const { up: upCounter } = makeCounterKit(3);
|
|
108
|
+
|
|
109
|
+
t.is(isInstance(upCounter), true);
|
|
110
|
+
t.is(isInstance(upCounter, 'up'), true);
|
|
111
|
+
t.is(isInstance(upCounter, 'down'), false);
|
|
112
|
+
t.throws(() => isInstance(upCounter, 'foo'), {
|
|
113
|
+
message: 'exo class kit "Counter" has no facet named "foo"',
|
|
114
|
+
});
|
|
115
|
+
});
|