mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
Remove exception from decoding issued currencies which evaluate to 'XRP' (#1920)
* Remove throw and revise tests * Update chai dependency * Disabling linter error about extraneous import * Fix typo in test description * Revert unnecessary test changes * Remove unnecessary comments * Revert chai change * Add HISTORY.md * Revert chai change in package-lock as well * Fix typo * Check the result of the decoding * Update tests with correct expected behavior. * Fix tests and update currency.js * Update currency.ts
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
- Exported `TRANSACTION_TYPES` value
|
- Exported `TRANSACTION_TYPES` value
|
||||||
### Fixed
|
### Fixed
|
||||||
- Adds missing fields from XLS-20 NFT implementation
|
- Adds missing fields from XLS-20 NFT implementation
|
||||||
|
- Fixed error being raised when decoding issued currencies in non-standard formats that decode to XRP.
|
||||||
|
|
||||||
## 1.2.3 (2022-2-2)
|
## 1.2.3 (2022-2-2)
|
||||||
- Fix issue where ISO is invalid when parsing currency code
|
- Fix issue where ISO is invalid when parsing currency code
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ function isIsoCode(iso: string): boolean {
|
|||||||
function isoCodeFromHex(code: Buffer): string | null {
|
function isoCodeFromHex(code: Buffer): string | null {
|
||||||
const iso = code.toString()
|
const iso = code.toString()
|
||||||
if (iso === 'XRP') {
|
if (iso === 'XRP') {
|
||||||
throw new Error(
|
return null
|
||||||
'Disallowed currency code: to indicate the currency XRP you must use 20 bytes of 0s',
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (isIsoCode(iso)) {
|
if (isIsoCode(iso)) {
|
||||||
return iso
|
return iso
|
||||||
|
|||||||
@@ -50,10 +50,9 @@ describe('Hash256', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Currency', function () {
|
describe('Currency', function () {
|
||||||
test('Will throw an error for dodgy XRP', function () {
|
test('Decoding allows dodgy XRP without throwing', function () {
|
||||||
expect(() =>
|
const currencyCode = '0000000000000000000000005852500000000000'
|
||||||
Currency.from('0000000000000000000000005852500000000000'),
|
expect(Currency.from(currencyCode).toJSON()).toBe(currencyCode)
|
||||||
).toThrow()
|
|
||||||
})
|
})
|
||||||
test('Currency with lowercase letters decode to hex', () => {
|
test('Currency with lowercase letters decode to hex', () => {
|
||||||
expect(Currency.from('xRp').toJSON()).toBe(
|
expect(Currency.from('xRp').toJSON()).toBe(
|
||||||
|
|||||||
@@ -50,6 +50,28 @@ describe('encoding and decoding tx_json', function () {
|
|||||||
const decoded = decode(encoded)
|
const decoded = decode(encoded)
|
||||||
expect(my_tx).toEqual(decoded)
|
expect(my_tx).toEqual(decoded)
|
||||||
})
|
})
|
||||||
|
test('can decode a transaction with an issued currency that evaluates to XRP', function () {
|
||||||
|
// Encoding is done prior, because this is disallowed during encoding with client libraries to avoid scam XRP tokens.
|
||||||
|
const expectedTx = {
|
||||||
|
TransactionType: 'TrustSet',
|
||||||
|
Flags: 0,
|
||||||
|
Sequence: 19,
|
||||||
|
LimitAmount: {
|
||||||
|
value: '200',
|
||||||
|
currency: '0000000000000000000000005852500000000000',
|
||||||
|
issuer: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K',
|
||||||
|
},
|
||||||
|
Fee: '10',
|
||||||
|
SigningPubKey:
|
||||||
|
'023076CBB7A61837F1A23D4A3DD7CE810B694992EB0959AB9D6F4BB6FED6F8CC26',
|
||||||
|
TxnSignature:
|
||||||
|
'304502202D0CD77D8E765E3783C309CD663723B18406B7950A348A6F301492916A990FC70221008A76D586111205304F10ADEFDFDDAF804EF202D8CD1E492DC6E1AA8030EA1844',
|
||||||
|
Account: 'rPtfQWdcdhuL9eNeNv5YfmekSX3K7vJHbG',
|
||||||
|
}
|
||||||
|
const encoded = encode(expectedTx)
|
||||||
|
const decoded = decode(encoded)
|
||||||
|
expect(expectedTx).toEqual(decoded)
|
||||||
|
})
|
||||||
test('throws when Amount is invalid', function () {
|
test('throws when Amount is invalid', function () {
|
||||||
const my_tx = Object.assign({}, tx_json, {
|
const my_tx = Object.assign({}, tx_json, {
|
||||||
Amount: '1000.001',
|
Amount: '1000.001',
|
||||||
|
|||||||
Reference in New Issue
Block a user