Skip to content

Commit

Permalink
fixup! fixup! test(orchestration): boostrap test for vat-orchestratio…
Browse files Browse the repository at this point in the history
…n (WIP)
  • Loading branch information
0xpatrickdev committed Apr 2, 2024
1 parent 752d603 commit 51bbee4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 77 deletions.
90 changes: 22 additions & 68 deletions packages/boot/test/bootstrapTests/test-vat-orchestration.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<ReturnType<typeof makeTestContext>>;
type StakeAtomPublicFacet = Awaited<
ReturnType<typeof stakeAtomStart>
>['publicFacet'];

const test: TestFn<DefaultTestContext> = 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(
Expand All @@ -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,
});
});
22 changes: 13 additions & 9 deletions packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -400,6 +400,7 @@ export const makeSwingsetTestKit = async (
relayer: 'agoric1gtkg0g6x8lqc734ht3qe2sdkrfugpdp2h7fuu0',
type: 'IBC_EVENT',
});
return undefined;
default:
return undefined;
}
Expand Down Expand Up @@ -440,7 +441,7 @@ export const makeSwingsetTestKit = async (
},
});
}
const { controller, timer } = await buildSwingset(
const { controller, timer, bridgeInbound } = await buildSwingset(
new Map(),
bridgeOutbound,
kernelStorage,
Expand All @@ -456,6 +457,8 @@ export const makeSwingsetTestKit = async (
debugVats,
},
);
inbound = bridgeInbound;

console.timeLog('makeBaseSwingsetTestKit', 'buildSwingset');

const runUtils = makeRunUtils(controller);
Expand Down Expand Up @@ -541,6 +544,7 @@ export const makeSwingsetTestKit = async (
advanceTimeBy,
advanceTimeTo,
buildProposal,
bridgeInbound,
controller,
evalProposal,
getCrankNumber,
Expand Down

0 comments on commit 51bbee4

Please sign in to comment.