mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
fix: encoding issue with encoding non-traditional currency codes (#1857)
* add test * fix decoding issue
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user