Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 13, 2021
1 parent f860c5b commit 7db7e5c
Show file tree
Hide file tree
Showing 121 changed files with 354 additions and 480 deletions.
8 changes: 4 additions & 4 deletions packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';
import { Far } from '@agoric/marshal';
import { mustBeComparable } from '@agoric/same-structure';

Expand Down Expand Up @@ -87,7 +87,7 @@ function makeAmountMath(brand, amountMathKind) {
const helpers = mathHelpers[amountMathKind];
assert(
helpers !== undefined,
details`unrecognized amountMathKind: ${amountMathKind}`,
X`unrecognized amountMathKind: ${amountMathKind}`,
);

// Cache the amount if we can.
Expand Down Expand Up @@ -126,11 +126,11 @@ function makeAmountMath(brand, amountMathKind) {
const { brand: allegedBrand, value } = allegedAmount;
assert(
allegedBrand !== undefined,
details`The brand in allegedAmount ${allegedAmount} is undefined. Did you pass a value rather than an amount?`,
X`The brand in allegedAmount ${allegedAmount} is undefined. Did you pass a value rather than an amount?`,
);
assert(
brand === allegedBrand,
details`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the amountMath brand ${brand}.`,
X`The brand in the allegedAmount ${allegedAmount} in 'coerce' didn't match the amountMath brand ${brand}.`,
);
// Will throw on inappropriate value
return amountMath.make(value);
Expand Down
6 changes: 3 additions & 3 deletions packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, details, q } from '@agoric/assert';
import { assert, details as X, q } from '@agoric/assert';
import {
pureCopy,
passStyleOf,
Expand All @@ -21,7 +21,7 @@ export const assertSubset = (whole, part) => {
assert.typeof(key, 'string');
assert(
whole.includes(key),
details`key ${q(key)} was not one of the expected keys ${q(whole)}`,
X`key ${q(key)} was not one of the expected keys ${q(whole)}`,
);
});
};
Expand All @@ -35,7 +35,7 @@ export const assertKeysAllowed = (allowedKeys, record) => {
// assert that there are no symbol properties.
assert(
Object.getOwnPropertySymbols(record).length === 0,
details`no symbol properties allowed`,
X`no symbol properties allowed`,
);
};

Expand Down
9 changes: 3 additions & 6 deletions packages/ERTP/src/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// @ts-check

