Skip to content

Commit

Permalink
fix: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iomekam committed Apr 22, 2024
1 parent f93cd66 commit fbab6d3
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
7 changes: 4 additions & 3 deletions packages/boot/test/bootstrapTests/ibcClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { V as E } from '@agoric/vat-data/vow.js';
/**
* @param {ZCF} zcf
* @param {{
* address: string,
* networkVat: ERef<ReturnType<typeof import('@agoric/vats/src/vat-network').buildRootObject>>;
* }} privateArgs
* @param {import("@agoric/vat-data").Baggage} _baggage
*/
export const start = async (zcf, privateArgs, _baggage) => {
const { address, networkVat } = privateArgs;
const myPort = await E(networkVat).bindPort(address);
const { networkVat } = privateArgs;

const portAllocator = await E(networkVat).getPortAllocator();
const myPort = E(portAllocator).allocateIBCPort();

const { log } = console;
let connP;
Expand Down
5 changes: 3 additions & 2 deletions packages/boot/test/bootstrapTests/ibcServerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ const { log } = console;
* @param {import("@agoric/vat-data").Baggage} _baggage
*/
export const start = async (zcf, privateArgs, _baggage) => {
const { address, networkVat } = privateArgs;
const { networkVat } = privateArgs;

const boundPort = await E(networkVat).bindPort(address);
const portAllocator = await E(networkVat).getPortAllocator();
const boundPort = E(portAllocator).allocateIBCPort();

/** @type {Array<[label: string, resolve: (value: any) => void, reject: (reason: any) => void]>} */
const queue = [];
Expand Down
4 changes: 2 additions & 2 deletions packages/boot/test/bootstrapTests/test-net-ibc-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ test.serial('upgrade at many points in network API flow', async t => {
installation.ibcServerMock,
{},
{},
{ address: '/ibc-port/', networkVat },
{ networkVat },
);
t.truthy(started.creatorFacet, `${label} ibcServerMock`);
return [label, { server: started.creatorFacet }];
Expand All @@ -140,7 +140,7 @@ test.serial('upgrade at many points in network API flow', async t => {
installation.ibcClientMock,
{},
{},
{ address: '/ibc-port/', networkVat },
{ networkVat },
);
t.truthy(started.creatorFacet, `${label} ibcClientMock`);
return [label, { ...opts, client: started.creatorFacet }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const makeMock = log =>

network: Far('network', {
registerProtocolHandler: noop,
bindPort: () => harden({ addListener: noop }),
}),
},
});
Expand Down
5 changes: 5 additions & 0 deletions packages/network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,11 @@ export const preparePortAllocator = (zone, { watch }) => {
),
);
},
allocateIBCPegasusPort() {
const { state } = this;
// Allocate an IBC port with a unique generated name.
return watch(E(state.protocol).bindPort(`/ibc-port/pegasus`));
},
},
);

Expand Down
7 changes: 2 additions & 5 deletions packages/orchestration/src/orchestration.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,8 @@ const prepareOrchestration = (zone, createChainAccount) =>
self: {
async bindPort() {
const network = getPower(this.state.powers, 'network');
const port = await E(network).bindPort(
`/ibc-port/icacontroller-${this.state.icaControllerNonce}`,
);
this.state.icaControllerNonce += 1;
return port;
const portAllocator = await E(network).getPortAllocator();
return E(portAllocator).allocateICAControllerPort();
},
},
public: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ export const setupOrchestrationVat = async (
await networkVat;
/** @type {AttenuatedNetwork} */
const network = Far('Attenuated Network', {
/** @param {string} localAddr */
async bindPort(localAddr) {
return E(networkVat).bindPort(localAddr);
async getPortAllocator() {
return E(networkVat).getPortAllocator();
},
});

Expand Down
20 changes: 10 additions & 10 deletions packages/vats/src/proposals/network-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const registerNetworkProtocols = async (vats, dibcBridgeManager) => {
*
* @param {BootstrapPowers & {
* consume: { loadCriticalVat: VatLoader<any> };
* produce: { networkVat: Producer<any> };
* produce: { portAllocator: Producer<any> };
* }} powers
* @param {object} options
* @param {{ networkRef: VatSourceRef; ibcRef: VatSourceRef }} options.options
Expand All @@ -100,7 +100,7 @@ export const setupNetworkProtocols = async (
provisioning,
vatUpgradeInfo: vatUpgradeInfoP,
},
produce: { networkVat, vatUpgradeInfo: produceVatUpgradeInfo },
produce: { portAllocator, vatUpgradeInfo: produceVatUpgradeInfo },
},
options,
) => {
Expand All @@ -121,9 +121,11 @@ export const setupNetworkProtocols = async (
info.init('ibc', ibcRef);
info.init('network', networkRef);

networkVat.reset();
networkVat.resolve(vats.network);
const portAllocator = E(vats.network).getPortAllocator();
const allocator = E(vats.network).getPortAllocator();

portAllocator.reset();
portAllocator.resolve(allocator);

const bridgeManager = await bridgeManagerP;
const dibcBridgeManager =
bridgeManager && E(bridgeManager).register(BRIDGE_ID.DIBC);
Expand All @@ -136,10 +138,10 @@ export const setupNetworkProtocols = async (
const ibcportP = [];
for (let i = 0; i < NUM_IBC_PORTS_PER_CLIENT; i += 1) {
if (i === NUM_IBC_PORTS_PER_CLIENT - 1) {
const portP = when(E(portAllocator).allocateICAControllerPort());
const portP = when(E(allocator).allocateICAControllerPort());
ibcportP.push(portP);
} else {
const portP = when(E(portAllocator).allocateIBCPort());
const portP = when(E(allocator).allocateIBCPort());
ibcportP.push(portP);
}
}
Expand All @@ -152,7 +154,7 @@ export const setupNetworkProtocols = async (
await registerNetworkProtocols(vats, dibcBridgeManager);

// Add an echo listener on our ibc-port network (whether real or virtual).
const echoPort = await when(E(vats.network).bindPort('/ibc-port/echo'));
const echoPort = await when(E(allocator).allocateICAControllerPort());
const { listener } = await E(vats.network).makeEchoConnectionKit();
await when(E(echoPort).addListener(listener));
return E(client).assignBundle([_a => ({ ibcport: makePorts() })]);
Expand All @@ -168,10 +170,8 @@ export const getManifestForNetwork = (_powers, { networkRef, ibcRef }) => ({
zoe: 'zoe',
provisioning: 'provisioning',
vatUpgradeInfo: true,
portAllocator: 'portAllocator',
},
produce: {
networkVat: 'network',
vatUpgradeInfo: true,
},
zone: true,
Expand Down
2 changes: 0 additions & 2 deletions packages/vats/src/vat-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export function buildRootObject(_vatPowers, _args, baggage) {
/** @param {Parameters<typeof protocol.unregisterProtocolHandler>} args */
unregisterProtocolHandler: (...args) =>
protocol.unregisterProtocolHandler(...args),
/** @param {Parameters<typeof protocol.bindPort>} args */
bindPort: (...args) => protocol.bindPort(...args),
getPortAllocator() {
return portAllocator;
},
Expand Down

0 comments on commit fbab6d3

Please sign in to comment.