From 9d066c05a44411c5b6802405f587e9a219fc302b Mon Sep 17 00:00:00 2001 From: anilhelvaci Date: Thu, 21 Nov 2024 14:27:13 +0300 Subject: [PATCH] chore(bootstrap-exports): WIP, override `provisionBridgeManager` Refs: #10425 --- .../proposals/p:upgrade-19/.gitignore | 1 + .../proposals/p:upgrade-19/package.json | 3 ++- .../p:upgrade-19/provisioning.test.js | 15 +++++++++++++- packages/vats/src/lib-provisioning.js | 20 ++++++++++++------- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/a3p-integration/proposals/p:upgrade-19/.gitignore b/a3p-integration/proposals/p:upgrade-19/.gitignore index 8c6dbb7f6af..3e632bfe226 100644 --- a/a3p-integration/proposals/p:upgrade-19/.gitignore +++ b/a3p-integration/proposals/p:upgrade-19/.gitignore @@ -1 +1,2 @@ replaceFeeDistributor/ +replaceProvisioningHandler/ diff --git a/a3p-integration/proposals/p:upgrade-19/package.json b/a3p-integration/proposals/p:upgrade-19/package.json index 2afd33dfb4b..5c51a86269c 100644 --- a/a3p-integration/proposals/p:upgrade-19/package.json +++ b/a3p-integration/proposals/p:upgrade-19/package.json @@ -2,7 +2,8 @@ "agoricProposal": { "type": "/agoric.swingset.CoreEvalProposal", "sdk-generate": [ - "testing/replace-feeDistributor-short.js replaceFeeDistributor" + "testing/replace-feeDistributor-short.js replaceFeeDistributor", + "vats/replace-provisioningHandler.js replaceProvisioningHandler" ] }, "type": "module", diff --git a/a3p-integration/proposals/p:upgrade-19/provisioning.test.js b/a3p-integration/proposals/p:upgrade-19/provisioning.test.js index cde8275cb45..ccc82a797d2 100644 --- a/a3p-integration/proposals/p:upgrade-19/provisioning.test.js +++ b/a3p-integration/proposals/p:upgrade-19/provisioning.test.js @@ -11,18 +11,21 @@ import { VALIDATORADDR, CHAINID, GOV1ADDR, + evalBundles, } from '@agoric/synthetic-chain'; import { retryUntilCondition, makeVstorageKit, waitUntilAccountFunded, + sleep, } from '@agoric/client-utils'; import { execFileSync } from 'child_process'; +const CORE_EVAL_DIR = 'replaceProvisioningHandler'; + const agd = makeAgd({ execFileSync }).withOpts({ keyringBackend: 'test' }); /** - * * @param {string} addr * @param {string} wanted * @param {string} [from] @@ -78,6 +81,16 @@ test.before(async t => { }; }); +test.serial.only('replace provisioningHandler', async t => { + await evalBundles(CORE_EVAL_DIR); + // Since the replaceProvisioningHandler does not signal anything to vstorage + // we have no way of knowing if the core eval executed successfully other than + // observing it from the logs. So we just wait for 30 seconds here to make + // sure there's enough time to evaluate the core eval. + await sleep(30000, { log: console.log, setTimeout }); + t.pass(); +}); + test.serial('provision manually', async t => { // @ts-expect-error casting const { vstorageKit } = t.context; diff --git a/packages/vats/src/lib-provisioning.js b/packages/vats/src/lib-provisioning.js index 9455afbe88e..8da63148521 100644 --- a/packages/vats/src/lib-provisioning.js +++ b/packages/vats/src/lib-provisioning.js @@ -1,17 +1,23 @@ -import { prepareExoClass } from '@agoric/vat-data'; import { Fail } from '@endo/errors'; import { E } from '@endo/far'; -import { BridgeHandlerI } from './bridge.js'; +import { getInterfaceGuardPayload } from '@endo/patterns'; +import { M } from '@agoric/store'; import { PowerFlags } from './walletFlags.js'; +import { makeDurableZone } from '@agoric/zone/durable.js'; +import { BridgeHandlerI } from './bridge.js'; + +const BridgeHandlerAdjustedI = M.interface('BridgeHandlerTest', { + ...getInterfaceGuardPayload(BridgeHandlerI).methodGuards +}); /** * @param {import('@agoric/store').MapStore} baggage */ export const prepareProvisionBridgeHandler = baggage => { - const makeProvisionBridgeHandler = prepareExoClass( - baggage, - 'provisioningHandler', - BridgeHandlerI, + const zone = makeDurableZone(baggage); + const makeProvisionBridgeHandler = zone.exoClass( + 'provisioningHandlerDurable', + BridgeHandlerAdjustedI, (provisioning, provisionWalletBridgeManager) => ({ provisioning, provisionWalletBridgeManager, @@ -19,7 +25,7 @@ export const prepareProvisionBridgeHandler = baggage => { { async fromBridge(obj) { const { provisionWalletBridgeManager, provisioning } = this.state; - switch (obj.type) { + switch (obj && obj.type) { case 'PLEASE_PROVISION': { const { nickname, address, powerFlags: rawPowerFlags } = obj; const powerFlags = rawPowerFlags || [];