feat: amm devnet to fundWallet and custom faucetPaths (#2083)

* Add amm devnet support

* Add option for faucet paths

Co-authored-by: Jackson Mills <aim4math@gmail.com>
This commit is contained in:
Connor Chen
2022-11-18 14:54:23 -05:00
committed by GitHub
parent a4c2bb998f
commit 5f5f06f1ab
6 changed files with 205 additions and 179 deletions

View File

@@ -4,7 +4,7 @@ import path from 'path'
import { expect, assert } from 'chai'
import puppeteer from 'puppeteer'
const TIMEOUT = 80000
const TIMEOUT = 150000
interface TestCaseInfo {
name: string
span: string

View File

@@ -7,6 +7,7 @@ import {
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.
@@ -14,121 +15,37 @@ describe('fundWallet', function () {
this.timeout(TIMEOUT)
it('submit generates a testnet wallet', async function () {
const api = new Client('wss://s.altnet.rippletest.net:51233')
await api.connect()
const { wallet, balance } = await api.fundWallet()
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)
const afterSent = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance)
await api.disconnect()
await generate_faucet_wallet_and_fund_again(
'wss://s.altnet.rippletest.net:51233',
)
})
it('submit generates a devnet wallet', async function () {
const api = new Client('wss://s.devnet.rippletest.net:51233')
await api.connect()
const { wallet, balance } = await api.fundWallet()
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)
const afterSent = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance)
await api.disconnect()
await generate_faucet_wallet_and_fund_again(
'wss://s.devnet.rippletest.net:51233',
)
})
it('can generate and fund wallets on nft-devnet', async function () {
const api = new Client('ws://xls20-sandbox.rippletest.net:51233')
await api.connect()
const { wallet, balance } = await api.fundWallet()
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: 'faucet-nft.ripple.com',
})
const afterSent = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance)
await api.disconnect()
await generate_faucet_wallet_and_fund_again(
'ws://xls20-sandbox.rippletest.net:51233',
)
})
it('can generate and fund wallets using a custom host', async function () {
const api = new Client('ws://xls20-sandbox.rippletest.net:51233')
await api.connect()
const { wallet, balance } = await api.fundWallet(null, {
faucetHost: 'faucet-nft.ripple.com',
})
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: 'faucet-nft.ripple.com',
})
const afterSent = await api.request({
command: 'account_info',
account: wallet.classicAddress,
})
assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance)
await api.disconnect()
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')
@@ -147,3 +64,43 @@ describe('fundWallet', function () {
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()
}

View File

@@ -1,10 +1,13 @@
import { assert } from 'chai'
import { _private } from '../../src/Wallet/fundWallet'
import {
FaucetNetwork,
FaucetNetworkPaths,
getFaucetHost,
getDefaultFaucetPath,
} from '../../src/Wallet/defaultFaucets'
import { setupClient, teardownClient } from '../setupClient'
const { FaucetNetwork, getFaucetHost } = _private
describe('Get Faucet host ', function () {
beforeEach(setupClient)
afterEach(teardownClient)
@@ -30,7 +33,30 @@ describe('Get Faucet host ', function () {
assert.strictEqual(getFaucetHost(this.client), expectedFaucet)
})
it('returns undefined if not a Testnet or Devnet server URL', function () {
it('returns the NFT-Devnet host with the XLS-20 Sandbox server', function () {
const expectedFaucet = FaucetNetwork.NFTDevnet
this.client.connection.url = 'ws://xls20-sandbox.rippletest.net:51233'
assert.strictEqual(getFaucetHost(this.client), expectedFaucet)
})
it('returns the correct faucetPath for Devnet host', function () {
const expectedFaucetPath = FaucetNetworkPaths[FaucetNetwork.Devnet]
this.client.connection.url = FaucetNetwork.Devnet
assert.strictEqual(
getDefaultFaucetPath(getFaucetHost(this.client)),
expectedFaucetPath,
)
})
it('returns the correct faucetPath for undefined host', function () {
const expectedFaucetPath = '/accounts'
assert.strictEqual(getDefaultFaucetPath(undefined), expectedFaucetPath)
})
it('throws if not connected to a known faucet host', function () {
// Info: setupClient.setup creates a connection to 'localhost'
assert.throws(() => getFaucetHost(this.client))
})