Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e testing: use CapData between vats (WIP) #33

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@agoric/eslint-config": "dev",
"@agoric/smart-wallet": "0.5.4-u14.0",
"@agoric/store": "0.9.3-u14.0",
"@agoric/xsnap": "0.14.3-u14.0",
"@agoric/zone": "0.2.3-u14.0",
"@endo/eslint-plugin": "^0.5.2",
"@endo/nat": "^4.1.27",
Expand Down
7 changes: 5 additions & 2 deletions contract/src/postal-service.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

const { keys, values } = Object;

/** @type {import('./@types/zoe-contract-facet').ContractMeta} */
/** @import { ContractMeta } from './@types/zoe-contract-facet'; */

Check warning on line 8 in contract/src/postal-service.contract.js

View workflow job for this annotation

GitHub Actions / unit

Invalid JSDoc tag name "import"
/** @import { NameHub } from '@agoric/vats'; */

Check warning on line 9 in contract/src/postal-service.contract.js

View workflow job for this annotation

GitHub Actions / unit

Invalid JSDoc tag name "import"

/** @type {ContractMeta} */
export const meta = harden({
customTermsShape: { namesByAddress: M.remotable('namesByAddress') },
});
Expand All @@ -14,7 +17,7 @@

/**
* @typedef {object} PostalSvcTerms
* @property {import('@agoric/vats').NameHub} namesByAddress
* @property {NameHub} namesByAddress
*/

/** @param {ZCF<PostalSvcTerms>} zcf */
Expand Down
12 changes: 9 additions & 3 deletions contract/src/swaparoo.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

