Skip to content

Commit

Permalink
fix: orchestrate() returns Vow
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 12, 2024
1 parent d7948c7 commit 8388f36
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
8 changes: 2 additions & 6 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export const makeOrchestrationFacade = ({

const { prepareEndowment, asyncFlow, adminAsyncFlow } = asyncFlowTools;

const { when } = vowTools;

/**
* @template RT - return type
* @template HC - host context
Expand All @@ -66,7 +64,7 @@ export const makeOrchestrationFacade = ({
* guestCtx: GuestInterface<HC>,
* ...args: GA
* ) => Promise<RT>} guestFn
* @returns {(...args: HostArgs<GA>) => Promise<RT>}
* @returns {(...args: HostArgs<GA>) => Vow<RT>}
*/
const orchestrate = (durableName, hostCtx, guestFn) => {
const subZone = zone.subZone(durableName);
Expand All @@ -81,10 +79,8 @@ export const makeOrchestrationFacade = ({
const hostFn = asyncFlow(subZone, 'asyncFlow', guestFn);

const orcFn = (...args) =>
// TODO remove the `when` after fixing the return type
// to `Vow<HostReturn>`
// @ts-expect-error cast
when(hostFn(wrappedOrc, wrappedCtx, ...args));
hostFn(wrappedOrc, wrappedCtx, ...args);

// @ts-expect-error cast
return harden(orcFn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ const orchestrationAccountScenario = test.macro({
return t.fail(`Unknown chain: ${chainName}`);
}

const { zoe, instance } = t.context;
const {
bootstrap: { vowTools: vt },
zoe,
instance,
} = t.context;
const publicFacet = await E(zoe).getPublicFacet(instance);
const inv = E(publicFacet).makeOrchAccountInvitation();
const userSeat = E(zoe).offer(inv, {}, undefined, { chainName });
const { invitationMakers, publicSubscribers } =
await E(userSeat).getOfferResult();
const { invitationMakers, publicSubscribers } = await vt.when(
E(userSeat).getOfferResult(),
);

t.regex(getInterfaceOf(invitationMakers)!, /invitationMakers/);

Expand Down
7 changes: 4 additions & 3 deletions packages/orchestration/test/examples/sendAnywhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ test('send using arbitrary chain info', async t => {
brands: { ist },
utils: { inspectLocalBridge, pourPayment },
} = await commonSetup(t);
const vt = bootstrap.vowTools;

const { zoe, bundleAndInstall } = await setUpZoeForTest();

Expand Down Expand Up @@ -121,7 +122,7 @@ test('send using arbitrary chain info', async t => {
{ Send },
{ destAddr: 'hot1destAddr', chainName },
);
await E(userSeat).getOfferResult();
await vt.when(E(userSeat).getOfferResult());

const history = inspectLocalBridge();
t.like(history, [
Expand Down Expand Up @@ -154,7 +155,7 @@ test('send using arbitrary chain info', async t => {
{ Send },
{ destAddr: 'cosmos1destAddr', chainName: 'cosmoshub' },
);
await E(userSeat).getOfferResult();
await vt.when(E(userSeat).getOfferResult());
const history = inspectLocalBridge();
const { messages, address: execAddr } = history.at(-1);
t.is(messages.length, 1);
Expand Down Expand Up @@ -200,7 +201,7 @@ test('send using arbitrary chain info', async t => {
{ Send },
{ destAddr: 'hot1destAddr', chainName: 'hot' },
);
await E(userSeat).getOfferResult();
await vt.when(E(userSeat).getOfferResult());
const history = inspectLocalBridge();
const { messages, address: execAddr } = history.at(-1);
t.is(messages.length, 1);
Expand Down
3 changes: 2 additions & 1 deletion packages/orchestration/test/examples/swapExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ test.skip('start', async t => {
} as const,
},
);
const result = await E(userSeat).getOfferResult();
const vt = bootstrap.vowTools;
const result = await vt.when(E(userSeat).getOfferResult());
t.is(result, undefined);

// bank purse now has the 10 IST
Expand Down
3 changes: 2 additions & 1 deletion packages/orchestration/test/examples/unbondExample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type StartFn =

test('start', async t => {
const {
bootstrap: { vowTools: vt },
brands: { ist },
commonPrivateArgs,
} = await commonSetup(t);
Expand Down Expand Up @@ -47,7 +48,7 @@ test('start', async t => {
{},
{ validator: 'agoric1valopsfufu' },
);
const result = await E(userSeat).getOfferResult();
const result = await vt.when(E(userSeat).getOfferResult());
t.is(result, undefined);

const tree = inspectMapStore(contractBaggage);
Expand Down
4 changes: 2 additions & 2 deletions packages/orchestration/test/facade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test.serial('chain info', async t => {
return orc.getChain('mock');
});

const result = (await handle()) as Chain<any>;
const result = (await vt.when(handle())) as Chain<any>;
t.deepEqual(await vt.when(result.getChainInfo()), mockChainInfo);
});

Expand Down Expand Up @@ -122,7 +122,7 @@ test.serial('faulty chain info', async t => {
return account;
});

await t.throwsAsync(handle(), {
await t.throwsAsync(vt.when(handle()), {
message: 'chain info lacks staking denom',
});
});
Expand Down

0 comments on commit 8388f36

Please sign in to comment.