mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-01 01:25:48 +00:00
refactor: define typescript types for CheckCancel Transaction Model (#1526)
* offer * accountroot * amendments * check * deposit preauth * directory node * escrow * fee settings * ledger hashes * negative unl * pay channel * ripple state * signer list * ticket * export * account_channels * account_currencies * account_info * account_lines * account_objects * account_offers * account_tx * gateway_balances * no ripple check * respond to comments * rename files to camelCase * account_channels * account_currencies * account_info * account_lines * account_objects * account_offers * account_tx * gateway_balances * no ripple check * respond to comments * export methods * fix typos * refactor: Define type for CommonFields * refactor: Define OfferCreate transaction type * add a commented out SignedTransaction * add tests for verifyCommonFields * remove outdated files * refactor: Define OfferCreate transaction * define checkCancel model * add tests * fix: add tests and resolve conflicts * fix: resolve typos and seperate out test * fix: commenting issue * refactor: add checkCreate to tx/index Co-authored-by: Mayukha Vadari <mvadari@ripple.com> Co-authored-by: Nathan Nichols <natenichols@cox.net>
This commit is contained in:
committed by
Mayukha Vadari
parent
f9bce29174
commit
293f09d409
21
src/models/transactions/checkCancel.ts
Normal file
21
src/models/transactions/checkCancel.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { ValidationError } from "../../common/errors";
|
||||||
|
import { BaseTransaction, verifyBaseTransaction } from "./common";
|
||||||
|
|
||||||
|
export interface CheckCancel extends BaseTransaction {
|
||||||
|
TransactionType: "CheckCancel";
|
||||||
|
CheckID: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an CheckCancel at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An CheckCancel Transaction
|
||||||
|
* @returns - Void.
|
||||||
|
* @throws - When the CheckCancel is Malformed.
|
||||||
|
*/
|
||||||
|
export function verifyCheckCancel(tx: CheckCancel): void {
|
||||||
|
verifyBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.CheckID !== undefined && typeof tx.CheckID !== 'string')
|
||||||
|
throw new ValidationError("CheckCancel: invalid CheckID")
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './transaction'
|
export * from './transaction'
|
||||||
export * from './offerCreate'
|
export * from './offerCreate'
|
||||||
export * from './checkCreate'
|
export * from './checkCancel'
|
||||||
|
export * from './checkCreate'
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
import Metadata from "../common/metadata";
|
import Metadata from "../common/metadata";
|
||||||
import { OfferCreate } from "./offerCreate";
|
import { OfferCreate } from "./offerCreate";
|
||||||
|
import { CheckCancel } from "./checkCancel";
|
||||||
import { CheckCreate } from "./checkCreate";
|
import { CheckCreate } from "./checkCreate";
|
||||||
|
|
||||||
|
|
||||||
export type Transaction =
|
export type Transaction =
|
||||||
// AccountSet
|
// AccountSet
|
||||||
// | AccountDelete
|
// | AccountDelete
|
||||||
// | CheckCancel
|
CheckCancel
|
||||||
// | CheckCash
|
// | CheckCash
|
||||||
CheckCreate
|
| CheckCreate
|
||||||
// | DepositPreauth
|
// | DepositPreauth
|
||||||
// | EscrowCancel
|
// | EscrowCancel
|
||||||
// | EscrowCreate
|
// | EscrowCreate
|
||||||
// | EscrowFinish
|
// | EscrowFinish
|
||||||
// | OfferCancel
|
// | OfferCancel
|
||||||
| OfferCreate
|
| OfferCreate
|
||||||
// | PaymentTransaction
|
// | PaymentTransaction
|
||||||
// | PaymentChannelClaim
|
// | PaymentChannelClaim
|
||||||
// | PaymentChannelCreate
|
// | PaymentChannelCreate
|
||||||
|
|||||||
35
test/models/checkCancel.ts
Normal file
35
test/models/checkCancel.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { ValidationError } from 'ripple-api/common/errors'
|
||||||
|
import { verifyCheckCancel} from './../../src/models/transactions/checkCancel'
|
||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CheckCancel Transaction Verification Testing
|
||||||
|
*
|
||||||
|
* Providing runtime verification testing for each specific transaction type
|
||||||
|
*/
|
||||||
|
describe('Transaction Verification', function () {
|
||||||
|
|
||||||
|
it (`verifies valid CheckCancel`, () => {
|
||||||
|
const validCheckCancel = {
|
||||||
|
Account : "rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo",
|
||||||
|
TransactionType : "CheckCancel",
|
||||||
|
CheckID : "49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0"
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.doesNotThrow(() => verifyCheckCancel(validCheckCancel))
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`throws w/ invalid CheckCancel`, () => {
|
||||||
|
const invalidCheckID = {
|
||||||
|
Account : "rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo",
|
||||||
|
TransactionType : "CheckCancel",
|
||||||
|
CheckID : 496473456789876545678909876545678
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyCheckCancel(invalidCheckID),
|
||||||
|
ValidationError,
|
||||||
|
"CheckCancel: invalid CheckID"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user