Skip to content

Commit

Permalink
refactor(test-sell): use mockBootstrapPowers, produceBoardAuxManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Mar 6, 2024
1 parent af17f09 commit 38f7062
Showing 1 changed file with 18 additions and 71 deletions.
89 changes: 18 additions & 71 deletions contract/test/test-sell-concert-tickets-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {
makeTerms,
} from '../src/sell-concert-tickets-proposal.js';
import { bagPrice } from '../src/sell-concert-tickets.contract.js';
import { getBundleId } from '../tools/bundle-tools.js';
import { mockBootstrapPowers } from './boot-tools.js';
import { produceEndoModules } from '../src/platform-goals/marshal-produce.js';
import { produceBoardAuxManager } from '../src/platform-goals/boardAux.js';

/** @typedef {typeof import('../src/sell-concert-tickets.contract.js').start} AssetContractFn */

Expand Down Expand Up @@ -218,82 +222,25 @@ test('Trade in IST rather than play money', async t => {
});

test('use the code that will go on chain to start the contract', async t => {
const noop = harden(() => {});

// Starting the contract consumes an installation
// and produces an instance, brand, and issuer.
// We coordinate these with promises.
const makeProducer = () => ({ ...makePromiseKit(), reset: noop });
const sync = {
installation: makeProducer(),
instance: makeProducer(),
brand: makeProducer(),
issuer: makeProducer(),
};

/**
* Chain bootstrap makes a number of powers available
* to code approved by BLD staker governance.
*
* Here we simulate the ones needed for starting this contract.
*/
const mockBootstrap = async () => {
const board = { getId: noop };
const chainStorage = Far('chainStorage', {
makeChildNode: async () => chainStorage,
setValue: async () => {},
});

const { zoe } = t.context;
const startUpgradable = async ({
installation,
issuerKeywordRecord,
label,
terms,
}) =>
E(zoe).startInstance(installation, issuerKeywordRecord, terms, {}, label);
const feeIssuer = await E(zoe).getFeeIssuer();
const feeBrand = await E(feeIssuer).getBrand();

const pFor = x => Promise.resolve(x);
const powers = {
consume: { zoe, chainStorage, startUpgradable, board },
brand: {
consume: { IST: pFor(feeBrand) },
produce: { Ticket: sync.brand },
},
issuer: {
consume: { IST: pFor(feeIssuer) },
produce: { Ticket: sync.issuer },
},
installation: {
consume: { sellConcertTickets: sync.installation.promise },
},
instance: { produce: { sellConcertTickets: sync.instance } },
};

/** @type {BootstrapPowers} */
// @ts-expect-error mock
const typedPowers = powers;

return typedPowers;
};

const powers = await mockBootstrap();

// Code to install the contract is automatically
// generated by `agoric run`. No need to test that part.
const { zoe, bundle } = t.context;
const installation = E(zoe).install(bundle);
sync.installation.resolve(installation);
const { bundle } = t.context;
const bundleID = getBundleId(bundle);
const { powers, vatAdminState } = await mockBootstrapPowers(t.log);
const { feeMintAccess, zoe } = powers.consume;

// When the BLD staker governance proposal passes,
// the startup function gets called.
await startSellConcertTicketsContract(powers);
const instance = await sync.instance.promise;
vatAdminState.installBundle(bundleID, bundle);
await Promise.all([
produceEndoModules(powers),
produceBoardAuxManager(powers),
startSellConcertTicketsContract(powers, {
options: { sellConcertTickets: { bundleID } },
}),
]);
const instance = await powers.instance.consume.sellConcertTickets;

// Now that we have the instance, resume testing as above.
const { feeMintAccess, bundleCache } = t.context;
const { bundleCache } = t.context;
const { faucet } = makeStableFaucet({ bundleCache, feeMintAccess, zoe });
await alice(t, zoe, instance, await faucet(5n * UNIT6));
});

0 comments on commit 38f7062

Please sign in to comment.