Skip to content

Commit

Permalink
feat(runUtils): EV detects vow and unwraps (WIP)
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Connolly <connolly@agoric.com>
  • Loading branch information
0xpatrickdev and dckc committed Jun 24, 2024
1 parent 7f5f1af commit 700da69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions packages/boot/test/bootstrapTests/vat-orchestration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ test('Query connection can send a query', async t => {
const queryConnection =
await EV(orchestration).provideICQConnection('connection-0');

const unwrappedQc: ICQConnection = await EV.whenVow(queryConnection);
const [result] = await EV(unwrappedQc).query([balanceQuery]);
const [result] = await EV(queryConnection).query([balanceQuery]);
t.is(result.code, 0);
t.is(result.height, '0'); // bigint
t.deepEqual(QueryBalanceResponse.decode(decodeBase64(result.key)), {
Expand All @@ -236,7 +235,10 @@ test('Query connection can send a query', async t => {
},
});

const results = await EV(unwrappedQc).query([balanceQuery, balanceQuery]);
const results = await EV(queryConnection).query([
balanceQuery,
balanceQuery,
]);
t.is(results.length, 2);
for (const { key } of results) {
t.deepEqual(QueryBalanceResponse.decode(decodeBase64(key)), {
Expand All @@ -248,7 +250,7 @@ test('Query connection can send a query', async t => {
}

await t.throwsAsync(
EV(unwrappedQc).query([
EV(queryConnection).query([
{ ...balanceQuery, path: '/cosmos.bank.v1beta1.QueryBalanceRequest' },
]),
{
Expand Down
11 changes: 9 additions & 2 deletions packages/vats/src/core/lib-boot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { E, Far } from '@endo/far';
import { makeHeapZone } from '@agoric/zone';
import { prepareVowTools } from '@agoric/vow/vat.js';
import { isVow } from '@agoric/vow/src/vow-utils.js';
import {
makeVatSpace,
makeWellKnownSpaces,
Expand Down Expand Up @@ -169,6 +170,12 @@ export const makeBootstrap = (
}
};

const unwrapIfVow = async specimenP => {
const specimen = await specimenP;
if (isVow(specimen)) return vowTools.when(specimen);
return specimen;
};

// For testing supports
const vatData = new Map();

Expand Down Expand Up @@ -207,9 +214,9 @@ export const makeBootstrap = (

//#region testing supports
awaitVatObject: async (presence, path = []) => {
let value = await presence;
let value = await unwrapIfVow(presence);
for (const key of path) {
value = await value[key];
value = await unwrapIfVow(value[key]);
}
return value;
},
Expand Down

0 comments on commit 700da69

Please sign in to comment.