Skip to content

Commit

Permalink
refactor: test-gimix clean lint
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Nov 15, 2023
1 parent fc47827 commit d4c0dad
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 54 deletions.
4 changes: 3 additions & 1 deletion packages/zoe/src/contracts/gimix/gimix.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
provideDurableMapStore,
} from '@agoric/vat-data';
import { AmountMath, AmountShape } from '@agoric/ertp';
import { OfferHandlerI } from '../../typeGuards';
import { OfferHandlerI } from '../../typeGuards.js';
import {
DeliverProposalShape,
JobReportProposalShape,
Expand All @@ -29,6 +29,8 @@ const { details: X, Fail, quote: q } = assert;

/**
* @param {ZCF<GiMiXTerms>} zcf
* @param {unknown} _privateArgs
* @param {import('@agoric/vat-data').Baggage} baggage
*/
export const prepare = async (zcf, _privateArgs, baggage) => {
const { namesByAddress } = zcf.getTerms();
Expand Down
99 changes: 46 additions & 53 deletions packages/zoe/test/unitTests/contracts/gimix/test-gimix.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
// eslint-disable-next-line import/order
import { test as anyTest } from '../../../../tools/prepare-test-env-ava.js';

import url from 'url';
import { unsafeMakeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';
import urlModule from 'url';
import { E, Far } from '@endo/far';
import { AmountMath } from '@agoric/ertp/src/amountMath.js';
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { makeCopyBag } from '@endo/patterns';
import { makePromiseKit } from '@endo/promise-kit';

import { unsafeMakeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js';
import { AmountMath } from '@agoric/ertp/src/amountMath.js';
// import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { makeNameHubKit } from '@agoric/vats';
import buildManualTimer from '../../../../tools/manualTimer.js';
import centralSupplyBundle from '@agoric/vats/bundles/bundle-centralSupply.js';
import { TimeMath } from '@agoric/time';

import { mintStablePayment } from './mintStable.js';
import { makePromiseKit } from '@endo/promise-kit';
import { TimeMath } from '@agoric/time';
import { makeZoeKitForTest } from '../../../../tools/setup-zoe.js';
import buildManualTimer from '../../../../tools/manualTimer.js';

const DAY = 24 * 60 * 60 * 1000;
const UNIT6 = 1_000_000n;
Expand All @@ -31,7 +32,7 @@ const NonNullish = x => {
/** @type {import('ava').TestFn<Awaited<ReturnType<makeTestContext>>>} */
const test = anyTest;

const asset = ref => url.fileURLToPath(new URL(ref, import.meta.url));
const asset = ref => urlModule.fileURLToPath(new URL(ref, import.meta.url));

const makeTestContext = async t => {
const bundleCache = await unsafeMakeBundleCache('bundles/');
Expand Down Expand Up @@ -126,6 +127,7 @@ test.before(async t => (t.context = await makeTestContext(t)));
* status?: 'merged'
* }} PRStatus
*/

const makeGitHub = log => {
/** @type {Map<string, IssueStatus | PRStatus>} */
const status = new Map();
Expand All @@ -145,27 +147,27 @@ const makeGitHub = log => {
*/
openIssue: ({ owner, repo }) => {
const num = status.size + 1;
const url = `https://github.com/${owner}/${repo}/issues/${num}`;
const issueURL = `https://github.com/${owner}/${repo}/issues/${num}`;
const pk = makePromiseKit();
status.set(url, { ...pk, type: 'issue', num, status: 'open' });
return url;
status.set(issueURL, { ...pk, type: 'issue', num, status: 'open' });
return issueURL;
},
assignIssue: (url, name) => {
const st = NonNullish(status.get(url));
assignIssue: (issueURL, name) => {
const st = NonNullish(status.get(issueURL));
assert(st.type === 'issue');
status.set(url, { ...st, assignee: name });
status.set(issueURL, { ...st, assignee: name });
},
/** @param {string} url */
getIssuePromise: url => {
const st = NonNullish(status.get(url));
/** @param {string} issueURL */
getIssuePromise: issueURL => {
const st = NonNullish(status.get(issueURL));
assert(st.type === 'issue');
return st.promise;
},
/** @param {string} url */
closeIssue: url => {
const st = NonNullish(status.get(url));
/** @param {string} issueURL */
closeIssue: issueURL => {
const st = NonNullish(status.get(issueURL));
assert(st.type === 'issue');
status.set(url, { ...st, status: 'closed' });
status.set(issueURL, { ...st, status: 'closed' });
// log('closed', url);
},

Expand All @@ -178,23 +180,23 @@ const makeGitHub = log => {
*/
openPR: ({ owner, repo, author, fixes }) => {
const num = status.size + 1;
const url = `https://github.com/${owner}/${repo}/pull/${num}`;
const prURL = `https://github.com/${owner}/${repo}/pull/${num}`;
const pk = makePromiseKit();
status.set(url, { type: 'pull', num, author, fixes });
notifyIssue(fixes, url);
return url;
status.set(prURL, { type: 'pull', num, author, fixes });
notifyIssue(fixes, prURL);
return prURL;
},
/** @param {string} url */
mergePR: url => {
const st = NonNullish(status.get(url));
/** @param {string} prURL */
mergePR: prURL => {
const st = NonNullish(status.get(prURL));
assert(st.type === 'pull');
status.set(url, { ...st, status: 'merged' });
status.set(prURL, { ...st, status: 'merged' });
const { fixes } = st;
self.closeIssue(fixes);
},
/** @param {string} url */
queryPR: url => {
const pull = NonNullish(status.get(url));
/** @param {string} prURL */
queryPR: prURL => {
const pull = NonNullish(status.get(prURL));
assert(pull.type === 'pull');
const issue = NonNullish(status.get(pull.fixes));
assert(issue.type === 'issue');
Expand All @@ -206,20 +208,16 @@ const makeGitHub = log => {
};

test('execute work agreement', async t => {
const { faucet, powers, bundle } = t.context;
const { zoe, namesByAddressAdmin, chainTimerService, namesByAddress } =
powers;

/**
* @param {Promise<DepositFacet>} oracleDepositP
* @param {PromiseKit<unknown>} oracleInvitedPK
*/
const coreEval = async (oracleDepositP, oracleInvitedPK) => {
const { powers, bundle } = t.context;
const {
agoricNames,
board,
chainTimerService,
namesByAddress,
namesByAddressAdmin,
zoe,
} = powers;
const { agoricNames, board } = powers;

// const id = await E(board).getId(chainTimerService);
board.set('board123', chainTimerService);
Expand Down Expand Up @@ -273,6 +271,9 @@ test('execute work agreement', async t => {
* @param {ERef<GitHub>} gitHub
* @param {SmartWallet} wallet
* @param {PromiseKit<{jobID: string, issue: string}>} assignIssuePK
* @param {bigint} dur
* @param {string} timerBoardId
* @param {bigint} bounty
*/
const alice = async (
gitHub,
Expand All @@ -284,7 +285,6 @@ test('execute work agreement', async t => {
) => {
const { make } = AmountMath;
const { brand: wkBrand, instance, issuer: wkIssuer } = agoricNames;
const { timerBrand } = wkBrand;
const timer = board.get(timerBoardId);

const gpf = await E(zoe).getPublicFacet(instance.gimix);
Expand Down Expand Up @@ -347,8 +347,6 @@ test('execute work agreement', async t => {
};

/**
* @param {import('@agoric/vats').NameAdmin} namesByAddressAdmin
* @param {ERef<ZoeService>} zoe
* @typedef {string} Address
*
* @typedef {{
Expand All @@ -362,7 +360,7 @@ test('execute work agreement', async t => {
* }
* }} SmartWallet
*/
const makeWalletFactory = (namesByAddressAdmin, zoe) => {
const makeWalletFactory = () => {
/** @type {Map<Address, SmartWallet>} */
const wallets = new Map();
const { entries } = Object;
Expand Down Expand Up @@ -407,7 +405,6 @@ test('execute work agreement', async t => {
* @param {unknown} [offerArgs]
*/
executeOffer: async (invitation, proposal, offerArgs) => {
const { entries } = Object;
/** @type {Record<string, Payment>} */
const payments = {};
for await (const [kw, amt] of entries(proposal.give || {})) {
Expand Down Expand Up @@ -576,14 +573,10 @@ test('execute work agreement', async t => {
t.deepEqual(amts, want);
};

const { rootNode, data } = makeFakeStorageKit('X');
// const { _rootNode, _data } = makeFakeStorageKit('X');

const gitHub = Promise.resolve(makeGitHub(t.log));
const {
faucet,
powers: { zoe, namesByAddressAdmin },
} = t.context;
const wf = makeWalletFactory(namesByAddressAdmin, zoe);
const wf = makeWalletFactory();

const wallet = {
alice: wf.provideWallet('agoric1alice'),
Expand Down

0 comments on commit d4c0dad

Please sign in to comment.