fix: fix error handling in generateFaucetWallet (#1671)

* fix: handle error correctly in generateFaucetWallet
* test: Adds generateFaucetWallet integration + browser tests
This commit is contained in:
Nathan Nichols
2021-09-27 13:05:15 -07:00
committed by Mayukha Vadari
parent edcdd3a0fc
commit 9e3654d7d6
6 changed files with 98 additions and 15 deletions

View File

@@ -0,0 +1,64 @@
import assert from 'assert'
import _ from 'lodash'
import { Client, isValidClassicAddress, isValidXAddress } 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('generateFaucetWallet', 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 = await api.generateFaucetWallet()
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(info.result.account_data.Balance, '1000000000')
await api.generateFaucetWallet(wallet)
const afterSent = await api.request({
command: 'account_info',
account: wallet?.classicAddress ?? '',
})
assert.equal(afterSent.result.account_data.Balance, '2000000000')
await api.disconnect()
})
it('submit generates a devnet wallet', async function () {
const api = new Client('wss://s.devnet.rippletest.net:51233')
await api.connect()
const wallet = await api.generateFaucetWallet()
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(info.result.account_data.Balance, '1000000000')
await api.generateFaucetWallet(wallet)
const afterSent = await api.request({
command: 'account_info',
account: wallet?.classicAddress ?? '',
})
assert.equal(afterSent.result.account_data.Balance, '2000000000')
await api.disconnect()
})
})