Skip to content

Commit

Permalink
test(test-vote-fee-change): start governed; change Fee
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Mar 8, 2024
1 parent acda19e commit 680a9a0
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions contract/test/test-vote-fee-change.js
Original file line number Diff line number Diff line change
@@ -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<Awaited<ReturnType<makeTestContext>>>} */
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');

0 comments on commit 680a9a0

Please sign in to comment.