Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inter-protocol): brands in CLI need not start with A-Z #8258

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/inter-protocol/src/clientSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,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,6 +7,7 @@ import { withAmountUtils } from './supports.js';

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

// uses actual Brand objects instead of BoardRemote to make the test output more legible
/**
Expand All @@ -18,6 +19,7 @@ const agoricNames = {
brand: {
IST: /** @type {any} */ (ist.brand),
ATOM: /** @type {any} */ (atom.brand),
stATOM: /** @type {any} */ (stAtom.brand),
},
vbankAsset: {
uist: {
Expand All @@ -36,6 +38,14 @@ const agoricNames = {
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 @@ -125,6 +135,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
Loading