Skip to content

Commit

Permalink
fix(ERTP): now that {} is data, always return a displayInfo object
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Apr 28, 2021
1 parent 547de45 commit fcc0cc4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export const assertKeysAllowed = (allowedKeys, record) => {
};

export const assertDisplayInfo = allegedDisplayInfo => {
if (allegedDisplayInfo === undefined) {
return;
}
assert(
passStyleOf(allegedDisplayInfo) === 'copyRecord',
X`A displayInfo can only be a pass-by-copy record: ${allegedDisplayInfo}`,
Expand All @@ -48,7 +45,11 @@ export const assertDisplayInfo = allegedDisplayInfo => {
assertKeysAllowed(displayInfoKeys, allegedDisplayInfo);
};

export const coerceDisplayInfo = allegedDisplayInfo => {
/**
* @param {any} [allegedDisplayInfo={}]
* @returns {DisplayInfo}
*/
export const coerceDisplayInfo = (allegedDisplayInfo = {}) => {
allegedDisplayInfo = pureCopy(allegedDisplayInfo);
assertDisplayInfo(allegedDisplayInfo);
return allegedDisplayInfo;
Expand Down
4 changes: 2 additions & 2 deletions packages/ERTP/src/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import './types';
function makeIssuerKit(
allegedName,
amountMathKind = MathKind.NAT,
displayInfo = undefined,
rawDisplayInfo = harden({}),
) {
assert.typeof(allegedName, 'string');
displayInfo = coerceDisplayInfo(displayInfo);
const displayInfo = coerceDisplayInfo(rawDisplayInfo);

/** @type {Brand} */
const brand = Far(makeFarName(allegedName, ERTPKind.BRAND), {
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
* @callback MakeIssuerKit
* @param {string} allegedName
* @param {AmountMathKind} [amountMathKind=MathKind.NAT]
* @param {DisplayInfo=} [displayInfo=undefined]
* @param {DisplayInfo} [displayInfo={}]
* @returns {IssuerKit}
*
* The allegedName becomes part of the brand in asset descriptions. The
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/test/unitTests/test-issuerObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('issuer.getBrand, brand.isMyIssuer', t => {
);
t.is(issuer.getAllegedName(), myBrand.getAllegedName());
t.is(issuer.getAllegedName(), 'fungible');
t.is(brand.getDisplayInfo(), undefined);
t.deepEqual(brand.getDisplayInfo(), {});
});

test('brand.getDisplayInfo()', t => {
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/test/unitTests/zcf/test-zcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ test(`zcf.makeZCFMint - NAT`, async t => {
};
await testTerms(t, zcf, expected);
t.is(issuerRecord.mathKind, MathKind.NAT);
t.is(issuerRecord.brand.getDisplayInfo(), undefined);
t.deepEqual(issuerRecord.brand.getDisplayInfo(), {});
});

test(`zcf.makeZCFMint - SET`, async t => {
Expand Down

0 comments on commit fcc0cc4

Please sign in to comment.