|
1 | 1 | import '@agoric/install-ses';
|
2 | 2 | import test from 'ava';
|
3 |
| -import { makeMarshal, Far } from '@agoric/marshal'; |
4 |
| -import { assert } from '@agoric/assert'; |
5 |
| -import { parseVatSlot } from '../../src/parseVatSlots'; |
6 |
| -import { makeVirtualObjectManager } from '../../src/kernel/virtualObjectManager'; |
| 3 | +import { Far } from '@agoric/marshal'; |
| 4 | +import { makeFakeVirtualObjectManager } from '../../tools/fakeVirtualObjectManager'; |
7 | 5 |
|
8 | 6 | function capdata(body, slots = []) {
|
9 | 7 | return harden({ body, slots });
|
10 | 8 | }
|
11 | 9 | const s = JSON.stringify;
|
12 | 10 |
|
13 |
| -function makeAllTheStuff(cacheSize) { |
14 |
| - const fakeStore = new Map(); |
15 |
| - |
16 |
| - function dumpStore() { |
17 |
| - const result = []; |
18 |
| - for (const entry of fakeStore.entries()) { |
19 |
| - result.push(entry); |
20 |
| - } |
21 |
| - result.sort((e1, e2) => e1[0].localeCompare(e2[0])); |
22 |
| - return result; |
23 |
| - } |
24 |
| - |
25 |
| - const fakeSyscall = { |
26 |
| - vatstoreGet: key => fakeStore.get(key), |
27 |
| - vatstoreSet: (key, value) => fakeStore.set(key, value), |
28 |
| - vatstoreDelete: key => fakeStore.delete(key), |
29 |
| - }; |
30 |
| - |
31 |
| - let nextExportID = 1; |
32 |
| - function fakeAllocateExportID() { |
33 |
| - const exportID = nextExportID; |
34 |
| - nextExportID += 1; |
35 |
| - return exportID; |
36 |
| - } |
37 |
| - |
38 |
| - const valToSlot = new WeakMap(); |
39 |
| - |
40 |
| - // eslint-disable-next-line no-use-before-define |
41 |
| - const fakeMarshal = makeMarshal(fakeConvertValToSlot, fakeConvertSlotToVal); |
42 |
| - |
43 |
| - const { |
44 |
| - makeVirtualObjectRepresentative, |
45 |
| - makeWeakStore, |
46 |
| - makeKind, |
47 |
| - flushCache, |
48 |
| - } = makeVirtualObjectManager( |
49 |
| - fakeSyscall, |
50 |
| - fakeAllocateExportID, |
51 |
| - valToSlot, |
52 |
| - fakeMarshal, |
53 |
| - cacheSize, |
54 |
| - ); |
55 |
| - |
56 |
| - function fakeConvertValToSlot(val) { |
57 |
| - return valToSlot.get(val); |
58 |
| - } |
59 |
| - |
60 |
| - function fakeConvertSlotToVal(slot) { |
61 |
| - const { type, virtual } = parseVatSlot(slot); |
62 |
| - assert( |
63 |
| - virtual, |
64 |
| - 'fakeConvertSlotToVal only works with virtual object references', |
65 |
| - ); |
66 |
| - assert.equal(type, 'object'); |
67 |
| - return makeVirtualObjectRepresentative(slot); |
68 |
| - } |
69 |
| - |
70 |
| - return { |
71 |
| - makeWeakStore, |
72 |
| - makeKind, |
73 |
| - flushCache, |
74 |
| - dumpStore, |
75 |
| - }; |
76 |
| -} |
77 |
| - |
78 | 11 | function makeThingInstance(state) {
|
79 | 12 | return {
|
80 | 13 | init(label = 'thing', counter = 0) {
|
@@ -132,7 +65,7 @@ function makeZotInstance(state) {
|
132 | 65 | }
|
133 | 66 |
|
134 | 67 | test('virtual object operations', t => {
|
135 |
| - const { makeKind, flushCache, dumpStore } = makeAllTheStuff(3); |
| 68 | + const { makeKind, flushCache, dumpStore } = makeFakeVirtualObjectManager(3); |
136 | 69 |
|
137 | 70 | const thingMaker = makeKind(makeThingInstance);
|
138 | 71 | const zotMaker = makeKind(makeZotInstance);
|
@@ -231,7 +164,7 @@ test('virtual object operations', t => {
|
231 | 164 | });
|
232 | 165 |
|
233 | 166 | test('weak store operations', t => {
|
234 |
| - const { makeWeakStore, makeKind } = makeAllTheStuff(3); |
| 167 | + const { makeWeakStore, makeKind } = makeFakeVirtualObjectManager(3); |
235 | 168 |
|
236 | 169 | const thingMaker = makeKind(makeThingInstance);
|
237 | 170 | const zotMaker = makeKind(makeZotInstance);
|
|
0 commit comments