From 680a9a0bf19ebcd928075903e8ab711299a5ff96 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Thu, 7 Mar 2024 17:31:47 -0600 Subject: [PATCH] test(test-vote-fee-change): start governed; change Fee --- contract/test/test-vote-fee-change.js | 109 ++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 contract/test/test-vote-fee-change.js diff --git a/contract/test/test-vote-fee-change.js b/contract/test/test-vote-fee-change.js new file mode 100644 index 00000000..c87c69a1 --- /dev/null +++ b/contract/test/test-vote-fee-change.js @@ -0,0 +1,109 @@ +// @ts-check +import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; +import { createRequire } from 'node:module'; +import { E, Far } from '@endo/far'; + +import { extractPowers } from '@agoric/vats/src/core/utils.js'; +import { AmountMath } from '@agoric/ertp/src/amountMath.js'; +import { mockBootstrapPowers } from './boot-tools.js'; +import { + installContract, + permit, + startContract, +} from '../src/swaparoo.proposal.js'; +import { makeBundleCacheContext } from '../tools/bundle-tools.js'; +import { installPuppetGovernance } from './lib-gov-test/puppet-gov.js'; +import { NonNullish } from '../src/objectTools.js'; + +/** @typedef {import('./wallet-tools.js').MockWallet} MockWallet */ + +/** @type {import('ava').TestFn>>} */ +const test = anyTest; + +const nodeRequire = createRequire(import.meta.url); + +const contractName = 'swaparoo'; +const assets = { + [contractName]: nodeRequire.resolve(`../src/${contractName}.contract.js`), + invitationMakerContract: nodeRequire.resolve( + '@agoric/zoe/src/contracts/automaticRefund.js', + ), +}; + +const makeTestContext = async t => { + const bc = await makeBundleCacheContext(t); + t.log('bootstrap'); + const { powers, vatAdminState } = await mockBootstrapPowers(t.log); + return { ...bc, powers, vatAdminState }; +}; + +test.before(async t => (t.context = await makeTestContext(t))); + +// a source of arbitrary invitations +const mockElectorate = async (zoe, bundleCache) => { + const installation = await E(zoe).install( + await bundleCache.load(assets.invitationMakerContract), + ); + const arbInstance = await E(zoe).startInstance(installation); + const committeeCreatorFacet = Far('Electorate CF', { + getPoserInvitation: async () => E(arbInstance.publicFacet).makeInvitation(), + }); + return { creatorFacet: committeeCreatorFacet }; +}; + +test.serial('start governed swap contract', async t => { + const { bundleCache, powers, vatAdminState } = t.context; + const { zoe } = powers.consume; + await installPuppetGovernance(zoe, powers.installation.produce, bundleCache); + + powers.produce[`${contractName}CommitteeKit`].resolve( + mockElectorate(zoe, bundleCache), + ); + + const bundle = await bundleCache.load(assets.swaparoo, contractName); + const bundleID = `b1-${bundle.endoZipBase64Sha512}`; + t.log('publish bundle', bundleID.slice(0, 8)); + vatAdminState.installBundle(bundleID, bundle); + + t.log('install contract'); + const config = { options: { [contractName]: { bundleID } } }; + await installContract(powers, config); + t.log('start contract'); + const permittedPowers = extractPowers(permit, powers); + await startContract(permittedPowers); + + const instance = await powers.instance.consume[contractName]; + t.log(instance); + t.is(typeof instance, 'object'); + + const puppetGovernors = { + [contractName]: E.get(powers.consume[`${contractName}Kit`]) + .governorCreatorFacet, + }; + + Object.assign(t.context.shared, { powers, puppetGovernors }); +}); + +test.serial('vote to change swap fee', async t => { + const { powers, shared } = t.context; + const { puppetGovernors } = shared; + const { zoe } = powers.consume; + + const istBrand = await powers.brand.consume.IST; + const CENT = 1_000_000n / 100n; + const targetFee = AmountMath.make(istBrand, 50n * CENT); + + const instance = await powers.instance.consume[contractName]; + const swapPub = E(zoe).getPublicFacet(instance); + + const changes = { Fee: targetFee }; + t.log('changeParams', changes); + const swapGov = NonNullish(puppetGovernors[contractName]); + await E(swapGov).changeParams(harden({ changes })); + const x = await E(swapPub).getAmount('Fee'); + t.deepEqual(x, targetFee); +}); + +test.todo('wallet-based voting'); +test.todo('swap after changing fee'); +test.todo('e2e swap after changing fee with voters');