Skip to content

Commit

Permalink
chore: revert Agoric#2025, but keep the additional tests. (Agoric#2029)
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills authored Nov 19, 2020
1 parent c50652a commit c3cca70
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 55 deletions.
45 changes: 23 additions & 22 deletions packages/zoe/src/contractFacet/contractFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,13 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {
const { notifier, updater } = makeNotifierKit();
/** @type {PromiseRecord<ZoeSeatAdmin>} */
const zoeSeatAdminPromiseKit = makePromiseKit();
zoeSeatAdminPromiseKit.promise.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
zoeSeatAdminPromiseKit.promise.catch(_ => {});
const userSeatPromiseKit = makePromiseKit();
userSeatPromiseKit.promise.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
userSeatPromiseKit.promise.catch(_ => {});
const seatHandle = makeHandle('SeatHandle');

const seatData = harden({
Expand Down Expand Up @@ -452,23 +450,26 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {

// First, evaluate the contract code bundle.
const contractCode = evalContractBundle(bundle);
contractCode.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
contractCode.catch(() => {});

// Next, execute the contract code, passing in zcf
const { creatorFacet, publicFacet, creatorInvitation } = await E(
contractCode,
).start(zcf);

/** @type {Promise<ExecuteContractResult>} */
return harden({
creatorFacet,
publicFacet,
creatorInvitation,
addSeatObj,
});
const result = E(contractCode)
.start(zcf)
.then(({ creatorFacet, publicFacet, creatorInvitation }) => {
return harden({
creatorFacet,
publicFacet,
creatorInvitation,
addSeatObj,
});
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
result.catch(() => {});
return result;
};

return harden({ executeContract });
Expand Down
7 changes: 3 additions & 4 deletions packages/zoe/src/contractFacet/evalContractCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ const evalContractBundle = (bundle, additionalEndowments = {}) => {
const installation = importBundle(bundle, {
endowments: fullEndowments,
});
installation.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
installation.catch(() => {});
return installation;
};

Expand Down
7 changes: 3 additions & 4 deletions packages/zoe/src/contractFacet/fakeVatAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ function makeFakeVatAdmin(testContextSetter = undefined, makeRemote = x => x) {
adminNode: {
done: () => {
const kit = makePromiseKit();
kit.promise.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
kit.promise.catch(_ => {});
return kit.promise;
},
terminateWithFailure: () => {},
Expand Down
34 changes: 15 additions & 19 deletions packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,13 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {

const bundle = installation.getBundle();
const addSeatObjPromiseKit = makePromiseKit();
addSeatObjPromiseKit.promise.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
addSeatObjPromiseKit.promise.catch(_ => {});
const publicFacetPromiseKit = makePromiseKit();
publicFacetPromiseKit.promise.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
publicFacetPromiseKit.promise.catch(_ => {});

const makeInstanceAdmin = () => {
/** @type {Set<ZoeSeatAdmin>} */
Expand Down Expand Up @@ -436,14 +434,13 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
);

const offerResultPromiseKit = makePromiseKit();
offerResultPromiseKit.promise.catch(_err => {
// Error suppressed to not trigger Node.js's UnhandledPromiseRejectionWarning
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
offerResultPromiseKit.promise.catch(_ => {});
const exitObjPromiseKit = makePromiseKit();
exitObjPromiseKit.promise.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
exitObjPromiseKit.promise.catch(_ => {});
const seatHandle = makeHandle('SeatHandle');

const { userSeat, notifier, zoeSeatAdmin } = makeZoeSeatAdminKit(
Expand Down Expand Up @@ -471,10 +468,9 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
offerResultPromiseKit.resolve(offerResultP);
exitObjPromiseKit.resolve(exitObj);
})
.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
.catch(() => {});

return userSeat;
});
Expand Down
7 changes: 3 additions & 4 deletions packages/zoe/src/zoeService/zoeSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ export const makeZoeSeatAdminKit = (
offerResult,
) => {
const payoutPromiseKit = makePromiseKit();
payoutPromiseKit.promise.catch(err => {
// Remove to suppress Node.js's UnhandledPromiseRejectionWarning
throw err;
});
// Don't trigger Node.js's UnhandledPromiseRejectionWarning.
// This does not suppress any error messages.
payoutPromiseKit.promise.catch(_ => {});
const { notifier, updater } = makeNotifierKit();

let currentAllocation = initialAllocation;
Expand Down
39 changes: 37 additions & 2 deletions packages/zoe/test/unitTests/contracts/test-throwInOfferHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,50 @@ test('throw in offerHandler', async t => {

const throwsInOfferHandlerSeat = E(zoe).offer(throwInOfferHandlerInvitation);

await t.throwsAsync(() => E(throwsInOfferHandlerSeat).getOfferResult(), {
const throwsInOfferHandlerResult = E(
throwsInOfferHandlerSeat,
).getOfferResult();

// Uncomment below to see what the user would see
// await throwsInOfferHandlerResult;

await t.throwsAsync(() => throwsInOfferHandlerResult, {
message: 'error thrown in offerHandler in contract',
});

const throwsInDepositToSeatSeat = E(zoe).offer(
throwInDepositToSeatInvitation,
);

await t.throwsAsync(() => E(throwsInDepositToSeatSeat).getOfferResult(), {
const throwsInDepositToSeatResult = E(
throwsInDepositToSeatSeat,
).getOfferResult();

// Uncomment below to see what the user would see
// await throwsInDepositToSeatResult;

// TODO: make this logging more informative, including information
// about the error originating in the offerHandler in depositToSeat

// Currently the entirety of the log is:

// "Rejected promise returned by test. Reason:
// Error {
// message: '"brand" not found: (an object)',
// }
// › makeDetailedError (/Users/katesills/code/agoric-sdk/node_modules/ses/dist/ses.cjs:3437:17)
// › fail (/Users/katesills/code/agoric-sdk/node_modules/ses/dist/ses.cjs:3582:19)
// › baseAssert (/Users/katesills/code/agoric-sdk/node_modules/ses/dist/ses.cjs:3600:13)
// › assertKeyExists (/Users/katesills/code/agoric-sdk/packages/store/src/weak-store.js:19:5)
// › Object.get [as getByBrand] (/Users/katesills/code/agoric-sdk/packages/store/src/weak-store.js:27:7)
// › getAmountMath (src/zoeService/zoe.js:44:46)
// › src/cleanProposal.js:65:5
// › Array.map (<anonymous>)
// › coerceAmountKeywordRecord (src/cleanProposal.js:64:34)
// › cleanProposal (src/cleanProposal.js:116:10)
// › src/zoeService/zoe.js:408:28"

await t.throwsAsync(() => throwsInDepositToSeatResult, {
message: `"brand" not found: (an object)`,
});
});

0 comments on commit c3cca70

Please sign in to comment.