mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
* Add amm devnet support * Add option for faucet paths Co-authored-by: Jackson Mills <aim4math@gmail.com>
107 lines
2.9 KiB
TypeScript
107 lines
2.9 KiB
TypeScript
import assert from 'assert'
|
|
|
|
import _ from 'lodash'
|
|
import {
|
|
Client,
|
|
isValidClassicAddress,
|
|
isValidXAddress,
|
|
dropsToXrp,
|
|
} from 'xrpl-local'
|
|
|
|
// how long before each test case times out
|
|
const TIMEOUT = 60000
|
|
// This test is reliant on external networks, and as such may be flaky.
|
|
describe('fundWallet', function () {
|
|
this.timeout(TIMEOUT)
|
|
|
|
it('submit generates a testnet wallet', async function () {
|
|
await generate_faucet_wallet_and_fund_again(
|
|
'wss://s.altnet.rippletest.net:51233',
|
|
)
|
|
})
|
|
|
|
it('submit generates a devnet wallet', async function () {
|
|
await generate_faucet_wallet_and_fund_again(
|
|
'wss://s.devnet.rippletest.net:51233',
|
|
)
|
|
})
|
|
|
|
it('can generate and fund wallets on nft-devnet', async function () {
|
|
await generate_faucet_wallet_and_fund_again(
|
|
'ws://xls20-sandbox.rippletest.net:51233',
|
|
)
|
|
})
|
|
|
|
it('can generate and fund wallets using a custom host and path', async function () {
|
|
await generate_faucet_wallet_and_fund_again(
|
|
'ws://xls20-sandbox.rippletest.net:51233',
|
|
'faucet-nft.ripple.com',
|
|
'/accounts',
|
|
)
|
|
})
|
|
|
|
it('can generate and fund wallets on AMM devnet', async function () {
|
|
await generate_faucet_wallet_and_fund_again(
|
|
'wss://amm.devnet.rippletest.net:51233',
|
|
)
|
|
})
|
|
|
|
it('submit funds wallet with custom amount', async function () {
|
|
const api = new Client('wss://s.altnet.rippletest.net:51233')
|
|
|
|
await api.connect()
|
|
const { wallet, balance } = await api.fundWallet(null, { amount: '2000' })
|
|
assert.equal(balance, '2000')
|
|
assert.notEqual(wallet, undefined)
|
|
assert(isValidClassicAddress(wallet.classicAddress))
|
|
assert(isValidXAddress(wallet.getXAddress()))
|
|
|
|
const info = await api.request({
|
|
command: 'account_info',
|
|
account: wallet.classicAddress,
|
|
})
|
|
assert.equal(dropsToXrp(info.result.account_data.Balance), balance)
|
|
await api.disconnect()
|
|
})
|
|
})
|
|
|
|
async function generate_faucet_wallet_and_fund_again(
|
|
client: string,
|
|
faucetHost: string | undefined = undefined,
|
|
faucetPath: string | undefined = undefined,
|
|
): Promise<void> {
|
|
const api = new Client(client)
|
|
|
|
await api.connect()
|
|
|
|
const { wallet, balance } = await api.fundWallet(null, {
|
|
faucetHost,
|
|
faucetPath,
|
|
})
|
|
assert.notEqual(wallet, undefined)
|
|
assert(isValidClassicAddress(wallet.classicAddress))
|
|
assert(isValidXAddress(wallet.getXAddress()))
|
|
|
|
const info = await api.request({
|
|
command: 'account_info',
|
|
account: wallet.classicAddress,
|
|
})
|
|
|
|
assert.equal(dropsToXrp(info.result.account_data.Balance), balance)
|
|
|
|
const { balance: newBalance } = await api.fundWallet(wallet, {
|
|
faucetHost,
|
|
faucetPath,
|
|
})
|
|
|
|
const afterSent = await api.request({
|
|
command: 'account_info',
|
|
account: wallet.classicAddress,
|
|
})
|
|
assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance)
|
|
|
|
assert(newBalance > balance)
|
|
|
|
await api.disconnect()
|
|
}
|