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:
Elliot Lee
2020-08-20 15:33:36 -07:00
parent 1660e819ee
commit 5b416a8862
2 changed files with 19 additions and 1 deletions

View File

@@ -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')

View File

@@ -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)
})