-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: incorporate fakeVirtualObjectManager for testing
- Loading branch information
1 parent
0133a3a
commit f9cb176
Showing
4 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { makeFakeVirtualObjectManager } from '@agoric/swingset-vat/tools/fakeVirtualObjectManager'; | ||
|
||
const { makeKind, makeWeakStore } = makeFakeVirtualObjectManager(3); | ||
|
||
global.makeKind = makeKind; | ||
global.makeWeakStore = makeWeakStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { makeMarshal } from '@agoric/marshal'; | ||
import { assert } from '@agoric/assert'; | ||
import { parseVatSlot } from '../src/parseVatSlots'; | ||
|
||
import { makeVirtualObjectManager } from '../src/kernel/virtualObjectManager'; | ||
|
||
export function makeFakeVirtualObjectManager(cacheSize = 100) { | ||
const fakeStore = new Map(); | ||
|
||
function dumpStore() { | ||
const result = []; | ||
for (const entry of fakeStore.entries()) { | ||
result.push(entry); | ||
} | ||
result.sort((e1, e2) => e1[0].localeCompare(e2[0])); | ||
return result; | ||
} | ||
|
||
const fakeSyscall = { | ||
vatstoreGet: key => fakeStore.get(key), | ||
vatstoreSet: (key, value) => fakeStore.set(key, value), | ||
vatstoreDelete: key => fakeStore.delete(key), | ||
}; | ||
|
||
let nextExportID = 1; | ||
function fakeAllocateExportID() { | ||
const exportID = nextExportID; | ||
nextExportID += 1; | ||
return exportID; | ||
} | ||
|
||
const valToSlot = new WeakMap(); | ||
|
||
function fakeConvertValToSlot(val) { | ||
return valToSlot.get(val); | ||
} | ||
|
||
function fakeConvertSlotToVal(slot) { | ||
const { type, virtual } = parseVatSlot(slot); | ||
assert( | ||
virtual, | ||
'fakeConvertSlotToVal only works with virtual object references', | ||
); | ||
assert.equal(type, 'object'); | ||
// eslint-disable-next-line no-use-before-define | ||
return makeVirtualObjectRepresentative(slot); | ||
} | ||
|
||
// eslint-disable-next-line no-use-before-define | ||
const fakeMarshal = makeMarshal(fakeConvertValToSlot, fakeConvertSlotToVal); | ||
|
||
const { | ||
makeVirtualObjectRepresentative, | ||
makeWeakStore, | ||
makeKind, | ||
flushCache, | ||
} = makeVirtualObjectManager( | ||
fakeSyscall, | ||
fakeAllocateExportID, | ||
valToSlot, | ||
fakeMarshal, | ||
cacheSize, | ||
); | ||
|
||
return { | ||
makeKind, | ||
makeWeakStore, | ||
flushCache, | ||
dumpStore, | ||
}; | ||
} |