mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
feat: hooksv2 wallet inferencing (#2142)
Allow hooksv2 wallet inferencing
This commit is contained in:
@@ -11,7 +11,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* Add support for Transaction objects in `verifyTransaction`
|
* 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
|
* Ability to specify faucet url for wallet generation/funding purposes
|
||||||
|
|
||||||
## 2.5.0 (2022-10-13)
|
## 2.5.0 (2022-10-13)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export enum FaucetNetwork {
|
|||||||
Devnet = 'faucet.devnet.rippletest.net',
|
Devnet = 'faucet.devnet.rippletest.net',
|
||||||
AMMDevnet = 'ammfaucet.devnet.rippletest.net',
|
AMMDevnet = 'ammfaucet.devnet.rippletest.net',
|
||||||
NFTDevnet = 'faucet-nft.ripple.com',
|
NFTDevnet = 'faucet-nft.ripple.com',
|
||||||
|
HooksV2Testnet = 'hooks-testnet-v2.xrpl-labs.com',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FaucetNetworkPaths: Record<string, string> = {
|
export const FaucetNetworkPaths: Record<string, string> = {
|
||||||
@@ -23,6 +24,7 @@ export const FaucetNetworkPaths: Record<string, string> = {
|
|||||||
[FaucetNetwork.Devnet]: '/accounts',
|
[FaucetNetwork.Devnet]: '/accounts',
|
||||||
[FaucetNetwork.AMMDevnet]: '/accounts',
|
[FaucetNetwork.AMMDevnet]: '/accounts',
|
||||||
[FaucetNetwork.NFTDevnet]: '/accounts',
|
[FaucetNetwork.NFTDevnet]: '/accounts',
|
||||||
|
[FaucetNetwork.HooksV2Testnet]: '/accounts',
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +37,10 @@ export const FaucetNetworkPaths: Record<string, string> = {
|
|||||||
export function getFaucetHost(client: Client): FaucetNetwork | undefined {
|
export function getFaucetHost(client: Client): FaucetNetwork | undefined {
|
||||||
const connectionUrl = client.url
|
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
|
// 'altnet' for Ripple Testnet server and 'testnet' for XRPL Labs Testnet server
|
||||||
if (connectionUrl.includes('altnet') || connectionUrl.includes('testnet')) {
|
if (connectionUrl.includes('altnet') || connectionUrl.includes('testnet')) {
|
||||||
return FaucetNetwork.Testnet
|
return FaucetNetwork.Testnet
|
||||||
|
|||||||
@@ -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 wallet - An existing XRPL Wallet to fund. If undefined or null, a new Wallet will be created.
|
||||||
* @param options - See below.
|
* @param options - See below.
|
||||||
* @param options.faucetHost - A custom host for a faucet server. On devnet,
|
* @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,
|
* attempt to determine the correct server automatically. In other environments,
|
||||||
* or if you would like to customize the faucet host in devnet or testnet,
|
* or if you would like to customize the faucet host in devnet or testnet,
|
||||||
* you should provide the host using this option.
|
* you should provide the host using this option.
|
||||||
* @param options.faucetPath - A custom path for a faucet server. On devnet,
|
* @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,
|
* attempt to determine the correct path automatically. In other environments,
|
||||||
* or if you would like to customize the faucet path in devnet or testnet,
|
* or if you would like to customize the faucet path in devnet or testnet,
|
||||||
* you should provide the path using this option.
|
* you should provide the path using this option.
|
||||||
|
|||||||
@@ -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 () {
|
it('submit funds wallet with custom amount', async function () {
|
||||||
const api = new Client('wss://s.altnet.rippletest.net:51233')
|
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',
|
command: 'account_info',
|
||||||
account: wallet.classicAddress,
|
account: wallet.classicAddress,
|
||||||
})
|
})
|
||||||
assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance)
|
|
||||||
|
|
||||||
|
assert.equal(dropsToXrp(afterSent.result.account_data.Balance), newBalance)
|
||||||
assert(newBalance > balance)
|
assert(newBalance > balance)
|
||||||
|
|
||||||
await api.disconnect()
|
await api.disconnect()
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ describe('Get Faucet host ', function () {
|
|||||||
assert.strictEqual(getFaucetHost(this.client), expectedFaucet)
|
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 () {
|
it('returns the correct faucetPath for Devnet host', function () {
|
||||||
const expectedFaucetPath = FaucetNetworkPaths[FaucetNetwork.Devnet]
|
const expectedFaucetPath = FaucetNetworkPaths[FaucetNetwork.Devnet]
|
||||||
this.client.connection.url = 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 () {
|
it('returns the correct faucetPath for undefined host', function () {
|
||||||
const expectedFaucetPath = '/accounts'
|
const expectedFaucetPath = '/accounts'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user