Skip to content

Commit

Permalink
fix: access when and makeWhenableKit correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
iomekam committed Jan 18, 2024
1 parent 31976bc commit 3194369
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
4 changes: 2 additions & 2 deletions packages/network/src/network.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { E } from '@endo/far';
import { Fail } from '@agoric/assert';
import { whileTrue } from '@agoric/internal';
import { when } from '@agoric/whenable';
import { toBytes } from './bytes.js';

import '@agoric/store/exported.js';
Expand Down Expand Up @@ -47,7 +46,7 @@ export function getPrefixes(addr) {
* @param {import('@agoric/base-zone').Zone} zone
* @param {ReturnType<import('@agoric/whenable').prepareWhenableModule>} powers
*/
const prepareHalfConnection = (zone, { watch }) => {
const prepareHalfConnection = (zone, { when }) => {
const makeHalfConnection = zone.exoClass(
'Connection',
undefined,
Expand Down Expand Up @@ -414,6 +413,7 @@ const prepareBinder = (zone, powers) => {
const makeInboundAttempt = prepareInboundAttempt(zone, makeConnection);
const makePort = preparePort(zone);
const detached = zone.detached();
const { when } = powers;

const makeBinderKit = zone.exoClassKit(
'binder',
Expand Down
31 changes: 21 additions & 10 deletions packages/network/test/test-network-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
import { reincarnate } from '@agoric/swingset-liveslots/tools/setup-vat-data.js';

Check failure on line 4 in packages/network/test/test-network-misc.js

View workflow job for this annotation

GitHub Actions / lint-rest

'@agoric/swingset-liveslots' should be listed in the project's dependencies. Run 'npm i -S @agoric/swingset-liveslots' to add it

import { makePromiseKit } from '@endo/promise-kit';
import { E, Far } from '@endo/far';
import { prepareWhenableModule, when } from '@agoric/whenable';
import { E } from '@endo/far';
import { prepareWhenableModule } from '@agoric/whenable';
import { makeDurableZone } from '@agoric/zone/durable.js';

Check failure on line 8 in packages/network/test/test-network-misc.js

View workflow job for this annotation

GitHub Actions / lint-rest

'@agoric/zone' should be listed in the project's dependencies. Run 'npm i -S @agoric/zone' to add it

import {
Expand All @@ -15,6 +14,7 @@ import {
makeNetworkProtocol,
prepareRouter,
prepareLoopbackProtocolHandler,
prepareNonceMaker,
} from '../src/index.js';

import '../src/types.js';
Expand Down Expand Up @@ -105,9 +105,10 @@ const provideBaggage = key => {

test('handled protocol', async t => {
const zone = makeDurableZone(provideBaggage('network-handled-protocol'));
const powers = prepareWhenableModule(zone);
const { makeWhenableKit, when } = powers;
const makeProtocolHandler = prepareProtocolHandler(zone, t);
const protocol = makeNetworkProtocol(zone, makeProtocolHandler());
const { makeWhenableKit } = prepareWhenableModule(zone);
const protocol = makeNetworkProtocol(zone, makeProtocolHandler(), powers);

const port = await when(protocol.bind('/ibc/*/ordered'));

Expand Down Expand Up @@ -154,9 +155,10 @@ test('handled protocol', async t => {

test('protocol connection listen', async t => {
const zone = makeDurableZone(provideBaggage('network-protocol-connection'));
const powers = prepareWhenableModule(zone);
const { makeWhenableKit, when } = powers;
const makeProtocolHandler = prepareProtocolHandler(zone, t);
const protocol = makeNetworkProtocol(zone, makeProtocolHandler());
const { makeWhenableKit } = prepareWhenableModule(zone);
const protocol = makeNetworkProtocol(zone, makeProtocolHandler(), powers);

const port = await when(protocol.bind('/net/ordered/ordered/some-portname'));
const { whenable, settler } = makeWhenableKit();
Expand Down Expand Up @@ -306,9 +308,18 @@ test('protocol connection listen', async t => {

test('loopback protocol', async t => {
const zone = makeDurableZone(provideBaggage('network-loopback-protocol'));
const makeLoopbackProtocolHandler = prepareLoopbackProtocolHandler(zone);
const protocol = makeNetworkProtocol(zone, makeLoopbackProtocolHandler());
const { makeWhenableKit } = prepareWhenableModule(zone);
const powers = prepareWhenableModule(zone);
const { makeWhenableKit, when } = powers;
const makeNonceMaker = prepareNonceMaker(zone);
const makeLoopbackProtocolHandler = prepareLoopbackProtocolHandler(
zone,
makeNonceMaker,
);
const protocol = makeNetworkProtocol(
zone,
makeLoopbackProtocolHandler(),
powers,
);
const { whenable, settler } = makeWhenableKit();

const port = await when(protocol.bind('/loopback/foo'));
Expand Down
14 changes: 0 additions & 14 deletions packages/vats/src/ibc.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,20 +558,6 @@ export const prepareIBCProtocol = (zone, { makeWhenableKit, watch, when }) => {
const data = base64ToBytes(data64);

watch(conn.send(data), makeAckWatcher(this.facets.util, packet));

/*
await E(conn)
.send(data)
.then(ack => {
const realAck = ack || DEFAULT_ACKNOWLEDGEMENT;
const ack64 = dataToBase64(realAck);
this.facets.util.downcall('receiveExecuted', {
packet,
ack: ack64,
});
})
.catch(e => console.error(e));
*/
break;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/vats/test/test-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { reincarnate } from '@agoric/swingset-liveslots/tools/setup-vat-data.js'

import { E, Far } from '@endo/far';
import {
makeSubscriptionKit,
makePinnedHistoryTopic,
prepareDurablePublishKit,
subscribeEach,
} from '@agoric/notifier';
import { makeDurableZone } from '@agoric/zone/durable.js';
import { makeWhenableKit, prepareWhenableModule } from '@agoric/whenable';
import { prepareWhenableModule } from '@agoric/whenable';

import { buildRootObject as ibcBuildRootObject } from '../src/vat-ibc.js';
import { buildRootObject as networkBuildRootObject } from '../src/vat-network.js';
Expand All @@ -23,7 +22,7 @@ const provideBaggage = key => {
return zone.mapStore(`${key} baggage`);
};

const preparePlusOneConnectionHandler = zone => {
const preparePlusOneConnectionHandler = (zone, { makeWhenableKit }) => {
const makePlusOneConnectionHandler = zone.exoClass(
'plusOne',
undefined,
Expand Down Expand Up @@ -80,7 +79,8 @@ Far('ibcListener', {}),
const ibcVat = E(ibcBuildRootObject)(null, null, provideBaggage('ibc'));
const baggage = provideBaggage('network - ibc');
const zone = makeDurableZone(baggage);
const { when } = prepareWhenableModule(zone);
const powers = prepareWhenableModule(zone);
const { when } = powers;

const makeDurablePublishKit = prepareDurablePublishKit(
baggage,
Expand Down Expand Up @@ -116,7 +116,7 @@ Far('ibcListener', {}),
t.assert(!ev1.done);
t.deepEqual(ev1.value, ['bindPort', { packet: { source_port: 'port-1' } }]);

const makePlusOne = preparePlusOneConnectionHandler(zone);
const makePlusOne = preparePlusOneConnectionHandler(zone, powers);
const makeIBCListener = prepareIBCListener(zone, makePlusOne);

const testEcho = async () => {
Expand Down

0 comments on commit 3194369

Please sign in to comment.