diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index fbfdd9b8..2a74acdd 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -2,12 +2,17 @@ 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`. + +### Changed +* Add support for Transaction objects in `verifyTransaction` ## 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/src/Wallet/index.ts b/packages/xrpl/src/Wallet/index.ts index a1b2ea88..48a66469 100644 --- a/packages/xrpl/src/Wallet/index.ts +++ b/packages/xrpl/src/Wallet/index.ts @@ -375,8 +375,11 @@ class Wallet { * @param signedTransaction - A signed transaction (hex string of signTransaction result) to be verified offline. * @returns Returns true if a signedTransaction is valid. */ - public verifyTransaction(signedTransaction: string): boolean { - const tx = decode(signedTransaction) + public verifyTransaction(signedTransaction: Transaction | string): boolean { + const tx = + typeof signedTransaction === 'string' + ? decode(signedTransaction) + : signedTransaction const messageHex: string = encodeForSigning(tx) const signature = tx.TxnSignature return verify(messageHex, signature, this.publicKey) 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() + }) }) diff --git a/packages/xrpl/test/wallet/index.ts b/packages/xrpl/test/wallet/index.ts index 38de31bb..957bcc26 100644 --- a/packages/xrpl/test/wallet/index.ts +++ b/packages/xrpl/test/wallet/index.ts @@ -1,5 +1,5 @@ import { assert } from 'chai' -import { decode } from 'ripple-binary-codec/dist' +import { decode } from 'ripple-binary-codec' import { NFTokenMint, Payment, Transaction } from 'xrpl-local' import ECDSA from 'xrpl-local/ECDSA' import Wallet from 'xrpl-local/Wallet' @@ -949,6 +949,16 @@ describe('Wallet', function () { assert.equal(isVerified, false) }) + + it('returns true when verifying a deserialized Transaction object', function () { + const wallet = new Wallet(publicKey, privateKey) + const decodedTransaction = decode( + prepared.signedTransaction, + ) as unknown as Transaction + const isVerified: boolean = wallet.verifyTransaction(decodedTransaction) + + assert.equal(isVerified, true) + }) }) describe('getXAddress', function () {