Skip to content

Commit

Permalink
Improve brand check (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills authored Apr 27, 2020
1 parent f3b8449 commit e303777
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import harden from '@agoric/harden';
import { assert, details } from '@agoric/assert';

import { mustBeSameStructure, mustBeComparable } from '@agoric/same-structure';
import { mustBeComparable } from '@agoric/same-structure';
import mathHelpersLib from './mathHelpersLib';

/**
Expand Down Expand Up @@ -186,7 +186,10 @@ function makeAmountMath(brand, mathHelpersName) {
allegedBrand !== undefined,
details`alleged brand is undefined. Did you pass an extent rather than an amount?`,
);
mustBeSameStructure(brand, allegedBrand, 'Unrecognized brand');
assert(
brand === allegedBrand,
details`the brand in the allegedAmount in 'coerce' didn't match the amountMath brand`,
);
// Will throw on inappropriate extent
return amountMath.make(extent);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import makeAmountMath from '../../../src/amountMath';

const mockBrand = harden({
isMyIssuer: () => false,
allegedName: () => 'mock',
getAllegedName: () => 'mock',
});

const amountMath = makeAmountMath(mockBrand, 'nat');
Expand Down Expand Up @@ -56,8 +56,11 @@ test('natMathHelpers', t => {
`coerce can take an amount`,
);
t.throws(
() => coerce(harden({ brand: {}, extent: 4 })),
/Unrecognized brand/,
() =>
coerce(
harden({ brand: { getAllegedName: () => 'somename' }, extent: 4 }),
),
/the brand in the allegedAmount in 'coerce' didn't match the amountMath brand/,
`coerce can't take the wrong brand`,
);
t.throws(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import makeAmountMath from '../../../src/amountMath';

const mockBrand = harden({
isMyIssuer: () => false,
allegedName: () => 'mock',
getAllegedName: () => 'mock',
});

const amountMath = makeAmountMath(mockBrand, 'set');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import makeAmountMath from '../../../src/amountMath';

const mockBrand = harden({
isMyIssuer: () => false,
allegedName: () => 'mock',
getAllegedName: () => 'mock',
});

const amountMath = makeAmountMath(mockBrand, 'strSet');
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 @@ -233,7 +233,7 @@ test('issuer.split bad amount', t => {
const payment = mint.mintPayment(amountMath.make(1000));
t.rejects(
_ => E(issuer).split(payment, otherUnitOps.make(10)),
/Unrecognized brand/,
/the brand in the allegedAmount in 'coerce' didn't match the amountMath brand/,
'throws for bad amount',
);
} catch (e) {
Expand Down

0 comments on commit e303777

Please sign in to comment.