Skip to content

Commit f525630

Browse files
committed
test(orca-contract): fix cosmosInterchainService mock interface (WIP)
1 parent 3a1d0a9 commit f525630

File tree

1 file changed

+46
-113
lines changed

1 file changed

+46
-113
lines changed

contract/test/orca-contract.test.js

Lines changed: 46 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { test as anyTest } from './prepare-test-env-ava.js';
55

66
import { createRequire } from 'module';
77
import { E, Far } from '@endo/far';
8-
// import { makeCopyBag } from '@endo/patterns';
98
import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
109
import { AmountMath, makeIssuerKit } from '@agoric/ertp';
1110
import { registerChain } from '@agoric/orchestration/src/chain-info.js';
@@ -15,6 +14,7 @@ import { startOrcaContract } from '../src/orca.proposal.js';
1514
import { makeMockTools, mockBootstrapPowers } from './boot-tools.js';
1615
import { startOrchCoreEval } from '../tools/startOrch.js';
1716
import { getBundleId } from '../tools/bundle-tools.js';
17+
import { Fail } from '@endo/errors';
1818

1919
/** @typedef {typeof import('../src/orca.contract.js').start} OrcaContractFn */
2020

@@ -115,75 +115,38 @@ const makeTestContext = async t => {
115115
const bundleCache = await makeNodeBundleCache('bundles/', {}, s => import(s));
116116
const bundle = await bundleCache.load(contractPath, 'orca');
117117

118-
const { powers } = await mockBootstrapPowers(t.log);
119-
// await publishChainInfo(powers.consume.agoricNamesAdmin);
118+
const { powers, vowTools: vt } = await mockBootstrapPowers(t.log);
119+
await publishChainInfo(powers.consume.agoricNamesAdmin);
120120
const tools = await makeMockTools(t, bundleCache);
121121

122-
const cosmosInterchainService = Far('DummyCosmosInterchainService', {
123-
getChainHub: async () => {
124-
const chainHub = {
125-
registerChain: async (name, details) => {
126-
console.log(`chain registered: ${name}`, details);
122+
const sent = [];
123+
const cosmosInterchainService = Far('MockCosmosInterchainService', {
124+
makeAccount(chainId, hostConnectionId, controllerConnectionId, opts) {
125+
return Far('IcaAccount', {
126+
getAddress: () =>
127+
harden({
128+
chainId,
129+
value: `agoric123`,
130+
encoding: 'bech32', // or 'ethereum', based on your requirements
131+
}),
132+
getLocalAddress: () => '/ibc-port/LOCAL',
133+
getRemoteAddress: () => '/ibc-port/REMOTE',
134+
getPort: () => Fail`not implemented`,
135+
executeTx: () => Fail`not implemented`,
136+
executeEncodedTx: (msgs, opts) => {
137+
sent.push({ msgs, opts });
138+
return vt.asVow(() => Fail`TODO`);
127139
},
128-
getChain: async name => {
129-
if (
130-
name === 'agoric' ||
131-
name === 'osmosis' ||
132-
name === 'agoriclocal' ||
133-
name === 'osmosislocal'
134-
) {
135-
const state = harden({
136-
name,
137-
chainId: `${name}local`,
138-
denom: name === 'agoric' ? 'ubld' : 'uosmo',
139-
expectedAddressPrefix: name === 'agoric' ? 'agoric' : 'osmo',
140-
details: `${name} chain details`,
141-
stakingTokens: [{ denom: name === 'agoric' ? 'ubld' : 'uosmo' }],
142-
});
143-
144-
return harden({
145-
...state,
146-
makeAccount: () =>
147-
Far('Account', {
148-
getChainId: () => state.chainId,
149-
getAccountAddress: () => `${state.name}AccountAddress`,
150-
getAddress: () =>
151-
harden({
152-
chainId: state.chainId,
153-
value: `${state.name}AccountAddress`,
154-
encoding: 'bech32', // or 'ethereum', based on your requirements
155-
}),
156-
getBalance: () => `1000${state.denom}`,
157-
}),
158-
getChainInfo: () =>
159-
Far('ChainInfo', {
160-
getChainId: () => state.chainId,
161-
getDenom: () => state.denom,
162-
getExpectedAddressPrefix: () => state.expectedAddressPrefix,
163-
}),
164-
});
165-
}
166-
throw Error(`chain not found: ${name}`);
167-
},
168-
};
169-
return chainHub;
170-
},
171-
makeAccount: async name => {
172-
const chainHub = await E(cosmosInterchainService).getChainHub();
173-
const chain = await E(chainHub).getChain(name);
174-
return E(chain).makeAccount();
175-
},
176-
getChainInfo: async name => {
177-
const chainHub = await E(cosmosInterchainService).getChainHub();
178-
const chain = await E(chainHub).getChain(name);
179-
return E(chain).getChainInfo();
140+
});
180141
},
142+
provideICQConnection: () => Fail`not implemented`,
181143
});
182144

183145
return {
184146
bundle,
185147
bundleCache,
186148
powers,
149+
vowTools: vt,
187150
cosmosInterchainService,
188151
...tools,
189152
};
@@ -295,17 +258,6 @@ const chainConfigs = {
295258
},
296259
};
297260

298-
test('Verify chain registration', async t => {
299-
const { cosmosInterchainService } = t.context;
300-
const chainHub = await E(cosmosInterchainService).getChainHub();
301-
302-
const agoricChain = await E(chainHub).getChain('agoric');
303-
t.truthy(agoricChain, 'Agoric chain should be registered');
304-
305-
const osmosisChain = await E(chainHub).getChain('osmosis');
306-
t.truthy(osmosisChain, 'Osmosis chain should be registered');
307-
});
308-
309261
const queryVstorage = async (t, qt, wallet, offerId) => {
310262
t.log(`querying vstorage for wallet: ${wallet}, offerId: ${offerId}`);
311263
const currentWalletRecord = await qt.queryData(
@@ -331,26 +283,25 @@ const orchestrationAccountScenario = test.macro({
331283
`orchestrate - ${chainName} makeAccount returns a ContinuingOfferResult`,
332284
exec: async (t, chainName) => {
333285
const config = chainConfigs[chainName];
334-
if (!config) {
335-
return t.fail(`unknown chain: ${chainName}`);
336-
}
286+
assert(config);
337287

338-
const { bundle, cosmosInterchainService, powers } = t.context;
288+
const { bundle, cosmosInterchainService, powers, vowTools: vt } = t.context;
339289
const { agoricNames, board, chainStorage, zoe } = powers.consume;
340290
t.log('installing the contract...');
341291
const installation = E(zoe).install(bundle);
342292

293+
await null;
343294
const privateArgs = harden({
344295
cosmosInterchainService,
345-
orchestrationService: cosmosInterchainService,
346-
storageNode: chainStorage,
347-
marshaller: E(board).getPublishingMarshaller(),
296+
orchestrationService: await cosmosInterchainService,
297+
storageNode: await chainStorage,
298+
marshaller: await E(board).getPublishingMarshaller(),
348299
timerService: Far('DummyTimer'),
349300
localchain: Far('DummyLocalchain'),
350-
agoricNames,
301+
agoricNames: await agoricNames,
351302
});
352303

353-
t.log('starting the instance...');
304+
t.log('starting the instance...', privateArgs);
354305
const { instance } = await E(zoe).startInstance(
355306
installation,
356307
{},
@@ -360,36 +311,24 @@ const orchestrationAccountScenario = test.macro({
360311
t.log('instance started:', instance);
361312
t.truthy(instance);
362313

363-
t.log('getting public facet...');
364314
const publicFacet = await E(zoe).getPublicFacet(instance);
365-
t.log('public facet obtained:', publicFacet);
366-
367-
t.log('creating account invitation...');
368315
const initialInvitation = await E(publicFacet).makeAccountInvitation();
369-
t.log('invitation created:', initialInvitation);
370-
371-
const makeAccountOffer = {
372-
give: {},
373-
want: {},
374-
exit: { onDemand: null },
375-
};
376316

377317
t.log('making offer...');
378318
const offerId = 'offerId';
379319
const initialUserSeat = await E(zoe).offer(
380320
initialInvitation,
381-
makeAccountOffer,
321+
{},
382322
undefined,
383-
{ id: offerId },
323+
{ chainName },
384324
);
385325
t.log('initial user seat:', initialUserSeat);
386326

387327
t.log('getting offer result...');
388-
const offerResult = await E(initialUserSeat).getOfferResult();
328+
const offerResult = await vt.when(E(initialUserSeat).getOfferResult());
389329
t.log('offer result:', offerResult);
390330
t.truthy(offerResult, 'Offer result should exist');
391331

392-
const { makeQueryTool } = t.context;
393332
const qt = makeQueryToolMock();
394333
const wallet = 'test-wallet';
395334
// log vstorage state before querying
@@ -410,22 +349,15 @@ const orchestrationAccountScenario = test.macro({
410349
);
411350
t.log('current wallet record', currentWalletRecord);
412351

413-
const continuingInvitation = await E(publicFacet).makeAccountInvitation();
414-
t.truthy(continuingInvitation, 'continuing invitation should be created');
352+
const toClose = await E(offerResult.invitationMakers).Undelegate([]);
353+
t.truthy(toClose, 'continuing invitation should be created');
415354

416-
const continuingOffer = {
417-
give: {},
418-
want: {},
419-
exit: { onDemand: null },
420-
};
421-
422-
const continuingUserSeat = await E(zoe).offer(
423-
continuingInvitation,
424-
continuingOffer,
425-
undefined,
426-
{ previousOffer: offerId },
355+
const continuingUserSeat = await E(zoe).offer(toClose, {}, undefined, {
356+
chainName,
357+
});
358+
const continuingOfferResult = await vt.when(
359+
E(continuingUserSeat).getOfferResult(),
427360
);
428-
const continuingOfferResult = await E(continuingUserSeat).getOfferResult();
429361

430362
t.truthy(continuingOfferResult, 'continuing offer should produce a result');
431363
t.log('continuing offer result', continuingOfferResult);
@@ -446,15 +378,16 @@ const orchestrationAccountAndFundScenario = test.macro({
446378
t.log('installing the contract...');
447379
const installation = E(zoe).install(bundle);
448380

381+
await null;
449382
const privateArgs = harden({
450383
cosmosInterchainService,
451-
orchestrationService: cosmosInterchainService,
452-
storageNode: chainStorage,
453-
marshaller: E(board).getPublishingMarshaller(),
384+
orchestrationService: await cosmosInterchainService,
385+
storageNode: await chainStorage,
386+
marshaller: await E(board).getPublishingMarshaller(),
454387
timer: Far('DummyTimer'),
455388
timerService: Far('DummyTimer'),
456389
localchain: Far('DummyLocalchain'),
457-
agoricNames,
390+
agoricNames: await agoricNames,
458391
});
459392

460393
const { mint, issuer, brand } = makeIssuerKit('BLD');

0 commit comments

Comments
 (0)