mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
refactor: define typescript types for OfferCancel Transaction Model (#1512)
* define typescript types for OfferCancel Transaction Model
This commit is contained in:
committed by
Mayukha Vadari
parent
57c4d8be39
commit
930d214107
@@ -1,5 +1,6 @@
|
|||||||
export * from './transaction'
|
export * from './transaction'
|
||||||
export * from './offerCreate'
|
export * from './offerCreate'
|
||||||
|
export * from './offerCancel'
|
||||||
export * from './checkCreate'
|
export * from './checkCreate'
|
||||||
export * from './checkCash'
|
export * from './checkCash'
|
||||||
export * from './checkCancel'
|
export * from './checkCancel'
|
||||||
|
|||||||
24
src/models/transactions/offerCancel.ts
Normal file
24
src/models/transactions/offerCancel.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { ValidationError } from "../../common/errors"
|
||||||
|
import { BaseTransaction, verifyBaseTransaction } from "./common"
|
||||||
|
|
||||||
|
export interface OfferCancel extends BaseTransaction {
|
||||||
|
TransactionType: "OfferCancel"
|
||||||
|
OfferSequence: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify the form and type of an OfferCancel at runtime.
|
||||||
|
*
|
||||||
|
* @param tx - An OfferCancel Transaction
|
||||||
|
* @returns - Void.
|
||||||
|
* @throws - When the OfferCancel is Malformed.
|
||||||
|
*/
|
||||||
|
export function verifyOfferCancel(tx: OfferCancel): void {
|
||||||
|
verifyBaseTransaction(tx)
|
||||||
|
|
||||||
|
if (tx.OfferSequence === undefined)
|
||||||
|
throw new ValidationError("OfferCancel: missing field OfferSequence")
|
||||||
|
|
||||||
|
if (typeof tx.OfferSequence !== 'number')
|
||||||
|
throw new ValidationError("OfferCancel: invalid OfferSequence")
|
||||||
|
}
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
import Metadata from "../common/metadata";
|
import Metadata from "../common/metadata"
|
||||||
import { OfferCreate } from "./offerCreate";
|
import { OfferCreate } from "./offerCreate"
|
||||||
import { CheckCash } from "./checkCash";
|
import { OfferCancel } from "./offerCancel"
|
||||||
import { CheckCancel } from "./checkCancel";
|
import { CheckCash } from "./checkCash"
|
||||||
import { CheckCreate } from "./checkCreate";
|
import { CheckCancel } from "./checkCancel"
|
||||||
import { SignerListSet } from "./signerListSet";
|
import { CheckCreate } from "./checkCreate"
|
||||||
|
import { SignerListSet } from "./signerListSet"
|
||||||
|
|
||||||
export type Transaction =
|
export type Transaction =
|
||||||
// AccountSet
|
// AccountSet
|
||||||
// | AccountDelete
|
// | AccountDelete
|
||||||
|
// | CheckCancel
|
||||||
|
// | CheckCash
|
||||||
|
// | CheckCreate
|
||||||
CheckCancel
|
CheckCancel
|
||||||
| CheckCash
|
| CheckCash
|
||||||
| CheckCreate
|
| CheckCreate
|
||||||
@@ -15,6 +19,7 @@ export type Transaction =
|
|||||||
// | EscrowCancel
|
// | EscrowCancel
|
||||||
// | EscrowCreate
|
// | EscrowCreate
|
||||||
// | EscrowFinish
|
// | EscrowFinish
|
||||||
|
| OfferCancel
|
||||||
// | OfferCancel
|
// | OfferCancel
|
||||||
| OfferCreate
|
| OfferCreate
|
||||||
// | PaymentTransaction
|
// | PaymentTransaction
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { assert } from 'chai'
|
|||||||
*
|
*
|
||||||
* Providing runtime verification testing for each specific transaction type
|
* Providing runtime verification testing for each specific transaction type
|
||||||
*/
|
*/
|
||||||
describe('Transaction Verification', function () {
|
describe('CheckCancel Transaction Verification', function () {
|
||||||
|
|
||||||
it (`verifies valid CheckCancel`, () => {
|
it (`verifies valid CheckCancel`, () => {
|
||||||
const validCheckCancel = {
|
const validCheckCancel = {
|
||||||
|
|||||||
53
test/models/offerCancel.ts
Normal file
53
test/models/offerCancel.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { ValidationError } from 'xrpl-local/common/errors'
|
||||||
|
import { verifyOfferCancel } from './../../src/models/transactions/offerCancel'
|
||||||
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OfferCancel Transaction Verification Testing
|
||||||
|
*
|
||||||
|
* Providing runtime verification testing for each specific transaction type
|
||||||
|
*/
|
||||||
|
describe('OfferCancel Transaction Verification', function () {
|
||||||
|
let offer
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
offer = {
|
||||||
|
Account: "rnKiczmiQkZFiDES8THYyLA2pQohC5C6EF",
|
||||||
|
Fee: "10",
|
||||||
|
LastLedgerSequence: 65477334,
|
||||||
|
OfferSequence: 60797528,
|
||||||
|
Sequence: 60797535,
|
||||||
|
SigningPubKey: "0361BFD43D1EEA54B77CC152887312949EBF052997FBFFCDAF6F2653164B55B21...",
|
||||||
|
TransactionType: "OfferCancel",
|
||||||
|
TxnSignature: "30450221008C43BDCFC68B4793857CA47DF454C07E5B45D3F80E8E6785CAB9292...",
|
||||||
|
date: "2021-08-06T21:04:11Z"
|
||||||
|
} as any
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`verifies valid OfferCancel`, () => {
|
||||||
|
assert.doesNotThrow(() => verifyOfferCancel(offer))
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`verifies valid OfferCancel with flags`, () => {
|
||||||
|
offer.Flags = 2147483648
|
||||||
|
assert.doesNotThrow(() => verifyOfferCancel(offer))
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`throws w/ invalid OfferSequence`, () => {
|
||||||
|
offer.OfferSequence = '99'
|
||||||
|
assert.throws(
|
||||||
|
() => verifyOfferCancel(offer),
|
||||||
|
ValidationError,
|
||||||
|
"OfferCancel: invalid OfferSequence"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it (`throws w/ missing OfferSequence`, () => {
|
||||||
|
delete offer.OfferSequence
|
||||||
|
assert.throws(
|
||||||
|
() => verifyOfferCancel(offer),
|
||||||
|
ValidationError,
|
||||||
|
"OfferCancel: missing field OfferSequence"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ValidationError } from 'ripple-api/common/errors'
|
import { ValidationError } from 'xrpl-local/common/errors'
|
||||||
import { verifySignerListSet } from './../../src/models/transactions/signerListSet'
|
import { verifySignerListSet } from './../../src/models/transactions/signerListSet'
|
||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user