mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +00:00
refactor: Define PaymentChannelCreate transaction (#1533)
refactor: Define PaymentChannelCreate transaction model (#1533)
This commit is contained in:
committed by
Mayukha Vadari
parent
f6b9878334
commit
05365a8690
@@ -12,6 +12,7 @@ export * from './escrowFinish'
|
|||||||
export * from './offerCancel'
|
export * from './offerCancel'
|
||||||
export * from './offerCreate'
|
export * from './offerCreate'
|
||||||
export * from './paymentTransaction'
|
export * from './paymentTransaction'
|
||||||
|
export * from './paymentChannelCreate'
|
||||||
export * from './signerListSet'
|
export * from './signerListSet'
|
||||||
export * from './trustSet'
|
export * from './trustSet'
|
||||||
|
|
||||||
|
|||||||
53
src/models/transactions/paymentChannelCreate.ts
Normal file
53
src/models/transactions/paymentChannelCreate.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { ValidationError } from "../../common/errors"
|
||||||
|
import { BaseTransaction, verifyBaseTransaction } from "./common"
|
||||||
|
|
||||||
|
export interface PaymentChannelCreate extends BaseTransaction {
|
||||||
|
TransactionType: "PaymentChannelCreate"
|
||||||
|
Amount: string
|
||||||
|
Destination: string
|
||||||
|
SettleDelay: number
|
||||||
|
PublicKey: string
|
||||||
|
CancelAfter?: number
|
||||||
|
DestinationTag?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an PaymentChannelCreate at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An PaymentChannelCreate Transaction
|
||||||
|
* @returns - Void.
|
||||||
|
* @throws - When the PaymentChannelCreate is Malformed.
|
||||||
|
*/
|
||||||
|
export function verifyPaymentChannelCreate(tx: PaymentChannelCreate): void {
|
||||||
|
verifyBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.Amount === undefined)
|
||||||
|
throw new ValidationError("PaymentChannelCreate: missing Amount")
|
||||||
|
|
||||||
|
if (typeof tx.Amount !== 'string')
|
||||||
|
throw new ValidationError("PaymentChannelCreate: Amount must be a string")
|
||||||
|
|
||||||
|
if (tx.Destination === undefined)
|
||||||
|
throw new ValidationError("PaymentChannelCreate: missing Destination")
|
||||||
|
|
||||||
|
if (typeof tx.Destination !== 'string')
|
||||||
|
throw new ValidationError("PaymentChannelCreate: Destination must be a string")
|
||||||
|
|
||||||
|
if (tx.SettleDelay === undefined)
|
||||||
|
throw new ValidationError("PaymentChannelCreate: missing SettleDelay")
|
||||||
|
|
||||||
|
if (typeof tx.SettleDelay !== 'number')
|
||||||
|
throw new ValidationError("PaymentChannelCreate: SettleDelay must be a number")
|
||||||
|
|
||||||
|
if (tx.PublicKey === undefined)
|
||||||
|
throw new ValidationError("PaymentChannelCreate: missing PublicKey")
|
||||||
|
|
||||||
|
if (typeof tx.PublicKey !== 'string')
|
||||||
|
throw new ValidationError("PaymentChannelCreate: PublicKey must be a string")
|
||||||
|
|
||||||
|
if (tx.CancelAfter !== undefined && typeof tx.CancelAfter !== 'number')
|
||||||
|
throw new ValidationError("PaymentChannelCreate: CancelAfter must be a number")
|
||||||
|
|
||||||
|
if (tx.DestinationTag !== undefined && typeof tx.DestinationTag !== 'number')
|
||||||
|
throw new ValidationError("PaymentChannelCreate: DestinationTag must be a number")
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import { EscrowFinish } from "./escrowFinish"
|
|||||||
import { OfferCancel } from "./offerCancel"
|
import { OfferCancel } from "./offerCancel"
|
||||||
import { OfferCreate } from "./offerCreate"
|
import { OfferCreate } from "./offerCreate"
|
||||||
import { PaymentTransaction } from "./paymentTransaction"
|
import { PaymentTransaction } from "./paymentTransaction"
|
||||||
|
import { PaymentChannelCreate } from "./paymentChannelCreate"
|
||||||
import { SignerListSet } from "./signerListSet"
|
import { SignerListSet } from "./signerListSet"
|
||||||
import { TicketCreate } from "./ticketCreate"
|
import { TicketCreate } from "./ticketCreate"
|
||||||
import { TrustSet } from "./trustSet"
|
import { TrustSet } from "./trustSet"
|
||||||
@@ -28,7 +29,7 @@ export type Transaction =
|
|||||||
| OfferCreate
|
| OfferCreate
|
||||||
| PaymentTransaction
|
| PaymentTransaction
|
||||||
// | PaymentChannelClaim
|
// | PaymentChannelClaim
|
||||||
// | PaymentChannelCreate
|
| PaymentChannelCreate
|
||||||
// | PaymentChannelFund
|
// | PaymentChannelFund
|
||||||
// | SetRegularKey
|
// | SetRegularKey
|
||||||
| SignerListSet
|
| SignerListSet
|
||||||
|
|||||||
140
test/models/paymentChannelCreate.ts
Normal file
140
test/models/paymentChannelCreate.ts
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
import { ValidationError } from 'xrpl-local/common/errors'
|
||||||
|
import { verifyPaymentChannelCreate } from './../../src/models/transactions/paymentChannelCreate'
|
||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PaymentChannelCreate Transaction Verification Testing
|
||||||
|
*
|
||||||
|
* Providing runtime verification testing for each specific transaction type
|
||||||
|
*/
|
||||||
|
describe('PaymentChannelCreate Transaction Verification', function () {
|
||||||
|
let channel
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
channel = {
|
||||||
|
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||||
|
"TransactionType": "PaymentChannelCreate",
|
||||||
|
"Amount": "10000",
|
||||||
|
"Destination": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW",
|
||||||
|
"SettleDelay": 86400,
|
||||||
|
"PublicKey": "32D2471DB72B27E3310F355BB33E339BF26F8392D5A93D3BC0FC3B566612DA0F0A",
|
||||||
|
"CancelAfter": 533171558,
|
||||||
|
"DestinationTag": 23480,
|
||||||
|
"SourceTag": 11747
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`verifies valid PaymentChannelCreate`, () => {
|
||||||
|
assert.doesNotThrow(() => verifyPaymentChannelCreate(channel))
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`verifies valid PaymentChannelCreate w/o optional`, () => {
|
||||||
|
delete channel.CancelAfter
|
||||||
|
delete channel.DestinationTag
|
||||||
|
delete channel.SourceTag
|
||||||
|
|
||||||
|
assert.doesNotThrow(() => verifyPaymentChannelCreate(channel))
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`missing Amount`, () => {
|
||||||
|
delete channel.Amount
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: missing Amount"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it (`missing Destination`, () => {
|
||||||
|
delete channel.Destination
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: missing Destination"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`missing SettleDelay`, () => {
|
||||||
|
delete channel.SettleDelay
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: missing SettleDelay"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`missing PublicKey`, () => {
|
||||||
|
delete channel.PublicKey
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: missing PublicKey"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`invalid Amount`, () => {
|
||||||
|
channel.Amount = 1000
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: Amount must be a string"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it (`invalid Destination`, () => {
|
||||||
|
channel.Destination = 10;
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: Destination must be a string"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`invalid SettleDelay`, () => {
|
||||||
|
channel.SettleDelay = "10"
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: SettleDelay must be a number"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`invalid PublicKey`, () => {
|
||||||
|
channel.PublicKey = 10
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: PublicKey must be a string"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`invalid DestinationTag`, () => {
|
||||||
|
channel.DestinationTag = "10"
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: DestinationTag must be a number"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`invalid CancelAfter`, () => {
|
||||||
|
channel.CancelAfter = "100"
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyPaymentChannelCreate(channel),
|
||||||
|
ValidationError,
|
||||||
|
"PaymentChannelCreate: CancelAfter must be a number"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user