Skip to content

Commit

Permalink
fix(inter-protocol): brands in CLI need not start with A-Z (#8258)
Browse files Browse the repository at this point in the history
* fix(inter-protocol): brands in CLI need not start with A-Z

* test(inter-protocol): clientSupport for initial non-uppercase

* fixup! fix(inter-protocol): brands in CLI need not start with A-Z

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and mhofman committed Dec 6, 2023
1 parent 89add68 commit fd9a44d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/inter-protocol/src/clientSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ export const makeParseAmount =
(agoricNames, makeError = msg => RangeError(msg)) =>
opt => {
assert.typeof(opt, 'string', 'parseAmount expected string');
const m = opt.match(/^(?<value>[\d_]+(\.[\d_]+)?)(?<brand>[A-Z]\w*?)$/);
const m = opt.match(
/^(?<value>[\d_]+(?:\.[\d_]+)?)\s*(?<brand>[A-Za-z]\w*)$/,
);
if (!m || !m.groups) {
throw makeError(`invalid amount: ${opt}`);
}
Expand Down
38 changes: 38 additions & 0 deletions packages/inter-protocol/test/test-clientSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { withAmountUtils } from './supports.js';

const ist = withAmountUtils(makeIssuerKit('IST'));
const atom = withAmountUtils(makeIssuerKit('ATOM'));
const stAtom = withAmountUtils(makeIssuerKit('stATOM'));

const brands = {
IST: ist.brand,
ATOM: atom.brand,
stATOM: stAtom.brand,
};

// XXX use @satisfies
Expand All @@ -34,6 +36,14 @@ const agoricNames = /** @type {any} */ ({
issuerName: 'ATOM',
proposedName: 'ATOM',
},
'ibc/sttoyatom': {
denom: 'ibc/sttoyatom',
brand: /** @type {any} */ (stAtom.brand),
displayInfo: { assetKind: 'nat', decimalPlaces: 6 },
issuer: /** @type {any} */ ({}),
issuerName: 'stATOM',
proposedName: 'stATOM',
},
},
});

Expand Down Expand Up @@ -123,6 +133,34 @@ test('Offers.auction.Bid', async t => {
'optional want',
);

const offerPrice2 = makeRatio(7n, ist.brand, 1n, stAtom.brand);
t.deepEqual(
Offers.auction.Bid(agoricNames, {
offerId: 'by-price3',
maxBuy: '10_000stATOM',
wantMinimum: '1.23stATOM',
give: '4.56IST',
price,
}),
{
id: 'by-price3',
invitationSpec: {
source: 'agoricContract',
instancePath: ['auctioneer'],
callPipe: [['makeBidInvitation', [stAtom.brand]]],
},
proposal: {
give: { Bid: ist.make(4_560_000n) },
want: { Collateral: stAtom.make(1_230_000n) },
},
offerArgs: {
offerPrice: offerPrice2,
maxBuy: stAtom.make(10_000_000_000n),
},
},
'lowercase brand',
);

t.throws(
() =>
// @ts-expect-error error checking test
Expand Down

0 comments on commit fd9a44d

Please sign in to comment.