From 01e6bfed7a0eef668f61ea8fc639a94ddc9085df Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 12 Feb 2025 17:55:30 -0500 Subject: [PATCH 1/9] refactor tests to use a helper function --- .../transactions/MPTokenIssuanceCreate.ts | 4 +- .../models/transactions/MPTokenIssuanceSet.ts | 2 +- .../models/transactions/NFTokenCreateOffer.ts | 9 +- packages/xrpl/test/models/AMMBid.test.ts | 54 ++-- packages/xrpl/test/models/AMMClawback.test.ts | 98 ++---- packages/xrpl/test/models/AMMCreate.test.ts | 71 +---- packages/xrpl/test/models/AMMDelete.test.ts | 41 +-- packages/xrpl/test/models/AMMDeposit.test.ts | 102 ++----- packages/xrpl/test/models/AMMVote.test.ts | 37 +-- packages/xrpl/test/models/AMMWithdraw.test.ts | 101 ++----- .../xrpl/test/models/CredentialAccept.test.ts | 101 +------ .../xrpl/test/models/CredentialCreate.test.ts | 156 ++-------- .../xrpl/test/models/CredentialDelete.test.ts | 112 ++----- packages/xrpl/test/models/DIDDelete.test.ts | 14 +- packages/xrpl/test/models/DIDSet.test.ts | 56 +--- .../xrpl/test/models/MPTokenAuthorize.test.ts | 23 +- .../test/models/MPTokenIssuanceCreate.test.ts | 68 ++--- .../models/MPTokenIssuanceDestroy.test.ts | 15 +- .../test/models/MPTokenIssuanceSet.test.ts | 32 +- .../test/models/NFTokenAcceptOffer.test.ts | 47 ++- packages/xrpl/test/models/NFTokenBurn.test.ts | 15 +- .../test/models/NFTokenCancelOffer.test.ts | 22 +- .../test/models/NFTokenCreateOffer.test.ts | 58 ++-- packages/xrpl/test/models/NFTokenMint.test.ts | 59 ++-- .../xrpl/test/models/NFTokenModify.test.ts | 32 +- .../models/XChainAccountCreateCommit.test.ts | 100 ++----- .../XChainAddAccountCreateAttestation.test.ts | 240 ++++----------- .../models/XChainAddClaimAttestation.test.ts | 215 +++----------- packages/xrpl/test/models/XChainClaim.test.ts | 112 +------ .../xrpl/test/models/XChainCommit.test.ts | 90 +----- .../test/models/XChainCreateBridge.test.ts | 68 +---- .../test/models/XChainCreateClaimID.test.ts | 80 +---- .../test/models/XChainModifyBridge.test.ts | 57 +--- .../xrpl/test/models/accountDelete.test.ts | 113 ++----- packages/xrpl/test/models/accountSet.test.ts | 143 ++------- .../xrpl/test/models/baseTransaction.test.ts | 81 ++--- packages/xrpl/test/models/checkCancel.test.ts | 22 +- packages/xrpl/test/models/checkCash.test.ts | 54 +--- packages/xrpl/test/models/checkCreate.test.ts | 65 +--- packages/xrpl/test/models/clawback.test.ts | 53 +--- .../xrpl/test/models/depositPreauth.test.ts | 171 +++-------- .../xrpl/test/models/escrowCancel.test.ts | 60 +--- .../xrpl/test/models/escrowCreate.test.ts | 116 ++------ .../xrpl/test/models/escrowFinish.test.ts | 98 ++---- packages/xrpl/test/models/offerCancel.test.ts | 42 +-- packages/xrpl/test/models/offerCreate.test.ts | 67 ++--- .../xrpl/test/models/oracleDelete.test.ts | 19 +- packages/xrpl/test/models/oracleSet.test.ts | 77 ++--- packages/xrpl/test/models/payment.test.ts | 281 ++++-------------- .../test/models/paymentChannelClaim.test.ts | 83 +----- .../test/models/paymentChannelCreate.test.ts | 127 ++------ .../test/models/paymentChannelFund.test.ts | 72 +---- .../models/permissionedDomainDelete.test.ts | 28 +- .../test/models/permissionedDomainSet.test.ts | 47 ++- .../xrpl/test/models/setRegularKey.test.ts | 34 +-- .../xrpl/test/models/signerListSet.test.ts | 71 +---- .../xrpl/test/models/ticketCreate.test.ts | 67 +---- packages/xrpl/test/models/trustSet.test.ts | 59 +--- packages/xrpl/test/testUtils.ts | 34 ++- 59 files changed, 1040 insertions(+), 3335 deletions(-) diff --git a/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts b/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts index 6566e4ce05..869dd9491b 100644 --- a/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts +++ b/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts @@ -157,7 +157,9 @@ export function validateMPTokenIssuanceCreate( if (typeof tx.TransferFee === 'number') { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Not necessary - const flags = tx.Flags as number | MPTokenIssuanceCreateFlagsInterface + const flags = (tx.Flags || 0) as + | number + | MPTokenIssuanceCreateFlagsInterface const isTfMPTCanTransfer = typeof flags === 'number' ? isFlagEnabled(flags, MPTokenIssuanceCreateFlags.tfMPTCanTransfer) diff --git a/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts b/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts index 7e1c723382..796362fd27 100644 --- a/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts +++ b/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts @@ -69,7 +69,7 @@ export function validateMPTokenIssuanceSet(tx: Record): void { validateOptionalField(tx, 'Holder', isAccount) // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Not necessary - const flags = tx.Flags as number | MPTokenIssuanceSetFlagsInterface + const flags = (tx.Flags || 0) as number | MPTokenIssuanceSetFlagsInterface const isTfMPTLock = typeof flags === 'number' ? isFlagEnabled(flags, MPTokenIssuanceSetFlags.tfMPTLock) diff --git a/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts b/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts index 9575d1b6be..abcb78cf08 100644 --- a/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts +++ b/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts @@ -1,6 +1,7 @@ import { ValidationError } from '../../errors' import { Amount } from '../common' import { isFlagEnabled } from '../utils' +import { convertTxFlagsToNumber } from '../utils/flags' import { BaseTransaction, @@ -13,6 +14,7 @@ import { Account, } from './common' import type { TransactionMetadataBase } from './metadata' +import type { Transaction } from './transaction' /** * Transaction Flags for an NFTokenCreateOffer Transaction. @@ -147,8 +149,11 @@ export function validateNFTokenCreateOffer(tx: Record): void { } if ( - typeof tx.Flags === 'number' && - isFlagEnabled(tx.Flags, NFTokenCreateOfferFlags.tfSellNFToken) + isFlagEnabled( + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked in BaseTransaction + convertTxFlagsToNumber(tx as unknown as Transaction), + NFTokenCreateOfferFlags.tfSellNFToken, + ) ) { validateNFTokenSellOfferCases(tx) } else { diff --git a/packages/xrpl/test/models/AMMBid.test.ts b/packages/xrpl/test/models/AMMBid.test.ts index d7f0ea7385..9cb95cfea1 100644 --- a/packages/xrpl/test/models/AMMBid.test.ts +++ b/packages/xrpl/test/models/AMMBid.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateAMMBid } from '../../src/models/transactions/AMMBid' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMBid) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAMMBid, message) /** * AMMBid Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateAMMBid } from '../../src/models/transactions/AMMBid' * Providing runtime verification testing for each specific transaction type. */ describe('AMMBid', function () { - let bid + let bid: any beforeEach(function () { bid = { @@ -55,54 +57,47 @@ describe('AMMBid', function () { }, ], Sequence: 1337, - } as any + } }) it(`verifies valid AMMBid`, function () { - assert.doesNotThrow(() => validateAMMBid(bid)) - assert.doesNotThrow(() => validate(bid)) + assertValid(bid) }) it(`throws w/ missing field Asset`, function () { delete bid.Asset const errorMessage = 'AMMBid: missing field Asset' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ Asset must be a Currency`, function () { bid.Asset = 1234 const errorMessage = 'AMMBid: Asset must be a Currency' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete bid.Asset2 const errorMessage = 'AMMBid: missing field Asset2' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ Asset2 must be a Currency`, function () { bid.Asset2 = 1234 const errorMessage = 'AMMBid: Asset2 must be a Currency' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ BidMin must be an Amount`, function () { bid.BidMin = 5 const errorMessage = 'AMMBid: BidMin must be an Amount' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ BidMax must be an Amount`, function () { bid.BidMax = 10 const errorMessage = 'AMMBid: BidMax must be an Amount' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ AuthAccounts length must not be greater than 4`, function () { @@ -113,15 +108,13 @@ describe('AMMBid', function () { }) const errorMessage = 'AMMBid: AuthAccounts length must not be greater than 4' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ AuthAccounts must be an AuthAccount array`, function () { bid.AuthAccounts = 1234 const errorMessage = 'AMMBid: AuthAccounts must be an AuthAccount array' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ invalid AuthAccounts when AuthAccount is null`, function () { @@ -129,8 +122,7 @@ describe('AMMBid', function () { AuthAccount: null, } const errorMessage = 'AMMBid: invalid AuthAccounts' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ invalid AuthAccounts when AuthAccount is undefined`, function () { @@ -138,8 +130,7 @@ describe('AMMBid', function () { AuthAccount: undefined, } const errorMessage = 'AMMBid: invalid AuthAccounts' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ invalid AuthAccounts when AuthAccount is not an object`, function () { @@ -147,8 +138,7 @@ describe('AMMBid', function () { AuthAccount: 1234, } const errorMessage = 'AMMBid: invalid AuthAccounts' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ invalid AuthAccounts when AuthAccount.Account is not a string`, function () { @@ -158,8 +148,7 @@ describe('AMMBid', function () { }, } const errorMessage = 'AMMBid: invalid AuthAccounts' - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) it(`throws w/ AuthAccounts must not include sender's address`, function () { @@ -170,7 +159,6 @@ describe('AMMBid', function () { } const errorMessage = "AMMBid: AuthAccounts must not include sender's address" - assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage) - assert.throws(() => validate(bid), ValidationError, errorMessage) + assertInvalid(bid, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMClawback.test.ts b/packages/xrpl/test/models/AMMClawback.test.ts index a64623fbe2..065839ee8f 100644 --- a/packages/xrpl/test/models/AMMClawback.test.ts +++ b/packages/xrpl/test/models/AMMClawback.test.ts @@ -1,10 +1,12 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { AMMClawbackFlags, validateAMMClawback, } from '../../src/models/transactions/AMMClawback' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMClawback) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAMMClawback, message) /** * AMMClawback Transaction Verification Testing. @@ -12,7 +14,7 @@ import { * Providing runtime verification testing for each specific transaction type. */ describe('AMMClawback', function () { - let ammClawback + let ammClawback: any beforeEach(function () { ammClawback = { @@ -32,145 +34,87 @@ describe('AMMClawback', function () { value: '1000', }, Sequence: 1337, - } as any + } }) it(`verifies valid AMMClawback`, function () { - assert.doesNotThrow(() => validateAMMClawback(ammClawback)) - assert.doesNotThrow(() => validate(ammClawback)) + assertValid(ammClawback) }) it(`verifies valid AMMClawback without Amount`, function () { delete ammClawback.Amount - assert.doesNotThrow(() => validateAMMClawback(ammClawback)) - assert.doesNotThrow(() => validate(ammClawback)) + assertValid(ammClawback) }) it(`verifies valid AMMClawback with tfClawTwoAssets`, function () { ammClawback.flags = AMMClawbackFlags.tfClawTwoAssets - assert.doesNotThrow(() => validateAMMClawback(ammClawback)) - assert.doesNotThrow(() => validate(ammClawback)) + assertValid(ammClawback) }) it(`throws w/ missing Holder`, function () { delete ammClawback.Holder const errorMessage = 'AMMClawback: missing field Holder' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ invalid field Holder`, function () { ammClawback.Holder = 1234 const errorMessage = 'AMMClawback: invalid field Holder' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ Holder and Asset.issuer must be distinct`, function () { ammClawback.Holder = ammClawback.Asset.issuer const errorMessage = 'AMMClawback: Holder and Asset.issuer must be distinct' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ missing Asset`, function () { delete ammClawback.Asset const errorMessage = 'AMMClawback: missing field Asset' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ invalid field Asset`, function () { ammClawback.Asset = '1000' const errorMessage = 'AMMClawback: invalid field Asset' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ Account must be the same as Asset.issuer`, function () { ammClawback.Account = 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn' const errorMessage = 'AMMClawback: Account must be the same as Asset.issuer' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ missing Asset2`, function () { delete ammClawback.Asset2 const errorMessage = 'AMMClawback: missing field Asset2' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ invalid field Asset2`, function () { ammClawback.Asset2 = '1000' const errorMessage = 'AMMClawback: invalid field Asset2' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ invalid field Amount`, function () { ammClawback.Amount = 1000 const errorMessage = 'AMMClawback: invalid field Amount' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ Amount.currency must match Asset.currency`, function () { ammClawback.Amount.currency = 'ETH' const errorMessage = 'AMMClawback: Amount.currency must match Asset.currency' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) it(`throws w/ Amount.issuer must match Amount.issuer`, function () { ammClawback.Amount.issuer = 'rnYgaEtpqpNRt3wxE39demVpDAA817rQEY' const errorMessage = 'AMMClawback: Amount.issuer must match Amount.issuer' - assert.throws( - () => validateAMMClawback(ammClawback), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammClawback), ValidationError, errorMessage) + assertInvalid(ammClawback, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMCreate.test.ts b/packages/xrpl/test/models/AMMCreate.test.ts index 56242140ab..d785bf001d 100644 --- a/packages/xrpl/test/models/AMMCreate.test.ts +++ b/packages/xrpl/test/models/AMMCreate.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateAMMCreate } from '../../src/models/transactions/AMMCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAMMCreate, message) /** * AMMCreate Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateAMMCreate } from '../../src/models/transactions/AMMCreate' * Providing runtime verification testing for each specific transaction type. */ describe('AMMCreate', function () { - let ammCreate + let ammCreate: any beforeEach(function () { ammCreate = { @@ -23,99 +25,58 @@ describe('AMMCreate', function () { }, TradingFee: 12, Sequence: 1337, - } as any + } }) it(`verifies valid AMMCreate`, function () { - assert.doesNotThrow(() => validateAMMCreate(ammCreate)) - assert.doesNotThrow(() => validate(ammCreate)) + assertValid(ammCreate) }) it(`throws w/ missing Amount`, function () { delete ammCreate.Amount const errorMessage = 'AMMCreate: missing field Amount' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) it(`throws w/ Amount must be an Amount`, function () { ammCreate.Amount = 1000 const errorMessage = 'AMMCreate: Amount must be an Amount' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) it(`throws w/ missing Amount2`, function () { delete ammCreate.Amount2 const errorMessage = 'AMMCreate: missing field Amount2' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) it(`throws w/ Amount2 must be an Amount`, function () { ammCreate.Amount2 = 1000 const errorMessage = 'AMMCreate: Amount2 must be an Amount' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) it(`throws w/ missing TradingFee`, function () { delete ammCreate.TradingFee const errorMessage = 'AMMCreate: missing field TradingFee' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) it(`throws w/ TradingFee must be a number`, function () { ammCreate.TradingFee = '12' const errorMessage = 'AMMCreate: TradingFee must be a number' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) it(`throws when TradingFee is greater than 1000`, function () { ammCreate.TradingFee = 1001 const errorMessage = 'AMMCreate: TradingFee must be between 0 and 1000' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) it(`throws when TradingFee is a negative number`, function () { ammCreate.TradingFee = -1 const errorMessage = 'AMMCreate: TradingFee must be between 0 and 1000' - assert.throws( - () => validateAMMCreate(ammCreate), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammCreate), ValidationError, errorMessage) + assertInvalid(ammCreate, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMDelete.test.ts b/packages/xrpl/test/models/AMMDelete.test.ts index 8c4c9936c8..4d81bfaa39 100644 --- a/packages/xrpl/test/models/AMMDelete.test.ts +++ b/packages/xrpl/test/models/AMMDelete.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateAMMDelete } from '../../src/models/transactions/AMMDelete' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMDelete) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAMMDelete, message) /** * AMMDelete Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateAMMDelete } from '../../src/models/transactions/AMMDelete' * Providing runtime verification testing for each specific transaction type. */ describe('AMMDelete', function () { - let ammDelete + let ammDelete: any beforeEach(function () { ammDelete = { @@ -28,51 +30,30 @@ describe('AMMDelete', function () { }) it(`verifies valid AMMDelete`, function () { - assert.doesNotThrow(() => validateAMMDelete(ammDelete)) - assert.doesNotThrow(() => validate(ammDelete)) + assertValid(ammDelete) }) it(`throws w/ missing field Asset`, function () { delete ammDelete.Asset const errorMessage = 'AMMDelete: missing field Asset' - assert.throws( - () => validateAMMDelete(ammDelete), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + assertInvalid(ammDelete, errorMessage) }) it(`throws w/ Asset must be a Currency`, function () { ammDelete.Asset = 1234 const errorMessage = 'AMMDelete: Asset must be a Currency' - assert.throws( - () => validateAMMDelete(ammDelete), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + assertInvalid(ammDelete, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete ammDelete.Asset2 const errorMessage = 'AMMDelete: missing field Asset2' - assert.throws( - () => validateAMMDelete(ammDelete), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + assertInvalid(ammDelete, errorMessage) }) it(`throws w/ Asset2 must be a Currency`, function () { ammDelete.Asset2 = 1234 const errorMessage = 'AMMDelete: Asset2 must be a Currency' - assert.throws( - () => validateAMMDelete(ammDelete), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(ammDelete), ValidationError, errorMessage) + assertInvalid(ammDelete, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMDeposit.test.ts b/packages/xrpl/test/models/AMMDeposit.test.ts index 0f041d86f4..d80a49b0d3 100644 --- a/packages/xrpl/test/models/AMMDeposit.test.ts +++ b/packages/xrpl/test/models/AMMDeposit.test.ts @@ -1,8 +1,12 @@ /* eslint-disable no-bitwise -- bitwise necessary for enabling flags */ -import { assert } from 'chai' -import { AMMDepositFlags, validate, ValidationError } from '../../src' +import { AMMDepositFlags } from '../../src' import { validateAMMDeposit } from '../../src/models/transactions/AMMDeposit' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMDeposit) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAMMDeposit, message) /** * AMMDeposit Transaction Verification Testing. @@ -15,7 +19,7 @@ describe('AMMDeposit', function () { issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', value: '1000', } - let deposit + let deposit: any beforeEach(function () { deposit = { @@ -36,15 +40,13 @@ describe('AMMDeposit', function () { it(`verifies valid AMMDeposit with LPTokenOut`, function () { deposit.LPTokenOut = LPTokenOut deposit.Flags |= AMMDepositFlags.tfLPToken - assert.doesNotThrow(() => validateAMMDeposit(deposit)) - assert.doesNotThrow(() => validate(deposit)) + assertValid(deposit) }) it(`verifies valid AMMDeposit with Amount`, function () { deposit.Amount = '1000' deposit.Flags |= AMMDepositFlags.tfSingleAsset - assert.doesNotThrow(() => validateAMMDeposit(deposit)) - assert.doesNotThrow(() => validate(deposit)) + assertValid(deposit) }) it(`verifies valid AMMDeposit with Amount and Amount2`, function () { @@ -55,78 +57,50 @@ describe('AMMDeposit', function () { value: '2.5', } deposit.Flags |= AMMDepositFlags.tfTwoAsset - assert.doesNotThrow(() => validateAMMDeposit(deposit)) - assert.doesNotThrow(() => validate(deposit)) + assertValid(deposit) }) it(`verifies valid AMMDeposit with Amount and LPTokenOut`, function () { deposit.Amount = '1000' deposit.LPTokenOut = LPTokenOut deposit.Flags |= AMMDepositFlags.tfOneAssetLPToken - assert.doesNotThrow(() => validateAMMDeposit(deposit)) - assert.doesNotThrow(() => validate(deposit)) + assertValid(deposit) }) it(`verifies valid AMMDeposit with Amount and EPrice`, function () { deposit.Amount = '1000' deposit.EPrice = '25' deposit.Flags |= AMMDepositFlags.tfLimitLPToken - assert.doesNotThrow(() => validateAMMDeposit(deposit)) - assert.doesNotThrow(() => validate(deposit)) + assertValid(deposit) }) it(`throws w/ missing field Asset`, function () { delete deposit.Asset const errorMessage = 'AMMDeposit: missing field Asset' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ Asset must be a Currency`, function () { deposit.Asset = 1234 const errorMessage = 'AMMDeposit: Asset must be a Currency' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete deposit.Asset2 const errorMessage = 'AMMDeposit: missing field Asset2' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ Asset2 must be a Currency`, function () { deposit.Asset2 = 1234 const errorMessage = 'AMMDeposit: Asset2 must be a Currency' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ must set at least LPTokenOut or Amount`, function () { const errorMessage = 'AMMDeposit: must set at least LPTokenOut or Amount' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ must set Amount with Amount2`, function () { @@ -136,69 +110,39 @@ describe('AMMDeposit', function () { value: '2.5', } const errorMessage = 'AMMDeposit: must set Amount with Amount2' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ must set Amount with EPrice`, function () { deposit.EPrice = '25' const errorMessage = 'AMMDeposit: must set Amount with EPrice' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ LPTokenOut must be an IssuedCurrencyAmount`, function () { deposit.LPTokenOut = 1234 const errorMessage = 'AMMDeposit: LPTokenOut must be an IssuedCurrencyAmount' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ Amount must be an Amount`, function () { deposit.Amount = 1234 const errorMessage = 'AMMDeposit: Amount must be an Amount' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ Amount2 must be an Amount`, function () { deposit.Amount = '1000' deposit.Amount2 = 1234 const errorMessage = 'AMMDeposit: Amount2 must be an Amount' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) it(`throws w/ EPrice must be an Amount`, function () { deposit.Amount = '1000' deposit.EPrice = 1234 const errorMessage = 'AMMDeposit: EPrice must be an Amount' - assert.throws( - () => validateAMMDeposit(deposit), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(deposit), ValidationError, errorMessage) + assertInvalid(deposit, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMVote.test.ts b/packages/xrpl/test/models/AMMVote.test.ts index 25f6cdeffe..71a4e78f27 100644 --- a/packages/xrpl/test/models/AMMVote.test.ts +++ b/packages/xrpl/test/models/AMMVote.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateAMMVote } from '../../src/models/transactions/AMMVote' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMVote) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAMMVote, message) /** * AMMVote Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateAMMVote } from '../../src/models/transactions/AMMVote' * Providing runtime verification testing for each specific transaction type. */ describe('AMMVote', function () { - let vote + let vote: any beforeEach(function () { vote = { @@ -28,63 +30,54 @@ describe('AMMVote', function () { }) it(`verifies valid AMMVote`, function () { - assert.doesNotThrow(() => validateAMMVote(vote)) - assert.doesNotThrow(() => validate(vote)) + assertValid(vote) }) it(`throws w/ missing field Asset`, function () { delete vote.Asset const errorMessage = 'AMMVote: missing field Asset' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) it(`throws w/ Asset must be a Currency`, function () { vote.Asset = 1234 const errorMessage = 'AMMVote: Asset must be a Currency' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete vote.Asset2 const errorMessage = 'AMMVote: missing field Asset2' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) it(`throws w/ Asset2 must be a Currency`, function () { vote.Asset2 = 1234 const errorMessage = 'AMMVote: Asset2 must be a Currency' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) it(`throws w/ missing field TradingFee`, function () { delete vote.TradingFee const errorMessage = 'AMMVote: missing field TradingFee' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) it(`throws w/ TradingFee must be a number`, function () { vote.TradingFee = '25' const errorMessage = 'AMMVote: TradingFee must be a number' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) it(`throws when TradingFee is greater than AMM_MAX_TRADING_FEE`, function () { vote.TradingFee = 1001 const errorMessage = 'AMMVote: TradingFee must be between 0 and 1000' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) it(`throws when TradingFee is a negative number`, function () { vote.TradingFee = -1 const errorMessage = 'AMMVote: TradingFee must be between 0 and 1000' - assert.throws(() => validateAMMVote(vote), ValidationError, errorMessage) - assert.throws(() => validate(vote), ValidationError, errorMessage) + assertInvalid(vote, errorMessage) }) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.test.ts b/packages/xrpl/test/models/AMMWithdraw.test.ts index 47092ef724..bf126b1085 100644 --- a/packages/xrpl/test/models/AMMWithdraw.test.ts +++ b/packages/xrpl/test/models/AMMWithdraw.test.ts @@ -1,8 +1,12 @@ /* eslint-disable no-bitwise -- bitwise necessary for enabling flags */ -import { assert } from 'chai' -import { AMMWithdrawFlags, validate, ValidationError } from '../../src' +import { AMMWithdrawFlags } from '../../src' import { validateAMMWithdraw } from '../../src/models/transactions/AMMWithdraw' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAMMWithdraw) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAMMWithdraw, message) /** * AMMWithdraw Transaction Verification Testing. @@ -15,7 +19,7 @@ describe('AMMWithdraw', function () { issuer: 'rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg', value: '1000', } - let withdraw + let withdraw: any beforeEach(function () { withdraw = { @@ -36,15 +40,13 @@ describe('AMMWithdraw', function () { it(`verifies valid AMMWithdraw with LPTokenIn`, function () { withdraw.LPTokenIn = LPTokenIn withdraw.Flags |= AMMWithdrawFlags.tfLPToken - assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) - assert.doesNotThrow(() => validate(withdraw)) + assertValid(withdraw) }) it(`verifies valid AMMWithdraw with Amount`, function () { withdraw.Amount = '1000' withdraw.Flags |= AMMWithdrawFlags.tfSingleAsset - assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) - assert.doesNotThrow(() => validate(withdraw)) + assertValid(withdraw) }) it(`verifies valid AMMWithdraw with Amount and Amount2`, function () { @@ -55,81 +57,56 @@ describe('AMMWithdraw', function () { value: '2.5', } withdraw.Flags |= AMMWithdrawFlags.tfTwoAsset - assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) - assert.doesNotThrow(() => validate(withdraw)) + assertValid(withdraw) }) it(`verifies valid AMMWithdraw with Amount and LPTokenIn`, function () { withdraw.Amount = '1000' withdraw.LPTokenIn = LPTokenIn withdraw.Flags |= AMMWithdrawFlags.tfOneAssetLPToken - assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) - assert.doesNotThrow(() => validate(withdraw)) + assertValid(withdraw) }) it(`verifies valid AMMWithdraw with Amount and EPrice`, function () { withdraw.Amount = '1000' withdraw.EPrice = '25' withdraw.Flags |= AMMWithdrawFlags.tfLimitLPToken - assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) - assert.doesNotThrow(() => validate(withdraw)) + assertValid(withdraw) }) it(`verifies valid AMMWithdraw one asset withdraw all`, function () { withdraw.Amount = '1000' withdraw.Flags |= AMMWithdrawFlags.tfOneAssetWithdrawAll - assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) - assert.doesNotThrow(() => validate(withdraw)) + assertValid(withdraw) }) it(`verifies valid AMMWithdraw withdraw all`, function () { withdraw.Flags |= AMMWithdrawFlags.tfWithdrawAll - assert.doesNotThrow(() => validateAMMWithdraw(withdraw)) - assert.doesNotThrow(() => validate(withdraw)) + assertValid(withdraw) }) it(`throws w/ missing field Asset`, function () { delete withdraw.Asset const errorMessage = 'AMMWithdraw: missing field Asset' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ Asset must be a Currency`, function () { withdraw.Asset = 1234 const errorMessage = 'AMMWithdraw: Asset must be a Currency' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ missing field Asset2`, function () { delete withdraw.Asset2 const errorMessage = 'AMMWithdraw: missing field Asset2' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ Asset2 must be a Currency`, function () { withdraw.Asset2 = 1234 const errorMessage = 'AMMWithdraw: Asset2 must be a Currency' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ must set Amount with Amount2`, function () { @@ -139,69 +116,39 @@ describe('AMMWithdraw', function () { value: '2.5', } const errorMessage = 'AMMWithdraw: must set Amount with Amount2' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ must set Amount with EPrice`, function () { withdraw.EPrice = '25' const errorMessage = 'AMMWithdraw: must set Amount with EPrice' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ LPTokenIn must be an IssuedCurrencyAmount`, function () { withdraw.LPTokenIn = 1234 const errorMessage = 'AMMWithdraw: LPTokenIn must be an IssuedCurrencyAmount' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ Amount must be an Amount`, function () { withdraw.Amount = 1234 const errorMessage = 'AMMWithdraw: Amount must be an Amount' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ Amount2 must be an Amount`, function () { withdraw.Amount = '1000' withdraw.Amount2 = 1234 const errorMessage = 'AMMWithdraw: Amount2 must be an Amount' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) it(`throws w/ EPrice must be an Amount`, function () { withdraw.Amount = '1000' withdraw.EPrice = 1234 const errorMessage = 'AMMWithdraw: EPrice must be an Amount' - assert.throws( - () => validateAMMWithdraw(withdraw), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(withdraw), ValidationError, errorMessage) + assertInvalid(withdraw, errorMessage) }) }) diff --git a/packages/xrpl/test/models/CredentialAccept.test.ts b/packages/xrpl/test/models/CredentialAccept.test.ts index 042101bd1f..66a73038dd 100644 --- a/packages/xrpl/test/models/CredentialAccept.test.ts +++ b/packages/xrpl/test/models/CredentialAccept.test.ts @@ -1,8 +1,12 @@ import { stringToHex } from '@xrplf/isomorphic/dist/utils' -import { assert } from 'chai' -import { validate, ValidationError } from '../../src' import { validateCredentialAccept } from '../../src/models/transactions/CredentialAccept' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateCredentialAccept) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateCredentialAccept, message) /** * CredentialAccept Transaction Verification Testing. @@ -10,7 +14,7 @@ import { validateCredentialAccept } from '../../src/models/transactions/Credenti * Providing runtime verification testing for each specific transaction type. */ describe('CredentialAccept', function () { - let credentialAccept + let credentialAccept: any beforeEach(function () { credentialAccept = { @@ -24,130 +28,57 @@ describe('CredentialAccept', function () { }) it(`verifies valid CredentialAccept`, function () { - assert.doesNotThrow(() => validateCredentialAccept(credentialAccept)) - assert.doesNotThrow(() => validate(credentialAccept)) + assertValid(credentialAccept) }) it(`throws w/ missing field Account`, function () { credentialAccept.Account = undefined const errorMessage = 'CredentialAccept: missing field Account' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) it(`throws w/ Account not a string`, function () { credentialAccept.Account = 123 const errorMessage = 'CredentialAccept: invalid field Account' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) it(`throws w/ missing field Issuer`, function () { credentialAccept.Issuer = undefined const errorMessage = 'CredentialAccept: missing field Issuer' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) it(`throws w/ Issuer not a string`, function () { credentialAccept.Issuer = 123 const errorMessage = 'CredentialAccept: invalid field Issuer' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) it(`throws w/ missing field CredentialType`, function () { credentialAccept.CredentialType = undefined const errorMessage = 'CredentialAccept: missing field CredentialType' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) it(`throws w/ credentialType field too long`, function () { credentialAccept.CredentialType = stringToHex('A'.repeat(129)) const errorMessage = 'CredentialAccept: CredentialType length cannot be > 128' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) it(`throws w/ credentialType field empty`, function () { credentialAccept.CredentialType = '' const errorMessage = 'CredentialAccept: CredentialType cannot be an empty string' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) it(`throws w/ credentialType field not hex`, function () { credentialAccept.CredentialType = 'this is not hex' const errorMessage = 'CredentialAccept: CredentialType must be encoded in hex' - assert.throws( - () => validateCredentialAccept(credentialAccept), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialAccept), - ValidationError, - errorMessage, - ) + assertInvalid(credentialAccept, errorMessage) }) }) diff --git a/packages/xrpl/test/models/CredentialCreate.test.ts b/packages/xrpl/test/models/CredentialCreate.test.ts index 96a530c538..723a366b7d 100644 --- a/packages/xrpl/test/models/CredentialCreate.test.ts +++ b/packages/xrpl/test/models/CredentialCreate.test.ts @@ -1,8 +1,12 @@ import { stringToHex } from '@xrplf/isomorphic/dist/utils' -import { assert } from 'chai' -import { validate, ValidationError } from '../../src' import { validateCredentialCreate } from '../../src/models/transactions/CredentialCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateCredentialCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateCredentialCreate, message) /** * CredentialCreate Transaction Verification Testing. @@ -10,7 +14,7 @@ import { validateCredentialCreate } from '../../src/models/transactions/Credenti * Providing runtime verification testing for each specific transaction type. */ describe('credentialCreate', function () { - let credentialCreate + let credentialCreate: any beforeEach(function () { credentialCreate = { @@ -26,205 +30,87 @@ describe('credentialCreate', function () { }) it(`verifies valid credentialCreate`, function () { - assert.doesNotThrow(() => validateCredentialCreate(credentialCreate)) - assert.doesNotThrow(() => validate(credentialCreate)) + assertValid(credentialCreate) }) it(`throws w/ missing field Account`, function () { credentialCreate.Account = undefined const errorMessage = 'CredentialCreate: missing field Account' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ Account not string`, function () { credentialCreate.Account = 123 const errorMessage = 'CredentialCreate: invalid field Account' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ missing field Subject`, function () { credentialCreate.Subject = undefined const errorMessage = 'CredentialCreate: missing field Subject' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ Subject not string`, function () { credentialCreate.Subject = 123 const errorMessage = 'CredentialCreate: invalid field Subject' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ missing field credentialType`, function () { credentialCreate.CredentialType = undefined const errorMessage = 'CredentialCreate: missing field CredentialType' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ credentialType field too long`, function () { credentialCreate.CredentialType = stringToHex('A'.repeat(129)) const errorMessage = 'CredentialCreate: CredentialType length cannot be > 128' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ credentialType field empty`, function () { credentialCreate.CredentialType = '' const errorMessage = 'CredentialCreate: CredentialType cannot be an empty string' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ credentialType field not hex`, function () { credentialCreate.CredentialType = 'this is not hex' const errorMessage = 'CredentialCreate: CredentialType must be encoded in hex' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ Expiration field not number`, function () { credentialCreate.Expiration = 'this is not a number' const errorMessage = 'CredentialCreate: invalid field Expiration' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ URI field not a string`, function () { credentialCreate.URI = 123 const errorMessage = 'CredentialCreate: invalid field URI' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ URI field empty`, function () { credentialCreate.URI = '' const errorMessage = 'CredentialCreate: URI cannot be an empty string' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ URI field too long`, function () { credentialCreate.URI = stringToHex('A'.repeat(129)) const errorMessage = 'CredentialCreate: URI length must be <= 256' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) it(`throws w/ URI field not hex`, function () { credentialCreate.URI = 'this is not hex' const errorMessage = 'CredentialCreate: URI must be encoded in hex' - assert.throws( - () => validateCredentialCreate(credentialCreate), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialCreate), - ValidationError, - errorMessage, - ) + assertInvalid(credentialCreate, errorMessage) }) }) diff --git a/packages/xrpl/test/models/CredentialDelete.test.ts b/packages/xrpl/test/models/CredentialDelete.test.ts index bb1ebc12c3..161bb3165a 100644 --- a/packages/xrpl/test/models/CredentialDelete.test.ts +++ b/packages/xrpl/test/models/CredentialDelete.test.ts @@ -1,8 +1,12 @@ import { stringToHex } from '@xrplf/isomorphic/dist/utils' -import { assert } from 'chai' -import { validate, ValidationError } from '../../src' import { validateCredentialDelete } from '../../src/models/transactions/CredentialDelete' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateCredentialDelete) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateCredentialDelete, message) /** * CredentialDelete Transaction Verification Testing. @@ -10,7 +14,7 @@ import { validateCredentialDelete } from '../../src/models/transactions/Credenti * Providing runtime verification testing for each specific transaction type. */ describe('CredentialDelete', function () { - let credentialDelete + let credentialDelete: any beforeEach(function () { credentialDelete = { @@ -25,68 +29,31 @@ describe('CredentialDelete', function () { }) it(`verifies valid credentialDelete`, function () { - assert.doesNotThrow(() => validateCredentialDelete(credentialDelete)) - assert.doesNotThrow(() => validate(credentialDelete)) + assertValid(credentialDelete) }) it(`throws w/ missing field Account`, function () { credentialDelete.Account = undefined const errorMessage = 'CredentialDelete: missing field Account' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ Account not string`, function () { credentialDelete.Account = 123 const errorMessage = 'CredentialDelete: invalid field Account' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ Subject not string`, function () { credentialDelete.Subject = 123 const errorMessage = 'CredentialDelete: invalid field Subject' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ Issuer not string`, function () { credentialDelete.Issuer = 123 const errorMessage = 'CredentialDelete: invalid field Issuer' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ missing field Subject and Issuer`, function () { @@ -94,78 +61,33 @@ describe('CredentialDelete', function () { credentialDelete.Issuer = undefined const errorMessage = 'CredentialDelete: either `Issuer` or `Subject` must be provided' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ missing field credentialType`, function () { credentialDelete.CredentialType = undefined const errorMessage = 'CredentialDelete: missing field CredentialType' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ credentialType field too long`, function () { credentialDelete.CredentialType = stringToHex('A'.repeat(129)) const errorMessage = 'CredentialDelete: CredentialType length cannot be > 128' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ credentialType field empty`, function () { credentialDelete.CredentialType = '' const errorMessage = 'CredentialDelete: CredentialType cannot be an empty string' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) it(`throws w/ credentialType field not hex`, function () { credentialDelete.CredentialType = 'this is not hex' const errorMessage = 'CredentialDelete: CredentialType must be encoded in hex' - assert.throws( - () => validateCredentialDelete(credentialDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(credentialDelete), - ValidationError, - errorMessage, - ) + assertInvalid(credentialDelete, errorMessage) }) }) diff --git a/packages/xrpl/test/models/DIDDelete.test.ts b/packages/xrpl/test/models/DIDDelete.test.ts index 7248579b43..cd35e9ec97 100644 --- a/packages/xrpl/test/models/DIDDelete.test.ts +++ b/packages/xrpl/test/models/DIDDelete.test.ts @@ -1,7 +1,7 @@ -import { assert } from 'chai' - -import { validate } from '../../src' import { validateDIDDelete } from '../../src/models/transactions/DIDDelete' +import { assertTxIsValid } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateDIDDelete) /** * DIDDelete Transaction Verification Testing. @@ -9,7 +9,7 @@ import { validateDIDDelete } from '../../src/models/transactions/DIDDelete' * Providing runtime verification testing for each specific transaction type. */ describe('DIDDelete', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -22,13 +22,11 @@ describe('DIDDelete', function () { }) it('verifies valid DIDDelete', function () { - assert.doesNotThrow(() => validateDIDDelete(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws on invalid DIDDelete', function () { tx.FakeField = 'blah' - assert.doesNotThrow(() => validateDIDDelete(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) }) diff --git a/packages/xrpl/test/models/DIDSet.test.ts b/packages/xrpl/test/models/DIDSet.test.ts index 2fc16ca597..0aae8287b2 100644 --- a/packages/xrpl/test/models/DIDSet.test.ts +++ b/packages/xrpl/test/models/DIDSet.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateDIDSet } from '../../src/models/transactions/DIDSet' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateDIDSet) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateDIDSet, message) /** * DIDSet Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateDIDSet } from '../../src/models/transactions/DIDSet' * Providing runtime verification testing for each specific transaction type. */ describe('DIDSet', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -25,53 +27,25 @@ describe('DIDSet', function () { }) it('verifies valid DIDSet', function () { - assert.doesNotThrow(() => validateDIDSet(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ invalid Data', function () { tx.Data = 123 - assert.throws( - () => validateDIDSet(tx), - ValidationError, - 'DIDSet: invalid field Data', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'DIDSet: invalid field Data', - ) + assertInvalid(tx, 'DIDSet: invalid field Data') }) it('throws w/ invalid DIDDocument', function () { tx.DIDDocument = 123 - assert.throws( - () => validateDIDSet(tx), - ValidationError, - 'DIDSet: invalid field DIDDocument', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'DIDSet: invalid field DIDDocument', - ) + assertInvalid(tx, 'DIDSet: invalid field DIDDocument') }) it('throws w/ invalid URI', function () { tx.URI = 123 - assert.throws( - () => validateDIDSet(tx), - ValidationError, - 'DIDSet: invalid field URI', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'DIDSet: invalid field URI', - ) + assertInvalid(tx, 'DIDSet: invalid field URI') }) it('throws w/ empty DID', function () { @@ -79,14 +53,8 @@ describe('DIDSet', function () { delete tx.DIDDocument delete tx.URI - assert.throws( - () => validateDIDSet(tx), - ValidationError, - 'DIDSet: Must have at least one of `Data`, `DIDDocument`, and `URI`', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'DIDSet: Must have at least one of `Data`, `DIDDocument`, and `URI`', ) }) diff --git a/packages/xrpl/test/models/MPTokenAuthorize.test.ts b/packages/xrpl/test/models/MPTokenAuthorize.test.ts index 9e87dfa561..c722128b65 100644 --- a/packages/xrpl/test/models/MPTokenAuthorize.test.ts +++ b/packages/xrpl/test/models/MPTokenAuthorize.test.ts @@ -1,6 +1,11 @@ -import { assert } from 'chai' +import { MPTokenAuthorizeFlags } from '../../src' +import { validateMPTokenAuthorize } from '../../src/models/transactions/MPTokenAuthorize' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError, MPTokenAuthorizeFlags } from '../../src' +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateMPTokenAuthorize) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateMPTokenAuthorize, message) const TOKEN_ID = '000004C463C52827307480341125DA0577DEFC38405B0E3E' @@ -17,7 +22,7 @@ describe('MPTokenAuthorize', function () { MPTokenIssuanceID: TOKEN_ID, } as any - assert.doesNotThrow(() => validate(validMPTokenAuthorize)) + assertValid(validMPTokenAuthorize) validMPTokenAuthorize = { TransactionType: 'MPTokenAuthorize', @@ -26,7 +31,7 @@ describe('MPTokenAuthorize', function () { MPTokenIssuanceID: TOKEN_ID, } as any - assert.doesNotThrow(() => validate(validMPTokenAuthorize)) + assertValid(validMPTokenAuthorize) validMPTokenAuthorize = { TransactionType: 'MPTokenAuthorize', @@ -35,7 +40,7 @@ describe('MPTokenAuthorize', function () { Flags: MPTokenAuthorizeFlags.tfMPTUnauthorize, } as any - assert.doesNotThrow(() => validate(validMPTokenAuthorize)) + assertValid(validMPTokenAuthorize) validMPTokenAuthorize = { TransactionType: 'MPTokenAuthorize', @@ -45,7 +50,7 @@ describe('MPTokenAuthorize', function () { Flags: MPTokenAuthorizeFlags.tfMPTUnauthorize, } as any - assert.doesNotThrow(() => validate(validMPTokenAuthorize)) + assertValid(validMPTokenAuthorize) }) it(`throws w/ missing MPTokenIssuanceID`, function () { @@ -54,10 +59,6 @@ describe('MPTokenAuthorize', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'MPTokenAuthorize: missing field MPTokenIssuanceID', - ) + assertInvalid(invalid, 'MPTokenAuthorize: missing field MPTokenIssuanceID') }) }) diff --git a/packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts b/packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts index 0752394382..b0f34737b5 100644 --- a/packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts +++ b/packages/xrpl/test/models/MPTokenIssuanceCreate.test.ts @@ -1,11 +1,13 @@ -import { assert } from 'chai' +import { stringToHex } from '@xrplf/isomorphic/src/utils' -import { - convertStringToHex, - validate, - ValidationError, - MPTokenIssuanceCreateFlags, -} from '../../src' +import { MPTokenIssuanceCreateFlags } from '../../src' +import { validateMPTokenIssuanceCreate } from '../../src/models/transactions/MPTokenIssuanceCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateMPTokenIssuanceCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateMPTokenIssuanceCreate, message) /** * MPTokenIssuanceCreate Transaction Verification Testing. @@ -22,10 +24,10 @@ describe('MPTokenIssuanceCreate', function () { AssetScale: 2, TransferFee: 1, Flags: MPTokenIssuanceCreateFlags.tfMPTCanTransfer, - MPTokenMetadata: convertStringToHex('http://xrpl.org'), + MPTokenMetadata: stringToHex('http://xrpl.org'), } as any - assert.doesNotThrow(() => validate(validMPTokenIssuanceCreate)) + assertValid(validMPTokenIssuanceCreate) }) it(`throws w/ MPTokenMetadata being an empty string`, function () { @@ -36,9 +38,8 @@ describe('MPTokenIssuanceCreate', function () { MPTokenMetadata: '', } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceCreate: MPTokenMetadata must not be empty string', ) }) @@ -51,9 +52,8 @@ describe('MPTokenIssuanceCreate', function () { MPTokenMetadata: 'http://xrpl.org', } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceCreate: MPTokenMetadata must be in hex format', ) }) @@ -65,11 +65,7 @@ describe('MPTokenIssuanceCreate', function () { MaximumAmount: '9223372036854775808', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'MPTokenIssuanceCreate: MaximumAmount out of range', - ) + assertInvalid(invalid, 'MPTokenIssuanceCreate: MaximumAmount out of range') invalid = { TransactionType: 'MPTokenIssuanceCreate', @@ -77,11 +73,7 @@ describe('MPTokenIssuanceCreate', function () { MaximumAmount: '-1', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'MPTokenIssuanceCreate: Invalid MaximumAmount', - ) + assertInvalid(invalid, 'MPTokenIssuanceCreate: Invalid MaximumAmount') invalid = { TransactionType: 'MPTokenIssuanceCreate', @@ -89,11 +81,7 @@ describe('MPTokenIssuanceCreate', function () { MaximumAmount: '0x12', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'MPTokenIssuanceCreate: Invalid MaximumAmount', - ) + assertInvalid(invalid, 'MPTokenIssuanceCreate: Invalid MaximumAmount') }) it(`throws w/ Invalid TransferFee`, function () { @@ -103,9 +91,8 @@ describe('MPTokenIssuanceCreate', function () { TransferFee: -1, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceCreate: TransferFee must be between 0 and 50000', ) @@ -115,9 +102,8 @@ describe('MPTokenIssuanceCreate', function () { TransferFee: 50001, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceCreate: TransferFee must be between 0 and 50000', ) @@ -127,9 +113,8 @@ describe('MPTokenIssuanceCreate', function () { TransferFee: 100, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceCreate: TransferFee cannot be provided without enabling tfMPTCanTransfer flag', ) @@ -140,9 +125,8 @@ describe('MPTokenIssuanceCreate', function () { Flags: { tfMPTCanClawback: true }, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceCreate: TransferFee cannot be provided without enabling tfMPTCanTransfer flag', ) }) diff --git a/packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts b/packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts index 46bd53814c..2fbc858738 100644 --- a/packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts +++ b/packages/xrpl/test/models/MPTokenIssuanceDestroy.test.ts @@ -1,6 +1,10 @@ -import { assert } from 'chai' +import { validateMPTokenIssuanceDestroy } from '../../src/models/transactions/MPTokenIssuanceDestroy' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError } from '../../src' +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateMPTokenIssuanceDestroy) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateMPTokenIssuanceDestroy, message) const TOKEN_ID = '000004C463C52827307480341125DA0577DEFC38405B0E3E' @@ -17,7 +21,7 @@ describe('MPTokenIssuanceDestroy', function () { MPTokenIssuanceID: TOKEN_ID, } as any - assert.doesNotThrow(() => validate(validMPTokenIssuanceDestroy)) + assertValid(validMPTokenIssuanceDestroy) }) it(`throws w/ missing MPTokenIssuanceID`, function () { @@ -26,9 +30,8 @@ describe('MPTokenIssuanceDestroy', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceDestroy: missing field MPTokenIssuanceID', ) }) diff --git a/packages/xrpl/test/models/MPTokenIssuanceSet.test.ts b/packages/xrpl/test/models/MPTokenIssuanceSet.test.ts index 0932727e54..2a05f2a71a 100644 --- a/packages/xrpl/test/models/MPTokenIssuanceSet.test.ts +++ b/packages/xrpl/test/models/MPTokenIssuanceSet.test.ts @@ -1,6 +1,11 @@ -import { assert } from 'chai' +import { MPTokenIssuanceSetFlags } from '../../src' +import { validateMPTokenIssuanceSet } from '../../src/models/transactions/MPTokenIssuanceSet' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError, MPTokenIssuanceSetFlags } from '../../src' +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateMPTokenIssuanceSet) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateMPTokenIssuanceSet, message) const TOKEN_ID = '000004C463C52827307480341125DA0577DEFC38405B0E3E' @@ -18,7 +23,7 @@ describe('MPTokenIssuanceSet', function () { Flags: MPTokenIssuanceSetFlags.tfMPTLock, } as any - assert.doesNotThrow(() => validate(validMPTokenIssuanceSet)) + assertValid(validMPTokenIssuanceSet) validMPTokenIssuanceSet = { TransactionType: 'MPTokenIssuanceSet', @@ -28,7 +33,7 @@ describe('MPTokenIssuanceSet', function () { Flags: MPTokenIssuanceSetFlags.tfMPTLock, } as any - assert.doesNotThrow(() => validate(validMPTokenIssuanceSet)) + assertValid(validMPTokenIssuanceSet) // It's fine to not specify any flag, it means only tx fee is deducted validMPTokenIssuanceSet = { @@ -38,7 +43,7 @@ describe('MPTokenIssuanceSet', function () { Holder: 'rajgkBmMxmz161r8bWYH7CQAFZP5bA9oSG', } as any - assert.doesNotThrow(() => validate(validMPTokenIssuanceSet)) + assertValid(validMPTokenIssuanceSet) }) it(`throws w/ missing MPTokenIssuanceID`, function () { @@ -47,9 +52,8 @@ describe('MPTokenIssuanceSet', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'MPTokenIssuanceSet: missing field MPTokenIssuanceID', ) }) @@ -65,18 +69,10 @@ describe('MPTokenIssuanceSet', function () { // eslint-disable-next-line no-bitwise -- not needed MPTokenIssuanceSetFlags.tfMPTLock | MPTokenIssuanceSetFlags.tfMPTUnlock - assert.throws( - () => validate(invalid), - ValidationError, - 'MPTokenIssuanceSet: flag conflict', - ) + assertInvalid(invalid, 'MPTokenIssuanceSet: flag conflict') invalid.Flags = { tfMPTLock: true, tfMPTUnlock: true } - assert.throws( - () => validate(invalid), - ValidationError, - 'MPTokenIssuanceSet: flag conflict', - ) + assertInvalid(invalid, 'MPTokenIssuanceSet: flag conflict') }) }) diff --git a/packages/xrpl/test/models/NFTokenAcceptOffer.test.ts b/packages/xrpl/test/models/NFTokenAcceptOffer.test.ts index f53b14c340..6a91d8ef4f 100644 --- a/packages/xrpl/test/models/NFTokenAcceptOffer.test.ts +++ b/packages/xrpl/test/models/NFTokenAcceptOffer.test.ts @@ -1,6 +1,10 @@ -import { assert } from 'chai' +import { validateNFTokenAcceptOffer } from '../../src/models/transactions/NFTokenAcceptOffer' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError } from '../../src' +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateNFTokenAcceptOffer) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateNFTokenAcceptOffer, message) const NFTOKEN_BUY_OFFER = 'AED08CC1F50DD5F23A1948AF86153A3F3B7593E5EC77D65A02BB1B29E05AB6AF' @@ -23,7 +27,7 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.doesNotThrow(() => validate(validNFTokenAcceptOffer)) + assertValid(validNFTokenAcceptOffer) }) it(`verifies valid NFTokenAcceptOffer with NFTokenSellOffer`, function () { @@ -36,7 +40,7 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.doesNotThrow(() => validate(validNFTokenAcceptOffer)) + assertValid(validNFTokenAcceptOffer) }) it(`throws w/ missing NFTokenSellOffer and NFTokenBuyOffer`, function () { @@ -48,9 +52,8 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenAcceptOffer: must set either NFTokenSellOffer or NFTokenBuyOffer', ) }) @@ -66,9 +69,8 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenAcceptOffer: both NFTokenSellOffer and NFTokenBuyOffer must be set if using brokered mode', ) }) @@ -84,9 +86,8 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenAcceptOffer: both NFTokenSellOffer and NFTokenBuyOffer must be set if using brokered mode', ) }) @@ -102,7 +103,7 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.doesNotThrow(() => validate(validNFTokenAcceptOffer)) + assertValid(validNFTokenAcceptOffer) }) it(`verifies valid NFTokenAcceptOffer with NFTokenBrokerFee`, function () { @@ -117,7 +118,7 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.doesNotThrow(() => validate(validNFTokenAcceptOffer)) + assertValid(validNFTokenAcceptOffer) }) it(`throws w/ NFTokenBrokerFee === 0`, function () { @@ -132,9 +133,8 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenAcceptOffer: NFTokenBrokerFee must be greater than 0; omit if there is no fee', ) }) @@ -151,9 +151,8 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenAcceptOffer: NFTokenBrokerFee must be greater than 0; omit if there is no fee', ) }) @@ -170,10 +169,6 @@ describe('NFTokenAcceptOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenAcceptOffer: invalid NFTokenBrokerFee', - ) + assertInvalid(invalid, 'NFTokenAcceptOffer: invalid NFTokenBrokerFee') }) }) diff --git a/packages/xrpl/test/models/NFTokenBurn.test.ts b/packages/xrpl/test/models/NFTokenBurn.test.ts index 9d799a3262..33d56c26da 100644 --- a/packages/xrpl/test/models/NFTokenBurn.test.ts +++ b/packages/xrpl/test/models/NFTokenBurn.test.ts @@ -1,6 +1,9 @@ -import { assert } from 'chai' +import { validateNFTokenBurn } from '../../src/models/transactions/NFTokenBurn' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError } from '../../src' +const assertValid = (tx: any): void => assertTxIsValid(tx, validateNFTokenBurn) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateNFTokenBurn, message) const TOKEN_ID = '00090032B5F762798A53D543A014CAF8B297CFF8F2F937E844B17C9E00000003' @@ -21,7 +24,7 @@ describe('NFTokenBurn', function () { Flags: 2147483648, } as any - assert.doesNotThrow(() => validate(validNFTokenBurn)) + assertValid(validNFTokenBurn) }) it(`throws w/ missing NFTokenID`, function () { @@ -33,10 +36,6 @@ describe('NFTokenBurn', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenBurn: missing field NFTokenID', - ) + assertInvalid(invalid, 'NFTokenBurn: missing field NFTokenID') }) }) diff --git a/packages/xrpl/test/models/NFTokenCancelOffer.test.ts b/packages/xrpl/test/models/NFTokenCancelOffer.test.ts index d020299529..e488dcee20 100644 --- a/packages/xrpl/test/models/NFTokenCancelOffer.test.ts +++ b/packages/xrpl/test/models/NFTokenCancelOffer.test.ts @@ -1,6 +1,10 @@ -import { assert } from 'chai' +import { validateNFTokenCancelOffer } from '../../src/models/transactions/NFTokenCancelOffer' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError } from '../../src' +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateNFTokenCancelOffer) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateNFTokenCancelOffer, message) const BUY_OFFER = 'AED08CC1F50DD5F23A1948AF86153A3F3B7593E5EC77D65A02BB1B29E05AB6AF' @@ -21,7 +25,7 @@ describe('NFTokenCancelOffer', function () { Flags: 2147483648, } as any - assert.doesNotThrow(() => validate(validNFTokenCancelOffer)) + assertValid(validNFTokenCancelOffer) }) it(`throws w/ missing NFTokenOffers`, function () { @@ -33,11 +37,7 @@ describe('NFTokenCancelOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenCancelOffer: missing field NFTokenOffers', - ) + assertInvalid(invalid, 'NFTokenCancelOffer: missing field NFTokenOffers') }) it(`throws w/ empty NFTokenOffers`, function () { @@ -50,10 +50,6 @@ describe('NFTokenCancelOffer', function () { Flags: 2147483648, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenCancelOffer: empty field NFTokenOffers', - ) + assertInvalid(invalid, 'NFTokenCancelOffer: empty field NFTokenOffers') }) }) diff --git a/packages/xrpl/test/models/NFTokenCreateOffer.test.ts b/packages/xrpl/test/models/NFTokenCreateOffer.test.ts index 6260861608..b287e70cce 100644 --- a/packages/xrpl/test/models/NFTokenCreateOffer.test.ts +++ b/packages/xrpl/test/models/NFTokenCreateOffer.test.ts @@ -1,6 +1,11 @@ -import { assert } from 'chai' +import { NFTokenCreateOfferFlags } from '../../src' +import { validateNFTokenCreateOffer } from '../../src/models/transactions/NFTokenCreateOffer' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError, NFTokenCreateOfferFlags } from '../../src' +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateNFTokenCreateOffer) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateNFTokenCreateOffer, message) const NFTOKEN_ID = '00090032B5F762798A53D543A014CAF8B297CFF8F2F937E844B17C9E00000003' @@ -24,7 +29,7 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.doesNotThrow(() => validate(validNFTokenCreateOffer)) + assertValid(validNFTokenCreateOffer) }) it(`verifies valid NFTokenCreateOffer sellside`, function () { @@ -42,7 +47,7 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.doesNotThrow(() => validate(validNFTokenCreateOffer)) + assertValid(validNFTokenCreateOffer) }) it(`verifies w/ 0 Amount NFTokenCreateOffer sellside`, function () { @@ -58,7 +63,7 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.doesNotThrow(() => validate(validNFTokenCreateOffer)) + assertValid(validNFTokenCreateOffer) }) it(`throws w/ Account === Owner`, function () { @@ -73,9 +78,8 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenCreateOffer: Owner and Account must not be equal', ) }) @@ -93,9 +97,8 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenCreateOffer: Destination and Account must not be equal', ) }) @@ -112,11 +115,7 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenCreateOffer: missing field NFTokenID', - ) + assertInvalid(invalid, 'NFTokenCreateOffer: missing field NFTokenID') }) it(`throws w/ invalid Amount`, function () { @@ -132,11 +131,7 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenCreateOffer: invalid Amount', - ) + assertInvalid(invalid, 'NFTokenCreateOffer: invalid Amount') }) it(`throws w/ missing Amount`, function () { @@ -151,11 +146,7 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenCreateOffer: invalid Amount', - ) + assertInvalid(invalid, 'NFTokenCreateOffer: invalid Amount') }) it(`throws w/ Owner for sell offer`, function () { @@ -171,9 +162,8 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenCreateOffer: Owner must not be present for sell offers', ) }) @@ -189,9 +179,8 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenCreateOffer: Owner must be present for buy offers', ) }) @@ -208,9 +197,8 @@ describe('NFTokenCreateOffer', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenCreateOffer: Amount must be greater than 0 for buy offers', ) }) diff --git a/packages/xrpl/test/models/NFTokenMint.test.ts b/packages/xrpl/test/models/NFTokenMint.test.ts index d859f3ff3f..74fc586d17 100644 --- a/packages/xrpl/test/models/NFTokenMint.test.ts +++ b/packages/xrpl/test/models/NFTokenMint.test.ts @@ -1,11 +1,12 @@ -import { assert } from 'chai' +import { stringToHex } from '@xrplf/isomorphic/src/utils' -import { - convertStringToHex, - validate, - ValidationError, - NFTokenMintFlags, -} from '../../src' +import { NFTokenMintFlags } from '../../src' +import { validateNFTokenMint } from '../../src/models/transactions/NFTokenMint' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateNFTokenMint) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateNFTokenMint, message) /** * NFTokenMint Transaction Verification Testing. @@ -25,10 +26,10 @@ describe('NFTokenMint', function () { NFTokenTaxon: 0, Issuer: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ', TransferFee: 1, - URI: convertStringToHex('http://xrpl.org'), + URI: stringToHex('http://xrpl.org'), } as any - assert.doesNotThrow(() => validate(validNFTokenMint)) + assertValid(validNFTokenMint) }) it(`verifies valid NFTokenMint with Amount, Destination and Expiration`, function () { @@ -44,7 +45,7 @@ describe('NFTokenMint', function () { Expiration: 123456, } as any - assert.doesNotThrow(() => validate(valid)) + assertValid(valid) }) it(`throws w/ missing NFTokenTaxon`, function () { @@ -56,14 +57,10 @@ describe('NFTokenMint', function () { Flags: NFTokenMintFlags.tfTransferable, Issuer: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ', TransferFee: 1, - URI: convertStringToHex('http://xrpl.org'), + URI: stringToHex('http://xrpl.org'), } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenMint: missing field NFTokenTaxon', - ) + assertInvalid(invalid, 'NFTokenMint: missing field NFTokenTaxon') }) it(`throws w/ Account === Issuer`, function () { @@ -76,14 +73,10 @@ describe('NFTokenMint', function () { Issuer: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', TransferFee: 1, NFTokenTaxon: 0, - URI: convertStringToHex('http://xrpl.org'), + URI: stringToHex('http://xrpl.org'), } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenMint: Issuer must not be equal to Account', - ) + assertInvalid(invalid, 'NFTokenMint: Issuer must not be equal to Account') }) it(`throws w/ URI being an empty string`, function () { @@ -99,11 +92,7 @@ describe('NFTokenMint', function () { URI: '', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenMint: URI must not be empty string', - ) + assertInvalid(invalid, 'NFTokenMint: URI must not be empty string') }) it(`throws w/ URI not in hex format`, function () { @@ -119,11 +108,7 @@ describe('NFTokenMint', function () { URI: 'http://xrpl.org', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenMint: URI must be in hex format', - ) + assertInvalid(invalid, 'NFTokenMint: URI must be in hex format') }) it(`throws when Amount is null but Expiration is present`, function () { @@ -137,9 +122,8 @@ describe('NFTokenMint', function () { Expiration: 123456, } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenMint: Amount is required when Expiration or Destination is present', ) }) @@ -155,9 +139,8 @@ describe('NFTokenMint', function () { Destination: 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn', } as any - assert.throws( - () => validate(invalid), - ValidationError, + assertInvalid( + invalid, 'NFTokenMint: Amount is required when Expiration or Destination is present', ) }) diff --git a/packages/xrpl/test/models/NFTokenModify.test.ts b/packages/xrpl/test/models/NFTokenModify.test.ts index 8d1bb9b0bf..e8168c1bd7 100644 --- a/packages/xrpl/test/models/NFTokenModify.test.ts +++ b/packages/xrpl/test/models/NFTokenModify.test.ts @@ -1,6 +1,12 @@ -import { assert } from 'chai' +import { stringToHex } from '@xrplf/isomorphic/src/utils' -import { convertStringToHex, validate, ValidationError } from '../../src' +import { validateNFTokenModify } from '../../src/models/transactions/NFTokenModify' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateNFTokenModify) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateNFTokenModify, message) const TOKEN_ID = '00090032B5F762798A53D543A014CAF8B297CFF8F2F937E844B17C9E00000003' @@ -18,10 +24,10 @@ describe('NFTokenModify', function () { NFTokenID: TOKEN_ID, Fee: '5000000', Sequence: 2470665, - URI: convertStringToHex('http://xrpl.org'), + URI: stringToHex('http://xrpl.org'), } as any - assert.doesNotThrow(() => validate(validNFTokenModify)) + assertValid(validNFTokenModify) }) it(`throws w/ missing NFTokenID`, function () { @@ -32,11 +38,7 @@ describe('NFTokenModify', function () { Sequence: 2470665, } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenModify: missing field NFTokenID', - ) + assertInvalid(invalid, 'NFTokenModify: missing field NFTokenID') }) it(`throws w/ URI being an empty string`, function () { @@ -49,11 +51,7 @@ describe('NFTokenModify', function () { URI: '', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenModify: URI must not be empty string', - ) + assertInvalid(invalid, 'NFTokenModify: URI must not be empty string') }) it(`throws w/ URI not in hex format`, function () { @@ -66,10 +64,6 @@ describe('NFTokenModify', function () { URI: '--', } as any - assert.throws( - () => validate(invalid), - ValidationError, - 'NFTokenModify: URI must be in hex format', - ) + assertInvalid(invalid, 'NFTokenModify: URI must be in hex format') }) }) diff --git a/packages/xrpl/test/models/XChainAccountCreateCommit.test.ts b/packages/xrpl/test/models/XChainAccountCreateCommit.test.ts index 454458fdae..fa75c98e26 100644 --- a/packages/xrpl/test/models/XChainAccountCreateCommit.test.ts +++ b/packages/xrpl/test/models/XChainAccountCreateCommit.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainAccountCreateCommit } from '../../src/models/transactions/XChainAccountCreateCommit' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateXChainAccountCreateCommit) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateXChainAccountCreateCommit, message) /** * XChainAccountCreateCommit Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validateXChainAccountCreateCommit } from '../../src/models/transactions * Providing runtime verification testing for each specific transaction type. */ describe('XChainAccountCreateCommit', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -35,51 +38,26 @@ describe('XChainAccountCreateCommit', function () { }) it('verifies valid XChainAccountCreateCommit', function () { - assert.doesNotThrow(() => validateXChainAccountCreateCommit(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAccountCreateCommit: missing field XChainBridge', - ) + assertInvalid(tx, 'XChainAccountCreateCommit: missing field XChainBridge') }) it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAccountCreateCommit: invalid field XChainBridge', - ) + assertInvalid(tx, 'XChainAccountCreateCommit: invalid field XChainBridge') }) it('throws w/ missing SignatureReward', function () { delete tx.SignatureReward - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: missing field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAccountCreateCommit: missing field SignatureReward', ) }) @@ -87,14 +65,8 @@ describe('XChainAccountCreateCommit', function () { it('throws w/ invalid SignatureReward', function () { tx.SignatureReward = { currency: 'ETH' } - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: invalid field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAccountCreateCommit: invalid field SignatureReward', ) }) @@ -102,60 +74,24 @@ describe('XChainAccountCreateCommit', function () { it('throws w/ missing Destination', function () { delete tx.Destination - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: missing field Destination', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAccountCreateCommit: missing field Destination', - ) + assertInvalid(tx, 'XChainAccountCreateCommit: missing field Destination') }) it('throws w/ invalid Destination', function () { tx.Destination = 123 - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: invalid field Destination', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAccountCreateCommit: invalid field Destination', - ) + assertInvalid(tx, 'XChainAccountCreateCommit: invalid field Destination') }) it('throws w/ missing Amount', function () { delete tx.Amount - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: missing field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAccountCreateCommit: missing field Amount', - ) + assertInvalid(tx, 'XChainAccountCreateCommit: missing field Amount') }) it('throws w/ invalid Amount', function () { tx.Amount = { currency: 'ETH' } - assert.throws( - () => validateXChainAccountCreateCommit(tx), - ValidationError, - 'XChainAccountCreateCommit: invalid field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAccountCreateCommit: invalid field Amount', - ) + assertInvalid(tx, 'XChainAccountCreateCommit: invalid field Amount') }) }) diff --git a/packages/xrpl/test/models/XChainAddAccountCreateAttestation.test.ts b/packages/xrpl/test/models/XChainAddAccountCreateAttestation.test.ts index 4fb98fd584..144a43a584 100644 --- a/packages/xrpl/test/models/XChainAddAccountCreateAttestation.test.ts +++ b/packages/xrpl/test/models/XChainAddAccountCreateAttestation.test.ts @@ -1,7 +1,14 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainAddAccountCreateAttestation } from '../../src/models/transactions/XChainAddAccountCreateAttestation' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateXChainAddAccountCreateAttestation) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError( + tx, + validateXChainAddAccountCreateAttestation, + message, + ) /** * XChainAddAccountCreateAttestation Transaction Verification Testing. @@ -9,7 +16,7 @@ import { validateXChainAddAccountCreateAttestation } from '../../src/models/tran * Providing runtime verification testing for each specific transaction type. */ describe('XChainAddAccountCreateAttestation', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -45,51 +52,26 @@ describe('XChainAddAccountCreateAttestation', function () { }) it('verifies valid XChainAddAccountCreateAttestation', function () { - assert.doesNotThrow(() => validateXChainAddAccountCreateAttestation(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing Amount', function () { delete tx.Amount - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field Amount', - ) + assertInvalid(tx, 'XChainAddAccountCreateAttestation: missing field Amount') }) it('throws w/ invalid Amount', function () { tx.Amount = { currency: 'ETH' } - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field Amount', - ) + assertInvalid(tx, 'XChainAddAccountCreateAttestation: invalid field Amount') }) it('throws w/ missing AttestationRewardAccount', function () { delete tx.AttestationRewardAccount - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field AttestationRewardAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field AttestationRewardAccount', ) }) @@ -97,14 +79,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid AttestationRewardAccount', function () { tx.AttestationRewardAccount = 123 - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field AttestationRewardAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field AttestationRewardAccount', ) }) @@ -112,14 +88,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing AttestationSignerAccount', function () { delete tx.AttestationSignerAccount - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field AttestationSignerAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field AttestationSignerAccount', ) }) @@ -127,14 +97,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid AttestationSignerAccount', function () { tx.AttestationSignerAccount = 123 - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field AttestationSignerAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field AttestationSignerAccount', ) }) @@ -142,14 +106,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing Destination', function () { delete tx.Destination - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field Destination', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field Destination', ) }) @@ -157,14 +115,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid Destination', function () { tx.Destination = 123 - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field Destination', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field Destination', ) }) @@ -172,14 +124,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing OtherChainSource', function () { delete tx.OtherChainSource - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field OtherChainSource', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field OtherChainSource', ) }) @@ -187,14 +133,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid OtherChainSource', function () { tx.OtherChainSource = 123 - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field OtherChainSource', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field OtherChainSource', ) }) @@ -202,14 +142,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing PublicKey', function () { delete tx.PublicKey - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field PublicKey', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field PublicKey', ) }) @@ -217,14 +151,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid PublicKey', function () { tx.PublicKey = 123 - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field PublicKey', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field PublicKey', ) }) @@ -232,14 +160,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing Signature', function () { delete tx.Signature - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field Signature', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field Signature', ) }) @@ -247,14 +169,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid Signature', function () { tx.Signature = 123 - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field Signature', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field Signature', ) }) @@ -262,14 +178,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing SignatureReward', function () { delete tx.SignatureReward - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field SignatureReward', ) }) @@ -277,14 +187,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid SignatureReward', function () { tx.SignatureReward = { currency: 'ETH' } - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field SignatureReward', ) }) @@ -292,14 +196,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing WasLockingChainSend', function () { delete tx.WasLockingChainSend - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field WasLockingChainSend', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field WasLockingChainSend', ) }) @@ -307,14 +205,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid WasLockingChainSend', function () { tx.WasLockingChainSend = 2 - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field WasLockingChainSend', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field WasLockingChainSend', ) }) @@ -322,14 +214,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing XChainAccountCreateCount', function () { delete tx.XChainAccountCreateCount - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field XChainAccountCreateCount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field XChainAccountCreateCount', ) }) @@ -337,14 +223,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid XChainAccountCreateCount', function () { tx.XChainAccountCreateCount = { currency: 'ETH' } - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field XChainAccountCreateCount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field XChainAccountCreateCount', ) }) @@ -352,14 +232,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: missing field XChainBridge', ) }) @@ -367,14 +241,8 @@ describe('XChainAddAccountCreateAttestation', function () { it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainAddAccountCreateAttestation(tx), - ValidationError, - 'XChainAddAccountCreateAttestation: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddAccountCreateAttestation: invalid field XChainBridge', ) }) diff --git a/packages/xrpl/test/models/XChainAddClaimAttestation.test.ts b/packages/xrpl/test/models/XChainAddClaimAttestation.test.ts index 4e7d1aeb7a..92783d9219 100644 --- a/packages/xrpl/test/models/XChainAddClaimAttestation.test.ts +++ b/packages/xrpl/test/models/XChainAddClaimAttestation.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainAddClaimAttestation } from '../../src/models/transactions/XChainAddClaimAttestation' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateXChainAddClaimAttestation) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateXChainAddClaimAttestation, message) /** * XChainAddClaimAttestation Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validateXChainAddClaimAttestation } from '../../src/models/transactions * Providing runtime verification testing for each specific transaction type. */ describe('XChainAddClaimAttestation', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -43,51 +46,26 @@ describe('XChainAddClaimAttestation', function () { }) it('verifies valid XChainAddClaimAttestation', function () { - assert.doesNotThrow(() => validateXChainAddClaimAttestation(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing Amount', function () { delete tx.Amount - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field Amount', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: missing field Amount') }) it('throws w/ invalid Amount', function () { tx.Amount = { currency: 'ETH' } - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field Amount', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: invalid field Amount') }) it('throws w/ missing AttestationRewardAccount', function () { delete tx.AttestationRewardAccount - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field AttestationRewardAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: missing field AttestationRewardAccount', ) }) @@ -95,14 +73,8 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ invalid AttestationRewardAccount', function () { tx.AttestationRewardAccount = 123 - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field AttestationRewardAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: invalid field AttestationRewardAccount', ) }) @@ -110,14 +82,8 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ missing AttestationSignerAccount', function () { delete tx.AttestationSignerAccount - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field AttestationSignerAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: missing field AttestationSignerAccount', ) }) @@ -125,14 +91,8 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ invalid AttestationSignerAccount', function () { tx.AttestationSignerAccount = 123 - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field AttestationSignerAccount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: invalid field AttestationSignerAccount', ) }) @@ -140,29 +100,14 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ invalid Destination', function () { tx.Destination = 123 - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field Destination', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field Destination', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: invalid field Destination') }) it('throws w/ missing OtherChainSource', function () { delete tx.OtherChainSource - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field OtherChainSource', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: missing field OtherChainSource', ) }) @@ -170,14 +115,8 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ invalid OtherChainSource', function () { tx.OtherChainSource = 123 - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field OtherChainSource', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: invalid field OtherChainSource', ) }) @@ -185,74 +124,32 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ missing PublicKey', function () { delete tx.PublicKey - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field PublicKey', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field PublicKey', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: missing field PublicKey') }) it('throws w/ invalid PublicKey', function () { tx.PublicKey = 123 - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field PublicKey', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field PublicKey', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: invalid field PublicKey') }) it('throws w/ missing Signature', function () { delete tx.Signature - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field Signature', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field Signature', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: missing field Signature') }) it('throws w/ invalid Signature', function () { tx.Signature = 123 - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field Signature', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field Signature', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: invalid field Signature') }) it('throws w/ missing WasLockingChainSend', function () { delete tx.WasLockingChainSend - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field WasLockingChainSend', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: missing field WasLockingChainSend', ) }) @@ -260,14 +157,8 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ invalid WasLockingChainSend', function () { tx.WasLockingChainSend = 2 - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field WasLockingChainSend', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainAddClaimAttestation: invalid field WasLockingChainSend', ) }) @@ -275,60 +166,24 @@ describe('XChainAddClaimAttestation', function () { it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field XChainBridge', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: missing field XChainBridge') }) it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field XChainBridge', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: invalid field XChainBridge') }) it('throws w/ missing XChainClaimID', function () { delete tx.XChainClaimID - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field XChainClaimID', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: missing field XChainClaimID', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: missing field XChainClaimID') }) it('throws w/ invalid XChainClaimID', function () { tx.XChainClaimID = { currency: 'ETH' } - assert.throws( - () => validateXChainAddClaimAttestation(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field XChainClaimID', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainAddClaimAttestation: invalid field XChainClaimID', - ) + assertInvalid(tx, 'XChainAddClaimAttestation: invalid field XChainClaimID') }) }) diff --git a/packages/xrpl/test/models/XChainClaim.test.ts b/packages/xrpl/test/models/XChainClaim.test.ts index 7b854ea786..8ec461224d 100644 --- a/packages/xrpl/test/models/XChainClaim.test.ts +++ b/packages/xrpl/test/models/XChainClaim.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainClaim } from '../../src/models/transactions/XChainClaim' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateXChainClaim) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateXChainClaim, message) /** * XChainClaim Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateXChainClaim } from '../../src/models/transactions/XChainClaim' * Providing runtime verification testing for each specific transaction type. */ describe('XChainClaim', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -35,142 +37,60 @@ describe('XChainClaim', function () { }) it('verifies valid XChainClaim', function () { - assert.doesNotThrow(() => validateXChainClaim(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: missing field XChainBridge', - ) + assertInvalid(tx, 'XChainClaim: missing field XChainBridge') }) it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: invalid field XChainBridge', - ) + assertInvalid(tx, 'XChainClaim: invalid field XChainBridge') }) it('throws w/ missing XChainClaimID', function () { delete tx.XChainClaimID - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: missing field XChainClaimID', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: missing field XChainClaimID', - ) + assertInvalid(tx, 'XChainClaim: missing field XChainClaimID') }) it('throws w/ invalid XChainClaimID', function () { tx.XChainClaimID = { currency: 'ETH' } - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: invalid field XChainClaimID', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: invalid field XChainClaimID', - ) + assertInvalid(tx, 'XChainClaim: invalid field XChainClaimID') }) it('throws w/ missing Destination', function () { delete tx.Destination - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: missing field Destination', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: missing field Destination', - ) + assertInvalid(tx, 'XChainClaim: missing field Destination') }) it('throws w/ invalid Destination', function () { tx.Destination = 123 - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: invalid field Destination', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: invalid field Destination', - ) + assertInvalid(tx, 'XChainClaim: invalid field Destination') }) it('throws w/ invalid DestinationTag', function () { tx.DestinationTag = 'number' - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: invalid field DestinationTag', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: invalid field DestinationTag', - ) + assertInvalid(tx, 'XChainClaim: invalid field DestinationTag') }) it('throws w/ missing Amount', function () { delete tx.Amount - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: missing field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: missing field Amount', - ) + assertInvalid(tx, 'XChainClaim: missing field Amount') }) it('throws w/ invalid Amount', function () { tx.Amount = { currency: 'ETH' } - assert.throws( - () => validateXChainClaim(tx), - ValidationError, - 'XChainClaim: invalid field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainClaim: invalid field Amount', - ) + assertInvalid(tx, 'XChainClaim: invalid field Amount') }) }) diff --git a/packages/xrpl/test/models/XChainCommit.test.ts b/packages/xrpl/test/models/XChainCommit.test.ts index 4963cf1bef..2d2952a8eb 100644 --- a/packages/xrpl/test/models/XChainCommit.test.ts +++ b/packages/xrpl/test/models/XChainCommit.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainCommit } from '../../src/models/transactions/XChainCommit' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateXChainCommit) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateXChainCommit, message) /** * XChainCommit Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateXChainCommit } from '../../src/models/transactions/XChainCommit * Providing runtime verification testing for each specific transaction type. */ describe('XChainCommit', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -34,112 +36,48 @@ describe('XChainCommit', function () { }) it('verifies valid XChainCommit', function () { - assert.doesNotThrow(() => validateXChainCommit(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainCommit(tx), - ValidationError, - 'XChainCommit: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCommit: missing field XChainBridge', - ) + assertInvalid(tx, 'XChainCommit: missing field XChainBridge') }) it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainCommit(tx), - ValidationError, - 'XChainCommit: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCommit: invalid field XChainBridge', - ) + assertInvalid(tx, 'XChainCommit: invalid field XChainBridge') }) it('throws w/ missing XChainClaimID', function () { delete tx.XChainClaimID - assert.throws( - () => validateXChainCommit(tx), - ValidationError, - 'XChainCommit: missing field XChainClaimID', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCommit: missing field XChainClaimID', - ) + assertInvalid(tx, 'XChainCommit: missing field XChainClaimID') }) it('throws w/ invalid XChainClaimID', function () { tx.XChainClaimID = { currency: 'ETH' } - assert.throws( - () => validateXChainCommit(tx), - ValidationError, - 'XChainCommit: invalid field XChainClaimID', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCommit: invalid field XChainClaimID', - ) + assertInvalid(tx, 'XChainCommit: invalid field XChainClaimID') }) it('throws w/ invalid OtherChainDestination', function () { tx.OtherChainDestination = 123 - assert.throws( - () => validateXChainCommit(tx), - ValidationError, - 'XChainCommit: invalid field OtherChainDestination', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCommit: invalid field OtherChainDestination', - ) + assertInvalid(tx, 'XChainCommit: invalid field OtherChainDestination') }) it('throws w/ missing Amount', function () { delete tx.Amount - assert.throws( - () => validateXChainCommit(tx), - ValidationError, - 'XChainCommit: missing field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCommit: missing field Amount', - ) + assertInvalid(tx, 'XChainCommit: missing field Amount') }) it('throws w/ invalid Amount', function () { tx.Amount = { currency: 'ETH' } - assert.throws( - () => validateXChainCommit(tx), - ValidationError, - 'XChainCommit: invalid field Amount', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCommit: invalid field Amount', - ) + assertInvalid(tx, 'XChainCommit: invalid field Amount') }) }) diff --git a/packages/xrpl/test/models/XChainCreateBridge.test.ts b/packages/xrpl/test/models/XChainCreateBridge.test.ts index dfd174058e..740c92030d 100644 --- a/packages/xrpl/test/models/XChainCreateBridge.test.ts +++ b/packages/xrpl/test/models/XChainCreateBridge.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainCreateBridge } from '../../src/models/transactions/XChainCreateBridge' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateXChainCreateBridge) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateXChainCreateBridge, message) /** * XChainCreateBridge Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validateXChainCreateBridge } from '../../src/models/transactions/XChain * Providing runtime verification testing for each specific transaction type. */ describe('XChainCreateBridge', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -34,81 +37,38 @@ describe('XChainCreateBridge', function () { }) it('verifies valid XChainCreateBridge', function () { - assert.doesNotThrow(() => validateXChainCreateBridge(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainCreateBridge(tx), - ValidationError, - 'XChainCreateBridge: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateBridge: missing field XChainBridge', - ) + assertInvalid(tx, 'XChainCreateBridge: missing field XChainBridge') }) it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainCreateBridge(tx), - ValidationError, - 'XChainCreateBridge: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateBridge: invalid field XChainBridge', - ) + assertInvalid(tx, 'XChainCreateBridge: invalid field XChainBridge') }) it('throws w/ missing SignatureReward', function () { delete tx.SignatureReward - assert.throws( - () => validateXChainCreateBridge(tx), - ValidationError, - 'XChainCreateBridge: missing field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateBridge: missing field SignatureReward', - ) + assertInvalid(tx, 'XChainCreateBridge: missing field SignatureReward') }) it('throws w/ invalid SignatureReward', function () { tx.SignatureReward = { currency: 'ETH' } - assert.throws( - () => validateXChainCreateBridge(tx), - ValidationError, - 'XChainCreateBridge: invalid field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateBridge: invalid field SignatureReward', - ) + assertInvalid(tx, 'XChainCreateBridge: invalid field SignatureReward') }) it('throws w/ invalid MinAccountCreateAmount', function () { tx.MinAccountCreateAmount = { currency: 'ETH' } - assert.throws( - () => validateXChainCreateBridge(tx), - ValidationError, - 'XChainCreateBridge: invalid field MinAccountCreateAmount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainCreateBridge: invalid field MinAccountCreateAmount', ) }) diff --git a/packages/xrpl/test/models/XChainCreateClaimID.test.ts b/packages/xrpl/test/models/XChainCreateClaimID.test.ts index 503fae0130..620e830954 100644 --- a/packages/xrpl/test/models/XChainCreateClaimID.test.ts +++ b/packages/xrpl/test/models/XChainCreateClaimID.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainCreateClaimID } from '../../src/models/transactions/XChainCreateClaimID' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateXChainCreateClaimID) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateXChainCreateClaimID, message) /** * XChainCreateClaimID Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validateXChainCreateClaimID } from '../../src/models/transactions/XChai * Providing runtime verification testing for each specific transaction type. */ describe('XChainCreateClaimID', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -34,97 +37,42 @@ describe('XChainCreateClaimID', function () { }) it('verifies valid XChainCreateClaimID', function () { - assert.doesNotThrow(() => validateXChainCreateClaimID(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainCreateClaimID(tx), - ValidationError, - 'XChainCreateClaimID: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateClaimID: missing field XChainBridge', - ) + assertInvalid(tx, 'XChainCreateClaimID: missing field XChainBridge') }) it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainCreateClaimID(tx), - ValidationError, - 'XChainCreateClaimID: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateClaimID: invalid field XChainBridge', - ) + assertInvalid(tx, 'XChainCreateClaimID: invalid field XChainBridge') }) it('throws w/ missing SignatureReward', function () { delete tx.SignatureReward - assert.throws( - () => validateXChainCreateClaimID(tx), - ValidationError, - 'XChainCreateClaimID: missing field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateClaimID: missing field SignatureReward', - ) + assertInvalid(tx, 'XChainCreateClaimID: missing field SignatureReward') }) it('throws w/ invalid SignatureReward', function () { tx.SignatureReward = { currency: 'ETH' } - assert.throws( - () => validateXChainCreateClaimID(tx), - ValidationError, - 'XChainCreateClaimID: invalid field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateClaimID: invalid field SignatureReward', - ) + assertInvalid(tx, 'XChainCreateClaimID: invalid field SignatureReward') }) it('throws w/ missing OtherChainSource', function () { delete tx.OtherChainSource - assert.throws( - () => validateXChainCreateClaimID(tx), - ValidationError, - 'XChainCreateClaimID: missing field OtherChainSource', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateClaimID: missing field OtherChainSource', - ) + assertInvalid(tx, 'XChainCreateClaimID: missing field OtherChainSource') }) it('throws w/ invalid OtherChainSource', function () { tx.OtherChainSource = 123 - assert.throws( - () => validateXChainCreateClaimID(tx), - ValidationError, - 'XChainCreateClaimID: invalid field OtherChainSource', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainCreateClaimID: invalid field OtherChainSource', - ) + assertInvalid(tx, 'XChainCreateClaimID: invalid field OtherChainSource') }) }) diff --git a/packages/xrpl/test/models/XChainModifyBridge.test.ts b/packages/xrpl/test/models/XChainModifyBridge.test.ts index 57eeb50823..4ad095c999 100644 --- a/packages/xrpl/test/models/XChainModifyBridge.test.ts +++ b/packages/xrpl/test/models/XChainModifyBridge.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateXChainModifyBridge } from '../../src/models/transactions/XChainModifyBridge' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateXChainModifyBridge) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateXChainModifyBridge, message) /** * XChainModifyBridge Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validateXChainModifyBridge } from '../../src/models/transactions/XChain * Providing runtime verification testing for each specific transaction type. */ describe('XChainModifyBridge', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -34,66 +37,32 @@ describe('XChainModifyBridge', function () { }) it('verifies valid XChainModifyBridge', function () { - assert.doesNotThrow(() => validateXChainModifyBridge(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it('throws w/ missing XChainBridge', function () { delete tx.XChainBridge - assert.throws( - () => validateXChainModifyBridge(tx), - ValidationError, - 'XChainModifyBridge: missing field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainModifyBridge: missing field XChainBridge', - ) + assertInvalid(tx, 'XChainModifyBridge: missing field XChainBridge') }) it('throws w/ invalid XChainBridge', function () { tx.XChainBridge = { XChainDoor: 'test' } - assert.throws( - () => validateXChainModifyBridge(tx), - ValidationError, - 'XChainModifyBridge: invalid field XChainBridge', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainModifyBridge: invalid field XChainBridge', - ) + assertInvalid(tx, 'XChainModifyBridge: invalid field XChainBridge') }) it('throws w/ invalid SignatureReward', function () { tx.SignatureReward = { currency: 'ETH' } - assert.throws( - () => validateXChainModifyBridge(tx), - ValidationError, - 'XChainModifyBridge: invalid field SignatureReward', - ) - assert.throws( - () => validate(tx), - ValidationError, - 'XChainModifyBridge: invalid field SignatureReward', - ) + assertInvalid(tx, 'XChainModifyBridge: invalid field SignatureReward') }) it('throws w/ invalid MinAccountCreateAmount', function () { tx.MinAccountCreateAmount = { currency: 'ETH' } - assert.throws( - () => validateXChainModifyBridge(tx), - ValidationError, - 'XChainModifyBridge: invalid field MinAccountCreateAmount', - ) - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'XChainModifyBridge: invalid field MinAccountCreateAmount', ) }) diff --git a/packages/xrpl/test/models/accountDelete.test.ts b/packages/xrpl/test/models/accountDelete.test.ts index 34b0cfa0f0..d309706905 100644 --- a/packages/xrpl/test/models/accountDelete.test.ts +++ b/packages/xrpl/test/models/accountDelete.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateAccountDelete } from '../../src/models/transactions/accountDelete' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateAccountDelete) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAccountDelete, message) /** * AccountDelete Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validateAccountDelete } from '../../src/models/transactions/accountDele * Providing runtime verification testing for each specific transaction type. */ describe('AccountDelete', function () { - let validAccountDelete + let validAccountDelete: any beforeEach(() => { validAccountDelete = { @@ -23,60 +26,28 @@ describe('AccountDelete', function () { CredentialIDs: [ 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66A', ], - } as any + } }) it(`verifies valid AccountDelete`, function () { - assert.doesNotThrow(() => validateAccountDelete(validAccountDelete)) + assertValid(validAccountDelete) }) it(`throws w/ missing Destination`, function () { validAccountDelete.Destination = undefined const errorMessage = 'AccountDelete: missing field Destination' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) it(`throws w/ invalid Destination`, function () { validAccountDelete.Destination = 65478965 const errorMessage = 'AccountDelete: invalid field Destination' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) it(`throws w/ invalid DestinationTag`, function () { validAccountDelete.DestinationTag = 'gvftyujnbv' const errorMessage = 'AccountDelete: invalid field DestinationTag' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) it(`throws w/ non-array CredentialIDs`, function () { @@ -84,17 +55,7 @@ describe('AccountDelete', function () { 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66A' const errorMessage = 'AccountDelete: Credentials must be an array' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) it(`throws CredentialIDs length exceeds max length`, function () { @@ -112,34 +73,14 @@ describe('AccountDelete', function () { const errorMessage = 'AccountDelete: Credentials length cannot exceed 8 elements' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) it(`throws w/ empty CredentialIDs`, function () { validAccountDelete.CredentialIDs = [] const errorMessage = 'AccountDelete: Credentials cannot be an empty array' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) it(`throws w/ non-string CredentialIDs`, function () { @@ -149,17 +90,7 @@ describe('AccountDelete', function () { ] const errorMessage = 'AccountDelete: Invalid Credentials ID list format' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) it(`throws w/ duplicate CredentialIDs`, function () { @@ -170,16 +101,6 @@ describe('AccountDelete', function () { const errorMessage = 'AccountDelete: Credentials cannot contain duplicate elements' - - assert.throws( - () => validateAccountDelete(validAccountDelete), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(validAccountDelete), - ValidationError, - errorMessage, - ) + assertInvalid(validAccountDelete, errorMessage) }) }) diff --git a/packages/xrpl/test/models/accountSet.test.ts b/packages/xrpl/test/models/accountSet.test.ts index b3ce24eadd..7bd25952e4 100644 --- a/packages/xrpl/test/models/accountSet.test.ts +++ b/packages/xrpl/test/models/accountSet.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateAccountSet } from '../../src/models/transactions/accountSet' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateAccountSet) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateAccountSet, message) /** * AccountSet Transaction Verification Testing. @@ -9,10 +11,10 @@ import { validateAccountSet } from '../../src/models/transactions/accountSet' * Providing runtime verification testing for each specific transaction type. */ describe('AccountSet', function () { - let account + let tx: any beforeEach(function () { - account = { + tx = { TransactionType: 'AccountSet', Account: 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn', Fee: '12', @@ -21,146 +23,55 @@ describe('AccountSet', function () { SetFlag: 5, MessageKey: '03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB', - } as any + } }) it(`verifies valid AccountSet`, function () { - assert.doesNotThrow(() => validateAccountSet(account)) - assert.doesNotThrow(() => validate(account)) + assertValid(tx) }) it(`throws w/ invalid SetFlag (out of range)`, function () { - account.SetFlag = 20 - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid SetFlag', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid SetFlag', - ) + tx.SetFlag = 20 + assertInvalid(tx, 'AccountSet: invalid SetFlag') }) it(`throws w/ invalid SetFlag (incorrect type)`, function () { - account.SetFlag = 'abc' - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid SetFlag', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid SetFlag', - ) + tx.SetFlag = 'abc' + assertInvalid(tx, 'AccountSet: invalid SetFlag') }) it(`throws w/ invalid ClearFlag`, function () { - account.ClearFlag = 20 - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid ClearFlag', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid ClearFlag', - ) + tx.ClearFlag = 20 + assertInvalid(tx, 'AccountSet: invalid ClearFlag') }) it(`throws w/ invalid Domain`, function () { - account.Domain = 6578616 - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid Domain', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid Domain', - ) + tx.Domain = 6578616 + assertInvalid(tx, 'AccountSet: invalid Domain') }) it(`throws w/ invalid EmailHash`, function () { - account.EmailHash = 6578656789876543 - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid EmailHash', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid EmailHash', - ) + tx.EmailHash = 6578656789876543 + assertInvalid(tx, 'AccountSet: invalid EmailHash') }) it(`throws w/ invalid MessageKey`, function () { - account.MessageKey = 6578656789876543 - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid MessageKey', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid MessageKey', - ) + tx.MessageKey = 6578656789876543 + assertInvalid(tx, 'AccountSet: invalid MessageKey') }) it(`throws w/ invalid TransferRate`, function () { - account.TransferRate = '1000000001' - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid TransferRate', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid TransferRate', - ) + tx.TransferRate = '1000000001' + assertInvalid(tx, 'AccountSet: invalid TransferRate') }) it(`throws w/ invalid TickSize`, function () { - account.TickSize = 20 - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid TickSize', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid TickSize', - ) + tx.TickSize = 20 + assertInvalid(tx, 'AccountSet: invalid TickSize') }) it(`throws w/ invalid NFTokenMinter`, function () { - account.NFTokenMinter = '' - - assert.throws( - () => validateAccountSet(account), - ValidationError, - 'AccountSet: invalid field NFTokenMinter', - ) - assert.throws( - () => validate(account), - ValidationError, - 'AccountSet: invalid field NFTokenMinter', - ) + tx.NFTokenMinter = '' + assertInvalid(tx, 'AccountSet: invalid field NFTokenMinter') }) }) diff --git a/packages/xrpl/test/models/baseTransaction.test.ts b/packages/xrpl/test/models/baseTransaction.test.ts index 10e272f7f2..631a5721c9 100644 --- a/packages/xrpl/test/models/baseTransaction.test.ts +++ b/packages/xrpl/test/models/baseTransaction.test.ts @@ -3,6 +3,11 @@ import { assert } from 'chai' import { ValidationError } from '../../src' import { validateBaseTransaction } from '../../src/models/transactions/common' +const assertValid = (tx: any): void => + assert.doesNotThrow(() => validateBaseTransaction(tx)) +const assertInvalid = (tx: any, message: string): void => + assert.throws(() => validateBaseTransaction(tx), ValidationError, message) + /** * Transaction Verification Testing. * @@ -10,7 +15,7 @@ import { validateBaseTransaction } from '../../src/models/transactions/common' */ describe('BaseTransaction', function () { it(`Verifies all optional BaseTransaction`, function () { - const txJson = { + const txJson: any = { Account: 'r97KeayHuEsDwyU1yPBVtMLLoQr79QcRFe', TransactionType: 'Payment', Fee: '12', @@ -56,7 +61,7 @@ describe('BaseTransaction', function () { '3045022100C6708538AE5A697895937C758E99A595B57A16393F370F11B8D4C032E80B532002207776A8E85BB9FAF460A92113B9C60F170CD964196B1F084E0DAB65BAEC368B66', } - assert.doesNotThrow(() => validateBaseTransaction(txJson)) + assertValid(txJson) }) it(`Verifies only required BaseTransaction`, function () { @@ -65,7 +70,7 @@ describe('BaseTransaction', function () { TransactionType: 'Payment', } - assert.doesNotThrow(() => validateBaseTransaction(txJson)) + assertValid(txJson) }) it(`Handles invalid Fee`, function () { @@ -75,11 +80,7 @@ describe('BaseTransaction', function () { Fee: 1000, } as any - assert.throws( - () => validateBaseTransaction(invalidFee), - ValidationError, - 'Payment: invalid field Fee', - ) + assertInvalid(invalidFee, 'Payment: invalid field Fee') }) it(`Handles invalid Sequence`, function () { @@ -89,11 +90,7 @@ describe('BaseTransaction', function () { Sequence: '145', } as any - assert.throws( - () => validateBaseTransaction(invalidSeq), - ValidationError, - 'Payment: invalid field Sequence', - ) + assertInvalid(invalidSeq, 'Payment: invalid field Sequence') }) it(`Handles invalid AccountTxnID`, function () { @@ -103,11 +100,7 @@ describe('BaseTransaction', function () { AccountTxnID: ['WRONG'], } as any - assert.throws( - () => validateBaseTransaction(invalidID), - ValidationError, - 'Payment: invalid field AccountTxnID', - ) + assertInvalid(invalidID, 'Payment: invalid field AccountTxnID') }) it(`Handles invalid LastLedgerSequence`, function () { @@ -117,9 +110,8 @@ describe('BaseTransaction', function () { LastLedgerSequence: '1000', } as any - assert.throws( - () => validateBaseTransaction(invalidLastLedgerSequence), - ValidationError, + assertInvalid( + invalidLastLedgerSequence, 'Payment: invalid field LastLedgerSequence', ) }) @@ -131,11 +123,7 @@ describe('BaseTransaction', function () { SourceTag: ['ARRAY'], } as any - assert.throws( - () => validateBaseTransaction(invalidSourceTag), - ValidationError, - 'Payment: invalid field SourceTag', - ) + assertInvalid(invalidSourceTag, 'Payment: invalid field SourceTag') }) it(`Handles invalid SigningPubKey`, function () { @@ -145,11 +133,7 @@ describe('BaseTransaction', function () { SigningPubKey: 1000, } as any - assert.throws( - () => validateBaseTransaction(invalidSigningPubKey), - ValidationError, - 'Payment: invalid field SigningPubKey', - ) + assertInvalid(invalidSigningPubKey, 'Payment: invalid field SigningPubKey') }) it(`Handles invalid TicketSequence`, function () { @@ -159,9 +143,8 @@ describe('BaseTransaction', function () { TicketSequence: '1000', } as any - assert.throws( - () => validateBaseTransaction(invalidTicketSequence), - ValidationError, + assertInvalid( + invalidTicketSequence, 'Payment: invalid field TicketSequence', ) }) @@ -173,11 +156,7 @@ describe('BaseTransaction', function () { TxnSignature: 1000, } as any - assert.throws( - () => validateBaseTransaction(invalidTxnSignature), - ValidationError, - 'Payment: invalid field TxnSignature', - ) + assertInvalid(invalidTxnSignature, 'Payment: invalid field TxnSignature') }) it(`Handles invalid Signers`, function () { @@ -187,11 +166,7 @@ describe('BaseTransaction', function () { Signers: [], } as any - assert.throws( - () => validateBaseTransaction(invalidSigners), - ValidationError, - 'BaseTransaction: invalid Signers', - ) + assertInvalid(invalidSigners, 'BaseTransaction: invalid Signers') const invalidSigners2 = { Account: 'r97KeayHuEsDwyU1yPBVtMLLoQr79QcRFe', @@ -205,11 +180,7 @@ describe('BaseTransaction', function () { ], } as any - assert.throws( - () => validateBaseTransaction(invalidSigners2), - ValidationError, - 'BaseTransaction: invalid Signers', - ) + assertInvalid(invalidSigners2, 'BaseTransaction: invalid Signers') }) it(`Handles invalid Memo`, function () { @@ -226,11 +197,7 @@ describe('BaseTransaction', function () { ], } as any - assert.throws( - () => validateBaseTransaction(invalidMemo), - ValidationError, - 'BaseTransaction: invalid Memos', - ) + assertInvalid(invalidMemo, 'BaseTransaction: invalid Memos') }) it(`Handles invalid NetworkID`, function () { @@ -239,10 +206,6 @@ describe('BaseTransaction', function () { TransactionType: 'Payment', NetworkID: '1024', } - assert.throws( - () => validateBaseTransaction(invalidNetworkID), - ValidationError, - 'Payment: invalid field NetworkID', - ) + assertInvalid(invalidNetworkID, 'Payment: invalid field NetworkID') }) }) diff --git a/packages/xrpl/test/models/checkCancel.test.ts b/packages/xrpl/test/models/checkCancel.test.ts index 1cf87834a7..ed180d5629 100644 --- a/packages/xrpl/test/models/checkCancel.test.ts +++ b/packages/xrpl/test/models/checkCancel.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateCheckCancel } from '../../src/models/transactions/checkCancel' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateCheckCancel) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateCheckCancel, message) /** * CheckCancel Transaction Verification Testing. @@ -17,8 +19,7 @@ describe('CheckCancel', function () { '49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0', } as any - assert.doesNotThrow(() => validateCheckCancel(validCheckCancel)) - assert.doesNotThrow(() => validate(validCheckCancel)) + assertValid(validCheckCancel) }) it(`throws w/ invalid CheckCancel`, function () { @@ -28,15 +29,6 @@ describe('CheckCancel', function () { CheckID: 4964734566545678, } as any - assert.throws( - () => validateCheckCancel(invalidCheckID), - ValidationError, - 'CheckCancel: invalid CheckID', - ) - assert.throws( - () => validate(invalidCheckID), - ValidationError, - 'CheckCancel: invalid CheckID', - ) + assertInvalid(invalidCheckID, 'CheckCancel: invalid CheckID') }) }) diff --git a/packages/xrpl/test/models/checkCash.test.ts b/packages/xrpl/test/models/checkCash.test.ts index 918bdeb300..401cd0df18 100644 --- a/packages/xrpl/test/models/checkCash.test.ts +++ b/packages/xrpl/test/models/checkCash.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateCheckCash } from '../../src/models/transactions/checkCash' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateCheckCash) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateCheckCash, message) /** * CheckCash Transaction Verification Testing. @@ -19,8 +21,7 @@ describe('CheckCash', function () { Fee: '12', } as any - assert.doesNotThrow(() => validateCheckCash(validCheckCash)) - assert.doesNotThrow(() => validate(validCheckCash)) + assertValid(validCheckCash) }) it(`throws w/ invalid CheckID`, function () { @@ -31,16 +32,7 @@ describe('CheckCash', function () { CheckID: 83876645678567890, } as any - assert.throws( - () => validateCheckCash(invalidCheckID), - ValidationError, - 'CheckCash: invalid CheckID', - ) - assert.throws( - () => validate(invalidCheckID), - ValidationError, - 'CheckCash: invalid CheckID', - ) + assertInvalid(invalidCheckID, 'CheckCash: invalid CheckID') }) it(`throws w/ invalid Amount`, function () { @@ -52,16 +44,7 @@ describe('CheckCash', function () { '838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334', } as any - assert.throws( - () => validateCheckCash(invalidAmount), - ValidationError, - 'CheckCash: invalid Amount', - ) - assert.throws( - () => validate(invalidAmount), - ValidationError, - 'CheckCash: invalid Amount', - ) + assertInvalid(invalidAmount, 'CheckCash: invalid Amount') }) it(`throws w/ having both Amount and DeliverMin`, function () { @@ -74,14 +57,8 @@ describe('CheckCash', function () { '838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334', } as any - assert.throws( - () => validateCheckCash(invalidDeliverMin), - ValidationError, - 'CheckCash: cannot have both Amount and DeliverMin', - ) - assert.throws( - () => validate(invalidDeliverMin), - ValidationError, + assertInvalid( + invalidDeliverMin, 'CheckCash: cannot have both Amount and DeliverMin', ) }) @@ -95,15 +72,6 @@ describe('CheckCash', function () { '838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334', } as any - assert.throws( - () => validateCheckCash(invalidDeliverMin), - ValidationError, - 'CheckCash: invalid DeliverMin', - ) - assert.throws( - () => validate(invalidDeliverMin), - ValidationError, - 'CheckCash: invalid DeliverMin', - ) + assertInvalid(invalidDeliverMin, 'CheckCash: invalid DeliverMin') }) }) diff --git a/packages/xrpl/test/models/checkCreate.test.ts b/packages/xrpl/test/models/checkCreate.test.ts index a97be25184..812973705f 100644 --- a/packages/xrpl/test/models/checkCreate.test.ts +++ b/packages/xrpl/test/models/checkCreate.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateCheckCreate } from '../../src/models/transactions/checkCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateCheckCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateCheckCreate, message) /** * CheckCreate Transaction Verification Testing. @@ -22,8 +24,7 @@ describe('CheckCreate', function () { Fee: '12', } as any - assert.doesNotThrow(() => validateCheckCreate(validCheck)) - assert.doesNotThrow(() => validate(validCheck)) + assertValid(validCheck) }) it(`throws w/ invalid Destination`, function () { @@ -39,16 +40,7 @@ describe('CheckCreate', function () { Fee: '12', } as any - assert.throws( - () => validateCheckCreate(invalidDestination), - ValidationError, - 'CheckCreate: invalid field Destination', - ) - assert.throws( - () => validate(invalidDestination), - ValidationError, - 'CheckCreate: invalid field Destination', - ) + assertInvalid(invalidDestination, 'CheckCreate: invalid field Destination') }) it(`throws w/ invalid SendMax`, function () { @@ -64,16 +56,7 @@ describe('CheckCreate', function () { Fee: '12', } as any - assert.throws( - () => validateCheckCreate(invalidSendMax), - ValidationError, - 'CheckCreate: invalid SendMax', - ) - assert.throws( - () => validate(invalidSendMax), - ValidationError, - 'CheckCreate: invalid SendMax', - ) + assertInvalid(invalidSendMax, 'CheckCreate: invalid SendMax') }) it(`throws w/ invalid DestinationTag`, function () { @@ -89,14 +72,8 @@ describe('CheckCreate', function () { Fee: '12', } as any - assert.throws( - () => validateCheckCreate(invalidDestinationTag), - ValidationError, - 'CheckCreate: invalid field DestinationTag', - ) - assert.throws( - () => validate(invalidDestinationTag), - ValidationError, + assertInvalid( + invalidDestinationTag, 'CheckCreate: invalid field DestinationTag', ) }) @@ -114,16 +91,7 @@ describe('CheckCreate', function () { Fee: '12', } as any - assert.throws( - () => validateCheckCreate(invalidExpiration), - ValidationError, - 'CheckCreate: invalid Expiration', - ) - assert.throws( - () => validate(invalidExpiration), - ValidationError, - 'CheckCreate: invalid Expiration', - ) + assertInvalid(invalidExpiration, 'CheckCreate: invalid Expiration') }) it(`throws w/ invalid InvoiceID`, function () { @@ -138,15 +106,6 @@ describe('CheckCreate', function () { Fee: '12', } as any - assert.throws( - () => validateCheckCreate(invalidInvoiceID), - ValidationError, - 'CheckCreate: invalid InvoiceID', - ) - assert.throws( - () => validate(invalidInvoiceID), - ValidationError, - 'CheckCreate: invalid InvoiceID', - ) + assertInvalid(invalidInvoiceID, 'CheckCreate: invalid InvoiceID') }) }) diff --git a/packages/xrpl/test/models/clawback.test.ts b/packages/xrpl/test/models/clawback.test.ts index 30abcdfcb9..38efaa7104 100644 --- a/packages/xrpl/test/models/clawback.test.ts +++ b/packages/xrpl/test/models/clawback.test.ts @@ -1,6 +1,9 @@ -import { assert } from 'chai' +import { validateClawback } from '../../src/models/transactions/clawback' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' -import { validate, ValidationError } from '../../src' +const assertValid = (tx: any): void => assertTxIsValid(tx, validateClawback) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateClawback, message) /** * Clawback Transaction Verification Testing. @@ -19,7 +22,7 @@ describe('Clawback', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.doesNotThrow(() => validate(validClawback)) + assertValid(validClawback) }) it(`throws w/ missing Amount`, function () { @@ -28,11 +31,7 @@ describe('Clawback', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(missingAmount), - ValidationError, - 'Clawback: missing field Amount', - ) + assertInvalid(missingAmount, 'Clawback: missing field Amount') }) it(`throws w/ invalid Amount`, function () { @@ -42,11 +41,7 @@ describe('Clawback', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalidAmount), - ValidationError, - 'Clawback: invalid Amount', - ) + assertInvalid(invalidAmount, 'Clawback: invalid Amount') const invalidStrAmount = { TransactionType: 'Clawback', @@ -54,11 +49,7 @@ describe('Clawback', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalidStrAmount), - ValidationError, - 'Clawback: invalid Amount', - ) + assertInvalid(invalidStrAmount, 'Clawback: invalid Amount') }) it(`throws w/ invalid holder Account`, function () { @@ -72,11 +63,7 @@ describe('Clawback', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalidAccount), - ValidationError, - 'Clawback: invalid holder Account', - ) + assertInvalid(invalidAccount, 'Clawback: invalid holder Account') }) it(`verifies valid MPT Clawback`, function () { @@ -90,7 +77,7 @@ describe('Clawback', function () { Holder: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy', } as any - assert.doesNotThrow(() => validate(validClawback)) + assertValid(validClawback) }) it(`throws w/ invalid Holder Account`, function () { @@ -104,11 +91,7 @@ describe('Clawback', function () { Holder: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalidAccount), - ValidationError, - 'Clawback: invalid holder Account', - ) + assertInvalid(invalidAccount, 'Clawback: invalid holder Account') }) it(`throws w/ invalid Holder`, function () { @@ -121,11 +104,7 @@ describe('Clawback', function () { Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm', } as any - assert.throws( - () => validate(invalidAccount), - ValidationError, - 'Clawback: missing Holder', - ) + assertInvalid(invalidAccount, 'Clawback: missing Holder') }) it(`throws w/ invalid currency Holder`, function () { @@ -140,10 +119,6 @@ describe('Clawback', function () { Holder: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy', } as any - assert.throws( - () => validate(invalidAccount), - ValidationError, - 'Clawback: cannot have Holder for currency', - ) + assertInvalid(invalidAccount, 'Clawback: cannot have Holder for currency') }) }) diff --git a/packages/xrpl/test/models/depositPreauth.test.ts b/packages/xrpl/test/models/depositPreauth.test.ts index d2598ba452..f659f57421 100644 --- a/packages/xrpl/test/models/depositPreauth.test.ts +++ b/packages/xrpl/test/models/depositPreauth.test.ts @@ -1,8 +1,13 @@ import { stringToHex } from '@xrplf/isomorphic/dist/utils' -import { assert } from 'chai' -import { AuthorizeCredential, validate, ValidationError } from '../../src' +import { AuthorizeCredential } from '../../src' import { validateDepositPreauth } from '../../src/models/transactions/depositPreauth' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateDepositPreauth) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateDepositPreauth, message) /** * DepositPreauth Transaction Verification Testing. @@ -10,7 +15,7 @@ import { validateDepositPreauth } from '../../src/models/transactions/depositPre * Providing runtime verification testing for each specific transaction type. */ describe('DepositPreauth', function () { - let depositPreauth + let depositPreauth: any const validCredential = { Credential: { @@ -28,26 +33,22 @@ describe('DepositPreauth', function () { it('verifies valid DepositPreauth when only Authorize is provided', function () { depositPreauth.Authorize = 'rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW' - assert.doesNotThrow(() => validateDepositPreauth(depositPreauth)) - assert.doesNotThrow(() => validate(depositPreauth)) + assertValid(depositPreauth) }) it('verifies valid DepositPreauth when only Unauthorize is provided', function () { depositPreauth.Unauthorize = 'raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n' - assert.doesNotThrow(() => validateDepositPreauth(depositPreauth)) - assert.doesNotThrow(() => validate(depositPreauth)) + assertValid(depositPreauth) }) it('verifies valid DepositPreauth when only AuthorizeCredentials is provided', function () { depositPreauth.AuthorizeCredentials = [validCredential] - assert.doesNotThrow(() => validateDepositPreauth(depositPreauth)) - assert.doesNotThrow(() => validate(depositPreauth)) + assertValid(depositPreauth) }) it('verifies valid DepositPreauth when only UnauthorizeCredentials is provided', function () { depositPreauth.UnauthorizeCredentials = [validCredential] - assert.doesNotThrow(() => validateDepositPreauth(depositPreauth)) - assert.doesNotThrow(() => validate(depositPreauth)) + assertValid(depositPreauth) }) it('throws when multiple of Authorize, Unauthorize, AuthorizeCredentials, UnauthorizeCredentials are provided', function () { @@ -56,104 +57,56 @@ describe('DepositPreauth', function () { depositPreauth.Authorize = 'rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW' depositPreauth.UnauthorizeCredentials = [validCredential] - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) depositPreauth.Unauthorize = 'raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n' - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) depositPreauth.AuthorizeCredentials = [validCredential] - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) depositPreauth.Authorize = undefined - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) depositPreauth.UnauthorizeCredentials = undefined - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when none of Authorize, Unauthorize, AuthorizeCredentials, UnauthorizeCredentials are provided', function () { const errorMessage = 'DepositPreauth: Requires exactly one field of the following: Authorize, Unauthorize, AuthorizeCredentials, UnauthorizeCredentials.' - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when Authorize is not a string', function () { depositPreauth.Authorize = 1234 - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - 'DepositPreauth: Authorize must be a string', - ) - assert.throws( - () => validate(depositPreauth), - ValidationError, - 'DepositPreauth: Authorize must be a string', - ) + assertInvalid(depositPreauth, 'DepositPreauth: Authorize must be a string') }) it('throws when an Account attempts to preauthorize its own address', function () { depositPreauth.Authorize = depositPreauth.Account - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, + assertInvalid( + depositPreauth, "DepositPreauth: Account can't preauthorize its own address", ) }) it('throws when Unauthorize is not a string', function () { depositPreauth.Unauthorize = 1234 - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - 'DepositPreauth: Unauthorize must be a string', - ) - assert.throws( - () => validate(depositPreauth), - ValidationError, + assertInvalid( + depositPreauth, 'DepositPreauth: Unauthorize must be a string', ) }) it('throws when an Account attempts to unauthorize its own address', function () { depositPreauth.Unauthorize = depositPreauth.Account - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, + assertInvalid( + depositPreauth, "DepositPreauth: Account can't unauthorize its own address", ) - assert.throws( - () => validate(depositPreauth), - ValidationError, + assertInvalid( + depositPreauth, "DepositPreauth: Account can't unauthorize its own address", ) }) @@ -162,48 +115,28 @@ describe('DepositPreauth', function () { const errorMessage = 'DepositPreauth: Credentials must be an array' depositPreauth.AuthorizeCredentials = validCredential - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when UnauthorizeCredentials is not an array', function () { const errorMessage = 'DepositPreauth: Credentials must be an array' depositPreauth.UnauthorizeCredentials = validCredential - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when AuthorizeCredentials is empty array', function () { const errorMessage = 'DepositPreauth: Credentials cannot be an empty array' depositPreauth.AuthorizeCredentials = [] - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when UnauthorizeCredentials is empty array', function () { const errorMessage = 'DepositPreauth: Credentials cannot be an empty array' depositPreauth.UnauthorizeCredentials = [] - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when AuthorizeCredentials is too long', function () { @@ -219,12 +152,7 @@ describe('DepositPreauth', function () { }) } depositPreauth.AuthorizeCredentials = sampleCredentials - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when UnauthorizeCredentials is too long', function () { @@ -240,12 +168,7 @@ describe('DepositPreauth', function () { }) } depositPreauth.UnauthorizeCredentials = sampleCredentials - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when AuthorizeCredentials is invalid shape', function () { @@ -256,12 +179,7 @@ describe('DepositPreauth', function () { const errorMessage = 'DepositPreauth: Invalid Credentials format' depositPreauth.AuthorizeCredentials = invalidCredentials - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when UnauthorizeCredentials is invalid shape', function () { @@ -272,12 +190,7 @@ describe('DepositPreauth', function () { const errorMessage = 'DepositPreauth: Invalid Credentials format' depositPreauth.UnauthorizeCredentials = invalidCredentials - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when AuthorizeCredentials has duplicates', function () { @@ -286,12 +199,7 @@ describe('DepositPreauth', function () { 'DepositPreauth: Credentials cannot contain duplicate elements' depositPreauth.AuthorizeCredentials = invalidCredentials - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) it('throws when UnauthorizeCredentials has duplicates', function () { @@ -300,11 +208,6 @@ describe('DepositPreauth', function () { 'DepositPreauth: Credentials cannot contain duplicate elements' depositPreauth.UnauthorizeCredentials = invalidCredentials - assert.throws( - () => validateDepositPreauth(depositPreauth), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(depositPreauth), ValidationError, errorMessage) + assertInvalid(depositPreauth, errorMessage) }) }) diff --git a/packages/xrpl/test/models/escrowCancel.test.ts b/packages/xrpl/test/models/escrowCancel.test.ts index 8ec73fe45f..1a679c77b0 100644 --- a/packages/xrpl/test/models/escrowCancel.test.ts +++ b/packages/xrpl/test/models/escrowCancel.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateEscrowCancel } from '../../src/models/transactions/escrowCancel' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateEscrowCancel) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateEscrowCancel, message) /** * Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateEscrowCancel } from '../../src/models/transactions/escrowCancel * Providing runtime verification testing for each specific transaction type. */ describe('EscrowCancel', function () { - let cancel + let cancel: any beforeEach(function () { cancel = { @@ -21,74 +23,36 @@ describe('EscrowCancel', function () { }) it(`Valid EscrowCancel`, function () { - assert.doesNotThrow(() => validateEscrowCancel(cancel)) - assert.doesNotThrow(() => validate(cancel)) + assertValid(cancel) }) it(`Valid EscrowCancel with string OfferSequence`, function () { cancel.OfferSequence = '7' - assert.doesNotThrow(() => validateEscrowCancel(cancel)) - assert.doesNotThrow(() => validate(cancel)) + assertValid(cancel) }) it(`Invalid EscrowCancel missing owner`, function () { delete cancel.Owner - assert.throws( - () => validateEscrowCancel(cancel), - ValidationError, - 'EscrowCancel: missing field Owner', - ) - assert.throws( - () => validate(cancel), - ValidationError, - 'EscrowCancel: missing field Owner', - ) + assertInvalid(cancel, 'EscrowCancel: missing field Owner') }) it(`Invalid EscrowCancel missing offerSequence`, function () { delete cancel.OfferSequence - assert.throws( - () => validateEscrowCancel(cancel), - ValidationError, - 'EscrowCancel: missing OfferSequence', - ) - assert.throws( - () => validate(cancel), - ValidationError, - 'EscrowCancel: missing OfferSequence', - ) + assertInvalid(cancel, 'EscrowCancel: missing OfferSequence') }) it(`Invalid Owner`, function () { cancel.Owner = 10 - assert.throws( - () => validateEscrowCancel(cancel), - ValidationError, - 'EscrowCancel: invalid field Owner', - ) - assert.throws( - () => validate(cancel), - ValidationError, - 'EscrowCancel: invalid field Owner', - ) + assertInvalid(cancel, 'EscrowCancel: invalid field Owner') }) it(`Invalid OfferSequence`, function () { cancel.OfferSequence = 'random' - assert.throws( - () => validateEscrowCancel(cancel), - ValidationError, - 'EscrowCancel: OfferSequence must be a number', - ) - assert.throws( - () => validate(cancel), - ValidationError, - 'EscrowCancel: OfferSequence must be a number', - ) + assertInvalid(cancel, 'EscrowCancel: OfferSequence must be a number') }) }) diff --git a/packages/xrpl/test/models/escrowCreate.test.ts b/packages/xrpl/test/models/escrowCreate.test.ts index 4458fdd128..ed4d72ba00 100644 --- a/packages/xrpl/test/models/escrowCreate.test.ts +++ b/packages/xrpl/test/models/escrowCreate.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateEscrowCreate } from '../../src/models/transactions/escrowCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateEscrowCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateEscrowCreate, message) /** * EscrowCreate Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateEscrowCreate } from '../../src/models/transactions/escrowCreate * Providing runtime verification testing for each specific transaction type. */ describe('EscrowCreate', function () { - let escrow + let escrow: any beforeEach(function () { escrow = { @@ -27,137 +29,63 @@ describe('EscrowCreate', function () { }) it(`verifies valid EscrowCreate`, function () { - assert.doesNotThrow(() => validateEscrowCreate(escrow)) - assert.doesNotThrow(() => validate(escrow)) + assertValid(escrow) }) it(`Missing amount`, function () { delete escrow.Amount - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: missing field Amount', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowCreate: missing field Amount', - ) + assertInvalid(escrow, 'EscrowCreate: missing field Amount') }) it(`Missing destination`, function () { delete escrow.Destination - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: missing field Destination', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowCreate: missing field Destination', - ) + assertInvalid(escrow, 'EscrowCreate: missing field Destination') }) it(`throws w/ invalid Destination`, function () { escrow.Destination = 10 - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: invalid field Destination', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowCreate: invalid field Destination', - ) + assertInvalid(escrow, 'EscrowCreate: invalid field Destination') }) it(`throws w/ invalid Amount`, function () { escrow.Amount = 1000 - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: Amount must be a string', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowCreate: Amount must be a string', - ) + assertInvalid(escrow, 'EscrowCreate: Amount must be a string') }) it(`invalid CancelAfter`, function () { escrow.CancelAfter = '100' - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: CancelAfter must be a number', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowCreate: CancelAfter must be a number', - ) + assertInvalid(escrow, 'EscrowCreate: CancelAfter must be a number') }) it(`invalid FinishAfter`, function () { escrow.FinishAfter = '1000' - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: FinishAfter must be a number', - ) + assertInvalid(escrow, 'EscrowCreate: FinishAfter must be a number') }) it(`invalid Condition`, function () { escrow.Condition = 0x141243 - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: Condition must be a string', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowCreate: Condition must be a string', - ) + assertInvalid(escrow, 'EscrowCreate: Condition must be a string') }) it(`invalid DestinationTag`, function () { escrow.DestinationTag = '100' - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: invalid field DestinationTag', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowCreate: invalid field DestinationTag', - ) + assertInvalid(escrow, 'EscrowCreate: invalid field DestinationTag') }) it(`Missing both CancelAfter and FinishAfter`, function () { delete escrow.CancelAfter delete escrow.FinishAfter - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: Either CancelAfter or FinishAfter must be specified', - ) - assert.throws( - () => validate(escrow), - ValidationError, + assertInvalid( + escrow, 'EscrowCreate: Either CancelAfter or FinishAfter must be specified', ) }) @@ -166,14 +94,8 @@ describe('EscrowCreate', function () { delete escrow.Condition delete escrow.FinishAfter - assert.throws( - () => validateEscrowCreate(escrow), - ValidationError, - 'EscrowCreate: Either Condition or FinishAfter must be specified', - ) - assert.throws( - () => validate(escrow), - ValidationError, + assertInvalid( + escrow, 'EscrowCreate: Either Condition or FinishAfter must be specified', ) }) diff --git a/packages/xrpl/test/models/escrowFinish.test.ts b/packages/xrpl/test/models/escrowFinish.test.ts index cac92d1e15..252858315e 100644 --- a/packages/xrpl/test/models/escrowFinish.test.ts +++ b/packages/xrpl/test/models/escrowFinish.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateEscrowFinish } from '../../src/models/transactions/escrowFinish' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateEscrowFinish) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateEscrowFinish, message) /** * EscrowFinish Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateEscrowFinish } from '../../src/models/transactions/escrowFinish * Providing runtime verification testing for each specific transaction type. */ describe('EscrowFinish', function () { - let escrow + let escrow: any beforeEach(function () { escrow = { @@ -26,8 +28,7 @@ describe('EscrowFinish', function () { } }) it(`verifies valid EscrowFinish`, function () { - assert.doesNotThrow(() => validateEscrowFinish(escrow)) - assert.doesNotThrow(() => validate(escrow)) + assertValid(escrow) }) it(`verifies valid EscrowFinish w/o optional`, function () { @@ -35,75 +36,37 @@ describe('EscrowFinish', function () { escrow.Fulfillment = undefined escrow.CredentialIDs = undefined - assert.doesNotThrow(() => validateEscrowFinish(escrow)) - assert.doesNotThrow(() => validate(escrow)) + assertValid(escrow) }) it(`verifies valid EscrowFinish w/string OfferSequence`, function () { escrow.OfferSequence = '7' - assert.doesNotThrow(() => validateEscrowFinish(escrow)) - assert.doesNotThrow(() => validate(escrow)) + assertValid(escrow) }) it(`throws w/ invalid Owner`, function () { escrow.Owner = 0x15415253 - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - 'EscrowFinish: invalid field Owner', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowFinish: invalid field Owner', - ) + assertInvalid(escrow, 'EscrowFinish: invalid field Owner') }) it(`throws w/ invalid OfferSequence`, function () { escrow.OfferSequence = 'random' - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - 'EscrowFinish: OfferSequence must be a number', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowFinish: OfferSequence must be a number', - ) + assertInvalid(escrow, 'EscrowFinish: OfferSequence must be a number') }) it(`throws w/ invalid Condition`, function () { escrow.Condition = 10 - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - 'EscrowFinish: Condition must be a string', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowFinish: Condition must be a string', - ) + assertInvalid(escrow, 'EscrowFinish: Condition must be a string') }) it(`throws w/ invalid Fulfillment`, function () { escrow.Fulfillment = 0x142341 - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - 'EscrowFinish: Fulfillment must be a string', - ) - assert.throws( - () => validate(escrow), - ValidationError, - 'EscrowFinish: Fulfillment must be a string', - ) + assertInvalid(escrow, 'EscrowFinish: Fulfillment must be a string') }) it(`throws w/ non-array CredentialIDs`, function () { @@ -112,12 +75,7 @@ describe('EscrowFinish', function () { const errorMessage = 'EscrowFinish: Credentials must be an array' - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(escrow), ValidationError, errorMessage) + assertInvalid(escrow, errorMessage) }) it(`throws CredentialIDs length exceeds max length`, function () { @@ -136,12 +94,7 @@ describe('EscrowFinish', function () { const errorMessage = 'EscrowFinish: Credentials length cannot exceed 8 elements' - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(escrow), ValidationError, errorMessage) + assertInvalid(escrow, errorMessage) }) it(`throws w/ empty CredentialIDs`, function () { @@ -149,12 +102,7 @@ describe('EscrowFinish', function () { const errorMessage = 'EscrowFinish: Credentials cannot be an empty array' - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(escrow), ValidationError, errorMessage) + assertInvalid(escrow, errorMessage) }) it(`throws w/ non-string CredentialIDs`, function () { @@ -165,12 +113,7 @@ describe('EscrowFinish', function () { const errorMessage = 'EscrowFinish: Invalid Credentials ID list format' - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(escrow), ValidationError, errorMessage) + assertInvalid(escrow, errorMessage) }) it(`throws w/ duplicate CredentialIDs`, function () { @@ -182,11 +125,6 @@ describe('EscrowFinish', function () { const errorMessage = 'EscrowFinish: Credentials cannot contain duplicate elements' - assert.throws( - () => validateEscrowFinish(escrow), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(escrow), ValidationError, errorMessage) + assertInvalid(escrow, errorMessage) }) }) diff --git a/packages/xrpl/test/models/offerCancel.test.ts b/packages/xrpl/test/models/offerCancel.test.ts index 2aea40c3cc..3d1c91b971 100644 --- a/packages/xrpl/test/models/offerCancel.test.ts +++ b/packages/xrpl/test/models/offerCancel.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateOfferCancel } from '../../src/models/transactions/offerCancel' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateOfferCancel) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateOfferCancel, message) /** * OfferCancel Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateOfferCancel } from '../../src/models/transactions/offerCancel' * Providing runtime verification testing for each specific transaction type. */ describe('OfferCancel', function () { - let offer + let offer: any beforeEach(function () { offer = { @@ -24,45 +26,25 @@ describe('OfferCancel', function () { TransactionType: 'OfferCancel', TxnSignature: '304402203EC848BD6AB42DC8509285245804B15E1652092CC0B189D369E12E563771D049022046DF40C16EA05DC99D01E553EA2E218FCA1C5B38927889A2BDF064D1F44D60F0', - } as any + } }) it(`verifies valid OfferCancel`, function () { - assert.doesNotThrow(() => validateOfferCancel(offer)) - assert.doesNotThrow(() => validate(offer)) + assertValid(offer) }) it(`verifies valid OfferCancel with flags`, function () { offer.Flags = 2147483648 - assert.doesNotThrow(() => validateOfferCancel(offer)) - assert.doesNotThrow(() => validate(offer)) + assertValid(offer) }) it(`throws w/ OfferSequence must be a number`, function () { - offer.OfferSequence = '99' - assert.throws( - () => validateOfferCancel(offer), - ValidationError, - 'OfferCancel: OfferSequence must be a number', - ) - assert.throws( - () => validate(offer), - ValidationError, - 'OfferCancel: OfferSequence must be a number', - ) + offer.OfferSequence = 'abcd' + assertInvalid(offer, 'OfferCancel: OfferSequence must be a number') }) it(`throws w/ missing OfferSequence`, function () { delete offer.OfferSequence - assert.throws( - () => validateOfferCancel(offer), - ValidationError, - 'OfferCancel: missing field OfferSequence', - ) - assert.throws( - () => validate(offer), - ValidationError, - 'OfferCancel: missing field OfferSequence', - ) + assertInvalid(offer, 'OfferCancel: missing field OfferSequence') }) }) diff --git a/packages/xrpl/test/models/offerCreate.test.ts b/packages/xrpl/test/models/offerCreate.test.ts index d3fa1c9d11..42ade33611 100644 --- a/packages/xrpl/test/models/offerCreate.test.ts +++ b/packages/xrpl/test/models/offerCreate.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateOfferCreate } from '../../src/models/transactions/offerCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateOfferCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateOfferCreate, message) /** * OfferCreate Transaction Verification Testing. @@ -29,11 +31,12 @@ describe('OfferCreate', function () { TransactionType: 'OfferCreate', TxnSignature: '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', - } as any + } - assert.doesNotThrow(() => validateOfferCreate(offer)) - assert.doesNotThrow(() => validate(offer)) + assertValid(offer) + }) + it(`verifies valid OfferCreate with flags`, function () { const offer2 = { Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W', Fee: '10', @@ -53,9 +56,10 @@ describe('OfferCreate', function () { '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', } as any - assert.doesNotThrow(() => validateOfferCreate(offer2)) - assert.doesNotThrow(() => validate(offer2)) + assertValid(offer2) + }) + it(`verifies valid OfferCreate with TakerGets and TakerPays as IOUs`, function () { const offer3 = { Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W', Fee: '10', @@ -79,8 +83,7 @@ describe('OfferCreate', function () { '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', } as any - assert.doesNotThrow(() => validateOfferCreate(offer3)) - assert.doesNotThrow(() => validate(offer3)) + assertValid(offer3) }) it(`throws w/ invalid Expiration`, function () { @@ -104,16 +107,7 @@ describe('OfferCreate', function () { '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', } as any - assert.throws( - () => validateOfferCreate(offer), - ValidationError, - 'OfferCreate: invalid Expiration', - ) - assert.throws( - () => validate(offer), - ValidationError, - 'OfferCreate: invalid Expiration', - ) + assertInvalid(offer, 'OfferCreate: invalid Expiration') }) it(`throws w/ invalid OfferSequence`, function () { @@ -137,16 +131,7 @@ describe('OfferCreate', function () { '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', } as any - assert.throws( - () => validateOfferCreate(offer), - ValidationError, - 'OfferCreate: invalid OfferSequence', - ) - assert.throws( - () => validate(offer), - ValidationError, - 'OfferCreate: invalid OfferSequence', - ) + assertInvalid(offer, 'OfferCreate: invalid OfferSequence') }) it(`throws w/ invalid TakerPays`, function () { @@ -166,16 +151,7 @@ describe('OfferCreate', function () { '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', } as any - assert.throws( - () => validateOfferCreate(offer), - ValidationError, - 'OfferCreate: invalid TakerPays', - ) - assert.throws( - () => validate(offer), - ValidationError, - 'OfferCreate: invalid TakerPays', - ) + assertInvalid(offer, 'OfferCreate: invalid TakerPays') }) it(`throws w/ invalid TakerGets`, function () { @@ -199,15 +175,6 @@ describe('OfferCreate', function () { '3045022100D874CDDD6BB24ED66E83B1D3574D3ECAC753A78F26DB7EBA89EAB8E7D72B95F802207C8CCD6CEA64E4AE2014E59EE9654E02CA8F03FE7FCE0539E958EAE182234D91', } as any - assert.throws( - () => validateOfferCreate(offer), - ValidationError, - 'OfferCreate: invalid TakerGets', - ) - assert.throws( - () => validate(offer), - ValidationError, - 'OfferCreate: invalid TakerGets', - ) + assertInvalid(offer, 'OfferCreate: invalid TakerGets') }) }) diff --git a/packages/xrpl/test/models/oracleDelete.test.ts b/packages/xrpl/test/models/oracleDelete.test.ts index 78188638bc..91d1561a7e 100644 --- a/packages/xrpl/test/models/oracleDelete.test.ts +++ b/packages/xrpl/test/models/oracleDelete.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateOracleDelete } from '../../src/models/transactions/oracleDelete' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateOracleDelete) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateOracleDelete, message) /** * OracleDelete Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateOracleDelete } from '../../src/models/transactions/oracleDelete * Providing runtime verification testing for each specific transaction type. */ describe('OracleDelete', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -20,21 +22,18 @@ describe('OracleDelete', function () { }) it('verifies valid OracleDelete', function () { - assert.doesNotThrow(() => validateOracleDelete(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it(`throws w/ missing field OracleDocumentID`, function () { delete tx.OracleDocumentID const errorMessage = 'OracleDelete: missing field OracleDocumentID' - assert.throws(() => validateOracleDelete(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid OracleDocumentID`, function () { tx.OracleDocumentID = '1234' const errorMessage = 'OracleDelete: invalid field OracleDocumentID' - assert.throws(() => validateOracleDelete(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) }) diff --git a/packages/xrpl/test/models/oracleSet.test.ts b/packages/xrpl/test/models/oracleSet.test.ts index b7f90a614a..d3170bf0c0 100644 --- a/packages/xrpl/test/models/oracleSet.test.ts +++ b/packages/xrpl/test/models/oracleSet.test.ts @@ -1,8 +1,11 @@ import { stringToHex } from '@xrplf/isomorphic/dist/utils' -import { assert } from 'chai' -import { validate, ValidationError } from '../../src' import { validateOracleSet } from '../../src/models/transactions/oracleSet' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateOracleSet) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateOracleSet, message) /** * OracleSet Transaction Verification Testing. @@ -10,7 +13,7 @@ import { validateOracleSet } from '../../src/models/transactions/oracleSet' * Providing runtime verification testing for each specific transaction type. */ describe('OracleSet', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -35,72 +38,62 @@ describe('OracleSet', function () { }) it('verifies valid OracleSet', function () { - assert.doesNotThrow(() => validateOracleSet(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it(`throws w/ missing field OracleDocumentID`, function () { delete tx.OracleDocumentID const errorMessage = 'OracleSet: missing field OracleDocumentID' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid OracleDocumentID`, function () { tx.OracleDocumentID = '1234' const errorMessage = 'OracleSet: invalid field OracleDocumentID' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing field LastUpdateTime`, function () { delete tx.LastUpdateTime const errorMessage = 'OracleSet: missing field LastUpdateTime' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid LastUpdateTime`, function () { tx.LastUpdateTime = '768062172' const errorMessage = 'OracleSet: invalid field LastUpdateTime' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing invalid Provider`, function () { tx.Provider = 1234 const errorMessage = 'OracleSet: invalid field Provider' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing invalid URI`, function () { tx.URI = 1234 const errorMessage = 'OracleSet: invalid field URI' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing invalid AssetClass`, function () { tx.AssetClass = 1234 const errorMessage = 'OracleSet: invalid field AssetClass' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid PriceDataSeries must be an array`, function () { tx.PriceDataSeries = 1234 const errorMessage = 'OracleSet: PriceDataSeries must be an array' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid PriceDataSeries must be an array of objects`, function () { tx.PriceDataSeries = [1234] const errorMessage = 'OracleSet: PriceDataSeries must be an array of objects' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ PriceDataSeries must have at most 10 PriceData objects`, function () { @@ -114,56 +107,49 @@ describe('OracleSet', function () { }) const errorMessage = 'OracleSet: PriceDataSeries must have at most 10 PriceData objects' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ PriceDataSeries must have a PriceData object`, function () { delete tx.PriceDataSeries[0].PriceData const errorMessage = 'OracleSet: PriceDataSeries must have a `PriceData` object' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ PriceDataSeries must only have a single PriceData object`, function () { tx.PriceDataSeries[0].ExtraProp = 'extraprop' const errorMessage = 'OracleSet: PriceDataSeries must only have a single PriceData object' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing BaseAsset of PriceDataSeries`, function () { delete tx.PriceDataSeries[0].PriceData.BaseAsset const errorMessage = 'OracleSet: PriceDataSeries must have a `BaseAsset` string' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing QuoteAsset of PriceDataSeries`, function () { delete tx.PriceDataSeries[0].PriceData.QuoteAsset const errorMessage = 'OracleSet: PriceDataSeries must have a `QuoteAsset` string' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing AssetPrice with Scale present of PriceDataSeries`, function () { delete tx.PriceDataSeries[0].PriceData.AssetPrice const errorMessage = 'OracleSet: PriceDataSeries must have both `AssetPrice` and `Scale` if any are present' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing Scale with AssetPrice present of PriceDataSeries`, function () { delete tx.PriceDataSeries[0].PriceData.Scale const errorMessage = 'OracleSet: PriceDataSeries must have both `AssetPrice` and `Scale` if any are present' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid AssetPrice of PriceDataSeries`, function () { @@ -171,42 +157,37 @@ describe('OracleSet', function () { tx.PriceDataSeries[0].PriceData.AssetPrice = 'ghij' const errorMessage = 'OracleSet: Field AssetPrice must be a valid hex string' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`verifies valid AssetPrice of PriceDataSeries`, function () { // valid string which can be parsed as hexadecimal number tx.PriceDataSeries[0].PriceData.AssetPrice = 'ab15' - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it(`throws w/ invalid AssetPrice type in PriceDataSeries`, function () { tx.PriceDataSeries[0].PriceData.AssetPrice = ['sample', 'invalid', 'type'] const errorMessage = 'OracleSet: Field AssetPrice must be a string or a number' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid Scale of PriceDataSeries`, function () { tx.PriceDataSeries[0].PriceData.Scale = '1234' const errorMessage = 'OracleSet: invalid field Scale' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ Scale must be in range 0-10 when above max`, function () { tx.PriceDataSeries[0].PriceData.Scale = 11 const errorMessage = 'OracleSet: Scale must be in range 0-10' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ Scale must be in range 0-10 when below min`, function () { tx.PriceDataSeries[0].PriceData.Scale = -1 const errorMessage = 'OracleSet: Scale must be in range 0-10' - assert.throws(() => validateOracleSet(tx), ValidationError, errorMessage) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) }) diff --git a/packages/xrpl/test/models/payment.test.ts b/packages/xrpl/test/models/payment.test.ts index 1af633e0a1..427d30f281 100644 --- a/packages/xrpl/test/models/payment.test.ts +++ b/packages/xrpl/test/models/payment.test.ts @@ -1,8 +1,12 @@ /* eslint-disable max-statements -- need additional tests for optional fields */ -import { assert } from 'chai' -import { validate, PaymentFlags, ValidationError } from '../../src' +import { PaymentFlags } from '../../src' import { validatePayment } from '../../src/models/transactions/payment' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validatePayment) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validatePayment, message) /** * PaymentTransaction Verification Testing. @@ -10,10 +14,10 @@ import { validatePayment } from '../../src/models/transactions/payment' * Providing runtime verification testing for each specific transaction type. */ describe('Payment', function () { - let paymentTransaction + let payment: any beforeEach(function () { - paymentTransaction = { + payment = { TransactionType: 'Payment', Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', Amount: '1234', @@ -36,13 +40,12 @@ describe('Payment', function () { } as any }) - it(`verifies valid PaymentTransaction`, function () { - assert.doesNotThrow(() => validatePayment(paymentTransaction)) - assert.doesNotThrow(() => validate(paymentTransaction)) + it(`verifies valid Payment`, function () { + assertValid(payment) }) it(`Verifies memos correctly`, function () { - paymentTransaction.Memos = [ + payment.Memos = [ { Memo: { MemoData: '32324324', @@ -50,11 +53,11 @@ describe('Payment', function () { }, ] - assert.doesNotThrow(() => validate(paymentTransaction)) + assertValid(payment) }) it(`Verifies memos correctly`, function () { - paymentTransaction.Memos = [ + payment.Memos = [ { Memo: { MemoData: '32324324', @@ -63,205 +66,92 @@ describe('Payment', function () { }, ] - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'BaseTransaction: invalid Memos', - ) + assertInvalid(payment, 'BaseTransaction: invalid Memos') }) it(`throws when Amount is missing`, function () { - delete paymentTransaction.Amount - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'PaymentTransaction: missing field Amount', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'PaymentTransaction: missing field Amount', - ) + delete payment.Amount + assertInvalid(payment, 'PaymentTransaction: missing field Amount') }) it(`throws when Amount is invalid`, function () { - paymentTransaction.Amount = 1234 - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid Amount', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid Amount', - ) + payment.Amount = 1234 + assertInvalid(payment, 'PaymentTransaction: invalid Amount') }) it(`throws when Destination is missing`, function () { - delete paymentTransaction.Destination - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'Payment: missing field Destination', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'Payment: missing field Destination', - ) + delete payment.Destination + assertInvalid(payment, 'Payment: missing field Destination') }) it(`throws when Destination is invalid`, function () { - paymentTransaction.Destination = 7896214 - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'Payment: invalid field Destination', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'Payment: invalid field Destination', - ) + payment.Destination = 7896214 + assertInvalid(payment, 'Payment: invalid field Destination') }) it(`throws when Destination is invalid classic address`, function () { - paymentTransaction.Destination = 'rABCD' - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'Payment: invalid field Destination', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'Payment: invalid field Destination', - ) + payment.Destination = 'rABCD' + assertInvalid(payment, 'Payment: invalid field Destination') }) it(`does not throw when Destination is a valid x-address`, function () { - paymentTransaction.Destination = - 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtSiS2eDBib7svZXuc2' - assert.doesNotThrow(() => validatePayment(paymentTransaction)) - assert.doesNotThrow(() => validate(paymentTransaction)) + payment.Destination = 'X7WZKEeNVS2p9Tire9DtNFkzWBZbFtSiS2eDBib7svZXuc2' + assertValid(payment) }) it(`throws when Destination is an empty string`, function () { - paymentTransaction.Destination = '' - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'Payment: invalid field Destination', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'Payment: invalid field Destination', - ) + payment.Destination = '' + assertInvalid(payment, 'Payment: invalid field Destination') }) it(`throws when DestinationTag is not a number`, function () { - paymentTransaction.DestinationTag = '1' - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'Payment: invalid field DestinationTag', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'Payment: invalid field DestinationTag', - ) + payment.DestinationTag = '1' + assertInvalid(payment, 'Payment: invalid field DestinationTag') }) it(`throws when InvoiceID is not a string`, function () { - paymentTransaction.InvoiceID = 19832 - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'PaymentTransaction: InvoiceID must be a string', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'PaymentTransaction: InvoiceID must be a string', - ) + payment.InvoiceID = 19832 + assertInvalid(payment, 'PaymentTransaction: InvoiceID must be a string') }) it(`throws when Paths is invalid`, function () { - paymentTransaction.Paths = [[{ account: 123 }]] - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid Paths', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid Paths', - ) + payment.Paths = [[{ account: 123 }]] + assertInvalid(payment, 'PaymentTransaction: invalid Paths') }) it(`throws when SendMax is invalid`, function () { - paymentTransaction.SendMax = 100000000 - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid SendMax', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid SendMax', - ) + payment.SendMax = 100000000 + assertInvalid(payment, 'PaymentTransaction: invalid SendMax') }) it(`verifies valid DeliverMin with tfPartialPayment flag set as a number`, function () { - paymentTransaction.DeliverMin = '10000' - paymentTransaction.Flags = PaymentFlags.tfPartialPayment - assert.doesNotThrow(() => validatePayment(paymentTransaction)) - assert.doesNotThrow(() => validate(paymentTransaction)) + payment.DeliverMin = '10000' + payment.Flags = PaymentFlags.tfPartialPayment + assertValid(payment) }) it(`verifies valid DeliverMin with tfPartialPayment flag set as a boolean`, function () { - paymentTransaction.DeliverMin = '10000' - paymentTransaction.Flags = { tfPartialPayment: true } - assert.doesNotThrow(() => validatePayment(paymentTransaction)) - assert.doesNotThrow(() => validate(paymentTransaction)) + payment.DeliverMin = '10000' + payment.Flags = { tfPartialPayment: true } + assertValid(payment) }) it(`throws when DeliverMin is invalid`, function () { - paymentTransaction.DeliverMin = 10000 - paymentTransaction.Flags = { tfPartialPayment: true } - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid DeliverMin', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - 'PaymentTransaction: invalid DeliverMin', - ) + payment.DeliverMin = 10000 + payment.Flags = { tfPartialPayment: true } + assertInvalid(payment, 'PaymentTransaction: invalid DeliverMin') }) it(`throws when tfPartialPayment flag is missing with valid DeliverMin`, function () { - paymentTransaction.DeliverMin = '10000' - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - 'PaymentTransaction: tfPartialPayment flag required with DeliverMin', - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, + payment.DeliverMin = '10000' + assertInvalid( + payment, 'PaymentTransaction: tfPartialPayment flag required with DeliverMin', ) }) it(`verifies valid MPT PaymentTransaction`, function () { - const mptPaymentTransaction = { + const mptPayment = { TransactionType: 'Payment', Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', Amount: { @@ -270,30 +160,19 @@ describe('Payment', function () { }, Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy', } as any - assert.doesNotThrow(() => validatePayment(mptPaymentTransaction)) - assert.doesNotThrow(() => validate(mptPaymentTransaction)) + assertValid(mptPayment) }) it(`throws w/ non-array CredentialIDs`, function () { - paymentTransaction.CredentialIDs = + payment.CredentialIDs = 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66A' const errorMessage = 'Payment: Credentials must be an array' - - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - errorMessage, - ) + assertInvalid(payment, errorMessage) }) it(`throws CredentialIDs length exceeds max length`, function () { - paymentTransaction.CredentialIDs = [ + payment.CredentialIDs = [ 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66A', 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66B', 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F66C', @@ -306,74 +185,34 @@ describe('Payment', function () { ] const errorMessage = 'Payment: Credentials length cannot exceed 8 elements' - - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - errorMessage, - ) + assertInvalid(payment, errorMessage) }) it(`throws w/ empty CredentialIDs`, function () { - paymentTransaction.CredentialIDs = [] + payment.CredentialIDs = [] const errorMessage = 'Payment: Credentials cannot be an empty array' - - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - errorMessage, - ) + assertInvalid(payment, errorMessage) }) it(`throws w/ non-string CredentialIDs`, function () { - paymentTransaction.CredentialIDs = [ + payment.CredentialIDs = [ 123123, 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F662', ] const errorMessage = 'Payment: Invalid Credentials ID list format' - - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - errorMessage, - ) + assertInvalid(payment, errorMessage) }) it(`throws w/ duplicate CredentialIDs`, function () { - paymentTransaction.CredentialIDs = [ + payment.CredentialIDs = [ 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F662', 'EA85602C1B41F6F1F5E83C0E6B87142FB8957BD209469E4CC347BA2D0C26F662', ] const errorMessage = 'Payment: Credentials cannot contain duplicate elements' - - assert.throws( - () => validatePayment(paymentTransaction), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(paymentTransaction), - ValidationError, - errorMessage, - ) + assertInvalid(payment, errorMessage) }) }) diff --git a/packages/xrpl/test/models/paymentChannelClaim.test.ts b/packages/xrpl/test/models/paymentChannelClaim.test.ts index af9c973556..2c5e0bdf4a 100644 --- a/packages/xrpl/test/models/paymentChannelClaim.test.ts +++ b/packages/xrpl/test/models/paymentChannelClaim.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validatePaymentChannelClaim } from '../../src/models/transactions/paymentChannelClaim' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validatePaymentChannelClaim) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validatePaymentChannelClaim, message) /** * PaymentChannelClaim Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validatePaymentChannelClaim } from '../../src/models/transactions/payme * Providing runtime verification testing for each specific transaction type. */ describe('PaymentChannelClaim', function () { - let channel + let channel: any beforeEach(function () { channel = { @@ -27,8 +30,7 @@ describe('PaymentChannelClaim', function () { }) it(`verifies valid PaymentChannelClaim`, function () { - assert.doesNotThrow(() => validatePaymentChannelClaim(channel)) - assert.doesNotThrow(() => validate(channel)) + assertValid(channel) }) it(`verifies valid PaymentChannelClaim w/o optional`, function () { @@ -37,97 +39,42 @@ describe('PaymentChannelClaim', function () { delete channel.Signature delete channel.PublicKey - assert.doesNotThrow(() => validatePaymentChannelClaim(channel)) - assert.doesNotThrow(() => validate(channel)) + assertValid(channel) }) it(`throws w/ missing Channel`, function () { delete channel.Channel - assert.throws( - () => validatePaymentChannelClaim(channel), - ValidationError, - 'PaymentChannelClaim: missing Channel', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelClaim: missing Channel', - ) + assertInvalid(channel, 'PaymentChannelClaim: missing Channel') }) it(`throws w/ invalid Channel`, function () { channel.Channel = 100 - assert.throws( - () => validatePaymentChannelClaim(channel), - ValidationError, - 'PaymentChannelClaim: Channel must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelClaim: Channel must be a string', - ) + assertInvalid(channel, 'PaymentChannelClaim: Channel must be a string') }) it(`throws w/ invalid Balance`, function () { channel.Balance = 100 - assert.throws( - () => validatePaymentChannelClaim(channel), - ValidationError, - 'PaymentChannelClaim: Balance must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelClaim: Balance must be a string', - ) + assertInvalid(channel, 'PaymentChannelClaim: Balance must be a string') }) it(`throws w/ invalid Amount`, function () { channel.Amount = 1000 - assert.throws( - () => validatePaymentChannelClaim(channel), - ValidationError, - 'PaymentChannelClaim: Amount must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelClaim: Amount must be a string', - ) + assertInvalid(channel, 'PaymentChannelClaim: Amount must be a string') }) it(`throws w/ invalid Signature`, function () { channel.Signature = 1000 - assert.throws( - () => validatePaymentChannelClaim(channel), - ValidationError, - 'PaymentChannelClaim: Signature must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelClaim: Signature must be a string', - ) + assertInvalid(channel, 'PaymentChannelClaim: Signature must be a string') }) it(`throws w/ invalid PublicKey`, function () { channel.PublicKey = ['100000'] - assert.throws( - () => validatePaymentChannelClaim(channel), - ValidationError, - 'PaymentChannelClaim: PublicKey must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelClaim: PublicKey must be a string', - ) + assertInvalid(channel, 'PaymentChannelClaim: PublicKey must be a string') }) }) diff --git a/packages/xrpl/test/models/paymentChannelCreate.test.ts b/packages/xrpl/test/models/paymentChannelCreate.test.ts index b3947cb9d4..18b560deff 100644 --- a/packages/xrpl/test/models/paymentChannelCreate.test.ts +++ b/packages/xrpl/test/models/paymentChannelCreate.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validatePaymentChannelCreate } from '../../src/models/transactions/paymentChannelCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validatePaymentChannelCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validatePaymentChannelCreate, message) /** * PaymentChannelCreate Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validatePaymentChannelCreate } from '../../src/models/transactions/paym * Providing runtime verification testing for each specific transaction type. */ describe('PaymentChannelCreate', function () { - let channel + let channel: any beforeEach(function () { channel = { @@ -27,8 +30,7 @@ describe('PaymentChannelCreate', function () { }) it(`verifies valid PaymentChannelCreate`, function () { - assert.doesNotThrow(() => validatePaymentChannelCreate(channel)) - assert.doesNotThrow(() => validate(channel)) + assertValid(channel) }) it(`verifies valid PaymentChannelCreate w/o optional`, function () { @@ -36,157 +38,66 @@ describe('PaymentChannelCreate', function () { delete channel.DestinationTag delete channel.SourceTag - assert.doesNotThrow(() => validatePaymentChannelCreate(channel)) - assert.doesNotThrow(() => validate(channel)) + assertValid(channel) }) it(`missing Amount`, function () { delete channel.Amount - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: missing Amount', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: missing Amount', - ) + assertInvalid(channel, 'PaymentChannelCreate: missing Amount') }) it(`missing Destination`, function () { delete channel.Destination - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: missing field Destination', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: missing field Destination', - ) + assertInvalid(channel, 'PaymentChannelCreate: missing field Destination') }) it(`missing SettleDelay`, function () { delete channel.SettleDelay - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: missing SettleDelay', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: missing SettleDelay', - ) + assertInvalid(channel, 'PaymentChannelCreate: missing SettleDelay') }) it(`missing PublicKey`, function () { delete channel.PublicKey - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: missing PublicKey', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: missing PublicKey', - ) + assertInvalid(channel, 'PaymentChannelCreate: missing PublicKey') }) it(`invalid Amount`, function () { channel.Amount = 1000 - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: Amount must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: Amount must be a string', - ) + assertInvalid(channel, 'PaymentChannelCreate: Amount must be a string') }) it(`invalid Destination`, function () { channel.Destination = 10 - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: invalid field Destination', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: invalid field Destination', - ) + assertInvalid(channel, 'PaymentChannelCreate: invalid field Destination') }) it(`invalid SettleDelay`, function () { channel.SettleDelay = '10' - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: SettleDelay must be a number', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: SettleDelay must be a number', - ) + assertInvalid(channel, 'PaymentChannelCreate: SettleDelay must be a number') }) it(`invalid PublicKey`, function () { channel.PublicKey = 10 - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: PublicKey must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: PublicKey must be a string', - ) + assertInvalid(channel, 'PaymentChannelCreate: PublicKey must be a string') }) it(`invalid DestinationTag`, function () { channel.DestinationTag = '10' - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: invalid field DestinationTag', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: invalid field DestinationTag', - ) + assertInvalid(channel, 'PaymentChannelCreate: invalid field DestinationTag') }) it(`invalid CancelAfter`, function () { channel.CancelAfter = '100' - assert.throws( - () => validatePaymentChannelCreate(channel), - ValidationError, - 'PaymentChannelCreate: CancelAfter must be a number', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelCreate: CancelAfter must be a number', - ) + assertInvalid(channel, 'PaymentChannelCreate: CancelAfter must be a number') }) }) diff --git a/packages/xrpl/test/models/paymentChannelFund.test.ts b/packages/xrpl/test/models/paymentChannelFund.test.ts index 65c39c9878..b7e5e4a38a 100644 --- a/packages/xrpl/test/models/paymentChannelFund.test.ts +++ b/packages/xrpl/test/models/paymentChannelFund.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validatePaymentChannelFund } from '../../src/models/transactions/paymentChannelFund' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validatePaymentChannelFund) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validatePaymentChannelFund, message) /** * PaymentChannelFund Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validatePaymentChannelFund } from '../../src/models/transactions/paymen * Providing runtime verification testing for each specific transaction type. */ describe('PaymentChannelFund', function () { - let channel + let channel: any beforeEach(function () { channel = { @@ -23,89 +26,42 @@ describe('PaymentChannelFund', function () { }) it(`verifies valid PaymentChannelFund`, function () { - assert.doesNotThrow(() => validatePaymentChannelFund(channel)) - assert.doesNotThrow(() => validate(channel)) + assertValid(channel) }) it(`verifies valid PaymentChannelFund w/o optional`, function () { delete channel.Expiration - assert.doesNotThrow(() => validatePaymentChannelFund(channel)) - assert.doesNotThrow(() => validate(channel)) + assertValid(channel) }) it(`throws w/ missing Amount`, function () { delete channel.Amount - assert.throws( - () => validatePaymentChannelFund(channel), - ValidationError, - 'PaymentChannelFund: missing Amount', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelFund: missing Amount', - ) + assertInvalid(channel, 'PaymentChannelFund: missing Amount') }) it(`throws w/ missing Channel`, function () { delete channel.Channel - assert.throws( - () => validatePaymentChannelFund(channel), - ValidationError, - 'PaymentChannelFund: missing Channel', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelFund: missing Channel', - ) + assertInvalid(channel, 'PaymentChannelFund: missing Channel') }) it(`throws w/ invalid Amount`, function () { channel.Amount = 100 - assert.throws( - () => validatePaymentChannelFund(channel), - ValidationError, - 'PaymentChannelFund: Amount must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelFund: Amount must be a string', - ) + assertInvalid(channel, 'PaymentChannelFund: Amount must be a string') }) it(`throws w/ invalid Channel`, function () { channel.Channel = 1000 - assert.throws( - () => validatePaymentChannelFund(channel), - ValidationError, - 'PaymentChannelFund: Channel must be a string', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelFund: Channel must be a string', - ) + assertInvalid(channel, 'PaymentChannelFund: Channel must be a string') }) it(`throws w/ invalid Expiration`, function () { channel.Expiration = '1000' - assert.throws( - () => validatePaymentChannelFund(channel), - ValidationError, - 'PaymentChannelFund: Expiration must be a number', - ) - assert.throws( - () => validate(channel), - ValidationError, - 'PaymentChannelFund: Expiration must be a number', - ) + assertInvalid(channel, 'PaymentChannelFund: Expiration must be a number') }) }) diff --git a/packages/xrpl/test/models/permissionedDomainDelete.test.ts b/packages/xrpl/test/models/permissionedDomainDelete.test.ts index 801a8817bb..269f873dd9 100644 --- a/packages/xrpl/test/models/permissionedDomainDelete.test.ts +++ b/packages/xrpl/test/models/permissionedDomainDelete.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validatePermissionedDomainDelete } from '../../src/models/transactions/permissionedDomainDelete' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validatePermissionedDomainDelete) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validatePermissionedDomainDelete, message) /** * PermissionedDomainDelete Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validatePermissionedDomainDelete } from '../../src/models/transactions/ * Providing runtime verification testing for each specific transaction type. */ describe('PermissionedDomainDelete', function () { - let tx + let tx: any beforeEach(function () { tx = { @@ -21,29 +24,18 @@ describe('PermissionedDomainDelete', function () { }) it('verifies valid PermissionedDomainDelete', function () { - assert.doesNotThrow(() => validatePermissionedDomainDelete(tx)) - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it(`throws w/ missing field DomainID`, function () { delete tx.DomainID const errorMessage = 'PermissionedDomainDelete: missing field DomainID' - assert.throws( - () => validatePermissionedDomainDelete(tx), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ invalid DomainID`, function () { tx.DomainID = 1234 const errorMessage = 'PermissionedDomainDelete: invalid field DomainID' - assert.throws( - () => validatePermissionedDomainDelete(tx), - ValidationError, - errorMessage, - ) - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) }) diff --git a/packages/xrpl/test/models/permissionedDomainSet.test.ts b/packages/xrpl/test/models/permissionedDomainSet.test.ts index 7d51faa9e4..c4df71c995 100644 --- a/packages/xrpl/test/models/permissionedDomainSet.test.ts +++ b/packages/xrpl/test/models/permissionedDomainSet.test.ts @@ -1,7 +1,13 @@ import { stringToHex } from '@xrplf/isomorphic/dist/utils' -import { assert } from 'chai' -import { AuthorizeCredential, validate, ValidationError } from '../../src' +import { AuthorizeCredential } from '../../src' +import { validatePermissionedDomainSet } from '../../src/models/transactions/permissionedDomainSet' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validatePermissionedDomainSet) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validatePermissionedDomainSet, message) /** * PermissionedDomainSet Transaction Verification Testing. @@ -9,7 +15,7 @@ import { AuthorizeCredential, validate, ValidationError } from '../../src' * Providing runtime verification testing for each specific transaction type. */ describe('PermissionedDomainSet', function () { - let tx + let tx: any const sampleCredential: AuthorizeCredential = { Credential: { CredentialType: stringToHex('Passport'), @@ -24,69 +30,62 @@ describe('PermissionedDomainSet', function () { DomainID: 'D88930B33C2B6831660BFD006D91FF100011AD4E67CBB78B460AF0A215103737', AcceptedCredentials: [sampleCredential], - } as any + } }) it('verifies valid PermissionedDomainSet', function () { - assert.doesNotThrow(() => validate(tx)) + assertValid(tx) }) it(`throws with invalid field DomainID`, function () { // DomainID is expected to be a string tx.DomainID = 1234 const errorMessage = 'PermissionedDomainSet: invalid field DomainID' - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it(`throws w/ missing field AcceptedCredentials`, function () { delete tx.AcceptedCredentials const errorMessage = 'PermissionedDomainSet: missing field AcceptedCredentials' - assert.throws(() => validate(tx), ValidationError, errorMessage) + assertInvalid(tx, errorMessage) }) it('throws when AcceptedCredentials exceeds maximum length', function () { tx.AcceptedCredentials = Array(11).fill(sampleCredential) - assert.throws( - () => validate(tx), - ValidationError, + + assertInvalid( + tx, 'PermissionedDomainSet: Credentials length cannot exceed 10 elements', ) }) it('throws when AcceptedCredentials is empty', function () { tx.AcceptedCredentials = [] - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'PermissionedDomainSet: Credentials cannot be an empty array', ) }) it('throws when AcceptedCredentials is not an array type', function () { tx.AcceptedCredentials = 'AcceptedCredentials is not an array' - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'PermissionedDomainSet: invalid field AcceptedCredentials', ) }) it('throws when AcceptedCredentials contains duplicates', function () { tx.AcceptedCredentials = [sampleCredential, sampleCredential] - assert.throws( - () => validate(tx), - ValidationError, + assertInvalid( + tx, 'PermissionedDomainSet: Credentials cannot contain duplicate elements', ) }) it('throws when AcceptedCredentials contains invalid format', function () { tx.AcceptedCredentials = [{ Field1: 'Value1', Field2: 'Value2' }] - assert.throws( - () => validate(tx), - ValidationError, - 'PermissionedDomainSet: Invalid Credentials format', - ) + assertInvalid(tx, 'PermissionedDomainSet: Invalid Credentials format') }) }) diff --git a/packages/xrpl/test/models/setRegularKey.test.ts b/packages/xrpl/test/models/setRegularKey.test.ts index 1dcb859891..66a75c8d5e 100644 --- a/packages/xrpl/test/models/setRegularKey.test.ts +++ b/packages/xrpl/test/models/setRegularKey.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateSetRegularKey } from '../../src/models/transactions/setRegularKey' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateSetRegularKey) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateSetRegularKey, message) /** * SetRegularKey Transaction Verification Testing. @@ -9,10 +12,10 @@ import { validateSetRegularKey } from '../../src/models/transactions/setRegularK * Providing runtime verification testing for each specific transaction type. */ describe('SetRegularKey', function () { - let account + let tx: any beforeEach(function () { - account = { + tx = { TransactionType: 'SetRegularKey', Account: 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn', Fee: '12', @@ -22,28 +25,17 @@ describe('SetRegularKey', function () { }) it(`verifies valid SetRegularKey`, function () { - assert.doesNotThrow(() => validateSetRegularKey(account)) - assert.doesNotThrow(() => validate(account)) + assertValid(tx) }) it(`verifies w/o SetRegularKey`, function () { - account.RegularKey = undefined - assert.doesNotThrow(() => validateSetRegularKey(account)) - assert.doesNotThrow(() => validate(account)) + tx.RegularKey = undefined + assertValid(tx) }) it(`throws w/ invalid RegularKey`, function () { - account.RegularKey = 12369846963 + tx.RegularKey = 12369846963 - assert.throws( - () => validateSetRegularKey(account), - ValidationError, - 'SetRegularKey: RegularKey must be a string', - ) - assert.throws( - () => validate(account), - ValidationError, - 'SetRegularKey: RegularKey must be a string', - ) + assertInvalid(tx, 'SetRegularKey: RegularKey must be a string') }) }) diff --git a/packages/xrpl/test/models/signerListSet.test.ts b/packages/xrpl/test/models/signerListSet.test.ts index d99062c586..5f3663132d 100644 --- a/packages/xrpl/test/models/signerListSet.test.ts +++ b/packages/xrpl/test/models/signerListSet.test.ts @@ -1,7 +1,10 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateSignerListSet } from '../../src/models/transactions/signerListSet' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => + assertTxIsValid(tx, validateSignerListSet) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateSignerListSet, message) /** * SignerListSet Transaction Verification Testing. @@ -9,7 +12,7 @@ import { validateSignerListSet } from '../../src/models/transactions/signerListS * Providing runtime verification testing for each specific transaction type. */ describe('SignerListSet', function () { - let signerListSetTx + let signerListSetTx: any beforeEach(function () { signerListSetTx = { @@ -42,36 +45,20 @@ describe('SignerListSet', function () { }) it(`verifies valid SignerListSet`, function () { - assert.doesNotThrow(() => validateSignerListSet(signerListSetTx)) - assert.doesNotThrow(() => validate(signerListSetTx)) + assertValid(signerListSetTx) }) it(`throws w/ missing SignerQuorum`, function () { signerListSetTx.SignerQuorum = undefined - assert.throws( - () => validateSignerListSet(signerListSetTx), - ValidationError, - 'SignerListSet: missing field SignerQuorum', - ) - assert.throws( - () => validate(signerListSetTx), - ValidationError, - 'SignerListSet: missing field SignerQuorum', - ) + assertInvalid(signerListSetTx, 'SignerListSet: missing field SignerQuorum') }) it(`throws w/ empty SignerEntries`, function () { signerListSetTx.SignerEntries = [] - assert.throws( - () => validateSignerListSet(signerListSetTx), - ValidationError, - 'SignerListSet: need at least 1 member in SignerEntries', - ) - assert.throws( - () => validate(signerListSetTx), - ValidationError, + assertInvalid( + signerListSetTx, 'SignerListSet: need at least 1 member in SignerEntries', ) }) @@ -79,16 +66,7 @@ describe('SignerListSet', function () { it(`throws w/ invalid SignerEntries`, function () { signerListSetTx.SignerEntries = 'khgfgyhujk' - assert.throws( - () => validateSignerListSet(signerListSetTx), - ValidationError, - 'SignerListSet: invalid SignerEntries', - ) - assert.throws( - () => validate(signerListSetTx), - ValidationError, - 'SignerListSet: invalid SignerEntries', - ) + assertInvalid(signerListSetTx, 'SignerListSet: invalid SignerEntries') }) it(`throws w/ maximum of 32 members allowed in SignerEntries`, function () { @@ -140,16 +118,7 @@ describe('SignerListSet', function () { const errorMessage = 'SignerListSet: maximum of 32 members allowed in SignerEntries' - assert.throws( - () => validateSignerListSet(signerListSetTx), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(signerListSetTx), - ValidationError, - errorMessage, - ) + assertInvalid(signerListSetTx, errorMessage) }) it(`verifies valid WalletLocator in SignerEntries`, function () { @@ -179,8 +148,7 @@ describe('SignerListSet', function () { }, ] - assert.doesNotThrow(() => validateSignerListSet(signerListSetTx)) - assert.doesNotThrow(() => validate(signerListSetTx)) + assertValid(signerListSetTx) }) it(`throws w/ invalid WalletLocator in SignerEntries`, function () { @@ -202,15 +170,6 @@ describe('SignerListSet', function () { ] const errorMessage = 'SignerListSet: WalletLocator in SignerEntry must be a 256-bit (32-byte) hexadecimal value' - assert.throws( - () => validateSignerListSet(signerListSetTx), - ValidationError, - errorMessage, - ) - assert.throws( - () => validate(signerListSetTx), - ValidationError, - errorMessage, - ) + assertInvalid(signerListSetTx, errorMessage) }) }) diff --git a/packages/xrpl/test/models/ticketCreate.test.ts b/packages/xrpl/test/models/ticketCreate.test.ts index 4ec21a8bf4..1cecf2dc12 100644 --- a/packages/xrpl/test/models/ticketCreate.test.ts +++ b/packages/xrpl/test/models/ticketCreate.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateTicketCreate } from '../../src/models/transactions/ticketCreate' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateTicketCreate) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateTicketCreate, message) /** * TicketCreate Transaction Verification Testing. @@ -9,87 +11,50 @@ import { validateTicketCreate } from '../../src/models/transactions/ticketCreate * Providing runtime verification testing for each specific transaction type. */ describe('TicketCreate', function () { - let ticketCreate + let ticketCreate: any beforeEach(function () { ticketCreate = { TransactionType: 'TicketCreate', Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo', TicketCount: 150, - } as any + } }) it('verifies valid TicketCreate', function () { - assert.doesNotThrow(() => validateTicketCreate(ticketCreate)) - assert.doesNotThrow(() => validate(ticketCreate)) + assertValid(ticketCreate) }) it('throws when TicketCount is missing', function () { delete ticketCreate.TicketCount - assert.throws( - () => validateTicketCreate(ticketCreate), - ValidationError, - 'TicketCreate: missing field TicketCount', - ) - assert.throws( - () => validate(ticketCreate), - ValidationError, - 'TicketCreate: missing field TicketCount', - ) + assertInvalid(ticketCreate, 'TicketCreate: missing field TicketCount') }) it('throws when TicketCount is not a number', function () { ticketCreate.TicketCount = '150' - assert.throws( - () => validateTicketCreate(ticketCreate), - ValidationError, - 'TicketCreate: TicketCount must be a number', - ) - assert.throws( - () => validate(ticketCreate), - ValidationError, - 'TicketCreate: TicketCount must be a number', - ) + assertInvalid(ticketCreate, 'TicketCreate: TicketCount must be a number') }) it('throws when TicketCount is not an integer', function () { ticketCreate.TicketCount = 12.5 - assert.throws( - () => validateTicketCreate(ticketCreate), - ValidationError, - 'TicketCreate: TicketCount must be an integer from 1 to 250', - ) - assert.throws( - () => validate(ticketCreate), - ValidationError, + assertInvalid( + ticketCreate, 'TicketCreate: TicketCount must be an integer from 1 to 250', ) }) it('throws when TicketCount is < 1', function () { ticketCreate.TicketCount = 0 - assert.throws( - () => validateTicketCreate(ticketCreate), - ValidationError, - 'TicketCreate: TicketCount must be an integer from 1 to 250', - ) - assert.throws( - () => validate(ticketCreate), - ValidationError, + assertInvalid( + ticketCreate, 'TicketCreate: TicketCount must be an integer from 1 to 250', ) }) it('throws when TicketCount is > 250', function () { ticketCreate.TicketCount = 251 - assert.throws( - () => validateTicketCreate(ticketCreate), - ValidationError, - 'TicketCreate: TicketCount must be an integer from 1 to 250', - ) - assert.throws( - () => validate(ticketCreate), - ValidationError, + assertInvalid( + ticketCreate, 'TicketCreate: TicketCount must be an integer from 1 to 250', ) }) diff --git a/packages/xrpl/test/models/trustSet.test.ts b/packages/xrpl/test/models/trustSet.test.ts index fe6cba9524..8ea965e76c 100644 --- a/packages/xrpl/test/models/trustSet.test.ts +++ b/packages/xrpl/test/models/trustSet.test.ts @@ -1,7 +1,9 @@ -import { assert } from 'chai' - -import { validate, ValidationError } from '../../src' import { validateTrustSet } from '../../src/models/transactions/trustSet' +import { assertTxIsValid, assertTxValidationError } from '../testUtils' + +const assertValid = (tx: any): void => assertTxIsValid(tx, validateTrustSet) +const assertInvalid = (tx: any, message: string): void => + assertTxValidationError(tx, validateTrustSet, message) /** * TrustSet Transaction Verification Testing. @@ -9,7 +11,7 @@ import { validateTrustSet } from '../../src/models/transactions/trustSet' * Providing runtime verification testing for each specific transaction type. */ describe('TrustSet', function () { - let trustSet + let trustSet: any beforeEach(function () { trustSet = { @@ -27,67 +29,30 @@ describe('TrustSet', function () { tfSetFreeze: true, tfSetDeepFreeze: true, }, - } as any + } }) it('verifies valid TrustSet', function () { - assert.doesNotThrow(() => validateTrustSet(trustSet)) - assert.doesNotThrow(() => validate(trustSet)) + assertValid(trustSet) }) it('throws when LimitAmount is missing', function () { delete trustSet.LimitAmount - assert.throws( - () => validateTrustSet(trustSet), - ValidationError, - 'TrustSet: missing field LimitAmount', - ) - assert.throws( - () => validate(trustSet), - ValidationError, - 'TrustSet: missing field LimitAmount', - ) + assertInvalid(trustSet, 'TrustSet: missing field LimitAmount') }) it('throws when LimitAmount is invalid', function () { trustSet.LimitAmount = 1234 - assert.throws( - () => validateTrustSet(trustSet), - ValidationError, - 'TrustSet: invalid LimitAmount', - ) - assert.throws( - () => validate(trustSet), - ValidationError, - 'TrustSet: invalid LimitAmount', - ) + assertInvalid(trustSet, 'TrustSet: invalid LimitAmount') }) it('throws when QualityIn is not a number', function () { trustSet.QualityIn = '1234' - assert.throws( - () => validateTrustSet(trustSet), - ValidationError, - 'TrustSet: QualityIn must be a number', - ) - assert.throws( - () => validate(trustSet), - ValidationError, - 'TrustSet: QualityIn must be a number', - ) + assertInvalid(trustSet, 'TrustSet: QualityIn must be a number') }) it('throws when QualityOut is not a number', function () { trustSet.QualityOut = '4321' - assert.throws( - () => validateTrustSet(trustSet), - ValidationError, - 'TrustSet: QualityOut must be a number', - ) - assert.throws( - () => validate(trustSet), - ValidationError, - 'TrustSet: QualityOut must be a number', - ) + assertInvalid(trustSet, 'TrustSet: QualityOut must be a number') }) }) diff --git a/packages/xrpl/test/testUtils.ts b/packages/xrpl/test/testUtils.ts index ee922a63e4..654fbfe3cf 100644 --- a/packages/xrpl/test/testUtils.ts +++ b/packages/xrpl/test/testUtils.ts @@ -5,7 +5,12 @@ import net from 'net' import { assert } from 'chai' import omit from 'lodash/omit' -import { rippleTimeToUnixTime, unixTimeToRippleTime } from '../src' +import { + rippleTimeToUnixTime, + unixTimeToRippleTime, + validate, + ValidationError, +} from '../src' import addresses from './fixtures/addresses.json' @@ -52,6 +57,33 @@ export function assertResultMatch( ) } +/** + * Check that a transaction error validation fails properly. + * + * @param tx The transaction that should fail validation. + * @param validateTx The transaction-specific validation function (e.g. `validatePayment`). + */ +export function assertTxIsValid(tx: any, validateTx: (tx: any) => void): void { + assert.doesNotThrow(() => validateTx(tx)) + assert.doesNotThrow(() => validate(tx)) +} + +/** + * Check that a transaction error validation fails properly. + * + * @param tx The transaction that should fail validation. + * @param validateTx The transaction-specific validation function (e.g. `validatePayment`). + * @param errorMessage The error message that should be included in the error. + */ +export function assertTxValidationError( + tx: any, + validateTx: (tx: any) => void, + errorMessage: string, +): void { + assert.throws(() => validateTx(tx), ValidationError, errorMessage) + assert.throws(() => validate(tx), ValidationError, errorMessage) +} + /** * Check that the promise rejects with an expected error. * From 0df5111e5eb8eebe6c58eefd97b101529849fa5d Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 16 Apr 2025 16:04:08 -0400 Subject: [PATCH 2/9] update history --- packages/xrpl/HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 0714983e50..cde1c0fa9e 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -11,6 +11,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * `OracleSet` transaction accepts hexadecimal string values for `AssetPrice` field * `TransactionStream` model includes `hash` field in APIv2 * `TransactionStream` model includes `close_time_iso` field only for APIv2 +* Fix issue with some transactions that would crash in validation ## 4.2.0 (2025-2-13) From 54164275d09f8d29a78c009ec75f8851e0d7d5a7 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 16 Apr 2025 16:06:41 -0400 Subject: [PATCH 3/9] delete bad tests --- packages/xrpl/test/models/DIDDelete.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/xrpl/test/models/DIDDelete.test.ts b/packages/xrpl/test/models/DIDDelete.test.ts index cd35e9ec97..a3d079a3ba 100644 --- a/packages/xrpl/test/models/DIDDelete.test.ts +++ b/packages/xrpl/test/models/DIDDelete.test.ts @@ -24,9 +24,4 @@ describe('DIDDelete', function () { it('verifies valid DIDDelete', function () { assertValid(tx) }) - - it('throws on invalid DIDDelete', function () { - tx.FakeField = 'blah' - assertValid(tx) - }) }) From a7df83512835a37a50bc6dfbd6755e31d12ed829 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 16 Apr 2025 16:07:22 -0400 Subject: [PATCH 4/9] slightly more efficient code --- packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts | 2 +- packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts b/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts index 869dd9491b..76d37ddee3 100644 --- a/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts +++ b/packages/xrpl/src/models/transactions/MPTokenIssuanceCreate.ts @@ -157,7 +157,7 @@ export function validateMPTokenIssuanceCreate( if (typeof tx.TransferFee === 'number') { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Not necessary - const flags = (tx.Flags || 0) as + const flags = (tx.Flags ?? 0) as | number | MPTokenIssuanceCreateFlagsInterface const isTfMPTCanTransfer = diff --git a/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts b/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts index 796362fd27..da1b1d2aec 100644 --- a/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts +++ b/packages/xrpl/src/models/transactions/MPTokenIssuanceSet.ts @@ -69,7 +69,7 @@ export function validateMPTokenIssuanceSet(tx: Record): void { validateOptionalField(tx, 'Holder', isAccount) // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Not necessary - const flags = (tx.Flags || 0) as number | MPTokenIssuanceSetFlagsInterface + const flags = (tx.Flags ?? 0) as number | MPTokenIssuanceSetFlagsInterface const isTfMPTLock = typeof flags === 'number' ? isFlagEnabled(flags, MPTokenIssuanceSetFlags.tfMPTLock) From 8a0d681de6676562e565261e612dd9bf26b1a16d Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 16 Apr 2025 16:09:19 -0400 Subject: [PATCH 5/9] fix dependency cycle --- .../models/transactions/NFTokenCreateOffer.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts b/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts index abcb78cf08..1f9c492b86 100644 --- a/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts +++ b/packages/xrpl/src/models/transactions/NFTokenCreateOffer.ts @@ -1,7 +1,6 @@ import { ValidationError } from '../../errors' import { Amount } from '../common' import { isFlagEnabled } from '../utils' -import { convertTxFlagsToNumber } from '../utils/flags' import { BaseTransaction, @@ -14,7 +13,6 @@ import { Account, } from './common' import type { TransactionMetadataBase } from './metadata' -import type { Transaction } from './transaction' /** * Transaction Flags for an NFTokenCreateOffer Transaction. @@ -148,13 +146,14 @@ export function validateNFTokenCreateOffer(tx: Record): void { throw new ValidationError('NFTokenCreateOffer: invalid Amount') } - if ( - isFlagEnabled( - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked in BaseTransaction - convertTxFlagsToNumber(tx as unknown as Transaction), - NFTokenCreateOfferFlags.tfSellNFToken, - ) - ) { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked in BaseTransaction + const flags = (tx.Flags ?? 0) as number | NFTokenCreateOfferFlagsInterface + const isTfSellNFToken = + typeof flags === 'number' + ? isFlagEnabled(flags, NFTokenCreateOfferFlags.tfSellNFToken) + : flags.tfSellNFToken ?? false + + if (isTfSellNFToken) { validateNFTokenSellOfferCases(tx) } else { validateNFTokenBuyOfferCases(tx) From 6950944354ec19d9d1822f1d119a6153ee60046e Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 16 Apr 2025 16:26:15 -0400 Subject: [PATCH 6/9] remove duplicate --- packages/xrpl/test/models/depositPreauth.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/xrpl/test/models/depositPreauth.test.ts b/packages/xrpl/test/models/depositPreauth.test.ts index f659f57421..ff31b72de6 100644 --- a/packages/xrpl/test/models/depositPreauth.test.ts +++ b/packages/xrpl/test/models/depositPreauth.test.ts @@ -105,10 +105,6 @@ describe('DepositPreauth', function () { depositPreauth, "DepositPreauth: Account can't unauthorize its own address", ) - assertInvalid( - depositPreauth, - "DepositPreauth: Account can't unauthorize its own address", - ) }) it('throws when AuthorizeCredentials is not an array', function () { From 5f0b30e2db8d96a83832d36df84249775681b2bf Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Thu, 17 Apr 2025 10:35:08 -0400 Subject: [PATCH 7/9] try to get text summary --- jest.config.base.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.base.js b/jest.config.base.js index aac588b656..4665c96bb7 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -9,6 +9,7 @@ module.exports = { collectCoverage: true, verbose: true, testEnvironment: "node", + coverageReporters: [["text", { skipFull: true }], "text-summary"], globals: { TextDecoder: TextDecoder, TextEncoder: TextEncoder, From d42104788e8efda08f599ac02bca37550fbada4c Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Thu, 3 Jul 2025 22:04:54 +0530 Subject: [PATCH 8/9] fix --- packages/xrpl/HISTORY.md | 2 +- packages/xrpl/test/models/baseTransaction.test.ts | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 03da4e18b1..57ab269a46 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -8,6 +8,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * Fix `AccountRoot` ledger object to correctly parse `FirstNFTokenSequence` field * Fail faster on `tem` errors with `submitAndWait` * Improved type-checking in models +* Fix issue with some transactions that would crash in validation ## 4.3.0 (2025-6-09) @@ -24,7 +25,6 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr * Adds `MPTCurrency` type * Improve faucet support * Improve multisign fee calculations -* Fix issue with some transactions that would crash in validation ## 4.2.0 (2025-2-13) diff --git a/packages/xrpl/test/models/baseTransaction.test.ts b/packages/xrpl/test/models/baseTransaction.test.ts index 84d56b7c43..0d85f44a33 100644 --- a/packages/xrpl/test/models/baseTransaction.test.ts +++ b/packages/xrpl/test/models/baseTransaction.test.ts @@ -215,11 +215,7 @@ describe('BaseTransaction', function () { TransactionType: 'Payment', Delegate: 1234, } - assert.throws( - () => validateBaseTransaction(invalidDelegate), - ValidationError, - 'Payment: invalid field Delegate', - ) + assertInvalid(invalidDelegate, 'Payment: invalid field Delegate') }) it(`Handles Account and Delegate being the same error`, function () { @@ -229,9 +225,8 @@ describe('BaseTransaction', function () { TransactionType: 'Payment', Delegate: account, } - assert.throws( - () => validateBaseTransaction(invalidDelegate), - ValidationError, + assertInvalid( + invalidDelegate, 'BaseTransaction: Account and Delegate addresses cannot be the same', ) }) From 1235ce7b0bb3e65c78bc3cfef88ee36387c5a6b5 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Thu, 3 Jul 2025 22:07:10 +0530 Subject: [PATCH 9/9] fix tests --- packages/xrpl/test/models/signerListSet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/xrpl/test/models/signerListSet.test.ts b/packages/xrpl/test/models/signerListSet.test.ts index 5f3663132d..6d605d5291 100644 --- a/packages/xrpl/test/models/signerListSet.test.ts +++ b/packages/xrpl/test/models/signerListSet.test.ts @@ -66,7 +66,7 @@ describe('SignerListSet', function () { it(`throws w/ invalid SignerEntries`, function () { signerListSetTx.SignerEntries = 'khgfgyhujk' - assertInvalid(signerListSetTx, 'SignerListSet: invalid SignerEntries') + assertInvalid(signerListSetTx, 'SignerListSet: invalid field SignerEntries') }) it(`throws w/ maximum of 32 members allowed in SignerEntries`, function () {