mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 23:55:49 +00:00
refactor: define typescript type for AccountDelete transaction (#1537)
* refactor: define typescript type for AccountDelete transaction
This commit is contained in:
committed by
Mayukha Vadari
parent
fef5f858fd
commit
c1edab547a
28
src/models/transactions/accountDelete.ts
Normal file
28
src/models/transactions/accountDelete.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { ValidationError } from "../../common/errors";
|
||||||
|
import { BaseTransaction, verifyBaseTransaction } from "./common";
|
||||||
|
|
||||||
|
export interface AccountDelete extends BaseTransaction {
|
||||||
|
TransactionType: "AccountDelete";
|
||||||
|
Destination: string;
|
||||||
|
DestinationTag?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an AccountDelete at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An AccountDelete Transaction
|
||||||
|
* @returns - Void.
|
||||||
|
* @throws - When the AccountDelete is Malformed.
|
||||||
|
*/
|
||||||
|
export function verifyAccountDelete(tx: AccountDelete): void {
|
||||||
|
verifyBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.Destination === undefined)
|
||||||
|
throw new ValidationError("AccountDelete: missing field Destination")
|
||||||
|
|
||||||
|
if (typeof tx.Destination !== 'string')
|
||||||
|
throw new ValidationError("AccountDelete: invalid Destination")
|
||||||
|
|
||||||
|
if (tx.DestinationTag !== undefined && typeof tx.DestinationTag !== 'number')
|
||||||
|
throw new ValidationError("AccountDelete: invalid DestinationTag")
|
||||||
|
}
|
||||||
@@ -5,4 +5,5 @@ export * from './offerCancel'
|
|||||||
export * from './checkCreate'
|
export * from './checkCreate'
|
||||||
export * from './checkCash'
|
export * from './checkCash'
|
||||||
export * from './checkCancel'
|
export * from './checkCancel'
|
||||||
|
export * from './accountDelete'
|
||||||
export * from './signerListSet'
|
export * from './signerListSet'
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import Metadata from "../common/metadata"
|
import Metadata from "../common/metadata";
|
||||||
import { OfferCreate } from "./offerCreate"
|
import { AccountDelete } from "./accountDelete";
|
||||||
import { OfferCancel } from "./offerCancel"
|
|
||||||
import { CheckCash } from "./checkCash"
|
|
||||||
import { CheckCancel } from "./checkCancel"
|
|
||||||
import { CheckCreate } from "./checkCreate"
|
|
||||||
import { SignerListSet } from "./signerListSet"
|
|
||||||
import { AccountSet } from "./accountSet";
|
import { AccountSet } from "./accountSet";
|
||||||
|
import { CheckCancel } from "./checkCancel";
|
||||||
|
import { CheckCash } from "./checkCash";
|
||||||
|
import { CheckCreate } from "./checkCreate";
|
||||||
|
import { OfferCancel } from "./offerCancel"
|
||||||
|
import { OfferCreate } from "./offerCreate";
|
||||||
|
import { SignerListSet } from "./signerListSet";
|
||||||
|
|
||||||
export type Transaction =
|
export type Transaction =
|
||||||
AccountSet
|
AccountSet
|
||||||
// | AccountDelete
|
| AccountDelete
|
||||||
| CheckCancel
|
| CheckCancel
|
||||||
| CheckCash
|
| CheckCash
|
||||||
| CheckCreate
|
| CheckCreate
|
||||||
|
|||||||
78
test/models/accountDelete.ts
Normal file
78
test/models/accountDelete.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { ValidationError } from 'xrpl-local/common/errors'
|
||||||
|
import { verifyAccountDelete } from './../../src/models/transactions/accountDelete'
|
||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AccountDelete Transaction Verification Testing
|
||||||
|
*
|
||||||
|
* Providing runtime verification testing for each specific transaction type
|
||||||
|
*/
|
||||||
|
describe('AccountDelete Transaction Verification', function () {
|
||||||
|
|
||||||
|
it (`verifies valid AccountDelete`, () => {
|
||||||
|
const validAccountDelete = {
|
||||||
|
TransactionType: "AccountDelete",
|
||||||
|
Account: "rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm",
|
||||||
|
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||||
|
DestinationTag: 13,
|
||||||
|
Fee: "5000000",
|
||||||
|
Sequence: 2470665,
|
||||||
|
Flags: 2147483648
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.doesNotThrow(() => verifyAccountDelete(validAccountDelete))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it (`throws w/ missing Destination`, () => {
|
||||||
|
const invalidDestination = {
|
||||||
|
TransactionType: "AccountDelete",
|
||||||
|
Account: "rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm",
|
||||||
|
Fee: "5000000",
|
||||||
|
Sequence: 2470665,
|
||||||
|
Flags: 2147483648
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyAccountDelete(invalidDestination),
|
||||||
|
ValidationError,
|
||||||
|
"AccountDelete: missing field Destination"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`throws w/ invalid Destination`, () => {
|
||||||
|
const invalidDestination = {
|
||||||
|
TransactionType: "AccountDelete",
|
||||||
|
Account: "rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm",
|
||||||
|
Destination: 65478965,
|
||||||
|
Fee: "5000000",
|
||||||
|
Sequence: 2470665,
|
||||||
|
Flags: 2147483648
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyAccountDelete(invalidDestination),
|
||||||
|
ValidationError,
|
||||||
|
"AccountDelete: invalid Destination"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`throws w/ invalid DestinationTag`, () => {
|
||||||
|
const invalidDestinationTag = {
|
||||||
|
TransactionType: "AccountDelete",
|
||||||
|
Account: "rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm",
|
||||||
|
Destination: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
|
||||||
|
DestinationTag: "gvftyujnbv",
|
||||||
|
Fee: "5000000",
|
||||||
|
Sequence: 2470665,
|
||||||
|
Flags: 2147483648
|
||||||
|
} as any
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => verifyAccountDelete(invalidDestinationTag),
|
||||||
|
ValidationError,
|
||||||
|
"AccountDelete: invalid DestinationTag"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user