diff --git a/packages/boot/test/bootstrapTests/test-wallet-upgrade.js b/packages/boot/test/bootstrapTests/test-wallet-upgrade.js index 6254b3a8e6e1..768958d56178 100644 --- a/packages/boot/test/bootstrapTests/test-wallet-upgrade.js +++ b/packages/boot/test/bootstrapTests/test-wallet-upgrade.js @@ -1,10 +1,10 @@ // @ts-check import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; -import { E } from '@endo/far'; import { eventLoopIteration } from '@agoric/notifier/tools/testSupports.js'; import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js'; import { makeWalletFactoryDriver } from '../../tools/drivers'; import { makeSwingsetTestKit } from '../../tools/supports'; +import { sendInvitationScript, upgradeZoeScript } from './wallet-scripts.js'; const { Fail } = assert; @@ -52,58 +52,6 @@ const makeTestContext = async t => { test.before(async t => (t.context = await makeTestContext(t))); -const upgradeZoeScript = () => { - /** - * @param {VatAdminSvc} vatAdminSvc - * @param {any} adminNode - * @param {string} bundleCapName - * @param {unknown} vatParameters - */ - const upgradeVat = async ( - vatAdminSvc, - adminNode, - bundleCapName, - vatParameters = {}, - ) => { - const bcap = await E(vatAdminSvc).getNamedBundleCap(bundleCapName); - const options = { vatParameters }; - const incarnationNumber = await E(adminNode).upgrade(bcap, options); - console.log('upgraded', bundleCapName, 'to', incarnationNumber); - }; - - const upgradeZoe = async powers => { - const { vatStore, vatAdminSvc } = powers.consume; - const { adminNode } = await E(vatStore).get('zoe'); - console.log('zoe admin node', adminNode); - await upgradeVat(vatAdminSvc, adminNode, 'zoe'); - }; - return upgradeZoe; -}; - -const sendInvitationScript = () => { - const addr = 'agoric1oracle-operator'; - const sendIt = async powers => { - // namesByAddress is broken #8113 - const { - consume: { namesByAddressAdmin, zoe }, - instance: { - consume: { reserve }, - }, - } = powers; - const pf = E(zoe).getPublicFacet(reserve); - const anInvitation = await E(pf).makeAddCollateralInvitation(); - await E(namesByAddressAdmin).reserve(addr); - // don't trigger the namesByAddressAdmin.readonly() bug - const addressAdmin = E(namesByAddressAdmin).lookupAdmin(addr); - await E(addressAdmin).reserve('depositFacet'); - const addressHub = E(addressAdmin).readonly(); - const addressDepositFacet = E(addressHub).lookup('depositFacet'); - await E(addressDepositFacet).receive(anInvitation); - }; - - return sendIt; -}; - test('update purse balance across upgrade', async t => { const oraAddr = 'agoric1oracle-operator'; const { walletFactoryDriver, agoricNamesRemotes } = t.context; diff --git a/packages/boot/test/bootstrapTests/wallet-scripts.js b/packages/boot/test/bootstrapTests/wallet-scripts.js new file mode 100644 index 000000000000..9b9f9e43617a --- /dev/null +++ b/packages/boot/test/bootstrapTests/wallet-scripts.js @@ -0,0 +1,55 @@ +// @ts-check + +import { E } from '@endo/far'; + +export const upgradeZoeScript = () => { + /** + * @param {VatAdminSvc} vatAdminSvc + * @param {any} adminNode + * @param {string} bundleCapName + * @param {unknown} vatParameters + */ + const upgradeVat = async ( + vatAdminSvc, + adminNode, + bundleCapName, + vatParameters = {}, + ) => { + const bcap = await E(vatAdminSvc).getNamedBundleCap(bundleCapName); + const options = { vatParameters }; + const incarnationNumber = await E(adminNode).upgrade(bcap, options); + console.log('upgraded', bundleCapName, 'to', incarnationNumber); + }; + + const upgradeZoe = async powers => { + const { vatStore, vatAdminSvc } = powers.consume; + const { adminNode } = await E(vatStore).get('zoe'); + console.log('zoe admin node', adminNode); + await upgradeVat(vatAdminSvc, adminNode, 'zoe'); + }; + return upgradeZoe; +}; + +export const sendInvitationScript = () => { + const addr = 'agoric1oracle-operator'; + const sendIt = async powers => { + // namesByAddress is broken #8113 + const { + consume: { namesByAddressAdmin, zoe }, + instance: { + consume: { reserve }, + }, + } = powers; + const pf = E(zoe).getPublicFacet(reserve); + const anInvitation = await E(pf).makeAddCollateralInvitation(); + await E(namesByAddressAdmin).reserve(addr); + // don't trigger the namesByAddressAdmin.readonly() bug + const addressAdmin = E(namesByAddressAdmin).lookupAdmin(addr); + await E(addressAdmin).reserve('depositFacet'); + const addressHub = E(addressAdmin).readonly(); + const addressDepositFacet = E(addressHub).lookup('depositFacet'); + await E(addressDepositFacet).receive(anInvitation); + }; + + return sendIt; +};