import { M, matches, mustMatch } from '@endo/patterns';
import { E, Far } from '@endo/far';
import '@agoric/zoe/exported.js';
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
import '@agoric/zoe/src/contracts/exported.js';
import { AmountShape } from '@agoric/ertp/src/typeGuards.js';
import {
InstanceHandleShape,
Expand All @@ -18,13 +16,21 @@
import { makeCollectFeesInvitation } from './collectFees.js';
import { fixHub } from './fixHub.js';

/** @template [Slot=unknown] @typedef {import('@endo/marshal').Marshal<Slot>} Marshaller */
/** @import { Marshal } from '@endo/marshal'; */

Check warning on line 19 in contract/src/swaparoo.contract.js

View workflow job for this annotation

GitHub Actions / unit

Invalid JSDoc tag name "import"
/** @template [Slot=unknown] @typedef {Marshal<Slot>} Marshaller */

const { quote: q } = assert;

const makeNatAmountShape = (brand, min) =>
harden({ brand, value: min ? M.gte(min) : M.nat() });

/**
* @param {ZCF} zcf
* @param {ZCFSeat} firstSeat
* @param {ZCFSeat} secondSeat
* @param {ZCFSeat} feeSeat
* @param {Amount} feeAmount
*/
export const swapWithFee = (zcf, firstSeat, secondSeat, feeSeat, feeAmount) => {
try {
const { Fee: _, ...firstGive } = firstSeat.getProposal().give;
Expand Down
2 changes: 0 additions & 2 deletions contract/src/types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import '@agoric/vats/src/core/types';

/**
* In agoric-sdk, the BootstrapPowers.consume['chainStorage'] type includes undefined because
* of some historical testing practices. It's tedious and unnecessary
Expand Down
9 changes: 7 additions & 2 deletions contract/test/boot-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const mockBootstrapPowers = async (
produce.priceAuthority.resolve(Far('NullPriceAuthority', {}));

/**
* @type {BootstrapPowers & import('../src/types').NonNullChainStorage}
* @type {BootstrapPowers & NonNullChainStorage}
*/
// @ts-expect-error mock
const powers = { produce, consume, ...spaces, zone };
Expand Down Expand Up @@ -193,7 +193,12 @@ export const makeMockTools = async (t, bundleCache) => {

const boardMarshaller = await E(board).getPublishingMarshaller();
const walletFactory = mockWalletFactory(
{ namesByAddressAdmin, zoe },
{
namesByAddressAdmin,
zoe,
// eslint-disable-next-line no-use-before-define
makeQueryTool: () => makeQueryTool(),
},
smartWalletIssuers,
);

Expand Down
11 changes: 3 additions & 8 deletions contract/test/market-actors.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ const { entries, fromEntries, keys } = Object;
* @param {import('ava').ExecutionContext} t
* @param {{
* wallet: import('./wallet-tools.js').MockWallet;
* queryTool: Pick<import('../tools/ui-kit-goals/queryKit.js').QueryTool, 'queryData'>;
* }} mine
* @param {{
* rxAddr: string,
* toSend: AmountKeywordRecord;
* }} shared
*/
export const payerPete = async (
t,
{ wallet, queryTool },
{ rxAddr, toSend },
) => {
const hub = await makeAgoricNames(queryTool);
export const payerPete = async (t, { wallet }, { rxAddr, toSend }) => {
const hub = await makeAgoricNames(wallet.query);
/** @type {WellKnown} */
const agoricNames = makeNameProxy(hub);

Expand All @@ -59,7 +54,6 @@ export const payerPete = async (
},
proposal: { give: toSend },
};
t.snapshot(sendOffer, 'client sends offer');
const updates = await E(wallet.offers).executeOffer(sendOffer);

const seat = seatLike(updates);
Expand All @@ -70,6 +64,7 @@ export const payerPete = async (
t.log('Pete payout should be empty', kwd, amt);
t.deepEqual(amt, AmountMath.makeEmpty(brand, kind));
}
t.snapshot(sendOffer, 'client sends offer');
};

const trackDeposits = async (t, initial, purseUpdates, toSend) =>
Expand Down
2 changes: 1 addition & 1 deletion contract/test/snapshots/test-postalSvc.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Generated by [AVA](https://avajs.dev).
invitationSpec: {
instance: Object @Alleged: InstanceHandle {},
invitationArgs: [
'agoric1aap7m84dt0rwhhfw49d4kv2gqetzl56vn8aaxj',
'agoric1ahsjklvps67a0y7wj0hqs0ekp55hxayppdw5az',
],
publicInvitationMaker: 'makeSendInvitation',
source: 'contract',
Expand Down
Binary file modified contract/test/snapshots/test-postalSvc.js.snap
Binary file not shown.
41 changes: 20 additions & 21 deletions contract/test/test-postalSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ const scriptRoots = {
postalService: nodeRequire.resolve('../src/postal-service.proposal.js'),
};

const keyring = {
// yarn docker:bash
// agd keys show -a user1 --keyring-backend=test
user1: 'agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk',
// agd keys show -a user2 --keyring-backend=test
user2: 'agoric1ahsjklvps67a0y7wj0hqs0ekp55hxayppdw5az',
};

/** @param {import('ava').ExecutionContext} t */
const makeTestContext = async t => {
const bc = await makeBundleCacheContext(t);
Expand Down Expand Up @@ -115,7 +123,7 @@ test.serial('deploy contract with core eval: postalService / send', async t => {
const { bundles } = t.context.shared;
const bundleID = getBundleId(bundles.postalService);

const name = 'send';
const name = 'postal-service';
const result = await runCoreEval({
name,
behavior: startPostalService,
Expand Down Expand Up @@ -155,31 +163,23 @@ test.serial('deliver payment using offer', async t => {

await null;
const { make: amt } = AmountMath;
const shared = {
rxAddr: 'agoric1aap7m84dt0rwhhfw49d4kv2gqetzl56vn8aaxj',

const shared = harden({
rxAddr: keyring.user2,
toSend: {
Pmt: amt(await agoricNames.brand.ATOM, 3n),
},
};
});

const wallet = {
pete: await provisionSmartWallet(
'agoric1xe269y3fhye8nrlduf826wgn499y6wmnv32tw5',
{ ATOM: 10n, BLD: 75n },
),
rose: await provisionSmartWallet(shared.rxAddr, {
BLD: 20n,
}),
pete: await provisionSmartWallet(keyring.user1, { ATOM: 10n, BLD: 75n }),
rose: await provisionSmartWallet(shared.rxAddr, { BLD: 20n }),
};
const pqt = makeQueryTool();
for (const kind of ['instance', 'brand']) {
const entries = await E(E(hub0).lookup(kind)).entries();
pqt.fromCapData(qt.toCapData(entries));
}

const wrt = who => x => wallet[who].query.fromCapData(qt.toCapData(x));
await Promise.all([
payerPete(t, { wallet: wallet.pete, queryTool: pqt }, shared),
receiverRose(t, { wallet: wallet.rose }, shared),
payerPete(t, { wallet: wallet.pete }, wrt('pete')(shared)),
receiverRose(t, { wallet: wallet.rose }, wrt('rose')(shared)),
]);
});

Expand All @@ -202,10 +202,9 @@ test('send invitation* from contract using publicFacet of postalService', async
IST: await E(zoe).getFeeIssuer(),
};

// TODO: use CapData across vats
// const boardMarshaller = await E(board).getPublishingMarshaller();
const { makeQueryTool } = t.context;
const walletFactory = mockWalletFactory(
{ zoe, namesByAddressAdmin },
{ zoe, namesByAddressAdmin, makeQueryTool },
smartWalletIssuers,
);

Expand Down
18 changes: 14 additions & 4 deletions contract/test/wallet-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@

const DEPOSIT_FACET_KEY = 'depositFacet'; // XXX does agoric-sdk export this?

/** @import { QueryTool } from '../tools/ui-kit-goals/queryKit.js'; */

Check warning on line 26 in contract/test/wallet-tools.js

View workflow job for this annotation

GitHub Actions / unit

Invalid JSDoc tag name "import"

/**
* @param {{
* zoe: ERef<ZoeService>;
* namesByAddressAdmin: ERef<import('@agoric/vats').NameAdmin>;
* makeQueryTool: () => Pick<QueryTool, 'toCapData' | 'fromCapData' | 'queryData'>;
* }} powers
* @param {IssuerKeywordRecord} issuerKeywordRecord
*
* @typedef {Awaited<ReturnType<Awaited<ReturnType<typeof mockWalletFactory>['makeSmartWallet']>>>} MockWallet
*/
export const mockWalletFactory = (
{ zoe, namesByAddressAdmin },
{ zoe, namesByAddressAdmin, makeQueryTool },
issuerKeywordRecord,
) => {
/** @param {string} address */
Expand Down Expand Up @@ -189,10 +192,13 @@
}
}

const theQueryTool = makeQueryTool();

return {
deposit: depositFacet,
offers: Far('Offers', { executeOffer, tryExit }),
peek: Far('Wallet Peek', { purseUpdates }),
query: theQueryTool,
};
};

Expand All @@ -210,7 +216,7 @@
/** @type {PromiseKit<AmountKeywordRecord>} */
payouts: makePromiseKit(),
};
(async () => {
const bg = async () => {
await null;
try {
// XXX an error here is somehow and unhandled rejection
Expand All @@ -227,9 +233,13 @@
} catch (reason) {
sync.result.reject(reason);
sync.payouts.reject(reason);
throw reason;
// throw reason;
}
})();
};
bg().catch(reason => {
sync.result.reject(reason);
sync.payouts.reject(reason);
});
return harden({
getOfferResult: () => sync.result.promise,
getPayoutAmounts: () => sync.payouts.promise,
Expand Down
2 changes: 1 addition & 1 deletion contract/tools/e2e-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export const provisionSmartWallet = async (
/** @type {import('../test/wallet-tools.js').MockWallet['peek']} */
const peek = Far('Peek', { purseUpdates });

return { offers, deposit, peek };
return { offers, deposit, peek, query: q };
};

/**
Expand Down
7 changes: 5 additions & 2 deletions contract/tools/ui-kit-goals/marshalTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ const makeTranslationTable = (makeSlot, makeVal) => {
};

/** @type {(slot: string, iface: string | undefined) => any} */
const synthesizeRemotable = (slot, iface) =>
Far(`${(iface ?? '').replace(/^Alleged: /, '')}#${slot}`, {});
const synthesizeRemotable = (slot, iface) => {
const ifaceStr = iface ?? '';
const suffix = ifaceStr.endsWith(`#${slot}`) ? '' : `#${slot}`;
return Far(`${ifaceStr.replace(/^Alleged: /, '')}${suffix}`, {});
};

/**
* Make a marshaller that synthesizes a remotable the first
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@agoric/ertp": "0.16.3-u14.0",
"@agoric/governance": "0.10.4-u14.0",
"@agoric/store": "0.9.3-u14.0",
"@agoric/xsnap": "0.14.3-u14.0",
"@agoric/xsnap": "0.14.3-dev-c060e65.0",
"@agoric/vat-data": "0.5.3-u14.0",
"@endo/bundle-source": "2.5.2-upstream-rollup",
"@endo/captp": "3.1.1",
Expand Down
Loading
Loading