feat: hooksv2 wallet inferencing (#2142)

Allow hooksv2 wallet inferencing
This commit is contained in:
Connor Chen
2022-11-21 16:51:41 -05:00
committed by GitHub
parent 5f5f06f1ab
commit 8921b6ac93
5 changed files with 55 additions and 4 deletions

View File

@@ -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)

View File

@@ -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<string, string> = {
@@ -23,6 +24,7 @@ export const FaucetNetworkPaths: Record<string, string> = {
[FaucetNetwork.Devnet]: '/accounts',
[FaucetNetwork.AMMDevnet]: '/accounts',
[FaucetNetwork.NFTDevnet]: '/accounts',
[FaucetNetwork.HooksV2Testnet]: '/accounts',
}
/**
@@ -35,6 +37,10 @@ export const FaucetNetworkPaths: Record<string, string> = {
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

View File

@@ -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.

View File

@@ -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()

View File

@@ -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'