mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
refactor: Define PaymentChannelFund transaction model (#1535)
refactor: Define PaymentChannelFund transaction model (#1535)
This commit is contained in:
committed by
Mayukha Vadari
parent
db8f7c1bcb
commit
d324056203
@@ -13,6 +13,7 @@ export * from './offerCreate'
|
||||
export * from './paymentTransaction'
|
||||
export * from './paymentChannelClaim'
|
||||
export * from './paymentChannelCreate'
|
||||
export * from './paymentChannelFund'
|
||||
export * from './signerListSet'
|
||||
export * from './ticketCreate'
|
||||
export * from './trustSet'
|
||||
|
||||
35
src/models/transactions/paymentChannelFund.ts
Normal file
35
src/models/transactions/paymentChannelFund.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { ValidationError } from "../../common/errors";
|
||||
import { BaseTransaction, verifyBaseTransaction } from "./common";
|
||||
|
||||
export interface PaymentChannelFund extends BaseTransaction {
|
||||
TransactionType: "PaymentChannelFund";
|
||||
Channel: string;
|
||||
Amount: string;
|
||||
Expiration?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the form and type of an PaymentChannelFund at runtime.
|
||||
*
|
||||
* @param tx - An PaymentChannelFund Transaction
|
||||
* @returns - Void.
|
||||
* @throws - When the PaymentChannelFund is Malformed.
|
||||
*/
|
||||
export function verifyPaymentChannelFund(tx: PaymentChannelFund): void {
|
||||
verifyBaseTransaction(tx)
|
||||
|
||||
if (tx.Channel === undefined)
|
||||
throw new ValidationError("PaymentChannelFund: missing Channel")
|
||||
|
||||
if (typeof tx.Channel !== 'string')
|
||||
throw new ValidationError("PaymentChannelFund: Channel must be a string")
|
||||
|
||||
if (tx.Amount === undefined)
|
||||
throw new ValidationError("PaymentChannelFund: missing Amount")
|
||||
|
||||
if (typeof tx.Amount !== 'string')
|
||||
throw new ValidationError("PaymentChannelFund: Amount must be a string")
|
||||
|
||||
if (tx.Expiration !== undefined && typeof tx.Expiration !== 'number')
|
||||
throw new ValidationError("PaymentChannelFund: Expiration must be a number")
|
||||
}
|
||||
@@ -11,8 +11,9 @@ import { EscrowFinish } from "./escrowFinish"
|
||||
import { OfferCancel } from "./offerCancel"
|
||||
import { OfferCreate } from "./offerCreate"
|
||||
import { PaymentTransaction } from "./paymentTransaction"
|
||||
import { PaymentChannelCreate } from "./paymentChannelCreate"
|
||||
import { PaymentChannelClaim } from './paymentChannelClaim'
|
||||
import { PaymentChannelCreate } from "./paymentChannelCreate"
|
||||
import { PaymentChannelFund } from "./paymentChannelFund"
|
||||
import { SignerListSet } from "./signerListSet"
|
||||
import { TicketCreate } from "./ticketCreate"
|
||||
import { TrustSet } from "./trustSet"
|
||||
@@ -32,7 +33,7 @@ export type Transaction =
|
||||
| PaymentTransaction
|
||||
| PaymentChannelClaim
|
||||
| PaymentChannelCreate
|
||||
// | PaymentChannelFund
|
||||
| PaymentChannelFund
|
||||
// | SetRegularKey
|
||||
| SignerListSet
|
||||
| TicketCreate
|
||||
|
||||
83
test/models/paymentChannelFund.ts
Normal file
83
test/models/paymentChannelFund.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { ValidationError } from 'xrpl-local/common/errors'
|
||||
import { verifyPaymentChannelFund } from './../../src/models/transactions/paymentChannelFund'
|
||||
import { assert } from 'chai'
|
||||
|
||||
/**
|
||||
* PaymentChannelFund Transaction Verification Testing
|
||||
*
|
||||
* Providing runtime verification testing for each specific transaction type
|
||||
*/
|
||||
describe('PaymentChannelFund Transaction Verification', function () {
|
||||
let channel
|
||||
|
||||
beforeEach(() => {
|
||||
channel = {
|
||||
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"TransactionType": "PaymentChannelFund",
|
||||
"Channel": "C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198",
|
||||
"Amount": "200000",
|
||||
"Expiration": 543171558
|
||||
}
|
||||
})
|
||||
|
||||
it (`verifies valid PaymentChannelFund`, () => {
|
||||
assert.doesNotThrow(() => verifyPaymentChannelFund(channel))
|
||||
})
|
||||
|
||||
it (`verifies valid PaymentChannelFund w/o optional`, () => {
|
||||
delete channel.Expiration
|
||||
|
||||
assert.doesNotThrow(() => verifyPaymentChannelFund(channel))
|
||||
})
|
||||
|
||||
it (`throws w/ missing Amount`, () => {
|
||||
delete channel.Amount
|
||||
|
||||
assert.throws(
|
||||
() => verifyPaymentChannelFund(channel),
|
||||
ValidationError,
|
||||
"PaymentChannelFund: missing Amount"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ missing Channel`, () => {
|
||||
delete channel.Channel
|
||||
|
||||
assert.throws(
|
||||
() => verifyPaymentChannelFund(channel),
|
||||
ValidationError,
|
||||
"PaymentChannelFund: missing Channel"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid Amount`, () => {
|
||||
channel.Amount = 100
|
||||
|
||||
assert.throws(
|
||||
() => verifyPaymentChannelFund(channel),
|
||||
ValidationError,
|
||||
"PaymentChannelFund: Amount must be a string"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid Channel`, () => {
|
||||
channel.Channel = 1000
|
||||
|
||||
assert.throws(
|
||||
() => verifyPaymentChannelFund(channel),
|
||||
ValidationError,
|
||||
"PaymentChannelFund: Channel must be a string"
|
||||
)
|
||||
})
|
||||
|
||||
it (`throws w/ invalid Expiration`, () => {
|
||||
channel.Expiration = "1000"
|
||||
|
||||
assert.throws(
|
||||
() => verifyPaymentChannelFund(channel),
|
||||
ValidationError,
|
||||
"PaymentChannelFund: Expiration must be a number"
|
||||
)
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user