import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';
import { makeExternalStore } from '@agoric/store';
import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';
Expand Down Expand Up @@ -56,10 +56,7 @@ function makeIssuerKit(
const paymentLedger = makePaymentWeakStore();

function assertKnownPayment(payment) {
assert(
paymentLedger.has(payment),
details`payment not found for ${allegedName}`,
);
assert(paymentLedger.has(payment), X`payment not found for ${allegedName}`);
}

// Methods like deposit() have an optional second parameter `amount`
Expand All @@ -69,7 +66,7 @@ function makeIssuerKit(
if (amount !== undefined) {
assert(
amountMath.isEqual(amount, paymentBalance),
details`payment balance ${paymentBalance} must equal amount ${amount}`,
X`payment balance ${paymentBalance} must equal amount ${amount}`,
);
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/ERTP/src/mathHelpers/setMathHelpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check

import { passStyleOf } from '@agoric/marshal';
import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';
import { sameStructure } from '@agoric/same-structure';

import '../types';
Expand Down Expand Up @@ -43,7 +43,7 @@ const checkForDupes = buckets => {
for (let j = i + 1; j < maybeMatches.length; j += 1) {
assert(
!sameStructure(maybeMatches[i], maybeMatches[j]),
details`value has duplicates: ${maybeMatches[i]} and ${maybeMatches[j]}`,
X`value has duplicates: ${maybeMatches[i]} and ${maybeMatches[j]}`,
);
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ const setMathHelpers = harden({
right.forEach(rightElem => {
assert(
hasElement(leftBuckets, rightElem),
details`right element ${rightElem} was not in left`,
X`right element ${rightElem} was not in left`,
);
});
const leftElemNotInRight = leftElem => !hasElement(rightBuckets, leftElem);
Expand Down
11 changes: 4 additions & 7 deletions packages/ERTP/src/mathHelpers/strSetMathHelpers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @ts-check

import { passStyleOf } from '@agoric/marshal';
import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';

const identity = harden([]);

const checkForDupes = list => {
const set = new Set(list);
assert(set.size === list.length, details`value has duplicates: ${list}`);
assert(set.size === list.length, X`value has duplicates: ${list}`);
};

/**
Expand Down Expand Up @@ -43,10 +43,7 @@ const strSetMathHelpers = harden({
doAdd: (left, right) => {
const union = new Set(left);
const addToUnion = elem => {
assert(
!union.has(elem),
details`left and right have same element ${elem}`,
);
assert(!union.has(elem), X`left and right have same element ${elem}`);
union.add(elem);
};
right.forEach(addToUnion);
Expand All @@ -58,7 +55,7 @@ const strSetMathHelpers = harden({
const allRemovedCorrectly = right.every(remove);
assert(
allRemovedCorrectly,
details`some of the elements in right (${right}) were not present in left (${left})`,
X`some of the elements in right (${right}) were not present in left (${left})`,
);
return harden(Array.from(leftSet));
},
Expand Down
10 changes: 5 additions & 5 deletions packages/ERTP/test/swingsetTests/splitPayments/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { E } from '@agoric/eventual-send';
import { assert, details as X } from '@agoric/assert';
import { makeIssuerKit } from '../../../src';

const { details: X } = assert;

export function buildRootObject(vatPowers, vatParameters) {
const arg0 = vatParameters.argv[0];

function testSplitPayments(aliceMaker) {
vatPowers.testLog('start test splitPayments');
const { mint: moolaMint, issuer, amountMath } = makeIssuerKit('moola');
Expand All @@ -14,15 +15,14 @@ export function buildRootObject(vatPowers, vatParameters) {
}

const obj0 = {
// eslint-disable-next-line consistent-return
async bootstrap(vats) {
switch (vatParameters.argv[0]) {
switch (arg0) {
case 'splitPayments': {
const aliceMaker = await E(vats.alice).makeAliceMaker();
return testSplitPayments(aliceMaker);
}
default: {
assert.fail(X`unrecognized argument value ${vatParameters.argv[0]}`);
assert.fail(X`unrecognized argument value ${arg0}`);
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/src/capdata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';

/* eslint-disable jsdoc/valid-types,jsdoc/require-returns-check */
/**
Expand All @@ -15,11 +15,11 @@ export function insistCapData(capdata) {
assert.typeof(
capdata.body,
'string',
details`capdata has non-string .body ${capdata.body}`,
X`capdata has non-string .body ${capdata.body}`,
);
assert(
Array.isArray(capdata.slots),
details`capdata has non-Array slots ${capdata.slots}`,
X`capdata has non-Array slots ${capdata.slots}`,
);
// TODO check that the .slots array elements are actually strings
}
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/bridge-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

function sanitize(data) {
// TODO: Use @agoric/marshal:pureCopy when it exists.
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/command-src.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Nat from '@agoric/nat';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

export function buildRootDeviceNode(tools) {
const { SO, getDeviceState, setDeviceState, endowments } = tools;
Expand Down
9 changes: 4 additions & 5 deletions packages/SwingSet/src/devices/command.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Nat from '@agoric/nat';
import { makePromiseKit } from '@agoric/promise-kit';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

export default function buildCommand(broadcastCallback) {
assert(broadcastCallback, X`broadcastCallback must be provided.`);
Expand Down Expand Up @@ -46,10 +46,9 @@ export default function buildCommand(broadcastCallback) {
if (kResponseString !== undefined) {
obj = JSON.parse(`${kResponseString}`);
}
if (!responses.has(count)) {
// maybe just ignore it
assert.fail(X`unknown response index ${count}`);
}
// TODO this might not qualify as an error, it needs more thought
// See https://github.com/Agoric/agoric-sdk/pull/2406#discussion_r575561554
assert(responses.has(count), X`unknown response index ${count}`);
const { resolve, reject } = responses.get(count);
if (isReject) {
reject(obj);
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/loopbox-src.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

export function buildRootDeviceNode(tools) {
const { SO, endowments } = tools;
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/loopbox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

/*
* The "loopbox" is a special device used for unit tests, which glues one
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/mailbox-src.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Nat from '@agoric/nat';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

export function buildRootDeviceNode(tools) {
const { SO, getDeviceState, setDeviceState, endowments } = tools;
Expand Down
8 changes: 4 additions & 4 deletions packages/SwingSet/src/devices/mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

import Nat from '@agoric/nat';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

// This Map-based mailboxState object is a good starting point, but we may
// replace it with one that tracks which parts of the state have been
Expand Down Expand Up @@ -135,11 +135,11 @@ export function buildMailboxStateMap(state = harden(new Map())) {
assert(!state.size, X`cannot populateFromData: outbox is not empty`);
for (const peer of Object.getOwnPropertyNames(data)) {
const inout = getOrCreatePeer(peer);
const dp = data[peer];
const d = data[peer];
importMailbox(
{
ack: dp.inboundAck,
outbox: dp.outbox,
ack: d.inboundAck,
outbox: d.outbox,
},
inout,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/plugin-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { makeCapTP } from '@agoric/captp';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

export function buildRootDeviceNode(tools) {
const { SO, getDeviceState, setDeviceState, endowments } = tools;
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/devices/timer-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import Nat from '@agoric/nat';
import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';

// Since we use harden when saving the state, we need to copy the arrays so they
// will continue to be mutable. each record inside handlers is immutable, so we
Expand Down Expand Up @@ -229,7 +229,7 @@ export function buildRootDeviceNode(tools) {
function updateTime(time) {
assert(
time >= lastPolled,
details`Time is monotonic. ${time} cannot be less than ${lastPolled}`,
X`Time is monotonic. ${time} cannot be less than ${lastPolled}`,
);
lastPolled = time;
saveState();
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/timer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Nat from '@agoric/nat';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

/**
* Endowments for a Timer device that can be made available to SwingSet vats.
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/hostStorage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { initSwingStore } from '@agoric/swing-store-simple';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

/*
The "Storage API" is a set of functions { has, getKeys, get, set, delete } that
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/id.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Nat from '@agoric/nat';

const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

// Vats are identified by an integer index, which (for typechecking purposes)
// is encoded as `vNN`. Devices are similarly identified as `dNN`. Both have
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kdebug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { details: X } = assert;
import { assert, details as X } from '@agoric/assert';

let enableKDebug = false;

Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/src/kernel/vatManager/deliver.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assert, details as X } from '@agoric/assert';
import { insistMessage } from '../../message';

const { details: X } = assert;

export function makeDeliver(tools, dispatch) {
const {
meterRecord,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// @ts-check
import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';
import { makeTranscriptManager } from './transcript';
import { createSyscall } from './syscall';

import '../../types';
import './types';

const { details: X } = assert;

// eslint-disable-next-line no-unused-vars
function parentLog(first, ...args) {
// console.error(`--parent: ${first}`, ...args);
Expand Down Expand Up @@ -134,7 +132,7 @@ export function makeXsSubprocessFactory({
parentLog(vatID, 'eval bundle', it);
assert(
superCode.moduleFormat === 'getExport',
details`${it} unexpected: ${superCode.moduleFormat}`,
X`${it} unexpected: ${superCode.moduleFormat}`,
);
await worker.evaluate(`(${superCode.source}\n)()`.trim());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// @ts-check
import { assert, details } from '@agoric/assert';
import { assert, details as X } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { Remotable, getInterfaceOf, makeMarshal } from '@agoric/marshal';
// grumble... waitUntilQuiescent is exported and closes over ambient authority
import { waitUntilQuiescent } from '../../waitUntilQuiescent';

import { makeLiveSlots } from '../liveSlots';

const { details: X } = assert;

const encoder = new TextEncoder();
const decoder = new TextDecoder();

Expand Down Expand Up @@ -38,8 +36,8 @@ function managerPort(issueCommand) {
function decode(msg) {
/** @type { Tagged } */
const item = decodeData(msg);
assert(Array.isArray(item), details`expected array`);
assert(item.length > 0, details`empty array lacks tag`);
assert(Array.isArray(item), X`expected array`);
assert(item.length > 0, X`empty array lacks tag`);
return item;
}

Expand Down
Loading

0 comments on commit 7db7e5c

Please sign in to comment.