From 5541632b7fad844ba2c84b11793e3e8307c5e217 Mon Sep 17 00:00:00 2001 From: dangell7 Date: Sun, 8 Jan 2023 22:39:12 -0500 Subject: [PATCH] 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 --- packages/ripple-binary-codec/src/binary.ts | 19 ++- .../src/enums/definitions.json | 23 +++- .../test/signing-data-encoding.test.js | 25 +++- packages/xrpl/src/Wallet/defaultFaucets.ts | 6 + packages/xrpl/src/models/ledger/Escrow.ts | 11 +- packages/xrpl/src/models/ledger/PayChannel.ts | 23 ++-- .../src/models/methods/accountChannels.ts | 5 +- .../xrpl/src/models/methods/accountLines.ts | 10 +- .../src/models/transactions/escrowCreate.ts | 3 +- .../transactions/paymentChannelClaim.ts | 28 +++-- .../transactions/paymentChannelCreate.ts | 9 +- .../models/transactions/paymentChannelFund.ts | 9 +- .../xrpl/test/integration/fundWallet.test.ts | 8 ++ packages/xrpl/test/integration/setup.ts | 112 +++++++++++++++++- .../transactions/escrowCreate.test.ts | 39 +++++- .../transactions/paymentChannelClaim.test.ts | 43 ++++++- .../transactions/paymentChannelCreate.test.ts | 19 ++- .../transactions/paymentChannelFund.test.ts | 41 ++++++- .../test/models/paymentChannelClaim.test.ts | 8 +- .../test/models/paymentChannelCreate.test.ts | 4 +- .../test/models/paymentChannelFund.test.ts | 4 +- 21 files changed, 394 insertions(+), 55 deletions(-) diff --git a/packages/ripple-binary-codec/src/binary.ts b/packages/ripple-binary-codec/src/binary.ts index 0f5d7755..93b90983 100644 --- a/packages/ripple-binary-codec/src/binary.ts +++ b/packages/ripple-binary-codec/src/binary.ts @@ -11,6 +11,7 @@ import { STObject } from './types/st-object' import { JsonObject } from './types/serialized-type' import { Buffer } from 'buffer/' import * as bigInt from 'big-integer' +import { Amount } from './types/amount' /** * Construct a BinaryParser @@ -93,9 +94,9 @@ function signingData( /** * Interface describing fields required for a Claim */ -interface ClaimObject extends JsonObject { +interface ClaimObject { channel: string - amount: string | number + amount: Amount } /** @@ -105,13 +106,19 @@ interface ClaimObject extends JsonObject { * @returns the serialized object with appropriate prefix */ function signingClaimData(claim: ClaimObject): Buffer { - const num = bigInt(String(claim.amount)) const prefix = HashPrefix.paymentChannelClaim 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 amount = coreTypes.UInt64.from(num).toBytes() bytesList.put(prefix) bytesList.put(channel) bytesList.put(amount) diff --git a/packages/ripple-binary-codec/src/enums/definitions.json b/packages/ripple-binary-codec/src/enums/definitions.json index 317e1feb..97a3d5cc 100644 --- a/packages/ripple-binary-codec/src/enums/definitions.json +++ b/packages/ripple-binary-codec/src/enums/definitions.json @@ -761,6 +761,16 @@ "type": "UInt32" } ], + [ + "LockCount", + { + "nth": 47, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "UInt32" + } + ], [ "IndexNext", { @@ -1421,6 +1431,16 @@ "type": "Amount" } ], + [ + "LockedBalance", + { + "nth": 21, + "isVLEncoded": false, + "isSerialized": true, + "isSigningField": true, + "type": "Amount" + } + ], [ "PublicKey", { @@ -2298,7 +2318,8 @@ "tecCANT_ACCEPT_OWN_NFTOKEN_OFFER": 158, "tecINSUFFICIENT_FUNDS": 159, "tecOBJECT_NOT_FOUND": 160, - "tecINSUFFICIENT_PAYMENT": 161 + "tecINSUFFICIENT_PAYMENT": 161, + "tecPRECISION_LOSS": 162 }, "TRANSACTION_TYPES": { "Invalid": -1, diff --git a/packages/ripple-binary-codec/test/signing-data-encoding.test.js b/packages/ripple-binary-codec/test/signing-data-encoding.test.js index eb4cedc8..78aae940 100644 --- a/packages/ripple-binary-codec/test/signing-data-encoding.test.js +++ b/packages/ripple-binary-codec/test/signing-data-encoding.test.js @@ -120,7 +120,7 @@ describe('Signing data', function () { ].join(''), ) }) - test('can create claim blob', function () { + test('can create native claim blob', function () { const channel = '43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1' const amount = '1000' @@ -137,4 +137,27 @@ describe('Signing data', function () { ].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(''), + ) + }) }) diff --git a/packages/xrpl/src/Wallet/defaultFaucets.ts b/packages/xrpl/src/Wallet/defaultFaucets.ts index 5624e1f0..f9493342 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', + Icv2 = 'icv2.faucet.transia.co', HooksV2Testnet = 'hooks-testnet-v2.xrpl-labs.com', } @@ -24,6 +25,7 @@ export const FaucetNetworkPaths: Record = { [FaucetNetwork.Devnet]: '/accounts', [FaucetNetwork.AMMDevnet]: '/accounts', [FaucetNetwork.NFTDevnet]: '/accounts', + [FaucetNetwork.Icv2]: '/accounts', [FaucetNetwork.HooksV2Testnet]: '/accounts', } @@ -58,6 +60,10 @@ export function getFaucetHost(client: Client): FaucetNetwork | undefined { return FaucetNetwork.NFTDevnet } + if (connectionUrl.includes('icv2')) { + return FaucetNetwork.Icv2 + } + throw new XRPLFaucetError('Faucet URL is not defined or inferrable.') } diff --git a/packages/xrpl/src/models/ledger/Escrow.ts b/packages/xrpl/src/models/ledger/Escrow.ts index 1ddd446e..5112c459 100644 --- a/packages/xrpl/src/models/ledger/Escrow.ts +++ b/packages/xrpl/src/models/ledger/Escrow.ts @@ -1,3 +1,5 @@ +import { Amount } from '../common' + import BaseLedgerEntry from './BaseLedgerEntry' /** @@ -19,8 +21,8 @@ export default interface Escrow extends BaseLedgerEntry { * successful. */ Destination: string - /** The amount of XRP, in drops, to be delivered by the held payment. */ - Amount: string + /** The amount of XRP/FT, as drops/Amount, to be delivered by the held payment. */ + Amount: Amount /** * A PREIMAGE-SHA-256 crypto-condition, as hexadecimal. If present, the * EscrowFinish transaction must contain a fulfillment that satisfies this @@ -71,4 +73,9 @@ export default interface Escrow extends BaseLedgerEntry { * modified this object. */ 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 } diff --git a/packages/xrpl/src/models/ledger/PayChannel.ts b/packages/xrpl/src/models/ledger/PayChannel.ts index 84080ac6..b2291c59 100644 --- a/packages/xrpl/src/models/ledger/PayChannel.ts +++ b/packages/xrpl/src/models/ledger/PayChannel.ts @@ -17,10 +17,10 @@ export default interface PayChannel extends BaseLedgerEntry { */ Account: string /** - * The destination address for this payment channel. While the payment - * channel is open, this address is the only one that can receive XRP from the - * channel. This comes from the Destination field of the transaction that - * created the channel. + * Total XRP/FT, as drops/Amount, that has been allocated to this channel. + * This includes XRP/FT that has been paid to the destination address. + * This is initially set by the transaction that created the channel and can + * be increased if the source address sends a PaymentChannelFund transaction. */ Destination: string /** @@ -31,10 +31,11 @@ export default interface PayChannel extends BaseLedgerEntry { */ Amount: string /** - * Total XRP, in drops, already paid out by the channel. The difference - * between this value and the Amount field is how much XRP can still be paid - * to the destination address with PaymentChannelClaim transactions. If the - * channel closes, the remaining difference is returned to the source address. + * Total XRP/FT, as drops/Amount, already paid out by the channel. The + * difference between this value and the Amount field is how much XRP/FT + * can still be paid to the destination address with PaymentChannelClaim + * transactions. If the channel closes, the remaining difference is returned + * to the source address. */ Balance: string /** @@ -104,4 +105,10 @@ export default interface PayChannel extends BaseLedgerEntry { * this object, in case the directory consists of multiple pages. */ 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 } diff --git a/packages/xrpl/src/models/methods/accountChannels.ts b/packages/xrpl/src/models/methods/accountChannels.ts index ad2c51af..beb0e2a3 100644 --- a/packages/xrpl/src/models/methods/accountChannels.ts +++ b/packages/xrpl/src/models/methods/accountChannels.ts @@ -1,10 +1,10 @@ -import { LedgerIndex } from '../common' +import { Amount, LedgerIndex } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' interface Channel { account: string - amount: string + amount: Amount balance: string channel_id: string destination_account: string @@ -15,6 +15,7 @@ interface Channel { cancel_after?: number source_tab?: number destination_tag?: number + transfer_rate?: number } /** diff --git a/packages/xrpl/src/models/methods/accountLines.ts b/packages/xrpl/src/models/methods/accountLines.ts index fb2e3c71..45e53ffc 100644 --- a/packages/xrpl/src/models/methods/accountLines.ts +++ b/packages/xrpl/src/models/methods/accountLines.ts @@ -1,4 +1,4 @@ -import { LedgerIndex } from '../common' +import { Amount, LedgerIndex } from '../common' import { BaseRequest, BaseResponse } from './baseMethod' @@ -64,6 +64,14 @@ export interface Trustline { * false. */ 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 } /** diff --git a/packages/xrpl/src/models/transactions/escrowCreate.ts b/packages/xrpl/src/models/transactions/escrowCreate.ts index aeb2d88b..f610dfa3 100644 --- a/packages/xrpl/src/models/transactions/escrowCreate.ts +++ b/packages/xrpl/src/models/transactions/escrowCreate.ts @@ -1,5 +1,6 @@ /* eslint-disable complexity -- Necessary for validateEscrowCreate */ import { ValidationError } from '../../errors' +import { Amount } 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. * FinishAfter time) or returned to the sender (after the CancelAfter time). */ - Amount: string + Amount: Amount /** Address to receive escrowed XRP. */ Destination: string /** diff --git a/packages/xrpl/src/models/transactions/paymentChannelClaim.ts b/packages/xrpl/src/models/transactions/paymentChannelClaim.ts index 4aeda9ac..e4521b5c 100644 --- a/packages/xrpl/src/models/transactions/paymentChannelClaim.ts +++ b/packages/xrpl/src/models/transactions/paymentChannelClaim.ts @@ -1,7 +1,13 @@ /* eslint-disable complexity -- Necessary for validatePaymentChannelClaim */ 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. @@ -108,13 +114,13 @@ export interface PaymentChannelClaim extends BaseTransaction { * delivered by the channel so far, but not greater than the Amount of the * 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 in the signed message. This is the cumulative amount of XRP that * 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 channel ID and the amount of the claim. Required unless the sender of @@ -147,12 +153,20 @@ export function validatePaymentChannelClaim(tx: Record): void { throw new ValidationError('PaymentChannelClaim: Channel must be a string') } - if (tx.Balance !== undefined && typeof tx.Balance !== 'string') { - throw new ValidationError('PaymentChannelClaim: Balance must be a string') + if ( + tx.Balance !== undefined && + typeof tx.Balance !== 'string' && + !isAmount(tx.Balance) + ) { + throw new ValidationError('PaymentChannelClaim: invalid Balance') } - if (tx.Amount !== undefined && typeof tx.Amount !== 'string') { - throw new ValidationError('PaymentChannelClaim: Amount must be a string') + if ( + tx.Amount !== undefined && + typeof tx.Amount !== 'string' && + !isAmount(tx.Amount) + ) { + throw new ValidationError('PaymentChannelClaim: invalid Amount') } if (tx.Signature !== undefined && typeof tx.Signature !== 'string') { diff --git a/packages/xrpl/src/models/transactions/paymentChannelCreate.ts b/packages/xrpl/src/models/transactions/paymentChannelCreate.ts index 6bde2c20..b03833df 100644 --- a/packages/xrpl/src/models/transactions/paymentChannelCreate.ts +++ b/packages/xrpl/src/models/transactions/paymentChannelCreate.ts @@ -1,7 +1,8 @@ /* eslint-disable complexity -- Necessary for validatePaymentChannelCreate */ 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 @@ -17,7 +18,7 @@ export interface PaymentChannelCreate extends BaseTransaction { * Destination address. When the channel closes, any unclaimed XRP is returned * to the source address's balance. */ - Amount: string + Amount: Amount /** * Address to receive XRP claims against this channel. This is also known as * the "destination address" for the channel. @@ -65,8 +66,8 @@ export function validatePaymentChannelCreate( throw new ValidationError('PaymentChannelCreate: missing Amount') } - if (typeof tx.Amount !== 'string') { - throw new ValidationError('PaymentChannelCreate: Amount must be a string') + if (typeof tx.Amount !== 'string' && !isAmount(tx.Amount)) { + throw new ValidationError('PaymentChannelCreate: invalid Amount') } if (tx.Destination === undefined) { diff --git a/packages/xrpl/src/models/transactions/paymentChannelFund.ts b/packages/xrpl/src/models/transactions/paymentChannelFund.ts index 8c46687a..aa6ca31d 100644 --- a/packages/xrpl/src/models/transactions/paymentChannelFund.ts +++ b/packages/xrpl/src/models/transactions/paymentChannelFund.ts @@ -1,6 +1,7 @@ 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 @@ -20,7 +21,7 @@ export interface PaymentChannelFund extends BaseTransaction { * Amount of XRP in drops to add to the channel. Must be a positive amount * of XRP. */ - Amount: string + Amount: Amount /** * 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 @@ -55,8 +56,8 @@ export function validatePaymentChannelFund(tx: Record): void { throw new ValidationError('PaymentChannelFund: missing Amount') } - if (typeof tx.Amount !== 'string') { - throw new ValidationError('PaymentChannelFund: Amount must be a string') + if (typeof tx.Amount !== 'string' && !isAmount(tx.Amount)) { + throw new ValidationError('PaymentChannelFund: invalid Amount') } if (tx.Expiration !== undefined && typeof tx.Expiration !== 'number') { diff --git a/packages/xrpl/test/integration/fundWallet.test.ts b/packages/xrpl/test/integration/fundWallet.test.ts index 3bdf3096..9d2b3758 100644 --- a/packages/xrpl/test/integration/fundWallet.test.ts +++ b/packages/xrpl/test/integration/fundWallet.test.ts @@ -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 () { const api = new Client('wss://hooks-testnet-v2.xrpl-labs.com') diff --git a/packages/xrpl/test/integration/setup.ts b/packages/xrpl/test/integration/setup.ts index 0fd011f9..8867c39a 100644 --- a/packages/xrpl/test/integration/setup.ts +++ b/packages/xrpl/test/integration/setup.ts @@ -1,24 +1,132 @@ -import { Client, Wallet } from 'xrpl-local' +import { AccountSet, Client, Payment, TrustSet, Wallet } from 'xrpl-local' import serverUrl from './serverUrl' -import { fundAccount } from './utils' +import { fundAccount, ledgerAccept } from './utils' export async function teardownClient(this: Mocha.Context): Promise { this.client.removeAllListeners() this.client.disconnect() } +// eslint-disable-next-line max-params -- need comments +async function initIC( + client: Client, + wallet: Wallet, + destination: Wallet, + gateway: Wallet, +): Promise { + 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( this: Mocha.Context, server = serverUrl, + ic?: boolean | false, ): Promise { this.wallet = Wallet.generate() + this.destination = Wallet.generate() + this.gateway = Wallet.generate() return new Promise((resolve, reject) => { this.client = new Client(server) this.client .connect() .then(async () => { 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() }) .catch(reject) diff --git a/packages/xrpl/test/integration/transactions/escrowCreate.test.ts b/packages/xrpl/test/integration/transactions/escrowCreate.test.ts index 0edca8c2..0c990c40 100644 --- a/packages/xrpl/test/integration/transactions/escrowCreate.test.ts +++ b/packages/xrpl/test/integration/transactions/escrowCreate.test.ts @@ -15,7 +15,7 @@ describe('EscrowCreate', function () { beforeEach(_.partial(setupClient, serverUrl)) afterEach(teardownClient) - it('base', async function () { + it('native', async function () { // get the most recent close_time from the standalone container for finish after. const CLOSE_TIME: number = ( await this.client.request({ @@ -28,7 +28,7 @@ describe('EscrowCreate', function () { const tx: EscrowCreate = { Account: this.wallet.classicAddress, TransactionType: 'EscrowCreate', - Amount: '10000', + Amount: '1000', Destination: wallet1.classicAddress, FinishAfter: CLOSE_TIME + 2, } @@ -46,4 +46,39 @@ describe('EscrowCreate', function () { 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, + ) + }) }) diff --git a/packages/xrpl/test/integration/transactions/paymentChannelClaim.test.ts b/packages/xrpl/test/integration/transactions/paymentChannelClaim.test.ts index 0d493a59..e74cc395 100644 --- a/packages/xrpl/test/integration/transactions/paymentChannelClaim.test.ts +++ b/packages/xrpl/test/integration/transactions/paymentChannelClaim.test.ts @@ -12,10 +12,10 @@ const { hashPaymentChannel } = hashes describe('PaymentChannelClaim', function () { this.timeout(TIMEOUT) - beforeEach(_.partial(setupClient, serverUrl)) + beforeEach(_.partial(setupClient, serverUrl, true)) afterEach(teardownClient) - it('base', async function () { + it('native', async function () { const wallet2 = await generateFundedWallet(this.client) const paymentChannelCreate: PaymentChannelCreate = { TransactionType: 'PaymentChannelCreate', @@ -46,4 +46,43 @@ describe('PaymentChannelClaim', function () { 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) + }) }) diff --git a/packages/xrpl/test/integration/transactions/paymentChannelCreate.test.ts b/packages/xrpl/test/integration/transactions/paymentChannelCreate.test.ts index 0134710b..d6fe9b6e 100644 --- a/packages/xrpl/test/integration/transactions/paymentChannelCreate.test.ts +++ b/packages/xrpl/test/integration/transactions/paymentChannelCreate.test.ts @@ -11,10 +11,10 @@ const TIMEOUT = 20000 describe('PaymentChannelCreate', function () { this.timeout(TIMEOUT) - beforeEach(_.partial(setupClient, serverUrl)) + beforeEach(_.partial(setupClient, serverUrl, true)) afterEach(teardownClient) - it('base', async function () { + it('native', async function () { const wallet2 = await generateFundedWallet(this.client) const paymentChannelCreate: PaymentChannelCreate = { TransactionType: 'PaymentChannelCreate', @@ -27,4 +27,19 @@ describe('PaymentChannelCreate', function () { 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) + }) }) diff --git a/packages/xrpl/test/integration/transactions/paymentChannelFund.test.ts b/packages/xrpl/test/integration/transactions/paymentChannelFund.test.ts index a3cc3a81..c6728bcc 100644 --- a/packages/xrpl/test/integration/transactions/paymentChannelFund.test.ts +++ b/packages/xrpl/test/integration/transactions/paymentChannelFund.test.ts @@ -12,10 +12,10 @@ const { hashPaymentChannel } = hashes describe('PaymentChannelFund', function () { this.timeout(TIMEOUT) - beforeEach(_.partial(setupClient, serverUrl)) + beforeEach(_.partial(setupClient, serverUrl, true)) afterEach(teardownClient) - it('base', async function () { + it('native', async function () { const wallet2 = await generateFundedWallet(this.client) const paymentChannelCreate: PaymentChannelCreate = { TransactionType: 'PaymentChannelCreate', @@ -43,6 +43,43 @@ describe('PaymentChannelFund', function () { 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) }) }) diff --git a/packages/xrpl/test/models/paymentChannelClaim.test.ts b/packages/xrpl/test/models/paymentChannelClaim.test.ts index 74d51260..51615d8d 100644 --- a/packages/xrpl/test/models/paymentChannelClaim.test.ts +++ b/packages/xrpl/test/models/paymentChannelClaim.test.ts @@ -76,12 +76,12 @@ describe('PaymentChannelClaim', function () { assert.throws( () => validatePaymentChannelClaim(channel), ValidationError, - 'PaymentChannelClaim: Balance must be a string', + 'PaymentChannelClaim: invalid Balance', ) assert.throws( () => validate(channel), ValidationError, - 'PaymentChannelClaim: Balance must be a string', + 'PaymentChannelClaim: invalid Balance', ) }) @@ -91,12 +91,12 @@ describe('PaymentChannelClaim', function () { assert.throws( () => validatePaymentChannelClaim(channel), ValidationError, - 'PaymentChannelClaim: Amount must be a string', + 'PaymentChannelClaim: invalid Amount', ) assert.throws( () => validate(channel), ValidationError, - 'PaymentChannelClaim: Amount must be a string', + 'PaymentChannelClaim: invalid Amount', ) }) diff --git a/packages/xrpl/test/models/paymentChannelCreate.test.ts b/packages/xrpl/test/models/paymentChannelCreate.test.ts index 7f4b27e7..5065f2bf 100644 --- a/packages/xrpl/test/models/paymentChannelCreate.test.ts +++ b/packages/xrpl/test/models/paymentChannelCreate.test.ts @@ -105,12 +105,12 @@ describe('PaymentChannelCreate', function () { assert.throws( () => validatePaymentChannelCreate(channel), ValidationError, - 'PaymentChannelCreate: Amount must be a string', + 'PaymentChannelCreate: invalid Amount', ) assert.throws( () => validate(channel), ValidationError, - 'PaymentChannelCreate: Amount must be a string', + 'PaymentChannelCreate: invalid Amount', ) }) diff --git a/packages/xrpl/test/models/paymentChannelFund.test.ts b/packages/xrpl/test/models/paymentChannelFund.test.ts index 07f7406e..e2329829 100644 --- a/packages/xrpl/test/models/paymentChannelFund.test.ts +++ b/packages/xrpl/test/models/paymentChannelFund.test.ts @@ -69,12 +69,12 @@ describe('PaymentChannelFund', function () { assert.throws( () => validatePaymentChannelFund(channel), ValidationError, - 'PaymentChannelFund: Amount must be a string', + 'PaymentChannelFund: invalid Amount', ) assert.throws( () => validate(channel), ValidationError, - 'PaymentChannelFund: Amount must be a string', + 'PaymentChannelFund: invalid Amount', ) })