From 51bbee4b1ca6ba4bd46b9cf9997f7f3266fe6c99 Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Tue, 2 Apr 2024 12:51:21 -0400 Subject: [PATCH] fixup! fixup! test(orchestration): boostrap test for vat-orchestration (WIP) --- .../bootstrapTests/test-vat-orchestration.ts | 90 +++++-------------- packages/boot/tools/supports.ts | 22 +++-- 2 files changed, 35 insertions(+), 77 deletions(-) diff --git a/packages/boot/test/bootstrapTests/test-vat-orchestration.ts b/packages/boot/test/bootstrapTests/test-vat-orchestration.ts index b89c545e502a..7a8787f14c94 100644 --- a/packages/boot/test/bootstrapTests/test-vat-orchestration.ts +++ b/packages/boot/test/bootstrapTests/test-vat-orchestration.ts @@ -1,5 +1,6 @@ import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import type { ExecutionContext, TestFn } from 'ava'; +import { M, matches } from '@endo/patterns'; import { createRequire } from 'module'; // import { BridgeId } from '@agoric/internal'; import type { start as stakeAtomStart } from '@agoric/orchestration/src/contracts/stakeAtom.contract.js'; @@ -8,36 +9,20 @@ import { makeWalletFactoryContext } from './walletFactory.ts'; const { assign, entries } = Object; -const nodeRequire = createRequire(import.meta.url); -const assets = { - ibcServerMock: nodeRequire.resolve('./ibcServerMock.js'), - ibcClientMock: nodeRequire.resolve('./ibcClientMock.js'), -}; - -const makeTestContext = async (t: ExecutionContext) => { - // const { bridgeHandler } = makeBridge(t); - return makeWalletFactoryContext(t, { - // [BridgeId.DIBC]: obj => bridgeHandler.toBridge(obj), - }); -}; +const makeTestContext = async (t: ExecutionContext) => + makeWalletFactoryContext(t); type DefaultTestContext = Awaited>; -type StakeAtomPublicFacet = Awaited< - ReturnType ->['publicFacet']; - const test: TestFn = anyTest; test.before(async t => (t.context = await makeTestContext(t))); test.after.always(t => t.context.shutdown?.()); -test('provideAccount returns an ICA connection', async t => { +test('createAccount returns an ICA connection', async t => { const { buildProposal, - bundleCache, evalProposal, runUtils: { EV }, - installations, } = t.context; /** ensure network, ibc, and orchestration are available */ await evalProposal( @@ -51,59 +36,28 @@ test('provideAccount returns an ICA connection', async t => { t.true(await EV(vatStore).has('network'), 'network'); t.true(await EV(vatStore).has('orchestration'), 'orchestration'); - /** ensure mock ibc services are available */ - const zoe: ZoeService = await EV.vat('bootstrap').consumeItem('zoe'); - for (const [name, path] of entries(assets)) { - const bundle = await bundleCache.load(path, name); - const installationRef = await EV(zoe).install(bundle); - t.truthy(installationRef); - assign(t.context.installations, { [name]: installationRef }); - } - const networkVat = await EV.vat('bootstrap').consumeItem('networkVat'); - const ibcServerMock = await EV(zoe).startInstance( - installations.ibcServerMock, - {}, - {}, - { - address: '/ibc-port/icahost', - networkVat, - }, - ); - t.truthy(ibcServerMock.creatorFacet, 'ibcServerMock started'); - await EV.sendOnly(ibcServerMock.creatorFacet).listen(); // request listening - await EV.sendOnly(ibcServerMock.creatorFacet).dequeue('onListen'); // start listening - - // const ibcClientMock = await EV(zoe).startInstance( - // installations.ibcClientMock, - // {}, - // {}, - // { address: '/ibc-port/', networkVat }, - // ); - // t.truthy(ibcClientMock.creatorFacet, 'ibcClientMock started'); - // get local addresses for testing - const serverLocalAddr = await EV( - ibcServerMock.creatorFacet, - ).getLocalAddress(); - t.truthy(serverLocalAddr, 'serverLocalAddr'); - // const clientLocalAddr = await EV( - // ibcClientMock.creatorFacet, - // ).getLocalAddress(); - // t.truthy(clientLocalAddr, 'clientLocalAddr'); - const orchestration = await EV.vat('bootstrap').consumeItem('orchestration'); - const account = EV(orchestration).provideAccount( + const account = await EV(orchestration).createAccount( 'connection-0', 'connection-0', ); - // await t.notThrowsAsync(async () => { - // await EV.sendOnly(ibcServerMock.creatorFacet).dequeue('onAccept'); - // }); - // await t.notThrowsAsync(async () => { - // await EV.sendOnly(ibcServerMock.creatorFacet).dequeue('onOpen'); - // }); - // XXX FIXME - await t.throwsAsync(async () => { - await account; + t.truthy(account, 'createAccount returns an account'); + t.truthy( + matches(account, M.remotable('ChainAccount')), + 'account is a remotable', + ); + const [remoteAddress, localAddress, accountAddress] = await Promise.all([ + EV(account).getRemoteAddress(), + EV(account).getLocalAddress(), + EV(account).getAccountAddress(), + ]); + t.truthy(remoteAddress.includes('icahost'), 'remoteAddress is returned'); + t.truthy(localAddress.includes('icacontroller'), 'localAddress is returned'); + t.truthy(accountAddress.includes('osmo1'), 'accountAddress is returned'); + t.log('ICA Account Addresses', { + remoteAddress, + localAddress, + accountAddress, }); }); diff --git a/packages/boot/tools/supports.ts b/packages/boot/tools/supports.ts index b073ecfd6c49..f4f9be2db875 100644 --- a/packages/boot/tools/supports.ts +++ b/packages/boot/tools/supports.ts @@ -289,6 +289,7 @@ export const makeSwingsetTestKit = async ( const outboundMessages = new Map(); + let inbound; /** * Mock the bridge outbound handler. The real one is implemented in Golang so * changes there will sometimes require changes here. @@ -357,15 +358,12 @@ export const makeSwingsetTestKit = async ( } case BridgeId.CORE: case BridgeId.DIBC: - // console.log('@@@DIBC bridgeOutbound', obj); switch (obj.type) { case 'IBC_METHOD': switch (obj.method) { - // IBC Connection Creation - // XXX How can we mock this? Do we need to? // ICA Channel Creation case 'startChannelOpenInit': - return harden({ + inbound(BridgeId.DIBC, { type: 'IBC_EVENT', blockHeight: 99, blockTime: 1711571357, @@ -376,12 +374,14 @@ export const makeSwingsetTestKit = async ( port_id: obj.packet.destination_port, channel_id: 'channel-1', }, - counterpartyVersion: obj.version, + counterpartyVersion: + '{"version":"ics27-1","controllerConnectionId":"connection-0","hostConnectionId":"connection-0","address":"osmo1234","encoding":"proto3","txType":"sdk_multi_msg"}', connectionHops: obj.hops, }); - // ICA Send Packet - case 'acknowledgementPacket': - return harden({ + return undefined; + // ICA Send Packet (Transaction) + case 'sendPacket': + inbound(BridgeId.DIBC, { acknowledgement: 'eyJyZXN1bHQiOiJFaTBLS3k5amIzTnRiM011YzNSaGEybHVaeTUyTVdKbGRHRXhMazF6WjBSbGJHVm5ZWFJsVW1WemNHOXVjMlU9In0=', blockHeight: 1126, @@ -400,6 +400,7 @@ export const makeSwingsetTestKit = async ( relayer: 'agoric1gtkg0g6x8lqc734ht3qe2sdkrfugpdp2h7fuu0', type: 'IBC_EVENT', }); + return undefined; default: return undefined; } @@ -440,7 +441,7 @@ export const makeSwingsetTestKit = async ( }, }); } - const { controller, timer } = await buildSwingset( + const { controller, timer, bridgeInbound } = await buildSwingset( new Map(), bridgeOutbound, kernelStorage, @@ -456,6 +457,8 @@ export const makeSwingsetTestKit = async ( debugVats, }, ); + inbound = bridgeInbound; + console.timeLog('makeBaseSwingsetTestKit', 'buildSwingset'); const runUtils = makeRunUtils(controller); @@ -541,6 +544,7 @@ export const makeSwingsetTestKit = async ( advanceTimeBy, advanceTimeTo, buildProposal, + bridgeInbound, controller, evalProposal, getCrankNumber,