From 3a98491b3aebe20832cb982ebd6fc18b6c77058f Mon Sep 17 00:00:00 2001 From: Kate Sills Date: Tue, 15 Sep 2020 13:49:26 -0700 Subject: [PATCH] fix: make brand optional in the types of `getAmountAllocated` (#1760) * fix: make brand optional in the types of `getAmountAllocated` * fix: add assert to fix the types * chore: fix error message in test * chore: change error message in brand assertion Co-authored-by: Chris Hibbert * chore: fix error message Co-authored-by: Chris Hibbert --- packages/zoe/src/contractFacet/seat.js | 1 + packages/zoe/src/contractFacet/types.js | 2 +- packages/zoe/test/unitTests/zcf/test-zcf.js | 5 +---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/zoe/src/contractFacet/seat.js b/packages/zoe/src/contractFacet/seat.js index 21ca13991a6..0a91039de20 100644 --- a/packages/zoe/src/contractFacet/seat.js +++ b/packages/zoe/src/contractFacet/seat.js @@ -73,6 +73,7 @@ export const makeZcfSeatAdminKit = ( if (currentAllocation[keyword] !== undefined) { return currentAllocation[keyword]; } + assert(brand, `A brand must be supplied when the keyword is not defined`); return getAmountMath(brand).getEmpty(); }, getCurrentAllocation: () => { diff --git a/packages/zoe/src/contractFacet/types.js b/packages/zoe/src/contractFacet/types.js index b7b7acab85e..d8695a12ebb 100644 --- a/packages/zoe/src/contractFacet/types.js +++ b/packages/zoe/src/contractFacet/types.js @@ -143,7 +143,7 @@ * @property {() => Notifier} getNotifier * @property {() => boolean} hasExited * @property {() => ProposalRecord} getProposal - * @property {(keyword: Keyword, brand: Brand) => Amount} getAmountAllocated + * @property {(keyword: Keyword, brand: Brand=) => Amount} getAmountAllocated * The brand is used for filling in an empty amount if the `keyword` * is not present in the allocation * @property {() => Allocation} getCurrentAllocation diff --git a/packages/zoe/test/unitTests/zcf/test-zcf.js b/packages/zoe/test/unitTests/zcf/test-zcf.js index 0d25d3ad2c4..ac942af1aa1 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcf.js +++ b/packages/zoe/test/unitTests/zcf/test-zcf.js @@ -795,8 +795,6 @@ test(`zcfSeat.getAmountAllocated from zcf.makeEmptySeatKit`, async t => { // Again, mint some gains to change the allocation. const { brand: brand2 } = await allocateEasy(zcf, 'Stuff2', zcfSeat, 'B', 6); - // TODO: make brand optional - // https://github.com/Agoric/agoric-sdk/issues/1725 t.deepEqual(zcfSeat.getAmountAllocated('B'), { brand: brand2, value: 6, @@ -807,9 +805,8 @@ test(`zcfSeat.getAmountAllocated from zcf.makeEmptySeatKit`, async t => { value: 6, }); - // @ts-ignore t.throws(() => zcfSeat.getAmountAllocated('DoesNotExist'), { - message: `"brand" not found: (an undefined)\nSee console for error data.`, + message: `A brand must be supplied when the keyword is not defined`, }); });