Skip to content

Commit

Permalink
test: factor out stringified functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Dec 1, 2023
1 parent e8e415f commit d0cdca3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 53 deletions.
54 changes: 1 addition & 53 deletions packages/boot/test/bootstrapTests/test-wallet-upgrade.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand Down
55 changes: 55 additions & 0 deletions packages/boot/test/bootstrapTests/wallet-scripts.js
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit d0cdca3

Please sign in to comment.