Skip to content

Commit

Permalink
fix: review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Sep 1, 2022
1 parent 726d551 commit 171448a
Show file tree
Hide file tree
Showing 27 changed files with 202 additions and 107 deletions.
3 changes: 2 additions & 1 deletion packages/ERTP/src/payment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import { initEmpty } from '@agoric/store';
import { vivifyFarClass } from '@agoric/vat-data';

/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
Expand All @@ -17,7 +18,7 @@ export const vivifyPaymentKind = (issuerBaggage, name, brand, PaymentI) => {
issuerBaggage,
`${name} payment`,
PaymentI,
() => ({}),
initEmpty,
{
getAllegedBrand() {
return brand;
Expand Down
20 changes: 10 additions & 10 deletions packages/ERTP/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ harden(isCopyBagValue);
// One GOOGOLth should be enough decimal places for anybody.
export const MAX_ABSOLUTE_DECIMAL_PLACES = 100;

export const AssetValueShape = M.or('nat', 'set', 'copySet', 'copyBag');
export const AssetKindShape = M.or('nat', 'set', 'copySet', 'copyBag');

export const DisplayInfoShape = M.partial(
harden({
decimalPlaces: M.and(
M.gte(-MAX_ABSOLUTE_DECIMAL_PLACES),
M.lte(MAX_ABSOLUTE_DECIMAL_PLACES),
),
assetKind: AssetValueShape,
assetKind: AssetKindShape,
}),
harden({
// Including this empty `rest` ensures that there are no other
Expand All @@ -148,19 +148,19 @@ export const BrandI = M.interface('Brand', {
});

/**
* @param {Pattern} [brand]
* @param {Pattern} [assetKind]
* @param {Pattern} [brandShape]
* @param {Pattern} [assetKindShape]
* @param {Pattern} [amountShape]
*/
export const makeIssuerInterfaces = (
brand = BrandShape,
assetKind = AssetValueShape,
brandShape = BrandShape,
assetKindShape = AssetKindShape,
amountShape = AmountShape,
) => {
const IssuerI = M.interface('Issuer', {
getBrand: M.call().returns(brand),
getBrand: M.call().returns(brandShape),
getAllegedName: M.call().returns(M.string()),
getAssetKind: M.call().returns(assetKind),
getAssetKind: M.call().returns(assetKindShape),
getDisplayInfo: M.call().returns(DisplayInfoShape),
makeEmptyPurse: M.call().returns(PurseShape),

Expand Down Expand Up @@ -190,11 +190,11 @@ export const makeIssuerInterfaces = (
});

const PaymentI = M.interface('Payment', {
getAllegedBrand: M.call().returns(brand),
getAllegedBrand: M.call().returns(brandShape),
});

const PurseI = M.interface('Purse', {
getAllegedBrand: M.call().returns(brand),
getAllegedBrand: M.call().returns(brandShape),
getCurrentAmount: M.call().returns(amountShape),
getCurrentAmountNotifier: M.call().returns(NotifierShape),
// PurseI does *not* delay `deposit` until `srcPayment` is fulfulled.
Expand Down
4 changes: 2 additions & 2 deletions packages/ERTP/test/unitTests/test-mintObj.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';

import { M } from '@agoric/store';
import { initEmpty, M } from '@agoric/store';
// eslint-disable-next-line import/no-extraneous-dependencies
import { assert } from '@agoric/assert';

Expand Down Expand Up @@ -52,7 +52,7 @@ test('mint.mintPayment set w strings AssetKind', async t => {

const makeDurableHandle = name => {
const kindHandle = makeKindHandle(name);
const maker = defineDurableKind(kindHandle, () => ({}), {});
const maker = defineDurableKind(kindHandle, initEmpty, {});
return maker();
};

Expand Down
5 changes: 2 additions & 3 deletions packages/SwingSet/src/liveslots/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,8 @@ export function makeVirtualObjectManager(
*
* @param {DefineKindOptions<*>} options
* Additional options to configure the virtual object kind
* being defined. Currently the only supported option is `finish`, an
* optional finisher function that can perform post-creation initialization
* operations, such as inserting the new object in a cyclical object graph.
* being defined. See the documentation of DefineKindOptions
* for the meaning of each option.
*
* @param {boolean} isDurable A flag indicating whether or not the newly defined
* kind should be a durable kind.
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/liveslots/watchedPromises.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable no-lonely-if */

import { assert } from '@agoric/assert';
import { M } from '@agoric/store';
import { initEmpty, M } from '@agoric/store';
import { parseVatSlot } from '../lib/parseVatSlots.js';

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ export function makeWatchedPromiseManager(
assert.typeof(fulfillHandler, 'function');
assert.typeof(rejectHandler, 'function');

const makeWatcher = defineDurableKind(kindHandle, () => ({}), {
const makeWatcher = defineDurableKind(kindHandle, initEmpty, {
// @ts-expect-error TS is confused by the spread operator
onFulfilled: (_context, res, ...args) => fulfillHandler(res, ...args),
// @ts-expect-error
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/promise-watcher/vat-upton.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { initEmpty } from '@agoric/store';
import { makePromiseKit } from '@endo/promise-kit';
import {
provideKindHandle,
Expand Down Expand Up @@ -27,7 +28,7 @@ export function buildRootObject(vatPowers, vatParameters, baggage) {
);

// prettier-ignore
const makeDK = defineDurableKindMulti(dkHandle, () => ({}), {
const makeDK = defineDurableKindMulti(dkHandle, initEmpty, {
full: {
onFulfilled: (_context, res, tag) =>
log(`${tag} resolved ${res} version ${vatParameters.version} via VDO`),
Expand Down
11 changes: 6 additions & 5 deletions packages/SwingSet/test/upgrade/vat-ulrik-1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Far } from '@endo/marshal';
import { E } from '@endo/eventual-send';
import { makePromiseKit } from '@endo/promise-kit';
import { initEmpty } from '@agoric/store';
import {
makeKindHandle,
defineDurableKind,
Expand Down Expand Up @@ -183,14 +184,14 @@ export const buildRootObject = (_vatPowers, vatParameters, baggage) => {
switch (mode) {
case 's2mFacetiousnessMismatch': {
// upgrade should fail
defineDurableKind(mkh, () => ({}), {
defineDurableKind(mkh, initEmpty, {
fooMethod: () => 1,
});
break;
}
case 'facetCountMismatch': {
// upgrade should fail
defineDurableKindMulti(mkh, () => ({}), {
defineDurableKindMulti(mkh, initEmpty, {
foo: {
fooMethod: () => 1,
},
Expand All @@ -202,7 +203,7 @@ export const buildRootObject = (_vatPowers, vatParameters, baggage) => {
}
case 'facetNameMismatch': {
// upgrade should fail
defineDurableKindMulti(mkh, () => ({}), {
defineDurableKindMulti(mkh, initEmpty, {
foo: {
fooMethod: () => 1,
},
Expand All @@ -217,7 +218,7 @@ export const buildRootObject = (_vatPowers, vatParameters, baggage) => {
}
case 'facetOrderMismatch': {
// upgrade should succeed since facet names get sorted
defineDurableKindMulti(mkh, () => ({}), {
defineDurableKindMulti(mkh, initEmpty, {
baz: {
bazMethod: () => 1,
},
Expand All @@ -232,7 +233,7 @@ export const buildRootObject = (_vatPowers, vatParameters, baggage) => {
}
default: {
// upgrade should succeed
defineDurableKindMulti(mkh, () => ({}), {
defineDurableKindMulti(mkh, initEmpty, {
foo: {
fooMethod: () => 1,
},
Expand Down
5 changes: 3 additions & 2 deletions packages/SwingSet/test/upgrade/vat-ulrik-2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Far } from '@endo/marshal';
import { E } from '@endo/eventual-send';
import { assert } from '@agoric/assert';
import { initEmpty } from '@agoric/store';
import { defineDurableKind, defineDurableKindMulti } from '@agoric/vat-data';

const initialize = (name, imp, value) => {
Expand Down Expand Up @@ -34,11 +35,11 @@ export const buildRootObject = (_vatPowers, vatParameters, baggage) => {
if (baggage.has('mkh')) {
const mkh = baggage.get('mkh');
if (vatParameters.mode === 'm2sFacetiousnessMismatch') {
defineDurableKind(mkh, () => ({}), {
defineDurableKind(mkh, initEmpty, {
fooMethod: () => 2,
});
} else {
defineDurableKindMulti(mkh, () => ({}), {
defineDurableKindMulti(mkh, initEmpty, {
bar: {
barMethod: () => 2,
},
Expand Down
5 changes: 3 additions & 2 deletions packages/SwingSet/test/virtualObjects/test-reachable-vrefs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// eslint-disable-next-line import/order
import { test } from '../../tools/prepare-test-env-ava.js';

// eslint-disable-next-line import/order
import { Remotable } from '@endo/marshal';
import { initEmpty } from '@agoric/store';

import { makeVatSlot } from '../../src/lib/parseVatSlots.js';
import { makeFakeVirtualStuff } from '../../tools/fakeVirtualSupport.js';
Expand All @@ -14,7 +15,7 @@ test('VOM tracks reachable vrefs', async t => {
const weakStore = makeScalarBigWeakMapStore('test');

// empty object, used as weap map store key
const makeKey = defineKind('key', () => ({}), {});
const makeKey = defineKind('key', initEmpty, {});
const makeHolder = defineKind('holder', held => ({ held }), {
setHeld: ({ state }, held) => {
state.held = held;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* global WeakRef */
// eslint-disable-next-line import/order
import { test } from '../../tools/prepare-test-env-ava.js';

// eslint-disable-next-line import/order
import { Far } from '@endo/marshal';
import { initEmpty } from '@agoric/store';

import engineGC from '../../src/lib-nodejs/engine-gc.js';
import { makeGcAndFinalize } from '../../src/lib-nodejs/gc-and-finalize.js';
Expand Down Expand Up @@ -60,7 +61,7 @@ test('remotables retained by virtualized data', async t => {
const { makeScalarBigWeakMapStore } = cm;
const weakStore = makeScalarBigWeakMapStore('ws');
// empty object, used as weak map store key
const makeKey = defineKind('key', () => ({}), {});
const makeKey = defineKind('key', initEmpty, {});
const makeHolder = defineKind('holder', held => ({ held }), {
setHeld: ({ state }, held) => {
state.held = held;
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/test/virtualObjects/vat-orphan-bob.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Far } from '@endo/marshal';
import { initEmpty } from '@agoric/store';
import { defineKindMulti } from '@agoric/vat-data';

export function buildRootObject(vatPowers) {
const { testLog } = vatPowers;

let extracted;

const makeThing = defineKindMulti('thing', () => ({}), {
const makeThing = defineKindMulti('thing', initEmpty, {
regularFacet: {
statelessMethod: () => 0,
extractState: ({ state }) => {
Expand Down
15 changes: 15 additions & 0 deletions packages/assert/src/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// but we need to import it here as well.
import './types.js';

/** @typedef {import('@endo/marshal').Checker} Checker */

const { freeze } = Object;

/** @type {Assert} */
Expand Down Expand Up @@ -89,3 +91,16 @@ function an(str) {
}
freeze(an);
export { an };

/**
* In the `assertFoo`/`isFoo`/`checkFoo` pattern, `checkFoo` has a `check`
* parameter of type `Checker`. `assertFoo` calls `checkFoo` passes
* `assertChecker` as the `check` argument. `isFoo` passes `identChecker`
* as the `check` argument. `identChecker` acts precisely like an
* identity function, but is typed as a `Checker` to indicate its
* intended use.
*
* @type {Checker}
*/
export const identChecker = (cond, _details) => cond;
harden(identChecker);
18 changes: 12 additions & 6 deletions packages/inter-protocol/src/psm/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
floorMultiplyBy,
} from '@agoric/zoe/src/contractSupport/index.js';
import { Far } from '@endo/marshal';
import { initEmpty } from '@agoric/store';
import { handleParamGovernance, ParamTypes } from '@agoric/governance';
import { provide, vivifyKindMulti, M } from '@agoric/vat-data';
import { AmountMath } from '@agoric/ertp';
Expand All @@ -30,13 +31,18 @@ const { details: X } = assert;

/**
* @typedef {object} MetricsNotification
* Metrics naming scheme is that nouns are present values and past-participles are accumulative.
* Metrics naming scheme is that nouns are present values and past-participles
* are accumulative.
*
* @property {Amount<'nat'>} anchorPoolBalance amount of Anchor token available to be swapped
* @property {Amount<'nat'>} feePoolBalance amount of Stable token fees available to be collected
* @property {Amount<'nat'>} anchorPoolBalance amount of Anchor token
* available to be swapped
* @property {Amount<'nat'>} feePoolBalance amount of Stable token
* fees available to be collected
*
* @property {Amount<'nat'>} totalAnchorProvided running sum of Anchor ever given by this contract
* @property {Amount<'nat'>} totalStableProvided running sum of Stable ever given by this contract
* @property {Amount<'nat'>} totalAnchorProvided running sum of Anchor
* ever given by this contract
* @property {Amount<'nat'>} totalStableProvided running sum of Stable
* ever given by this contract
*/

/**
Expand Down Expand Up @@ -259,7 +265,7 @@ export const start = async (zcf, privateArgs, baggage) => {
const { limitedCreatorFacet, governorFacet } =
// @ts-expect-error over-determined decl of creatorFacet
makeVirtualGovernorFacet(creatorFacet);
const makePSM = vivifyKindMulti(baggage, 'PSM', () => ({}), {
const makePSM = vivifyKindMulti(baggage, 'PSM', initEmpty, {
creatorFacet: governorFacet,
limitedCreatorFacet,
publicFacet: augmentVirtualPublicFacet(publicFacet),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/far';
import { Far } from '@endo/marshal';
import { initEmpty } from '@agoric/store';
import {
provideDurableMapStore,
provideDurableWeakMapStore,
Expand Down Expand Up @@ -483,7 +484,7 @@ const start = async (zcf, privateArgs, baggage) => {
}),
);

const makeAMM = vivifyKindMulti(baggage, 'AMM', () => ({}), {
const makeAMM = vivifyKindMulti(baggage, 'AMM', initEmpty, {
publicFacet,
creatorFacet: governorFacet,
limitedCreatorFacet,
Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export {
matches,
fit,
} from './patterns/patternMatchers.js';
export { defendPrototype } from './patterns/interface-tools.js';
export { defendPrototype, initEmpty } from './patterns/interface-tools.js';
export { compareRank, isRankSorted, sortByRank } from './patterns/rankOrder.js';
export {
makeDecodePassable,
Expand Down
Loading

0 comments on commit 171448a

Please sign in to comment.