test: Add PayChannel Transaction Integration Tests (#1662)

* Add test for PaymentChannelCreate

* Add PaymentChannelFund test

* Add PaymentChannelClaim test
This commit is contained in:
Jackson Mills
2021-09-24 11:03:17 -07:00
committed by Mayukha Vadari
parent dcfc31a036
commit cc0b5a4ac9
4 changed files with 143 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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