Skip to content

Commit

Permalink
Merge pull request #7391 from Agoric/mfig-looser-tests
Browse files Browse the repository at this point in the history
fix: minor cleanups in preparation for Endo upgrade
  • Loading branch information
mergify[bot] authored Apr 14, 2023
2 parents 5d158b2 + 66a6817 commit aed398a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
27 changes: 23 additions & 4 deletions packages/inter-protocol/test/smartWallet/contexts.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
import { BridgeId, deeplyFulfilledObject } from '@agoric/internal';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
// eslint-disable-next-line no-unused-vars -- used by TS
import { coalesceUpdates } from '@agoric/smart-wallet/src/utils.js';
import { unsafeMakeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js';
import { E } from '@endo/far';
import path from 'path';
import { createPriceFeed } from '../../src/proposals/price-feed-proposal.js';
import { withAmountUtils } from '../supports.js';

// referenced by TS
coalesceUpdates;

const bundlesToCache = harden({
psm: './src/psm/psm.js',
econCommitteeCharter: './src/econCommitteeCharter.js',
});

export const importBootTestUtils = async (log, bundleCache) => {
// Preload the cache entries needed by boot-test-utils.js.
await Promise.all(
Object.entries(bundlesToCache).map(async ([name, entrypoint]) =>
bundleCache.validateOrAdd(entrypoint, name),
),
);
return import('@agoric/vats/tools/boot-test-utils.js');
};

/**
* @param {import('ava').ExecutionContext} t
* @param {(logger) => Promise<ChainBootstrapSpace>} makeSpace
* @param {(logger, cache) => Promise<ChainBootstrapSpace>} makeSpace
*/
export const makeDefaultTestContext = async (t, makeSpace) => {
// To debug, pass t.log instead of null logger
const log = () => null;
const { consume, produce } = await makeSpace(log);

const bundleCache = await unsafeMakeBundleCache('bundles/');

const { consume, produce } = await makeSpace(log, bundleCache);
const { agoricNames, zoe } = consume;

//#region Installs
const pathname = new URL(import.meta.url).pathname;
const dirname = path.dirname(pathname);

const bundleCache = await unsafeMakeBundleCache('bundles/');
const bundle = await bundleCache.load(
`${dirname}/../../../smart-wallet/src/walletFactory.js`,
'walletFactory',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { NonNullish } from '@agoric/assert';
import { coalesceUpdates } from '@agoric/smart-wallet/src/utils.js';
import { buildRootObject } from '@agoric/vats/src/core/boot-psm.js';
import '@agoric/vats/src/core/types.js';
import {
mockDProxy,
mockPsmBootstrapArgs,
} from '@agoric/vats/tools/boot-test-utils.js';
import { eventLoopIteration } from '@agoric/zoe/tools/eventLoopIteration.js';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { E } from '@endo/far';
Expand All @@ -18,6 +14,7 @@ import { ensureOracleBrands } from '../../src/proposals/price-feed-proposal.js';
import { headValue } from '../supports.js';
import {
currentPurseBalance,
importBootTestUtils,
makeDefaultTestContext,
voteForOpenQuestion,
} from './contexts.js';
Expand All @@ -31,7 +28,12 @@ const test = anyTest;

const committeeAddress = 'econCommitteeMemberA';

const makeTestSpace = async log => {
const makeTestSpace = async (log, bundleCache) => {
const { mockDProxy, mockPsmBootstrapArgs } = await importBootTestUtils(
log,
bundleCache,
);

const psmParams = {
anchorAssets: [{ denom: 'ibc/toyusdc', keyword: 'AUSD' }],
economicCommitteeAddresses: {
Expand Down
11 changes: 6 additions & 5 deletions packages/inter-protocol/test/smartWallet/test-psm-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { AmountMath, makeIssuerKit } from '@agoric/ertp';
import { buildRootObject as buildPSMRootObject } from '@agoric/vats/src/core/boot-psm.js';
import '@agoric/vats/src/core/types.js';
import { Stable } from '@agoric/vats/src/tokens.js';
import {
mockDProxy,
mockPsmBootstrapArgs,
} from '@agoric/vats/tools/boot-test-utils.js';
import { eventLoopIteration } from '@agoric/zoe/tools/eventLoopIteration.js';
import { E } from '@endo/far';
import { NonNullish } from '@agoric/assert';
Expand All @@ -16,6 +12,7 @@ import { coalesceUpdates } from '@agoric/smart-wallet/src/utils.js';
import { INVITATION_MAKERS_DESC } from '../../src/econCommitteeCharter.js';
import {
currentPurseBalance,
importBootTestUtils,
makeDefaultTestContext,
voteForOpenQuestion,
} from './contexts.js';
Expand All @@ -30,7 +27,11 @@ const test = anyTest;

const committeeAddress = 'psmTestAddress';

const makePsmTestSpace = async log => {
const makePsmTestSpace = async (log, bundleCache) => {
const { mockDProxy, mockPsmBootstrapArgs } = await importBootTestUtils(
log,
bundleCache,
);
const psmParams = {
anchorAssets: [{ denom: 'ibc/toyusdc', keyword: 'AUSD' }],
economicCommitteeAddresses: { aMember: committeeAddress },
Expand Down
6 changes: 3 additions & 3 deletions packages/solo/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { E, makeCapTP } from '@endo/captp';
import { Far } from '@endo/marshal';

export const getCapTPHandler = (send, getLocalBootstrap, fallback) => {
let lastEpoch;
let lastEpoch = 0;
const chans = new Map();
const doFallback = async (method, ...args) => {
if (!fallback) {
return harden({});
return false;
}
return E(fallback)[method](...args);
};
Expand Down Expand Up @@ -74,7 +74,7 @@ export const getCapTPHandler = (send, getLocalBootstrap, fallback) => {
}
const done = await doFallback('onMessage', obj, meta);
if (!done) {
console.error(`Could not find handler ${obj.type}`, meta);
console.error(`Could not find handler ${obj.type}`, obj, meta);
}
return done;
},
Expand Down
7 changes: 4 additions & 3 deletions packages/solo/src/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ export async function makeHTTPListener(
try {
obj = JSON.parse(message);
const res = await inboundCommand(obj, meta, id);
if (typeof res === 'boolean') {
return;
}

// eslint-disable-next-line no-use-before-define
sendJSON({ ...res, meta });
Expand All @@ -371,9 +374,7 @@ export async function makeHTTPListener(
wss.on('connection', newChannel);

function sendJSON(rawObj) {
const { meta: { channelID } = {} } = rawObj;
const obj = { ...rawObj };
delete obj.meta;
const { meta: { channelID } = {}, ...obj } = rawObj;

// Point-to-point.
const c = channels.get(channelID);
Expand Down
2 changes: 0 additions & 2 deletions packages/vats/src/core/types.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @ts-check

/** @typedef { import('@endo/eventual-send').EProxy } EProxy */

/**
* This type conflicts with packages/SwingSet/src/vats/plugin-manager.js
*
Expand Down
1 change: 0 additions & 1 deletion packages/zoe/src/contracts/mintAndSellNFT.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const start = zcf => {
const sellItemsTerms = harden({
pricePerItem,
});
// FIXME EProxy types, startInstance is any
const instanceRecordP = E(zoeService).startInstance(
sellItemsInstallation,
issuerKeywordRecord,
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/zoeService/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Callable } from '@agoric/eventual-send';
import type { Callable } from '@agoric/internal/src/utils.js';

import type { IssuerKeywordRecord, Payment } from './types.js';

Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/test/unitTests/contracts/test-automaticRefund.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ test('multiple instances of automaticRefund for the same Zoe', async t => {
});

test('zoe - alice tries to complete after completion has already occurred', async t => {
t.plan(5);
t.plan(6);
// Setup zoe and mints
const { moolaKit, simoleanKit, moola, simoleans, zoe, vatAdminState } =
setup();
Expand Down Expand Up @@ -350,10 +350,10 @@ test('zoe - alice tries to complete after completion has already occurred', asyn
alicePayments,
);

await E(aliceSeat).getOfferResult();
t.is(await E(aliceSeat).getOfferResult(), 'The offer was accepted');

await t.throwsAsync(() => E(aliceSeat).tryExit(), {
message: /seat has already exited/,
message: /seat has (already|been) exited/,
});

const moolaPayout = await aliceSeat.getPayout('ContributionA');
Expand Down

0 comments on commit aed398a

Please sign in to comment.