From 08180cb9354269f1e8c0ecd648aa0ac9059fc18c Mon Sep 17 00:00:00 2001 From: jonathanlei Date: Tue, 15 Nov 2022 14:31:46 -0800 Subject: [PATCH] add amount field to faucet (#2129) * add optional amount field to `fundWallet` --- packages/xrpl/HISTORY.md | 5 +++-- packages/xrpl/src/Wallet/fundWallet.ts | 4 ++++ packages/xrpl/test/integration/fundWallet.ts | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 0c14c152..d881d4a0 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -2,12 +2,13 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release. ## Unreleased - +### Added +* Optional custom amount field to `fundWallet`. ## 2.5.0 (2022-10-13) ### Added * Support for ExpandedSignerList amendment that expands the maximum signer list to 32 entries. * Add `cookie` and `data` to `ValidationStream` interface -* Addtional check for memos field format, provide more detailed error messages. +* Additional check for memos field format, provide more detailed error messages. ## 2.4.0 (2022-09-01) ### Added diff --git a/packages/xrpl/src/Wallet/fundWallet.ts b/packages/xrpl/src/Wallet/fundWallet.ts index 66e2c3ba..5ffa02e8 100644 --- a/packages/xrpl/src/Wallet/fundWallet.ts +++ b/packages/xrpl/src/Wallet/fundWallet.ts @@ -47,15 +47,18 @@ const MAX_ATTEMPTS = 20 * automatically. In other environments, or if you would like to customize the * faucet host in devnet or testnet, you should provide the host using this * option. + * @param options.amount - A custom amount to fund, if undefined or null, the default amount will be 1000. * @returns A Wallet on the Testnet or Devnet that contains some amount of XRP, * and that wallet's balance in XRP. * @throws When either Client isn't connected or unable to fund wallet address. */ +// eslint-disable-next-line max-lines-per-function -- this function needs to display and do with more information. async function fundWallet( this: Client, wallet?: Wallet | null, options?: { faucetHost?: string + amount?: string }, ): Promise<{ wallet: Wallet @@ -76,6 +79,7 @@ async function fundWallet( new TextEncoder().encode( JSON.stringify({ destination: walletToFund.classicAddress, + xrpAmount: options?.amount, }), ), ) diff --git a/packages/xrpl/test/integration/fundWallet.ts b/packages/xrpl/test/integration/fundWallet.ts index 837e3e9c..2eb190aa 100644 --- a/packages/xrpl/test/integration/fundWallet.ts +++ b/packages/xrpl/test/integration/fundWallet.ts @@ -129,4 +129,21 @@ describe('fundWallet', function () { await api.disconnect() }) + 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() + }) })