mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-25 14:45:48 +00:00
amendment-xls34d
add transfer rate Update definitions.json update test error text update validation error fix undefined validation switch claim signing order, update claim object update workflow docker tests (paychan + escrow) add ic gateway (test) add faucet update sdk fixup git-workflow
This commit is contained in:
@@ -11,6 +11,7 @@ import { STObject } from './types/st-object'
|
|||||||
import { JsonObject } from './types/serialized-type'
|
import { JsonObject } from './types/serialized-type'
|
||||||
import { Buffer } from 'buffer/'
|
import { Buffer } from 'buffer/'
|
||||||
import * as bigInt from 'big-integer'
|
import * as bigInt from 'big-integer'
|
||||||
|
import { Amount } from './types/amount'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a BinaryParser
|
* Construct a BinaryParser
|
||||||
@@ -93,9 +94,9 @@ function signingData(
|
|||||||
/**
|
/**
|
||||||
* Interface describing fields required for a Claim
|
* Interface describing fields required for a Claim
|
||||||
*/
|
*/
|
||||||
interface ClaimObject extends JsonObject {
|
interface ClaimObject {
|
||||||
channel: string
|
channel: string
|
||||||
amount: string | number
|
amount: Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,13 +106,19 @@ interface ClaimObject extends JsonObject {
|
|||||||
* @returns the serialized object with appropriate prefix
|
* @returns the serialized object with appropriate prefix
|
||||||
*/
|
*/
|
||||||
function signingClaimData(claim: ClaimObject): Buffer {
|
function signingClaimData(claim: ClaimObject): Buffer {
|
||||||
const num = bigInt(String(claim.amount))
|
|
||||||
const prefix = HashPrefix.paymentChannelClaim
|
const prefix = HashPrefix.paymentChannelClaim
|
||||||
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
|
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
|
||||||
const amount = coreTypes.UInt64.from(num).toBytes()
|
if (typeof claim.amount === 'object') {
|
||||||
|
const amount = coreTypes.Amount.from(claim.amount).toBytes()
|
||||||
|
const bytesList = new BytesList()
|
||||||
|
bytesList.put(prefix)
|
||||||
|
bytesList.put(channel)
|
||||||
|
bytesList.put(amount)
|
||||||
|
return bytesList.toBytes()
|
||||||
|
}
|
||||||
|
const num = bigInt(String(claim.amount))
|
||||||
const bytesList = new BytesList()
|
const bytesList = new BytesList()
|
||||||
|
const amount = coreTypes.UInt64.from(num).toBytes()
|
||||||
bytesList.put(prefix)
|
bytesList.put(prefix)
|
||||||
bytesList.put(channel)
|
bytesList.put(channel)
|
||||||
bytesList.put(amount)
|
bytesList.put(amount)
|
||||||
|
|||||||
@@ -761,6 +761,16 @@
|
|||||||
"type": "UInt32"
|
"type": "UInt32"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"LockCount",
|
||||||
|
{
|
||||||
|
"nth": 47,
|
||||||
|
"isVLEncoded": false,
|
||||||
|
"isSerialized": true,
|
||||||
|
"isSigningField": true,
|
||||||
|
"type": "UInt32"
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"IndexNext",
|
"IndexNext",
|
||||||
{
|
{
|
||||||
@@ -1421,6 +1431,16 @@
|
|||||||
"type": "Amount"
|
"type": "Amount"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"LockedBalance",
|
||||||
|
{
|
||||||
|
"nth": 21,
|
||||||
|
"isVLEncoded": false,
|
||||||
|
"isSerialized": true,
|
||||||
|
"isSigningField": true,
|
||||||
|
"type": "Amount"
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"PublicKey",
|
"PublicKey",
|
||||||
{
|
{
|
||||||
@@ -2298,7 +2318,8 @@
|
|||||||
"tecCANT_ACCEPT_OWN_NFTOKEN_OFFER": 158,
|
"tecCANT_ACCEPT_OWN_NFTOKEN_OFFER": 158,
|
||||||
"tecINSUFFICIENT_FUNDS": 159,
|
"tecINSUFFICIENT_FUNDS": 159,
|
||||||
"tecOBJECT_NOT_FOUND": 160,
|
"tecOBJECT_NOT_FOUND": 160,
|
||||||
"tecINSUFFICIENT_PAYMENT": 161
|
"tecINSUFFICIENT_PAYMENT": 161,
|
||||||
|
"tecPRECISION_LOSS": 162
|
||||||
},
|
},
|
||||||
"TRANSACTION_TYPES": {
|
"TRANSACTION_TYPES": {
|
||||||
"Invalid": -1,
|
"Invalid": -1,
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ describe('Signing data', function () {
|
|||||||
].join(''),
|
].join(''),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
test('can create claim blob', function () {
|
test('can create native claim blob', function () {
|
||||||
const channel =
|
const channel =
|
||||||
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
|
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
|
||||||
const amount = '1000'
|
const amount = '1000'
|
||||||
@@ -137,4 +137,27 @@ describe('Signing data', function () {
|
|||||||
].join(''),
|
].join(''),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
test('can create ic claim blob', function () {
|
||||||
|
const channel =
|
||||||
|
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
|
||||||
|
const amount = {
|
||||||
|
issuer: 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN',
|
||||||
|
currency: 'USD',
|
||||||
|
value: '10',
|
||||||
|
}
|
||||||
|
const json = { channel, amount }
|
||||||
|
const actual = encodeForSigningClaim(json)
|
||||||
|
expect(actual).toBe(
|
||||||
|
[
|
||||||
|
// hash prefix
|
||||||
|
'434C4D00',
|
||||||
|
// channel ID
|
||||||
|
'43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1',
|
||||||
|
// amount as a uint64
|
||||||
|
'D4C38D7EA4C680000000000000000000000000005553440000000000C0A5ABEF',
|
||||||
|
// amount as a uint64
|
||||||
|
'242802EFED4B041E8F2D4A8CC86AE3D1',
|
||||||
|
].join(''),
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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',
|
||||||
|
Icv2 = 'icv2.faucet.transia.co',
|
||||||
HooksV2Testnet = 'hooks-testnet-v2.xrpl-labs.com',
|
HooksV2Testnet = 'hooks-testnet-v2.xrpl-labs.com',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,6 +25,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.Icv2]: '/accounts',
|
||||||
[FaucetNetwork.HooksV2Testnet]: '/accounts',
|
[FaucetNetwork.HooksV2Testnet]: '/accounts',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +60,10 @@ export function getFaucetHost(client: Client): FaucetNetwork | undefined {
|
|||||||
return FaucetNetwork.NFTDevnet
|
return FaucetNetwork.NFTDevnet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connectionUrl.includes('icv2')) {
|
||||||
|
return FaucetNetwork.Icv2
|
||||||
|
}
|
||||||
|
|
||||||
throw new XRPLFaucetError('Faucet URL is not defined or inferrable.')
|
throw new XRPLFaucetError('Faucet URL is not defined or inferrable.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { Amount } from '../common'
|
||||||
|
|
||||||
import BaseLedgerEntry from './BaseLedgerEntry'
|
import BaseLedgerEntry from './BaseLedgerEntry'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,8 +21,8 @@ export default interface Escrow extends BaseLedgerEntry {
|
|||||||
* successful.
|
* successful.
|
||||||
*/
|
*/
|
||||||
Destination: string
|
Destination: string
|
||||||
/** The amount of XRP, in drops, to be delivered by the held payment. */
|
/** The amount of XRP/FT, as drops/Amount, to be delivered by the held payment. */
|
||||||
Amount: string
|
Amount: Amount
|
||||||
/**
|
/**
|
||||||
* A PREIMAGE-SHA-256 crypto-condition, as hexadecimal. If present, the
|
* A PREIMAGE-SHA-256 crypto-condition, as hexadecimal. If present, the
|
||||||
* EscrowFinish transaction must contain a fulfillment that satisfies this
|
* EscrowFinish transaction must contain a fulfillment that satisfies this
|
||||||
@@ -71,4 +73,9 @@ export default interface Escrow extends BaseLedgerEntry {
|
|||||||
* modified this object.
|
* modified this object.
|
||||||
*/
|
*/
|
||||||
PreviousTxnLgrSeq: number
|
PreviousTxnLgrSeq: number
|
||||||
|
/**
|
||||||
|
* The fee to charge when users finish an escrow, initially set on the
|
||||||
|
* creation of an escrow contract, and updated on subsequent finish transactions
|
||||||
|
*/
|
||||||
|
TransferRate?: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ export default interface PayChannel extends BaseLedgerEntry {
|
|||||||
*/
|
*/
|
||||||
Account: string
|
Account: string
|
||||||
/**
|
/**
|
||||||
* The destination address for this payment channel. While the payment
|
* Total XRP/FT, as drops/Amount, that has been allocated to this channel.
|
||||||
* channel is open, this address is the only one that can receive XRP from the
|
* This includes XRP/FT that has been paid to the destination address.
|
||||||
* channel. This comes from the Destination field of the transaction that
|
* This is initially set by the transaction that created the channel and can
|
||||||
* created the channel.
|
* be increased if the source address sends a PaymentChannelFund transaction.
|
||||||
*/
|
*/
|
||||||
Destination: string
|
Destination: string
|
||||||
/**
|
/**
|
||||||
@@ -31,10 +31,11 @@ export default interface PayChannel extends BaseLedgerEntry {
|
|||||||
*/
|
*/
|
||||||
Amount: string
|
Amount: string
|
||||||
/**
|
/**
|
||||||
* Total XRP, in drops, already paid out by the channel. The difference
|
* Total XRP/FT, as drops/Amount, already paid out by the channel. The
|
||||||
* between this value and the Amount field is how much XRP can still be paid
|
* difference between this value and the Amount field is how much XRP/FT
|
||||||
* to the destination address with PaymentChannelClaim transactions. If the
|
* can still be paid to the destination address with PaymentChannelClaim
|
||||||
* channel closes, the remaining difference is returned to the source address.
|
* transactions. If the channel closes, the remaining difference is returned
|
||||||
|
* to the source address.
|
||||||
*/
|
*/
|
||||||
Balance: string
|
Balance: string
|
||||||
/**
|
/**
|
||||||
@@ -104,4 +105,10 @@ export default interface PayChannel extends BaseLedgerEntry {
|
|||||||
* this object, in case the directory consists of multiple pages.
|
* this object, in case the directory consists of multiple pages.
|
||||||
*/
|
*/
|
||||||
DestinationNode?: string
|
DestinationNode?: string
|
||||||
|
/**
|
||||||
|
* The fee to charge when users make claims on a payment channel, initially
|
||||||
|
* set on the creation of a payment channel and updated on subsequent funding
|
||||||
|
* or claim transactions.
|
||||||
|
*/
|
||||||
|
TransferRate?: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { LedgerIndex } from '../common'
|
import { Amount, LedgerIndex } from '../common'
|
||||||
|
|
||||||
import { BaseRequest, BaseResponse } from './baseMethod'
|
import { BaseRequest, BaseResponse } from './baseMethod'
|
||||||
|
|
||||||
interface Channel {
|
interface Channel {
|
||||||
account: string
|
account: string
|
||||||
amount: string
|
amount: Amount
|
||||||
balance: string
|
balance: string
|
||||||
channel_id: string
|
channel_id: string
|
||||||
destination_account: string
|
destination_account: string
|
||||||
@@ -15,6 +15,7 @@ interface Channel {
|
|||||||
cancel_after?: number
|
cancel_after?: number
|
||||||
source_tab?: number
|
source_tab?: number
|
||||||
destination_tag?: number
|
destination_tag?: number
|
||||||
|
transfer_rate?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LedgerIndex } from '../common'
|
import { Amount, LedgerIndex } from '../common'
|
||||||
|
|
||||||
import { BaseRequest, BaseResponse } from './baseMethod'
|
import { BaseRequest, BaseResponse } from './baseMethod'
|
||||||
|
|
||||||
@@ -64,6 +64,14 @@ export interface Trustline {
|
|||||||
* false.
|
* false.
|
||||||
*/
|
*/
|
||||||
freeze_peer?: boolean
|
freeze_peer?: boolean
|
||||||
|
/**
|
||||||
|
* The total amount of FT, in drops/Amount locked in payment channels or escrow.
|
||||||
|
*/
|
||||||
|
locked_balance?: Amount
|
||||||
|
/**
|
||||||
|
* The total number of lock balances on a RippleState ledger object.
|
||||||
|
*/
|
||||||
|
lock_count?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable complexity -- Necessary for validateEscrowCreate */
|
/* eslint-disable complexity -- Necessary for validateEscrowCreate */
|
||||||
import { ValidationError } from '../../errors'
|
import { ValidationError } from '../../errors'
|
||||||
|
import { Amount } from '../common'
|
||||||
|
|
||||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ export interface EscrowCreate extends BaseTransaction {
|
|||||||
* Once escrowed, the XRP can either go to the Destination address (after the.
|
* Once escrowed, the XRP can either go to the Destination address (after the.
|
||||||
* FinishAfter time) or returned to the sender (after the CancelAfter time).
|
* FinishAfter time) or returned to the sender (after the CancelAfter time).
|
||||||
*/
|
*/
|
||||||
Amount: string
|
Amount: Amount
|
||||||
/** Address to receive escrowed XRP. */
|
/** Address to receive escrowed XRP. */
|
||||||
Destination: string
|
Destination: string
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
/* eslint-disable complexity -- Necessary for validatePaymentChannelClaim */
|
/* eslint-disable complexity -- Necessary for validatePaymentChannelClaim */
|
||||||
import { ValidationError } from '../../errors'
|
import { ValidationError } from '../../errors'
|
||||||
|
import { Amount } from '../common'
|
||||||
|
|
||||||
import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
|
import {
|
||||||
|
BaseTransaction,
|
||||||
|
GlobalFlags,
|
||||||
|
validateBaseTransaction,
|
||||||
|
isAmount,
|
||||||
|
} from './common'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum representing values for PaymentChannelClaim transaction flags.
|
* Enum representing values for PaymentChannelClaim transaction flags.
|
||||||
@@ -108,13 +114,13 @@ export interface PaymentChannelClaim extends BaseTransaction {
|
|||||||
* delivered by the channel so far, but not greater than the Amount of the
|
* delivered by the channel so far, but not greater than the Amount of the
|
||||||
* signed claim. Must be provided except when closing the channel.
|
* signed claim. Must be provided except when closing the channel.
|
||||||
*/
|
*/
|
||||||
Balance?: string
|
Balance?: Amount
|
||||||
/**
|
/**
|
||||||
* The amount of XRP, in drops, authorized by the Signature. This must match
|
* The amount of XRP, in drops, authorized by the Signature. This must match
|
||||||
* the amount in the signed message. This is the cumulative amount of XRP that
|
* the amount in the signed message. This is the cumulative amount of XRP that
|
||||||
* can be dispensed by the channel, including XRP previously redeemed.
|
* can be dispensed by the channel, including XRP previously redeemed.
|
||||||
*/
|
*/
|
||||||
Amount?: string
|
Amount?: Amount
|
||||||
/**
|
/**
|
||||||
* The signature of this claim, as hexadecimal. The signed message contains
|
* The signature of this claim, as hexadecimal. The signed message contains
|
||||||
* the channel ID and the amount of the claim. Required unless the sender of
|
* the channel ID and the amount of the claim. Required unless the sender of
|
||||||
@@ -147,12 +153,20 @@ export function validatePaymentChannelClaim(tx: Record<string, unknown>): void {
|
|||||||
throw new ValidationError('PaymentChannelClaim: Channel must be a string')
|
throw new ValidationError('PaymentChannelClaim: Channel must be a string')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx.Balance !== undefined && typeof tx.Balance !== 'string') {
|
if (
|
||||||
throw new ValidationError('PaymentChannelClaim: Balance must be a string')
|
tx.Balance !== undefined &&
|
||||||
|
typeof tx.Balance !== 'string' &&
|
||||||
|
!isAmount(tx.Balance)
|
||||||
|
) {
|
||||||
|
throw new ValidationError('PaymentChannelClaim: invalid Balance')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx.Amount !== undefined && typeof tx.Amount !== 'string') {
|
if (
|
||||||
throw new ValidationError('PaymentChannelClaim: Amount must be a string')
|
tx.Amount !== undefined &&
|
||||||
|
typeof tx.Amount !== 'string' &&
|
||||||
|
!isAmount(tx.Amount)
|
||||||
|
) {
|
||||||
|
throw new ValidationError('PaymentChannelClaim: invalid Amount')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx.Signature !== undefined && typeof tx.Signature !== 'string') {
|
if (tx.Signature !== undefined && typeof tx.Signature !== 'string') {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/* eslint-disable complexity -- Necessary for validatePaymentChannelCreate */
|
/* eslint-disable complexity -- Necessary for validatePaymentChannelCreate */
|
||||||
import { ValidationError } from '../../errors'
|
import { ValidationError } from '../../errors'
|
||||||
|
import { Amount } from '../common'
|
||||||
|
|
||||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
import { BaseTransaction, validateBaseTransaction, isAmount } from './common'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a unidirectional channel and fund it with XRP. The address sending
|
* Create a unidirectional channel and fund it with XRP. The address sending
|
||||||
@@ -17,7 +18,7 @@ export interface PaymentChannelCreate extends BaseTransaction {
|
|||||||
* Destination address. When the channel closes, any unclaimed XRP is returned
|
* Destination address. When the channel closes, any unclaimed XRP is returned
|
||||||
* to the source address's balance.
|
* to the source address's balance.
|
||||||
*/
|
*/
|
||||||
Amount: string
|
Amount: Amount
|
||||||
/**
|
/**
|
||||||
* Address to receive XRP claims against this channel. This is also known as
|
* Address to receive XRP claims against this channel. This is also known as
|
||||||
* the "destination address" for the channel.
|
* the "destination address" for the channel.
|
||||||
@@ -65,8 +66,8 @@ export function validatePaymentChannelCreate(
|
|||||||
throw new ValidationError('PaymentChannelCreate: missing Amount')
|
throw new ValidationError('PaymentChannelCreate: missing Amount')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof tx.Amount !== 'string') {
|
if (typeof tx.Amount !== 'string' && !isAmount(tx.Amount)) {
|
||||||
throw new ValidationError('PaymentChannelCreate: Amount must be a string')
|
throw new ValidationError('PaymentChannelCreate: invalid Amount')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx.Destination === undefined) {
|
if (tx.Destination === undefined) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ValidationError } from '../../errors'
|
import { ValidationError } from '../../errors'
|
||||||
|
import { Amount } from '../common'
|
||||||
|
|
||||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
import { BaseTransaction, validateBaseTransaction, isAmount } from './common'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add additional XRP to an open payment channel, and optionally update the
|
* Add additional XRP to an open payment channel, and optionally update the
|
||||||
@@ -20,7 +21,7 @@ export interface PaymentChannelFund extends BaseTransaction {
|
|||||||
* Amount of XRP in drops to add to the channel. Must be a positive amount
|
* Amount of XRP in drops to add to the channel. Must be a positive amount
|
||||||
* of XRP.
|
* of XRP.
|
||||||
*/
|
*/
|
||||||
Amount: string
|
Amount: Amount
|
||||||
/**
|
/**
|
||||||
* New Expiration time to set for the channel in seconds since the Ripple
|
* New Expiration time to set for the channel in seconds since the Ripple
|
||||||
* Epoch. This must be later than either the current time plus the SettleDelay
|
* Epoch. This must be later than either the current time plus the SettleDelay
|
||||||
@@ -55,8 +56,8 @@ export function validatePaymentChannelFund(tx: Record<string, unknown>): void {
|
|||||||
throw new ValidationError('PaymentChannelFund: missing Amount')
|
throw new ValidationError('PaymentChannelFund: missing Amount')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof tx.Amount !== 'string') {
|
if (typeof tx.Amount !== 'string' && !isAmount(tx.Amount)) {
|
||||||
throw new ValidationError('PaymentChannelFund: Amount must be a string')
|
throw new ValidationError('PaymentChannelFund: invalid Amount')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx.Expiration !== undefined && typeof tx.Expiration !== 'number') {
|
if (tx.Expiration !== undefined && typeof tx.Expiration !== 'number') {
|
||||||
|
|||||||
@@ -46,6 +46,14 @@ describe('fundWallet', function () {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can generate and fund wallets on icv2 net', async function () {
|
||||||
|
await generate_faucet_wallet_and_fund_again(
|
||||||
|
'wss://icv2.ws.transia.co',
|
||||||
|
'icv2.faucet.transia.co',
|
||||||
|
'/accounts',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('can generate wallet on hooks v2 testnet', async function () {
|
it('can generate wallet on hooks v2 testnet', async function () {
|
||||||
const api = new Client('wss://hooks-testnet-v2.xrpl-labs.com')
|
const api = new Client('wss://hooks-testnet-v2.xrpl-labs.com')
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,132 @@
|
|||||||
import { Client, Wallet } from 'xrpl-local'
|
import { AccountSet, Client, Payment, TrustSet, Wallet } from 'xrpl-local'
|
||||||
|
|
||||||
import serverUrl from './serverUrl'
|
import serverUrl from './serverUrl'
|
||||||
import { fundAccount } from './utils'
|
import { fundAccount, ledgerAccept } from './utils'
|
||||||
|
|
||||||
export async function teardownClient(this: Mocha.Context): Promise<void> {
|
export async function teardownClient(this: Mocha.Context): Promise<void> {
|
||||||
this.client.removeAllListeners()
|
this.client.removeAllListeners()
|
||||||
this.client.disconnect()
|
this.client.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line max-params -- need comments
|
||||||
|
async function initIC(
|
||||||
|
client: Client,
|
||||||
|
wallet: Wallet,
|
||||||
|
destination: Wallet,
|
||||||
|
gateway: Wallet,
|
||||||
|
): Promise<void> {
|
||||||
|
const atx: AccountSet = {
|
||||||
|
TransactionType: 'AccountSet',
|
||||||
|
Account: gateway.classicAddress,
|
||||||
|
SetFlag: 8,
|
||||||
|
}
|
||||||
|
const atxr = await client.submit(atx, {
|
||||||
|
wallet: gateway,
|
||||||
|
})
|
||||||
|
if (atxr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(atxr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const wtl: TrustSet = {
|
||||||
|
TransactionType: 'TrustSet',
|
||||||
|
Account: wallet.classicAddress,
|
||||||
|
LimitAmount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '100000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const wtlr = await client.submit(wtl, {
|
||||||
|
wallet,
|
||||||
|
})
|
||||||
|
if (wtlr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(wtlr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const dtl: TrustSet = {
|
||||||
|
TransactionType: 'TrustSet',
|
||||||
|
Account: destination.classicAddress,
|
||||||
|
LimitAmount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '100000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const dtlr = await client.submit(dtl, {
|
||||||
|
wallet: destination,
|
||||||
|
})
|
||||||
|
if (wtlr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(dtlr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const wp: Payment = {
|
||||||
|
TransactionType: 'Payment',
|
||||||
|
Account: gateway.classicAddress,
|
||||||
|
Destination: wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '10000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const wpr = await client.submit(wp, {
|
||||||
|
wallet: gateway,
|
||||||
|
})
|
||||||
|
if (wpr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(wpr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
|
||||||
|
const dp: Payment = {
|
||||||
|
TransactionType: 'Payment',
|
||||||
|
Account: gateway.classicAddress,
|
||||||
|
Destination: destination.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: gateway.classicAddress,
|
||||||
|
value: '10000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const dpr = await client.submit(dp, {
|
||||||
|
wallet: gateway,
|
||||||
|
})
|
||||||
|
if (dpr.result.engine_result !== 'tesSUCCESS') {
|
||||||
|
// eslint-disable-next-line no-console -- happens only when something goes wrong
|
||||||
|
console.log(dpr)
|
||||||
|
}
|
||||||
|
await ledgerAccept(client)
|
||||||
|
}
|
||||||
|
|
||||||
export async function setupClient(
|
export async function setupClient(
|
||||||
this: Mocha.Context,
|
this: Mocha.Context,
|
||||||
server = serverUrl,
|
server = serverUrl,
|
||||||
|
ic?: boolean | false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this.wallet = Wallet.generate()
|
this.wallet = Wallet.generate()
|
||||||
|
this.destination = Wallet.generate()
|
||||||
|
this.gateway = Wallet.generate()
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
this.client = new Client(server)
|
this.client = new Client(server)
|
||||||
this.client
|
this.client
|
||||||
.connect()
|
.connect()
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
await fundAccount(this.client, this.wallet)
|
await fundAccount(this.client, this.wallet)
|
||||||
|
await fundAccount(this.client, this.destination)
|
||||||
|
await fundAccount(this.client, this.gateway)
|
||||||
|
if (ic) {
|
||||||
|
await initIC(this.client, this.wallet, this.destination, this.gateway)
|
||||||
|
}
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
.catch(reject)
|
.catch(reject)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe('EscrowCreate', function () {
|
|||||||
beforeEach(_.partial(setupClient, serverUrl))
|
beforeEach(_.partial(setupClient, serverUrl))
|
||||||
afterEach(teardownClient)
|
afterEach(teardownClient)
|
||||||
|
|
||||||
it('base', async function () {
|
it('native', async function () {
|
||||||
// get the most recent close_time from the standalone container for finish after.
|
// get the most recent close_time from the standalone container for finish after.
|
||||||
const CLOSE_TIME: number = (
|
const CLOSE_TIME: number = (
|
||||||
await this.client.request({
|
await this.client.request({
|
||||||
@@ -28,7 +28,7 @@ describe('EscrowCreate', function () {
|
|||||||
const tx: EscrowCreate = {
|
const tx: EscrowCreate = {
|
||||||
Account: this.wallet.classicAddress,
|
Account: this.wallet.classicAddress,
|
||||||
TransactionType: 'EscrowCreate',
|
TransactionType: 'EscrowCreate',
|
||||||
Amount: '10000',
|
Amount: '1000',
|
||||||
Destination: wallet1.classicAddress,
|
Destination: wallet1.classicAddress,
|
||||||
FinishAfter: CLOSE_TIME + 2,
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
}
|
}
|
||||||
@@ -46,4 +46,39 @@ describe('EscrowCreate', function () {
|
|||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('ic', async function () {
|
||||||
|
// get the most recent close_time from the standalone container for finish after.
|
||||||
|
const CLOSE_TIME: number = (
|
||||||
|
await this.client.request({
|
||||||
|
command: 'ledger',
|
||||||
|
ledger_index: 'validated',
|
||||||
|
})
|
||||||
|
).result.ledger.close_time
|
||||||
|
|
||||||
|
const tx: EscrowCreate = {
|
||||||
|
Account: this.wallet.classicAddress,
|
||||||
|
TransactionType: 'EscrowCreate',
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.gateway.classicAddress,
|
||||||
|
value: '1000',
|
||||||
|
},
|
||||||
|
Destination: this.destination.classicAddress,
|
||||||
|
FinishAfter: CLOSE_TIME + 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(this.client, tx, this.wallet)
|
||||||
|
|
||||||
|
// check that the object was actually created
|
||||||
|
assert.equal(
|
||||||
|
(
|
||||||
|
await this.client.request({
|
||||||
|
command: 'account_objects',
|
||||||
|
account: this.wallet.classicAddress,
|
||||||
|
})
|
||||||
|
).result.account_objects.length,
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ const { hashPaymentChannel } = hashes
|
|||||||
describe('PaymentChannelClaim', function () {
|
describe('PaymentChannelClaim', function () {
|
||||||
this.timeout(TIMEOUT)
|
this.timeout(TIMEOUT)
|
||||||
|
|
||||||
beforeEach(_.partial(setupClient, serverUrl))
|
beforeEach(_.partial(setupClient, serverUrl, true))
|
||||||
afterEach(teardownClient)
|
afterEach(teardownClient)
|
||||||
|
|
||||||
it('base', async function () {
|
it('native', async function () {
|
||||||
const wallet2 = await generateFundedWallet(this.client)
|
const wallet2 = await generateFundedWallet(this.client)
|
||||||
const paymentChannelCreate: PaymentChannelCreate = {
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
TransactionType: 'PaymentChannelCreate',
|
TransactionType: 'PaymentChannelCreate',
|
||||||
@@ -46,4 +46,43 @@ describe('PaymentChannelClaim', function () {
|
|||||||
|
|
||||||
await testTransaction(this.client, paymentChannelClaim, this.wallet)
|
await testTransaction(this.client, paymentChannelClaim, this.wallet)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('ic', async function () {
|
||||||
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
|
TransactionType: 'PaymentChannelCreate',
|
||||||
|
Account: this.wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: this.destination.classicAddress,
|
||||||
|
SettleDelay: 86400,
|
||||||
|
PublicKey: this.wallet.publicKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
const paymentChannelResponse = await this.client.submit(
|
||||||
|
paymentChannelCreate,
|
||||||
|
{ wallet: this.wallet },
|
||||||
|
)
|
||||||
|
|
||||||
|
await testTransaction(this.client, paymentChannelCreate, this.wallet)
|
||||||
|
|
||||||
|
const paymentChannelClaim: PaymentChannelClaim = {
|
||||||
|
Account: this.wallet.classicAddress,
|
||||||
|
TransactionType: 'PaymentChannelClaim',
|
||||||
|
Channel: hashPaymentChannel(
|
||||||
|
this.wallet.classicAddress,
|
||||||
|
this.destination.classicAddress,
|
||||||
|
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||||
|
),
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await testTransaction(this.client, paymentChannelClaim, this.wallet)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ const TIMEOUT = 20000
|
|||||||
describe('PaymentChannelCreate', function () {
|
describe('PaymentChannelCreate', function () {
|
||||||
this.timeout(TIMEOUT)
|
this.timeout(TIMEOUT)
|
||||||
|
|
||||||
beforeEach(_.partial(setupClient, serverUrl))
|
beforeEach(_.partial(setupClient, serverUrl, true))
|
||||||
afterEach(teardownClient)
|
afterEach(teardownClient)
|
||||||
|
|
||||||
it('base', async function () {
|
it('native', async function () {
|
||||||
const wallet2 = await generateFundedWallet(this.client)
|
const wallet2 = await generateFundedWallet(this.client)
|
||||||
const paymentChannelCreate: PaymentChannelCreate = {
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
TransactionType: 'PaymentChannelCreate',
|
TransactionType: 'PaymentChannelCreate',
|
||||||
@@ -27,4 +27,19 @@ describe('PaymentChannelCreate', function () {
|
|||||||
|
|
||||||
await testTransaction(this.client, paymentChannelCreate, this.wallet)
|
await testTransaction(this.client, paymentChannelCreate, this.wallet)
|
||||||
})
|
})
|
||||||
|
it('ic', async function () {
|
||||||
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
|
TransactionType: 'PaymentChannelCreate',
|
||||||
|
Account: this.wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: this.destination.classicAddress,
|
||||||
|
SettleDelay: 86400,
|
||||||
|
PublicKey: this.wallet.publicKey,
|
||||||
|
}
|
||||||
|
await testTransaction(this.client, paymentChannelCreate, this.wallet)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ const { hashPaymentChannel } = hashes
|
|||||||
describe('PaymentChannelFund', function () {
|
describe('PaymentChannelFund', function () {
|
||||||
this.timeout(TIMEOUT)
|
this.timeout(TIMEOUT)
|
||||||
|
|
||||||
beforeEach(_.partial(setupClient, serverUrl))
|
beforeEach(_.partial(setupClient, serverUrl, true))
|
||||||
afterEach(teardownClient)
|
afterEach(teardownClient)
|
||||||
|
|
||||||
it('base', async function () {
|
it('native', async function () {
|
||||||
const wallet2 = await generateFundedWallet(this.client)
|
const wallet2 = await generateFundedWallet(this.client)
|
||||||
const paymentChannelCreate: PaymentChannelCreate = {
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
TransactionType: 'PaymentChannelCreate',
|
TransactionType: 'PaymentChannelCreate',
|
||||||
@@ -43,6 +43,43 @@ describe('PaymentChannelFund', function () {
|
|||||||
Amount: '100',
|
Amount: '100',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await testTransaction(this.client, paymentChannelFund, this.wallet)
|
||||||
|
})
|
||||||
|
it('ic', async function () {
|
||||||
|
const paymentChannelCreate: PaymentChannelCreate = {
|
||||||
|
TransactionType: 'PaymentChannelCreate',
|
||||||
|
Account: this.wallet.classicAddress,
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
Destination: this.destination.classicAddress,
|
||||||
|
SettleDelay: 86400,
|
||||||
|
PublicKey: this.wallet.publicKey,
|
||||||
|
}
|
||||||
|
|
||||||
|
const paymentChannelResponse = await this.client.submit(
|
||||||
|
paymentChannelCreate,
|
||||||
|
{ wallet: this.wallet },
|
||||||
|
)
|
||||||
|
await testTransaction(this.client, paymentChannelCreate, this.wallet)
|
||||||
|
|
||||||
|
const paymentChannelFund: PaymentChannelFund = {
|
||||||
|
Account: this.wallet.classicAddress,
|
||||||
|
TransactionType: 'PaymentChannelFund',
|
||||||
|
Channel: hashPaymentChannel(
|
||||||
|
this.wallet.classicAddress,
|
||||||
|
this.destination.classicAddress,
|
||||||
|
paymentChannelResponse.result.tx_json.Sequence ?? 0,
|
||||||
|
),
|
||||||
|
Amount: {
|
||||||
|
currency: 'USD',
|
||||||
|
issuer: this.gateway.classicAddress,
|
||||||
|
value: '100',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
await testTransaction(this.client, paymentChannelFund, this.wallet)
|
await testTransaction(this.client, paymentChannelFund, this.wallet)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -76,12 +76,12 @@ describe('PaymentChannelClaim', function () {
|
|||||||
assert.throws(
|
assert.throws(
|
||||||
() => validatePaymentChannelClaim(channel),
|
() => validatePaymentChannelClaim(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelClaim: Balance must be a string',
|
'PaymentChannelClaim: invalid Balance',
|
||||||
)
|
)
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => validate(channel),
|
() => validate(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelClaim: Balance must be a string',
|
'PaymentChannelClaim: invalid Balance',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -91,12 +91,12 @@ describe('PaymentChannelClaim', function () {
|
|||||||
assert.throws(
|
assert.throws(
|
||||||
() => validatePaymentChannelClaim(channel),
|
() => validatePaymentChannelClaim(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelClaim: Amount must be a string',
|
'PaymentChannelClaim: invalid Amount',
|
||||||
)
|
)
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => validate(channel),
|
() => validate(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelClaim: Amount must be a string',
|
'PaymentChannelClaim: invalid Amount',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -105,12 +105,12 @@ describe('PaymentChannelCreate', function () {
|
|||||||
assert.throws(
|
assert.throws(
|
||||||
() => validatePaymentChannelCreate(channel),
|
() => validatePaymentChannelCreate(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelCreate: Amount must be a string',
|
'PaymentChannelCreate: invalid Amount',
|
||||||
)
|
)
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => validate(channel),
|
() => validate(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelCreate: Amount must be a string',
|
'PaymentChannelCreate: invalid Amount',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -69,12 +69,12 @@ describe('PaymentChannelFund', function () {
|
|||||||
assert.throws(
|
assert.throws(
|
||||||
() => validatePaymentChannelFund(channel),
|
() => validatePaymentChannelFund(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelFund: Amount must be a string',
|
'PaymentChannelFund: invalid Amount',
|
||||||
)
|
)
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => validate(channel),
|
() => validate(channel),
|
||||||
ValidationError,
|
ValidationError,
|
||||||
'PaymentChannelFund: Amount must be a string',
|
'PaymentChannelFund: invalid Amount',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user