Skip to content

Commit

Permalink
WIP: refactor test-launchIt to use starterSam
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jan 14, 2024
1 parent a9cd5f9 commit 67332ee
Showing 1 changed file with 59 additions and 17 deletions.
76 changes: 59 additions & 17 deletions contract/test/test-launchIt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
};
Expand All @@ -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 });
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 67332ee

Please sign in to comment.