Skip to content

Commit

Permalink
fix: declare lots more remotables
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 15, 2021
1 parent 4236b3f commit 2d3d901
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 110 deletions.
4 changes: 2 additions & 2 deletions packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check

import { assert, details } from '@agoric/assert';

import { Remotable } from '@agoric/marshal';
import { mustBeComparable } from '@agoric/same-structure';

import './types';
Expand Down Expand Up @@ -94,7 +94,7 @@ function makeAmountMath(brand, amountMathKind) {
const cache = new WeakSet();

/** @type {AmountMath} */
const amountMath = harden({
const amountMath = Remotable('Alleged: amountMath', undefined, {
getBrand: () => brand,
getAmountMathKind: () => amountMathKind,

Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/initializeKernel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-use-before-define */

import { makeMarshal } from '@agoric/marshal';
import { makeMarshal, Remotable } from '@agoric/marshal';
import { assert } from '@agoric/assert';
import { assertKnownOptions } from '../assertOptions';
import { insistVatID } from './id';
Expand Down Expand Up @@ -133,7 +133,7 @@ export function initializeKernel(config, hostStorage, verbose = false) {
// non-empty object as vatObj0s, since an empty object would be
// serialized as pass-by-presence. It wouldn't make much sense for the
// bootstrap object to call itself, though.
const vref = harden({
const vref = Remotable('Alleged: vref', undefined, {
toString() {
return name;
},
Expand Down
8 changes: 3 additions & 5 deletions packages/SwingSet/test/test-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ test('bootstrap export', async t => {
method: 'bootstrap',
args: {
body:
'[{"bootstrap":{"@qclass":"slot","index":0},"comms":{"@qclass":"slot","index":1},"left":{"@qclass":"slot","index":2},"right":{"@qclass":"slot","index":3},"timer":{"@qclass":"slot","index":4},"vatAdmin":{"@qclass":"slot","index":5},"vattp":{"@qclass":"slot","index":6}},{"vatAdmin":{"@qclass":"slot","index":7}}]',
'[{"bootstrap":{"@qclass":"slot","iface":"Alleged: vref","index":0},"comms":{"@qclass":"slot","iface":"Alleged: vref","index":1},"left":{"@qclass":"slot","iface":"Alleged: vref","index":2},"right":{"@qclass":"slot","iface":"Alleged: vref","index":3},"timer":{"@qclass":"slot","iface":"Alleged: vref","index":4},"vatAdmin":{"@qclass":"slot","iface":"Alleged: vref","index":5},"vattp":{"@qclass":"slot","iface":"Alleged: vref","index":6}},{"vatAdmin":{"@qclass":"slot","index":7}}]',
slots: [
boot0,
comms0,
Expand Down Expand Up @@ -182,8 +182,7 @@ test('bootstrap export', async t => {
msg: {
method: 'foo',
args: {
body:
'[1,{"@qclass":"slot","iface":"Alleged: presence o-52","index":0}]',
body: '[1,{"@qclass":"slot","iface":"Alleged: vref","index":0}]',
slots: [right0],
},
result: fooP,
Expand All @@ -205,8 +204,7 @@ test('bootstrap export', async t => {
msg: {
method: 'bar',
args: {
body:
'[2,{"@qclass":"slot","iface":"Alleged: presence o-52","index":0}]',
body: '[2,{"@qclass":"slot","iface":"Alleged: vref","index":0}]',
slots: [right0],
},
result: barP,
Expand Down
10 changes: 5 additions & 5 deletions packages/SwingSet/test/test-devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ test.serial('d0', async t => {
// console.log(util.inspect(c.dump(), { depth: null }));
t.deepEqual(JSON.parse(c.dump().log[0]), [
{
bootstrap: { '@qclass': 'slot', index: 0 },
comms: { '@qclass': 'slot', index: 1 },
timer: { '@qclass': 'slot', index: 2 },
vatAdmin: { '@qclass': 'slot', index: 3 },
vattp: { '@qclass': 'slot', index: 4 },
bootstrap: { '@qclass': 'slot', iface: 'Alleged: vref', index: 0 },
comms: { '@qclass': 'slot', iface: 'Alleged: vref', index: 1 },
timer: { '@qclass': 'slot', iface: 'Alleged: vref', index: 2 },
vatAdmin: { '@qclass': 'slot', iface: 'Alleged: vref', index: 3 },
vattp: { '@qclass': 'slot', iface: 'Alleged: vref', index: 4 },
},
{
d0: { '@qclass': 'slot', index: 5 },
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/test-liveslots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@agoric/install-ses';
import test from 'ava';
import { E } from '@agoric/eventual-send';
import { Remotable } from '@agoric/marshal';
import { WeakRef, FinalizationRegistry } from '../src/weakref';
import { waitUntilQuiescent } from '../src/waitUntilQuiescent';
import { makeLiveSlots } from '../src/kernel/liveSlots';
Expand Down Expand Up @@ -190,7 +191,7 @@ test('liveslots pipeline/non-pipeline calls', async t => {

function build(_vatPowers) {
let p1;
return harden({
return Remotable('Alleged: onetwo', undefined, {
one(p) {
p1 = p;
E(p1).pipe1();
Expand Down
13 changes: 7 additions & 6 deletions packages/SwingSet/test/test-marshal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@agoric/install-ses';
import { Remotable } from '@agoric/marshal';
import test from 'ava';
import { makePromiseKit } from '@agoric/promise-kit';

Expand All @@ -18,23 +19,23 @@ async function prep() {
test('serialize exports', t => {
const { m } = makeMarshaller(undefined, gcTools);
const ser = val => m.serialize(val);
const o1 = harden({});
const o2 = harden({
const o1 = Remotable('Alleged: o1', undefined, {});
const o2 = Remotable('Alleged: o2', undefined, {
meth1() {
return 4;
},
});
t.deepEqual(ser(o1), {
body: '{"@qclass":"slot","index":0}',
body: '{"@qclass":"slot","iface":"Alleged: o1","index":0}',
slots: ['o+1'],
});
// m now remembers that o1 is exported as 1
t.deepEqual(ser(harden([o1, o1])), {
body: '[{"@qclass":"slot","index":0},{"@qclass":"ibid","index":1}]',
body: '[{"@qclass":"slot","iface":"Alleged: o1","index":0},{"@qclass":"ibid","index":1}]',
slots: ['o+1'],
});
t.deepEqual(ser(harden([o2, o1])), {
body: '[{"@qclass":"slot","index":0},{"@qclass":"slot","index":1}]',
body: '[{"@qclass":"slot","iface":"Alleged: o2","index":0},{"@qclass":"slot","iface":"Alleged: o1","index":1}]',
slots: ['o+2', 'o+1'],
});
});
Expand Down Expand Up @@ -67,7 +68,7 @@ test('deserialize imports', async t => {

test('deserialize exports', t => {
const { m } = makeMarshaller(undefined, gcTools);
const o1 = harden({});
const o1 = Remotable('Alleged: o1', undefined, {});
m.serialize(o1); // allocates slot=1
const a = m.unserialize({
body: '{"@qclass":"slot","index":0}',
Expand Down
5 changes: 3 additions & 2 deletions packages/SwingSet/test/test-vpid-liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import '@agoric/install-ses';
import test from 'ava';
import { Remotable } from '@agoric/marshal';

import { E } from '@agoric/eventual-send';
import { makePromiseKit } from '@agoric/promise-kit';
Expand Down Expand Up @@ -117,7 +118,7 @@ function resolvePR(pr, mode, targets) {
break;
case 'local-object':
pr.resolve(
harden({
Remotable('Alleged: vpid resolve test', undefined, {
two() {
/* console.log(`local two() called`); */
},
Expand Down Expand Up @@ -595,7 +596,7 @@ async function doVatResolveCase4(t, mode) {

function build(_vatPowers) {
let p1;
return harden({
return Remotable('Alleged: test vpid', undefined, {
async get(p) {
p1 = p;
// if we don't add this, node will complain when the kernel notifies
Expand Down
5 changes: 3 additions & 2 deletions packages/captp/lib/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,16 @@ export function makeLoopback(ourId) {
let nextNonce = 0;
const nonceToRef = new Map();

// TODO use the correct Remotable, which is not currently in scope here.
const bootstrap = harden({
refGetter: {
refGetter: defaultRemotable('Alleged: captp bootstrap', undefined, {
getRef(nonce) {
// Find the local ref for the specified nonce.
const xFar = nonceToRef.get(nonce);
nonceToRef.delete(nonce);
return xFar;
},
},
}),
});

// Create the tunnel.
Expand Down
5 changes: 3 additions & 2 deletions packages/captp/test/test-crosstalk.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import '@agoric/install-ses';
import { Remotable } from '@agoric/marshal';
import test from 'ava';
import { makeLoopback, E } from '../lib/captp';

test('prevent crosstalk', async t => {
const { makeFar } = makeLoopback('alice');
const rightRef = makeFar(
harden({
Remotable('Alleged: rightRef', undefined, {
isSide(objP, side) {
return E(objP)
.side()
Expand All @@ -18,7 +19,7 @@ test('prevent crosstalk', async t => {
);

await E(rightRef).isSide(rightRef, 'right');
const leftRef = harden({
const leftRef = Remotable('Alleged: leftRef', undefined, {
side() {
return 'left';
},
Expand Down
7 changes: 5 additions & 2 deletions packages/captp/test/test-disco.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@agoric/install-ses';
import { Remotable } from '@agoric/marshal';
import test from 'ava';
import { E, makeCapTP } from '../lib/captp';

Expand All @@ -8,8 +9,9 @@ test('try disconnecting captp', async t => {
const { getBootstrap, abort } = makeCapTP(
'us',
obj => objs.push(obj),
// TODO Can we avoid the function wrapper? makeCapTP does the needed test
() =>
harden({
Remotable('Alleged: test hello', undefined, {
method() {
return 'hello';
},
Expand Down Expand Up @@ -68,8 +70,9 @@ test('try aborting captp with reason', async t => {
const { getBootstrap, abort } = makeCapTP(
'us',
obj => objs.push(obj),
// TODO Can we avoid the function wrapper? makeCapTP does the needed test
() =>
harden({
Remotable('Alleged: test hello', undefined, {
method() {
return 'hello';
},
Expand Down
21 changes: 12 additions & 9 deletions packages/captp/test/test-loopback.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '@agoric/install-ses';
import { Remotable } from '@agoric/marshal';
import test from 'ava';
import { E, makeLoopback } from '../lib/captp';

Expand All @@ -10,7 +11,7 @@ test('try loopback captp', async t => {
});

const syncHandle = harden({});
const syncAccess = {
const syncAccess = Remotable('Alleged: syncAccess', undefined, {
checkHandle(hnd) {
// console.log('check', hnd, oobHandle);
return hnd === syncHandle;
Expand All @@ -21,28 +22,30 @@ test('try loopback captp', async t => {
getHandle() {
return syncHandle;
},
};
});

const { makeFar } = makeLoopback('dean');
const objNear = harden({
promise: pr.p,
syncAccess,
encourager: {
encourager: Remotable('Alleged: encourager', undefined, {
encourage(name) {
const bang = new Promise(resolve => {
setTimeout(
() =>
resolve({
trigger() {
return `${name} BANG!`;
},
}),
resolve(
Remotable('Alleged: triggerObj', undefined, {
trigger() {
return `${name} BANG!`;
},
}),
),
200,
);
});
return { comment: `good work, ${name}`, bang };
},
},
}),
});

// Mark obj as far.
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/test/test-lib-dehydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test('makeDehydrator', async t => {
);

const makeMockBrand = () =>
harden({
Remotable('Alleged: mock brand', undefined, {
isMyIssuer: _allegedIssuer => {},
getAllegedName: () => {},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t
],
currentAmountSlots: {
body:
'{"brand":{"@qclass":"slot","iface":"Alleged: Zoe Invitation brand","index":0},"value":[{"description":"getRefund","handle":{"@qclass":"slot","index":1},"instance":{"@qclass":"slot","index":2},"installation":{"@qclass":"slot","index":3}}]}',
'{"brand":{"@qclass":"slot","iface":"Alleged: Zoe Invitation brand","index":0},"value":[{"description":"getRefund","handle":{"@qclass":"slot","index":1},"instance":{"@qclass":"slot","iface":"Alleged: InstanceHandleHandle","index":2},"installation":{"@qclass":"slot","iface":"Alleged: Installation","index":3}}]}',
slots: [
{ kind: 'brand', petname: 'zoe invite' },
{ kind: 'unnamed', petname: 'unnamed-4' },
Expand Down
29 changes: 25 additions & 4 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,29 @@ export function makeMarshal(
slotMap.set(val, slotIndex);
}

/*
if (iface === undefined && passStyleOf(val) === REMOTE_STYLE) {
iface = `Alleged: remotable at slot ${slotIndex}`;
const err = new Error(`Serialize generates iface ${iface}`);
console.info(err);
// iface = `Alleged: remotable at slot ${slotIndex}`;
if (
Object.getPrototypeOf(val) === Object.prototype &&
Object.getOwnPropertyNames(val).length === 0
) {
// For now, skip the diagnostic if we have a pure empty object
} else {
try {
assert.fail(d`Serialize ${val} generates needs iface`);
} catch (err) {
console.info(err);
}
}
}
*/

if (iface === undefined) {
return harden({
[QCLASS]: 'slot',
index: slotIndex,
});
}
return harden({
[QCLASS]: 'slot',
Expand Down Expand Up @@ -824,7 +843,9 @@ function Remotable(iface = 'Remotable', props = {}, remotable = {}) {
// TODO unimplemented
assert(
iface === 'Remotable' || iface.startsWith('Alleged: '),
d`For now, iface ${iface} must be "Remotable" or begin with "Alleged: "; unimplemented`,
d`For now, iface ${q(
iface,
)} must be "Remotable" or begin with "Alleged: "; unimplemented`,
);
iface = pureCopy(harden(iface));

Expand Down
9 changes: 5 additions & 4 deletions packages/swingset-runner/demo/vatResolveTest/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { E } from '@agoric/eventual-send';
import { Remotable } from '@agoric/marshal';

const log = console.log;

log(`=> loading bootstrap.js`);

export function buildRootObject(_vatPowers) {
const target1 = {
const target1 = Remotable('Alleged: target1', undefined, {
one(_p) {
log(`target1 in one`);
},
Expand All @@ -18,8 +19,8 @@ export function buildRootObject(_vatPowers) {
four() {
log(`target1 in four`);
},
};
const target2 = {
});
const target2 = Remotable('Alleged: target2', undefined, {
one(_p) {
log(`target2 in one`);
},
Expand All @@ -32,7 +33,7 @@ export function buildRootObject(_vatPowers) {
four() {
log(`target2 in four`);
},
};
});
return harden({
bootstrap(vats) {
const bob = vats.bob;
Expand Down
Loading

0 comments on commit 2d3d901

Please sign in to comment.