diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 07a598dc..18c6aec7 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -11,7 +11,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ### Changed * Add support for Transaction objects in `verifyTransaction` -* When connected to amm devnet, Client.fundWallet now defaults to using the faucet instead of requiring specification. +* When connected to hooks v2 testnet or amm devnet, Client.fundWallet now defaults to using the faucet instead of requiring specification. * Ability to specify faucet url for wallet generation/funding purposes ## 2.5.0 (2022-10-13) diff --git a/packages/xrpl/src/Wallet/defaultFaucets.ts b/packages/xrpl/src/Wallet/defaultFaucets.ts index f6d9a253..5624e1f0 100644 --- a/packages/xrpl/src/Wallet/defaultFaucets.ts +++ b/packages/xrpl/src/Wallet/defaultFaucets.ts @@ -16,6 +16,7 @@ export enum FaucetNetwork { Devnet = 'faucet.devnet.rippletest.net', AMMDevnet = 'ammfaucet.devnet.rippletest.net', NFTDevnet = 'faucet-nft.ripple.com', + HooksV2Testnet = 'hooks-testnet-v2.xrpl-labs.com', } export const FaucetNetworkPaths: Record = { @@ -23,6 +24,7 @@ export const FaucetNetworkPaths: Record = { [FaucetNetwork.Devnet]: '/accounts', [FaucetNetwork.AMMDevnet]: '/accounts', [FaucetNetwork.NFTDevnet]: '/accounts', + [FaucetNetwork.HooksV2Testnet]: '/accounts', } /** @@ -35,6 +37,10 @@ export const FaucetNetworkPaths: Record = { export function getFaucetHost(client: Client): FaucetNetwork | undefined { const connectionUrl = client.url + if (connectionUrl.includes('hooks-testnet-v2')) { + return FaucetNetwork.HooksV2Testnet + } + // 'altnet' for Ripple Testnet server and 'testnet' for XRPL Labs Testnet server if (connectionUrl.includes('altnet') || connectionUrl.includes('testnet')) { return FaucetNetwork.Testnet diff --git a/packages/xrpl/src/Wallet/fundWallet.ts b/packages/xrpl/src/Wallet/fundWallet.ts index 09f09955..5cac2f14 100644 --- a/packages/xrpl/src/Wallet/fundWallet.ts +++ b/packages/xrpl/src/Wallet/fundWallet.ts @@ -33,12 +33,12 @@ const MAX_ATTEMPTS = 20 * @param wallet - An existing XRPL Wallet to fund. If undefined or null, a new Wallet will be created. * @param options - See below. * @param options.faucetHost - A custom host for a faucet server. On devnet, - * testnet, AMM devnet, NFT devnet testnet, `fundWallet` will + * testnet, AMM devnet, NFT devnet, and HooksV2 testnet, `fundWallet` will * attempt to determine the correct server 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.faucetPath - A custom path for a faucet server. On devnet, - * testnet, AMM devnet, NFT devnet testnet, `fundWallet` will + * testnet, AMM devnet, NFT devnet, and HooksV2 testnet, `fundWallet` will * attempt to determine the correct path automatically. In other environments, * or if you would like to customize the faucet path in devnet or testnet, * you should provide the path using this option. diff --git a/packages/xrpl/test/integration/fundWallet.ts b/packages/xrpl/test/integration/fundWallet.ts index fca2d50a..3bdf3096 100644 --- a/packages/xrpl/test/integration/fundWallet.ts +++ b/packages/xrpl/test/integration/fundWallet.ts @@ -46,6 +46,34 @@ describe('fundWallet', function () { ) }) + it('can generate wallet on hooks v2 testnet', async function () { + const api = new Client('wss://hooks-testnet-v2.xrpl-labs.com') + + 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) + assert.equal(balance, 10000) + + /* + * No test for fund given wallet because the hooks v2 testnet faucet + * requires 10 seconds between requests. Would significantly slow down + * the test suite. + */ + + await api.disconnect() + }) + it('submit funds wallet with custom amount', async function () { const api = new Client('wss://s.altnet.rippletest.net:51233') @@ -98,8 +126,8 @@ async function generate_faucet_wallet_and_fund_again( command: 'account_info', account: wallet.classicAddress, }) - assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance) + assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance) assert(newBalance > balance) await api.disconnect() diff --git a/packages/xrpl/test/wallet/fundWallet.ts b/packages/xrpl/test/wallet/fundWallet.ts index b4ca41a6..0adf0a00 100644 --- a/packages/xrpl/test/wallet/fundWallet.ts +++ b/packages/xrpl/test/wallet/fundWallet.ts @@ -40,6 +40,13 @@ describe('Get Faucet host ', function () { assert.strictEqual(getFaucetHost(this.client), expectedFaucet) }) + it('returns the Hooks V2 Testnet host', function () { + const expectedFaucet = FaucetNetwork.HooksV2Testnet + this.client.connection.url = FaucetNetwork.HooksV2Testnet + + 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 @@ -50,6 +57,16 @@ describe('Get Faucet host ', function () { ) }) + it('returns the correct faucetPath for Hooks V2 Testnet host', function () { + const expectedFaucetPath = FaucetNetworkPaths[FaucetNetwork.HooksV2Testnet] + this.client.connection.url = FaucetNetwork.HooksV2Testnet + + assert.strictEqual( + getDefaultFaucetPath(getFaucetHost(this.client)), + expectedFaucetPath, + ) + }) + it('returns the correct faucetPath for undefined host', function () { const expectedFaucetPath = '/accounts'