From 2ac22d3353281e7319adca67a8580024171a8066 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Thu, 5 Oct 2023 13:26:23 -0500 Subject: [PATCH] fix(inter-protocol): brands in CLI need not start with A-Z (#8258) * 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> --- packages/inter-protocol/src/clientSupport.js | 4 +- .../inter-protocol/test/test-clientSupport.js | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/inter-protocol/src/clientSupport.js b/packages/inter-protocol/src/clientSupport.js index 304cf54173f..56e0b283498 100644 --- a/packages/inter-protocol/src/clientSupport.js +++ b/packages/inter-protocol/src/clientSupport.js @@ -260,7 +260,9 @@ export const makeParseAmount = (agoricNames, makeError = msg => RangeError(msg)) => opt => { assert.typeof(opt, 'string', 'parseAmount expected string'); - const m = opt.match(/^(?[\d_]+(\.[\d_]+)?)(?[A-Z]\w*?)$/); + const m = opt.match( + /^(?[\d_]+(?:\.[\d_]+)?)\s*(?[A-Za-z]\w*)$/, + ); if (!m || !m.groups) { throw makeError(`invalid amount: ${opt}`); } diff --git a/packages/inter-protocol/test/test-clientSupport.js b/packages/inter-protocol/test/test-clientSupport.js index a841b4d682f..2c64d390012 100644 --- a/packages/inter-protocol/test/test-clientSupport.js +++ b/packages/inter-protocol/test/test-clientSupport.js @@ -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 /** @@ -18,6 +19,7 @@ const agoricNames = { brand: { IST: /** @type {any} */ (ist.brand), ATOM: /** @type {any} */ (atom.brand), + stATOM: /** @type {any} */ (stAtom.brand), }, vbankAsset: { uist: { @@ -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', + }, }, }; @@ -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