diff --git a/contract/test/test-launchIt.js b/contract/test/test-launchIt.js index 3768836..1687dd5 100644 --- a/contract/test/test-launchIt.js +++ b/contract/test/test-launchIt.js @@ -7,17 +7,18 @@ import { makeBundleCacheContext, bootAndInstallBundles, getBundleId, + makeBootstrapPowers, } from './boot-tools.js'; import { mockWalletFactory } from './wallet-tools.js'; import { makeNameHubKit } from '@agoric/vats'; import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; -import { AmountMath } from '@agoric/ertp/src/amountMath.js'; +import { AmountMath, AssetKind } from '@agoric/ertp/src/amountMath.js'; import { makeIssuerKit } from '@agoric/ertp'; -import { startLaunchIt, contractName } from '../src/start-launchIt.js'; -import { creatorCathy } from './market-actors.js'; +import { creatorCathy, starterSam } from './market-actors.js'; const nodeRequire = createRequire(import.meta.url); +const contractName = 'launchIt'; const bundleRoots = { [contractName]: nodeRequire.resolve('../src/launchIt.js'), }; @@ -27,17 +28,67 @@ const test = anyTest; test.before(async t => (t.context = await makeBundleCacheContext(t))); +const makeWalletFactory = async (powers, issuers) => { + const { zoe, namesByAddressAdmin, chainStorage } = powers.consume; + + const invitationIssuer = await E(zoe).getInvitationIssuer(); + const walletFactory = mockWalletFactory( + { zoe, namesByAddressAdmin, chainStorage }, + { Invitation: invitationIssuer, ...issuers }, + ); + return walletFactory; +}; + +test.serial('boot walletFactory', async t => { + const { powers, boardAux } = await makeBootstrapPowers(t.log); + const walletFactory = await makeWalletFactory(powers, {}); + Object.assign(t.context.shared, { powers, walletFactory, boardAux }); // XXX untyped +}); + test.serial('start contract', async t => { - const { powers, bundles } = await bootAndInstallBundles(t, bundleRoots); + const { bundleCache, shared } = t.context; + const { powers, boardAux } = shared; + const bundle = await bundleCache.load( + bundleRoots[contractName], + contractName, + ); + const bundleID = getBundleId(bundle); const MNY = makeIssuerKit('MNY'); - const bundleID = getBundleId(bundles[contractName]); - await startLaunchIt(powers, { - options: { [contractName]: { bundleID, issuers: { MNY: MNY.issuer } } }, + const { walletFactory } = t.context.shared; + + const brand = { + Invitation: await powers.brand.consume.Invitation, + }; + /** + * @type {import('./market-actors').WellKnown & + * import('./market-actors').WellKnownKinds & + * import('./market-actors').BoardAux} + */ + const wellKnown = { + installation: powers.installation.consume, + instance: powers.instance.consume, + issuer: powers.issuer.consume, + brand: powers.brand.consume, + assetKind: new Map( + /** @type {[Brand, AssetKind][]} */ ([[brand.Invitation, AssetKind.SET]]), + ), + boardAux, + }; + const sam = starterSam( + t, + { + wallet: await walletFactory.makeSmartWallet('agoric1sam'), + }, + wellKnown, + ); + + const { instance } = await E(sam).installAndStart({ + bundleID, + issuers: { MNY: MNY.issuer }, }); - const instance = await powers.instance.consume[contractName]; t.is(typeof instance, 'object'); Object.assign(t.context.shared, { powers, MNY }); @@ -78,15 +129,6 @@ test.serial('launch a token', async t => { brand: powers.brand.consume, }; - const { zoe } = powers.consume; - - const { nameAdmin: namesByAddressAdmin } = await makeNameHubKit(); - const { rootNode: chainStorage, data } = makeFakeStorageKit('published'); - const invitationIssuer = await E(zoe).getInvitationIssuer(); - const walletFactory = mockWalletFactory( - { zoe, namesByAddressAdmin, chainStorage }, - { Invitation: invitationIssuer }, - ); assert(await wellKnown.brand.timer, 'no timer brand???'); await creatorCathy( t,