Skip to content

Commit

Permalink
feat: add displayInfo as a parameter to makeZcfMint. (#2189)
Browse files Browse the repository at this point in the history
with tests
  • Loading branch information
Chris-Hibbert authored Jan 13, 2021
1 parent 50ecfd2 commit f5cb3b9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/zoe/src/contractFacet/contractFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,21 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {
};

/** @type {MakeZCFMint} */
const makeZCFMint = async (keyword, amountMathKind = MathKind.NAT) => {
const makeZCFMint = async (
keyword,
amountMathKind = MathKind.NAT,
displayInfo,
) => {
assert(
!(keyword in instanceRecord.terms.issuers),
details`Keyword ${keyword} already registered`,
);

const zoeMintP = E(zoeInstanceAdmin).makeZoeMint(keyword, amountMathKind);
const zoeMintP = E(zoeInstanceAdmin).makeZoeMint(
keyword,
amountMathKind,
displayInfo,
);
const { brand: mintyBrand, issuer: mintyIssuer } = await E(
zoeMintP,
).getIssuerRecord();
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/contractFacet/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
* @callback MakeZCFMint
* @param {Keyword} keyword
* @param {AmountMathKind=} amountMathKind
* @param {DisplayInfo=} displayInfo
* @returns {Promise<ZCFMint>}
*/

Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
* @callback MakeZoeMint
* @param {Keyword} keyword
* @param {AmountMathKind=} amountMathKind
* @param {DisplayInfo=} displayInfo
* @returns {ZoeMint}
*/

Expand Down
8 changes: 6 additions & 2 deletions packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,19 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
};

/** @type {MakeZoeMint} */
const makeZoeMint = (keyword, amountMathKind = MathKind.NAT) => {
const makeZoeMint = (
keyword,
amountMathKind = MathKind.NAT,
displayInfo,
) => {
// Local indicates one that zoe itself makes from vetted code,
// and so can be assumed correct and fresh by zoe.
const {
mint: localMint,
issuer: localIssuer,
amountMath: localAmountMath,
brand: localBrand,
} = makeIssuerKit(keyword, amountMathKind);
} = makeIssuerKit(keyword, amountMathKind, displayInfo);
const localIssuerRecord = harden({
brand: localBrand,
issuer: localIssuer,
Expand Down
20 changes: 20 additions & 0 deletions packages/zoe/test/unitTests/zcf/test-zcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ test(`zcf.makeZCFMint - NAT`, async t => {
};
await testTerms(t, zcf, expected);
t.is(issuerRecord.amountMath.getAmountMathKind(), MathKind.NAT);
t.is(issuerRecord.brand.getDisplayInfo(), undefined);
});

test(`zcf.makeZCFMint - STRING_SET`, async t => {
Expand Down Expand Up @@ -544,6 +545,25 @@ test(`zcf.makeZCFMint - burnLosses - seat exited`, async t => {
});
});

test(`zcf.makeZCFMint - displayInfo`, async t => {
const { zcf } = await setupZCFTest();
const zcfMint = await zcf.makeZCFMint(
'A',
MathKind.NAT,
harden({
decimalPlaces: 3,
}),
);
const issuerRecord = zcfMint.getIssuerRecord();
const expected = {
issuers: { A: issuerRecord.issuer },
brands: { A: issuerRecord.brand },
maths: { A: issuerRecord.amountMath },
};
await testTerms(t, zcf, expected);
t.is(issuerRecord.brand.getDisplayInfo().decimalPlaces, 3);
});

/**
* @param {ZoeService} zoe
* @param {ContractFacet} zcf
Expand Down

0 comments on commit f5cb3b9

Please sign in to comment.