mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
Fix docs for xAddressToClassicAddress when there is no tag (#114)
Add a redundant test to ensure the behavior is abundantly clear
This commit is contained in:
@@ -30,7 +30,7 @@ Encode a test address e.g. for use with [Testnet or Devnet](https://xrpl.org/xrp
|
||||
|
||||
### xAddressToClassicAddress(xAddress: string): {classicAddress: string, tag: number | false, test: boolean}
|
||||
|
||||
Convert an X-address to a classic address and tag. If the X-address did not have a tag, the returned object will not have a `tag` field. If the X-address is intended for use on test network(s), `test` will be `true`; if it is intended for use on the main network (mainnet), `test` will be `false`.
|
||||
Convert an X-address to a classic address and tag. If the X-address did not have a tag, the returned object's `tag` will be `false`. (Since `0` is a valid tag, instead of `if (tag)`, use `if (tag !== false)` if you want to check for a tag.) If the X-address is intended for use on test network(s), `test` will be `true`; if it is intended for use on the main network (mainnet), `test` will be `false`.
|
||||
|
||||
```js
|
||||
> const api = require('ripple-address-codec')
|
||||
|
||||
@@ -239,3 +239,21 @@ test(`Invalid Account ID throws`, () => {
|
||||
test(`isValidXAddress returns false for invalid X-address`, () => {
|
||||
expect(isValidXAddress('XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8zeUygYrCgrPh')).toBe(false)
|
||||
})
|
||||
|
||||
test(`Converts X7AcgcsBL6XDcUb289X4mJ8djcdyKaB5hJDWMArnXr61cqZ to r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59 and tag: false`, () => {
|
||||
const classicAddress = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'
|
||||
const tag = false
|
||||
const xAddress = 'X7AcgcsBL6XDcUb289X4mJ8djcdyKaB5hJDWMArnXr61cqZ'
|
||||
const isTestAddress = false
|
||||
expect(classicAddressToXAddress(classicAddress, tag, isTestAddress)).toBe(xAddress)
|
||||
const myClassicAddress = xAddressToClassicAddress(xAddress)
|
||||
expect(myClassicAddress).toEqual({
|
||||
classicAddress,
|
||||
tag,
|
||||
test: isTestAddress
|
||||
})
|
||||
expect(isValidXAddress(xAddress)).toBe(true)
|
||||
|
||||
// Notice that converting an X-address to a classic address has `result.tag === false` (not undefined)
|
||||
expect(myClassicAddress.tag).toEqual(false)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user