diff --git a/src/models/transactions/escrowCancel.ts b/src/models/transactions/escrowCancel.ts new file mode 100644 index 00000000..d0c204f9 --- /dev/null +++ b/src/models/transactions/escrowCancel.ts @@ -0,0 +1,31 @@ +import { ValidationError } from "../../common/errors" +import { BaseTransaction, verifyBaseTransaction } from "./common" + +export interface EscrowCancel extends BaseTransaction { + TransactionType: "EscrowCancel" + Owner: string + OfferSequence: number +} + +/** + * Verify the form and type of an EscrowCancel at runtime. + * + * @param tx - An EscrowCancel Transaction + * @returns - Void. + * @throws - When the EscrowCancel is Malformed. + */ + export function verifyEscrowCancel(tx: EscrowCancel): void { + verifyBaseTransaction(tx) + + if (tx.Owner === undefined) + throw new ValidationError('EscrowCancel: missing Owner') + + if (typeof tx.Owner !== 'string') + throw new ValidationError('EscrowCancel: Owner must be a string') + + if (tx.OfferSequence === undefined) + throw new ValidationError('EscrowCancel: missing OfferSequence') + + if (typeof tx.OfferSequence !== 'number') + throw new ValidationError('EscrowCancel: OfferSequence must be a number') +} \ No newline at end of file diff --git a/src/models/transactions/index.ts b/src/models/transactions/index.ts index 8a88e365..0cccba7b 100644 --- a/src/models/transactions/index.ts +++ b/src/models/transactions/index.ts @@ -1,12 +1,15 @@ export * from './transaction' -export * from './offerCreate' export * from './accountSet' -export * from './offerCancel' -export * from './checkCreate' -export * from './checkCash' -export * from './checkCancel' export * from './accountDelete' +export * from './checkCancel' +export * from './checkCash' +export * from './checkCreate' +export * from './signerListSet' +export * from './depositPreauth' +export * from './escrowCancel' +export * from './offerCancel' +export * from './offerCreate' +export * from './paymentTransaction' export * from './signerListSet' export * from './trustSet' -export * from './depositPreauth' -export * from './paymentTransaction' + diff --git a/src/models/transactions/transaction.ts b/src/models/transactions/transaction.ts index 66223e01..6bda6f33 100644 --- a/src/models/transactions/transaction.ts +++ b/src/models/transactions/transaction.ts @@ -1,10 +1,11 @@ -import Metadata from "../common/metadata" -import { AccountDelete } from "./accountDelete" -import { AccountSet } from "./accountSet" -import { CheckCancel } from "./checkCancel" -import { CheckCash } from "./checkCash" -import { CheckCreate } from "./checkCreate" +import Metadata from "../common/metadata"; +import { AccountDelete } from "./accountDelete"; +import { AccountSet } from "./accountSet"; +import { CheckCancel } from "./checkCancel"; +import { CheckCash } from "./checkCash"; +import { CheckCreate } from "./checkCreate"; import { DepositPreauth } from "./depositPreauth" +import { EscrowCancel } from './escrowCancel' import { OfferCancel } from "./offerCancel" import { OfferCreate } from "./offerCreate" import { PaymentTransaction } from "./paymentTransaction" @@ -18,7 +19,7 @@ export type Transaction = | CheckCash | CheckCreate | DepositPreauth -// | EscrowCancel + | EscrowCancel // | EscrowCreate // | EscrowFinish | OfferCancel diff --git a/test/models/escrowCancel.ts b/test/models/escrowCancel.ts new file mode 100644 index 00000000..e6bc3474 --- /dev/null +++ b/test/models/escrowCancel.ts @@ -0,0 +1,65 @@ +import { verifyEscrowCancel } from './../../src/models/transactions/escrowCancel' +import { assert } from 'chai' +import { ValidationError } from '../../src/common/errors' + +/** + * Transaction Verification Testing + * + * Providing runtime verification testing for each specific transaction type + */ +describe('Transaction Verification', function () { + let cancel + + beforeEach(() => { + cancel = { + TransactionType: "EscrowCancel", + Account: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + Owner: "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + OfferSequence: 7, + } + }) + + it (`Valid EscrowCancel`, () => { + assert.doesNotThrow(() => verifyEscrowCancel(cancel)) + }) + + it (`Invalid EscrowCancel missing owner`, () => { + delete cancel.Owner + + assert.throws( + () => verifyEscrowCancel(cancel), + ValidationError, + 'EscrowCancel: missing Owner' + ) + }) + + it (`Invalid EscrowCancel missing offerSequence`, () => { + delete cancel.OfferSequence + + assert.throws( + () => verifyEscrowCancel(cancel), + ValidationError, + 'EscrowCancel: missing OfferSequence' + ) + }) + + it (`Invalid OfferSequence`, () => { + cancel.Owner = 10 + + assert.throws( + () => verifyEscrowCancel(cancel), + ValidationError, + 'EscrowCancel: Owner must be a string' + ) + }) + + it (`Invalid owner`, () => { + cancel.OfferSequence = "10" + + assert.throws( + () => verifyEscrowCancel(cancel), + ValidationError, + 'EscrowCancel: OfferSequence must be a number' + ) + }) +}) \ No newline at end of file