From cc0b5a4ac943da03d914d3aff10ae81bf48939a2 Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Fri, 24 Sep 2021 11:03:17 -0700 Subject: [PATCH] test: Add PayChannel Transaction Integration Tests (#1662) * Add test for PaymentChannelCreate * Add PaymentChannelFund test * Add PaymentChannelClaim test --- test/integration/index.ts | 3 ++ .../transactions/paymentChannelClaim.ts | 54 +++++++++++++++++++ .../transactions/paymentChannelCreate.ts | 32 +++++++++++ .../transactions/paymentChannelFund.ts | 54 +++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 test/integration/transactions/paymentChannelClaim.ts create mode 100644 test/integration/transactions/paymentChannelCreate.ts create mode 100644 test/integration/transactions/paymentChannelFund.ts diff --git a/test/integration/index.ts b/test/integration/index.ts index ebd54c4d..5dda1ba0 100644 --- a/test/integration/index.ts +++ b/test/integration/index.ts @@ -8,6 +8,9 @@ export * from './transactions/checkCancel' export * from './transactions/checkCash' export * from './transactions/checkCreate' export * from './transactions/depositPreauth' +export * from './transactions/paymentChannelCreate' +export * from './transactions/paymentChannelClaim' +export * from './transactions/paymentChannelFund' export * from './requests/accountChannels' export * from './requests/accountCurrencies' diff --git a/test/integration/transactions/paymentChannelClaim.ts b/test/integration/transactions/paymentChannelClaim.ts new file mode 100644 index 00000000..db2c8e8c --- /dev/null +++ b/test/integration/transactions/paymentChannelClaim.ts @@ -0,0 +1,54 @@ +import _ from 'lodash' + +import { + PaymentChannelCreate, + computePaymentChannelHash, + PaymentChannelClaim, +} from 'xrpl-local' + +import serverUrl from '../serverUrl' +import { setupClient, suiteClientSetup, teardownClient } from '../setup' +import { generateFundedWallet, testTransaction } from '../utils' + +// how long before each test case times out +const TIMEOUT = 20000 + +describe('PaymentChannelFund', function () { + this.timeout(TIMEOUT) + + before(suiteClientSetup) + beforeEach(_.partial(setupClient, serverUrl)) + afterEach(teardownClient) + + it('base', async function () { + const wallet2 = await generateFundedWallet(this.client) + const paymentChannelCreate: PaymentChannelCreate = { + TransactionType: 'PaymentChannelCreate', + Account: this.wallet.getClassicAddress(), + Amount: '100', + Destination: wallet2.getClassicAddress(), + SettleDelay: 86400, + PublicKey: this.wallet.publicKey, + } + + const paymentChannelResponse = await this.client.submitTransaction( + this.wallet, + paymentChannelCreate, + ) + + await testTransaction(this.client, paymentChannelCreate, this.wallet) + + const paymentChannelClaim: PaymentChannelClaim = { + Account: this.wallet.getClassicAddress(), + TransactionType: 'PaymentChannelClaim', + Channel: computePaymentChannelHash( + this.wallet.getClassicAddress(), + wallet2.getClassicAddress(), + paymentChannelResponse.result.tx_json.Sequence ?? 0, + ), + Amount: '100', + } + + await testTransaction(this.client, paymentChannelClaim, this.wallet) + }) +}) diff --git a/test/integration/transactions/paymentChannelCreate.ts b/test/integration/transactions/paymentChannelCreate.ts new file mode 100644 index 00000000..fd45b9e0 --- /dev/null +++ b/test/integration/transactions/paymentChannelCreate.ts @@ -0,0 +1,32 @@ +import _ from 'lodash' + +import { PaymentChannelCreate } from 'xrpl-local' + +import serverUrl from '../serverUrl' +import { setupClient, suiteClientSetup, teardownClient } from '../setup' +import { generateFundedWallet, testTransaction } from '../utils' + +// how long before each test case times out +const TIMEOUT = 20000 + +describe('PaymentChannelCreate', function () { + this.timeout(TIMEOUT) + + before(suiteClientSetup) + beforeEach(_.partial(setupClient, serverUrl)) + afterEach(teardownClient) + + it('base', async function () { + const wallet2 = await generateFundedWallet(this.client) + const paymentChannelCreate: PaymentChannelCreate = { + TransactionType: 'PaymentChannelCreate', + Account: this.wallet.getClassicAddress(), + Amount: '100', + Destination: wallet2.getClassicAddress(), + SettleDelay: 86400, + PublicKey: this.wallet.publicKey, + } + + await testTransaction(this.client, paymentChannelCreate, this.wallet) + }) +}) diff --git a/test/integration/transactions/paymentChannelFund.ts b/test/integration/transactions/paymentChannelFund.ts new file mode 100644 index 00000000..a8628e08 --- /dev/null +++ b/test/integration/transactions/paymentChannelFund.ts @@ -0,0 +1,54 @@ +import _ from 'lodash' + +import { + PaymentChannelCreate, + computePaymentChannelHash, + PaymentChannelFund, +} from 'xrpl-local' + +import serverUrl from '../serverUrl' +import { setupClient, suiteClientSetup, teardownClient } from '../setup' +import { generateFundedWallet, testTransaction } from '../utils' + +// how long before each test case times out +const TIMEOUT = 20000 + +describe('PaymentChannelFund', function () { + this.timeout(TIMEOUT) + + before(suiteClientSetup) + beforeEach(_.partial(setupClient, serverUrl)) + afterEach(teardownClient) + + it('base', async function () { + const wallet2 = await generateFundedWallet(this.client) + const paymentChannelCreate: PaymentChannelCreate = { + TransactionType: 'PaymentChannelCreate', + Account: this.wallet.getClassicAddress(), + Amount: '100', + Destination: wallet2.getClassicAddress(), + SettleDelay: 86400, + PublicKey: this.wallet.publicKey, + } + + const paymentChannelResponse = await this.client.submitTransaction( + this.wallet, + paymentChannelCreate, + ) + + await testTransaction(this.client, paymentChannelCreate, this.wallet) + + const paymentChannelFund: PaymentChannelFund = { + Account: this.wallet.getClassicAddress(), + TransactionType: 'PaymentChannelFund', + Channel: computePaymentChannelHash( + this.wallet.getClassicAddress(), + wallet2.getClassicAddress(), + paymentChannelResponse.result.tx_json.Sequence ?? 0, + ), + Amount: '100', + } + + await testTransaction(this.client, paymentChannelFund, this.wallet) + }) +})