diff --git a/packages/ripple-binary-codec/src/types/currency.ts b/packages/ripple-binary-codec/src/types/currency.ts index e0ebc7f5..69d1078f 100644 --- a/packages/ripple-binary-codec/src/types/currency.ts +++ b/packages/ripple-binary-codec/src/types/currency.ts @@ -89,7 +89,7 @@ class Currency extends Hash160 { if (this.bytes[0] !== 0) { this._iso = null - } else if (code.toString('hex') === '000000') { + } else if (/^0*$/.test(this.bytes.toString('hex'))) { this._iso = 'XRP' } else { this._iso = isoCodeFromHex(code) diff --git a/packages/ripple-binary-codec/test/hash.test.js b/packages/ripple-binary-codec/test/hash.test.js index 28f2cfa0..1e70dd6e 100644 --- a/packages/ripple-binary-codec/test/hash.test.js +++ b/packages/ripple-binary-codec/test/hash.test.js @@ -69,6 +69,7 @@ describe('Currency', function () { expect(Currency.from('X8P').toJSON()).toBe('X8P') expect(Currency.from('USD').toJSON()).toBe('USD') }) + test('can be constructed from a Buffer', function () { const xrp = new Currency(Buffer.alloc(20)) expect(xrp.iso()).toBe('XRP') @@ -77,6 +78,12 @@ describe('Currency', function () { const currency = '015841551A748AD2C1F76FF6ECB0CCCD00000000' expect(Currency.from(currency).toJSON()).toBe(currency) }) + + test('Can handle other non-standard currency codes', () => { + const currency = '0000000000414C6F676F30330000000000000000' + expect(Currency.from(currency).toJSON()).toBe(currency) + }) + test('throws on invalid reprs', function () { expect(() => Currency.from(Buffer.alloc(19))).toThrow() expect(() => Currency.from(1)).toThrow()