From 700da69efc2e590164a53dfc71bf10b636280d83 Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Mon, 24 Jun 2024 18:51:41 -0400 Subject: [PATCH] feat(runUtils): EV detects vow and unwraps (WIP) Co-authored-by: Dan Connolly --- .../test/bootstrapTests/vat-orchestration.test.ts | 10 ++++++---- packages/vats/src/core/lib-boot.js | 11 +++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/boot/test/bootstrapTests/vat-orchestration.test.ts b/packages/boot/test/bootstrapTests/vat-orchestration.test.ts index 2974233d474..d2e80928b9e 100644 --- a/packages/boot/test/bootstrapTests/vat-orchestration.test.ts +++ b/packages/boot/test/bootstrapTests/vat-orchestration.test.ts @@ -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)), { @@ -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)), { @@ -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' }, ]), { diff --git a/packages/vats/src/core/lib-boot.js b/packages/vats/src/core/lib-boot.js index 8e3ec089065..85d1e2c5105 100644 --- a/packages/vats/src/core/lib-boot.js +++ b/packages/vats/src/core/lib-boot.js @@ -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, @@ -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(); @@ -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; },