refactor: add verify() function (#1552)

* refactor: add verify() function
This commit is contained in:
Mukul Jangid
2021-09-13 11:31:29 -04:00
committed by Mayukha Vadari
parent 0d32071e0e
commit 148cac6f3f
21 changed files with 732 additions and 103 deletions

View File

@@ -2,7 +2,11 @@
/* eslint-disable import/max-dependencies -- Needs to export all types + verify methods */
// TODO: replace * imports with direct imports
export * from './transaction'
export * from './accountSet'
export {
AccountSetFlagsInterface,
AccountSet,
verifyAccountSet,
} from './accountSet'
export * from './accountDelete'
export * from './checkCancel'
export * from './checkCash'
@@ -12,12 +16,20 @@ export * from './escrowCancel'
export * from './escrowCreate'
export * from './escrowFinish'
export * from './offerCancel'
export * from './offerCreate'
export * from './payment'
export * from './paymentChannelClaim'
export {
OfferCreateFlagsInterface,
OfferCreate,
verifyOfferCreate,
} from './offerCreate'
export { PaymentFlagsInterface, Payment, verifyPayment } from './payment'
export {
PaymentChannelClaimFlagsInterface,
PaymentChannelClaim,
verifyPaymentChannelClaim,
} from './paymentChannelClaim'
export * from './paymentChannelCreate'
export * from './paymentChannelFund'
export * from './setRegularKey'
export * from './signerListSet'
export * from './ticketCreate'
export * from './trustSet'
export { TrustSetFlagsInterface, TrustSet, verifyTrustSet } from './trustSet'

View File

@@ -1,32 +1,52 @@
/* eslint-disable import/max-dependencies -- All methods need to be exported */
/* eslint-disable complexity -- verifies 19 tx types hence a lot of checks needed */
/* eslint-disable max-lines-per-function -- need to work with a lot of Tx verifications */
/* eslint-disable import/max-dependencies -- need to test more than 5 TxTypes */
import { AccountDelete } from './accountDelete'
import _ from 'lodash'
import { encode, decode } from 'ripple-binary-codec'
import { ValidationError } from '../../common/errors'
import TransactionMetadata from './metadata'
import { AccountDelete, verifyAccountDelete } from './accountDelete'
import {
AccountSet,
verifyAccountSet,
AccountSetFlags,
AccountSetTransactionFlags,
} from './accountSet'
import { CheckCancel } from './checkCancel'
import { CheckCash } from './checkCash'
import { CheckCreate } from './checkCreate'
import { DepositPreauth } from './depositPreauth'
import { EscrowCancel } from './escrowCancel'
import { EscrowCreate } from './escrowCreate'
import { EscrowFinish } from './escrowFinish'
import Metadata from './metadata'
import { OfferCancel } from './offerCancel'
import { OfferCreate, OfferCreateTransactionFlags } from './offerCreate'
import { Payment, PaymentTransactionFlags } from './payment'
import { CheckCancel, verifyCheckCancel } from './checkCancel'
import { CheckCash, verifyCheckCash } from './checkCash'
import { CheckCreate, verifyCheckCreate } from './checkCreate'
import { DepositPreauth, verifyDepositPreauth } from './depositPreauth'
import { EscrowCancel, verifyEscrowCancel } from './escrowCancel'
import { EscrowCreate, verifyEscrowCreate } from './escrowCreate'
import { EscrowFinish, verifyEscrowFinish } from './escrowFinish'
import { OfferCancel, verifyOfferCancel } from './offerCancel'
import {
OfferCreate,
verifyOfferCreate,
OfferCreateTransactionFlags,
} from './offerCreate'
import {
PaymentChannelClaim,
verifyPaymentChannelClaim,
PaymentChannelClaimTransactionFlags,
} from './paymentChannelClaim'
import { PaymentChannelCreate } from './paymentChannelCreate'
import { PaymentChannelFund } from './paymentChannelFund'
import { SetRegularKey } from './setRegularKey'
import { SignerListSet } from './signerListSet'
import { TicketCreate } from './ticketCreate'
import { TrustSet, TrustSetTransactionFlags } from './trustSet'
import {
PaymentChannelCreate,
verifyPaymentChannelCreate,
} from './paymentChannelCreate'
import {
PaymentChannelFund,
verifyPaymentChannelFund,
} from './paymentChannelFund'
import { Payment, verifyPayment, PaymentTransactionFlags } from './payment'
import { SetRegularKey, verifySetRegularKey } from './setRegularKey'
import { SignerListSet, verifySignerListSet } from './signerListSet'
import { TicketCreate, verifyTicketCreate } from './ticketCreate'
import { TrustSet, verifyTrustSet, TrustSetTransactionFlags } from './trustSet'
import { setTransactionFlagsToNumber } from '../utils'
export type Transaction =
| AccountDelete
@@ -51,7 +71,110 @@ export type Transaction =
export interface TransactionAndMetadata {
transaction: Transaction
metadata: Metadata
metadata: TransactionMetadata
}
/**
* Verifies various Transaction Types.
* Encode/decode and individual type validation.
*
* @param tx - A Transaction.
* @throws ValidationError When the Transaction is malformed.
*/
export function verify(transaction: Record<string, unknown>): void {
const tx = { ...transaction }
setTransactionFlagsToNumber(tx as unknown as Transaction)
switch (tx.TransactionType) {
case 'AccountDelete':
verifyAccountDelete(tx)
break
case 'AccountSet':
verifyAccountSet(tx)
break
case 'CheckCancel':
verifyCheckCancel(tx)
break
case 'CheckCash':
verifyCheckCash(tx)
break
case 'CheckCreate':
verifyCheckCreate(tx)
break
case 'DepositPreauth':
verifyDepositPreauth(tx)
break
case 'EscrowCancel':
verifyEscrowCancel(tx)
break
case 'EscrowCreate':
verifyEscrowCreate(tx)
break
case 'EscrowFinish':
verifyEscrowFinish(tx)
break
case 'OfferCancel':
verifyOfferCancel(tx)
break
case 'OfferCreate':
verifyOfferCreate(tx)
break
case 'Payment':
verifyPayment(tx)
break
case 'PaymentChannelClaim':
verifyPaymentChannelClaim(tx)
break
case 'PaymentChannelCreate':
verifyPaymentChannelCreate(tx)
break
case 'PaymentChannelFund':
verifyPaymentChannelFund(tx)
break
case 'SetRegularKey':
verifySetRegularKey(tx)
break
case 'SignerListSet':
verifySignerListSet(tx)
break
case 'TicketCreate':
verifyTicketCreate(tx)
break
case 'TrustSet':
verifyTrustSet(tx)
break
default:
throw new ValidationError(
`Invalid field TransactionType: ${tx.TransactionType}`,
)
}
if (
!_.isEqual(
decode(encode(tx)),
_.omitBy(tx, (value) => value == null),
)
) {
throw new ValidationError(`Invalid Transaction: ${tx.TransactionType}`)
}
}
export {

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyAccountDelete } from '../../src/models/transactions/accountDelete'
import { verifyAccountDelete } from './../../src/models/transactions/accountDelete'
import { verify } from './../../src/models/transactions'
import { assert } from 'chai'
/**
* AccountDelete Transaction Verification Testing.
@@ -38,6 +37,12 @@ describe('AccountDelete', function () {
ValidationError,
'AccountDelete: missing field Destination',
)
assert.throws(
() => verify(invalidDestination),
ValidationError,
'AccountDelete: missing field Destination',
)
})
it(`throws w/ invalid Destination`, function () {
@@ -55,6 +60,11 @@ describe('AccountDelete', function () {
ValidationError,
'AccountDelete: invalid Destination',
)
assert.throws(
() => verify(invalidDestination),
ValidationError,
'AccountDelete: invalid Destination',
)
})
it(`throws w/ invalid DestinationTag`, function () {
@@ -73,5 +83,11 @@ describe('AccountDelete', function () {
ValidationError,
'AccountDelete: invalid DestinationTag',
)
assert.throws(
() => verify(invalidDestinationTag),
ValidationError,
'AccountDelete: invalid DestinationTag',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyAccountSet } from '../../src/models/transactions/accountSet'
import { verifyAccountSet } from './../../src/models/transactions/accountSet'
import { verify } from '../../src/models/transactions'
import { assert } from 'chai'
/**
* AccountSet Transaction Verification Testing.
@@ -27,6 +26,7 @@ describe('AccountSet', function () {
it(`verifies valid AccountSet`, function () {
assert.doesNotThrow(() => verifyAccountSet(account))
assert.doesNotThrow(() => verify(account))
})
it(`throws w/ invalid SetFlag (out of range)`, function () {
@@ -37,6 +37,11 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid SetFlag',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid SetFlag',
)
})
it(`throws w/ invalid SetFlag (incorrect type)`, function () {
@@ -47,6 +52,11 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid SetFlag',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid SetFlag',
)
})
it(`throws w/ invalid ClearFlag`, function () {
@@ -57,6 +67,11 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid ClearFlag',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid ClearFlag',
)
})
it(`throws w/ invalid Domain`, function () {
@@ -67,6 +82,11 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid Domain',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid Domain',
)
})
it(`throws w/ invalid EmailHash`, function () {
@@ -77,6 +97,11 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid EmailHash',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid EmailHash',
)
})
it(`throws w/ invalid MessageKey`, function () {
@@ -87,6 +112,11 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid MessageKey',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid MessageKey',
)
})
it(`throws w/ invalid TransferRate`, function () {
@@ -97,6 +127,11 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid TransferRate',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid TransferRate',
)
})
it(`throws w/ invalid TickSize`, function () {
@@ -107,5 +142,10 @@ describe('AccountSet', function () {
ValidationError,
'AccountSet: invalid TickSize',
)
assert.throws(
() => verify(account),
ValidationError,
'AccountSet: invalid TickSize',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyCheckCancel } from '../../src/models/transactions/checkCancel'
import { verifyCheckCancel } from './../../src/models/transactions/checkCancel'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* CheckCancel Transaction Verification Testing.
@@ -19,6 +18,7 @@ describe('CheckCancel', function () {
} as any
assert.doesNotThrow(() => verifyCheckCancel(validCheckCancel))
assert.doesNotThrow(() => verify(validCheckCancel))
})
it(`throws w/ invalid CheckCancel`, function () {
@@ -33,5 +33,10 @@ describe('CheckCancel', function () {
ValidationError,
'CheckCancel: invalid CheckID',
)
assert.throws(
() => verify(invalidCheckID),
ValidationError,
'CheckCancel: invalid CheckID',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyCheckCash } from '../../src/models/transactions/checkCash'
import { verifyCheckCash } from './../../src/models/transactions/checkCash'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* CheckCash Transaction Verification Testing.
@@ -21,6 +20,7 @@ describe('CheckCash', function () {
} as any
assert.doesNotThrow(() => verifyCheckCash(validCheckCash))
assert.doesNotThrow(() => verify(validCheckCash))
})
it(`throws w/ invalid CheckID`, function () {
@@ -36,6 +36,11 @@ describe('CheckCash', function () {
ValidationError,
'CheckCash: invalid CheckID',
)
assert.throws(
() => verify(invalidCheckID),
ValidationError,
'CheckCash: invalid CheckID',
)
})
it(`throws w/ invalid Amount`, function () {
@@ -52,6 +57,11 @@ describe('CheckCash', function () {
ValidationError,
'CheckCash: invalid Amount',
)
assert.throws(
() => verify(invalidAmount),
ValidationError,
'CheckCash: invalid Amount',
)
})
it(`throws w/ having both Amount and DeliverMin`, function () {
@@ -69,6 +79,11 @@ describe('CheckCash', function () {
ValidationError,
'CheckCash: cannot have both Amount and DeliverMin',
)
assert.throws(
() => verify(invalidDeliverMin),
ValidationError,
'CheckCash: cannot have both Amount and DeliverMin',
)
})
it(`throws w/ invalid DeliverMin`, function () {
@@ -85,5 +100,10 @@ describe('CheckCash', function () {
ValidationError,
'CheckCash: invalid DeliverMin',
)
assert.throws(
() => verify(invalidDeliverMin),
ValidationError,
'CheckCash: invalid DeliverMin',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyCheckCreate } from '../../src/models/transactions/checkCreate'
import { verifyCheckCreate } from './../../src/models/transactions/checkCreate'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* CheckCreate Transaction Verification Testing.
@@ -24,6 +23,7 @@ describe('CheckCreate', function () {
} as any
assert.doesNotThrow(() => verifyCheckCreate(validCheck))
assert.doesNotThrow(() => verify(validCheck))
})
it(`throws w/ invalid Destination`, function () {
@@ -44,6 +44,11 @@ describe('CheckCreate', function () {
ValidationError,
'CheckCreate: invalid Destination',
)
assert.throws(
() => verify(invalidDestination),
ValidationError,
'CheckCreate: invalid Destination',
)
})
it(`throws w/ invalid SendMax`, function () {
@@ -64,6 +69,11 @@ describe('CheckCreate', function () {
ValidationError,
'CheckCreate: invalid SendMax',
)
assert.throws(
() => verify(invalidSendMax),
ValidationError,
'CheckCreate: invalid SendMax',
)
})
it(`throws w/ invalid DestinationTag`, function () {
@@ -84,6 +94,11 @@ describe('CheckCreate', function () {
ValidationError,
'CheckCreate: invalid DestinationTag',
)
assert.throws(
() => verify(invalidDestinationTag),
ValidationError,
'CheckCreate: invalid DestinationTag',
)
})
it(`throws w/ invalid Expiration`, function () {
@@ -104,6 +119,11 @@ describe('CheckCreate', function () {
ValidationError,
'CheckCreate: invalid Expiration',
)
assert.throws(
() => verify(invalidExpiration),
ValidationError,
'CheckCreate: invalid Expiration',
)
})
it(`throws w/ invalid InvoiceID`, function () {
@@ -123,5 +143,10 @@ describe('CheckCreate', function () {
ValidationError,
'CheckCreate: invalid InvoiceID',
)
assert.throws(
() => verify(invalidInvoiceID),
ValidationError,
'CheckCreate: invalid InvoiceID',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyDepositPreauth } from '../../src/models/transactions/depositPreauth'
import { verifyDepositPreauth } from './../../src/models/transactions/depositPreauth'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* DepositPreauth Transaction Verification Testing.
@@ -22,11 +21,13 @@ describe('DepositPreauth', function () {
it('verifies valid DepositPreauth when only Authorize is provided', function () {
depositPreauth.Authorize = 'rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW'
assert.doesNotThrow(() => verifyDepositPreauth(depositPreauth))
assert.doesNotThrow(() => verify(depositPreauth))
})
it('verifies valid DepositPreauth when only Unauthorize is provided', function () {
depositPreauth.Unauthorize = 'raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n'
assert.doesNotThrow(() => verifyDepositPreauth(depositPreauth))
assert.doesNotThrow(() => verify(depositPreauth))
})
it('throws when both Authorize and Unauthorize are provided', function () {
@@ -37,6 +38,11 @@ describe('DepositPreauth', function () {
ValidationError,
"DepositPreauth: can't provide both Authorize and Unauthorize fields",
)
assert.throws(
() => verify(depositPreauth),
ValidationError,
"DepositPreauth: can't provide both Authorize and Unauthorize fields",
)
})
it('throws when neither Authorize nor Unauthorize are provided', function () {
@@ -45,6 +51,11 @@ describe('DepositPreauth', function () {
ValidationError,
'DepositPreauth: must provide either Authorize or Unauthorize field',
)
assert.throws(
() => verify(depositPreauth),
ValidationError,
'DepositPreauth: must provide either Authorize or Unauthorize field',
)
})
it('throws when Authorize is not a string', function () {
@@ -54,6 +65,11 @@ describe('DepositPreauth', function () {
ValidationError,
'DepositPreauth: Authorize must be a string',
)
assert.throws(
() => verify(depositPreauth),
ValidationError,
'DepositPreauth: Authorize must be a string',
)
})
it('throws when an Account attempts to preauthorize its own address', function () {
@@ -72,6 +88,11 @@ describe('DepositPreauth', function () {
ValidationError,
'DepositPreauth: Unauthorize must be a string',
)
assert.throws(
() => verify(depositPreauth),
ValidationError,
'DepositPreauth: Unauthorize must be a string',
)
})
it('throws when an Account attempts to unauthorize its own address', function () {
@@ -81,5 +102,10 @@ describe('DepositPreauth', function () {
ValidationError,
"DepositPreauth: Account can't unauthorize its own address",
)
assert.throws(
() => verify(depositPreauth),
ValidationError,
"DepositPreauth: Account can't unauthorize its own address",
)
})
})

View File

@@ -1,7 +1,7 @@
import { verifyEscrowCancel } from './../../src/models/transactions/escrowCancel'
import { assert } from 'chai'
import { ValidationError } from '../../src/common/errors'
import { verifyEscrowCancel } from '../../src/models/transactions/escrowCancel'
import { verify } from '../../src/models/transactions'
/**
* Transaction Verification Testing.
@@ -22,6 +22,7 @@ describe('EscrowCancel', function () {
it(`Valid EscrowCancel`, function () {
assert.doesNotThrow(() => verifyEscrowCancel(cancel))
assert.doesNotThrow(() => verify(cancel))
})
it(`Invalid EscrowCancel missing owner`, function () {
@@ -32,6 +33,11 @@ describe('EscrowCancel', function () {
ValidationError,
'EscrowCancel: missing Owner',
)
assert.throws(
() => verify(cancel),
ValidationError,
'EscrowCancel: missing Owner',
)
})
it(`Invalid EscrowCancel missing offerSequence`, function () {
@@ -42,6 +48,11 @@ describe('EscrowCancel', function () {
ValidationError,
'EscrowCancel: missing OfferSequence',
)
assert.throws(
() => verify(cancel),
ValidationError,
'EscrowCancel: missing OfferSequence',
)
})
it(`Invalid OfferSequence`, function () {
@@ -52,6 +63,11 @@ describe('EscrowCancel', function () {
ValidationError,
'EscrowCancel: Owner must be a string',
)
assert.throws(
() => verify(cancel),
ValidationError,
'EscrowCancel: Owner must be a string',
)
})
it(`Invalid owner`, function () {
@@ -62,5 +78,10 @@ describe('EscrowCancel', function () {
ValidationError,
'EscrowCancel: OfferSequence must be a number',
)
assert.throws(
() => verify(cancel),
ValidationError,
'EscrowCancel: OfferSequence must be a number',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyEscrowCreate } from '../../src/models/transactions/escrowCreate'
import { verifyEscrowCreate } from './../../src/models/transactions/escrowCreate'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* EscrowCreate Transaction Verification Testing.
@@ -29,6 +28,7 @@ describe('EscrowCreate', function () {
it(`verifies valid EscrowCreate`, function () {
assert.doesNotThrow(() => verifyEscrowCreate(escrow))
assert.doesNotThrow(() => verify(escrow))
})
it(`Missing amount`, function () {
@@ -39,6 +39,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: missing field Amount',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: missing field Amount',
)
})
it(`Missing destination`, function () {
@@ -49,6 +54,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: missing field Destination',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: missing field Destination',
)
})
it(`throws w/ invalid Destination`, function () {
@@ -59,6 +69,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: Destination must be a string',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: Destination must be a string',
)
})
it(`throws w/ invalid Amount`, function () {
@@ -69,6 +84,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: Amount must be a string',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: Amount must be a string',
)
})
it(`invalid CancelAfter`, function () {
@@ -79,6 +99,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: CancelAfter must be a number',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: CancelAfter must be a number',
)
})
it(`invalid FinishAfter`, function () {
@@ -99,6 +124,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: Condition must be a string',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: Condition must be a string',
)
})
it(`invalid DestinationTag`, function () {
@@ -109,6 +139,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: DestinationTag must be a number',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: DestinationTag must be a number',
)
})
it(`Missing both CancelAfter and FinishAfter`, function () {
@@ -120,6 +155,11 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: Either CancelAfter or FinishAfter must be specified',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: Either CancelAfter or FinishAfter must be specified',
)
})
it(`Missing both Condition and FinishAfter`, function () {
@@ -131,5 +171,10 @@ describe('EscrowCreate', function () {
ValidationError,
'EscrowCreate: Either Condition or FinishAfter must be specified',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowCreate: Either Condition or FinishAfter must be specified',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyEscrowFinish } from '../../src/models/transactions/escrowFinish'
import { verifyEscrowFinish } from './../../src/models/transactions/escrowFinish'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* EscrowFinish Transaction Verification Testing.
@@ -25,6 +24,7 @@ describe('EscrowFinish', function () {
})
it(`verifies valid EscrowFinish`, function () {
assert.doesNotThrow(() => verifyEscrowFinish(escrow))
assert.doesNotThrow(() => verify(escrow))
})
it(`verifies valid EscrowFinish w/o optional`, function () {
@@ -32,6 +32,7 @@ describe('EscrowFinish', function () {
delete escrow.Fulfillment
assert.doesNotThrow(() => verifyEscrowFinish(escrow))
assert.doesNotThrow(() => verify(escrow))
})
it(`throws w/ invalid Owner`, function () {
@@ -42,6 +43,11 @@ describe('EscrowFinish', function () {
ValidationError,
'EscrowFinish: Owner must be a string',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowFinish: Owner must be a string',
)
})
it(`throws w/ invalid OfferSequence`, function () {
@@ -52,6 +58,11 @@ describe('EscrowFinish', function () {
ValidationError,
'EscrowFinish: OfferSequence must be a number',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowFinish: OfferSequence must be a number',
)
})
it(`throws w/ invalid Condition`, function () {
@@ -62,6 +73,11 @@ describe('EscrowFinish', function () {
ValidationError,
'EscrowFinish: Condition must be a string',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowFinish: Condition must be a string',
)
})
it(`throws w/ invalid Fulfillment`, function () {
@@ -72,5 +88,10 @@ describe('EscrowFinish', function () {
ValidationError,
'EscrowFinish: Fulfillment must be a string',
)
assert.throws(
() => verify(escrow),
ValidationError,
'EscrowFinish: Fulfillment must be a string',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyOfferCancel } from '../../src/models/transactions/offerCancel'
import { verifyOfferCancel } from './../../src/models/transactions/offerCancel'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* OfferCancel Transaction Verification Testing.
@@ -19,22 +18,24 @@ describe('OfferCancel', function () {
LastLedgerSequence: 65477334,
OfferSequence: 60797528,
Sequence: 60797535,
Flags: 2147483648,
SigningPubKey:
'0361BFD43D1EEA54B77CC152887312949EBF052997FBFFCDAF6F2653164B55B21...',
'0369C9BC4D18FAE741898828A1F48E53E53F6F3DB3191441CC85A14D4FC140E031',
TransactionType: 'OfferCancel',
TxnSignature:
'30450221008C43BDCFC68B4793857CA47DF454C07E5B45D3F80E8E6785CAB9292...',
date: '2021-08-06T21:04:11Z',
'304402203EC848BD6AB42DC8509285245804B15E1652092CC0B189D369E12E563771D049022046DF40C16EA05DC99D01E553EA2E218FCA1C5B38927889A2BDF064D1F44D60F0',
} as any
})
it(`verifies valid OfferCancel`, function () {
assert.doesNotThrow(() => verifyOfferCancel(offer))
assert.doesNotThrow(() => verify(offer))
})
it(`verifies valid OfferCancel with flags`, function () {
offer.Flags = 2147483648
assert.doesNotThrow(() => verifyOfferCancel(offer))
assert.doesNotThrow(() => verify(offer))
})
it(`throws w/ OfferSequence must be a number`, function () {
@@ -44,6 +45,11 @@ describe('OfferCancel', function () {
ValidationError,
'OfferCancel: OfferSequence must be a number',
)
assert.throws(
() => verify(offer),
ValidationError,
'OfferCancel: OfferSequence must be a number',
)
})
it(`throws w/ missing OfferSequence`, function () {
@@ -53,5 +59,10 @@ describe('OfferCancel', function () {
ValidationError,
'OfferCancel: missing field OfferSequence',
)
assert.throws(
() => verify(offer),
ValidationError,
'OfferCancel: missing field OfferSequence',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyOfferCreate } from '../../src/models/transactions/offerCreate'
import { verifyOfferCreate } from './../../src/models/transactions/offerCreate'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* OfferCreate Transaction Verification Testing.
@@ -33,6 +32,7 @@ describe('OfferCreate', function () {
} as any
assert.doesNotThrow(() => verifyOfferCreate(offer))
assert.doesNotThrow(() => verify(offer))
const offer2 = {
Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W',
@@ -54,6 +54,7 @@ describe('OfferCreate', function () {
} as any
assert.doesNotThrow(() => verifyOfferCreate(offer2))
assert.doesNotThrow(() => verify(offer2))
const offer3 = {
Account: 'r3rhWeE31Jt5sWmi4QiGLMZnY3ENgqw96W',
@@ -79,6 +80,7 @@ describe('OfferCreate', function () {
} as any
assert.doesNotThrow(() => verifyOfferCreate(offer3))
assert.doesNotThrow(() => verify(offer3))
})
it(`throws w/ invalid Expiration`, function () {
@@ -107,6 +109,11 @@ describe('OfferCreate', function () {
ValidationError,
'OfferCreate: invalid Expiration',
)
assert.throws(
() => verify(offer),
ValidationError,
'OfferCreate: invalid Expiration',
)
})
it(`throws w/ invalid OfferSequence`, function () {
@@ -135,6 +142,11 @@ describe('OfferCreate', function () {
ValidationError,
'OfferCreate: invalid OfferSequence',
)
assert.throws(
() => verify(offer),
ValidationError,
'OfferCreate: invalid OfferSequence',
)
})
it(`throws w/ invalid TakerPays`, function () {
@@ -159,6 +171,11 @@ describe('OfferCreate', function () {
ValidationError,
'OfferCreate: invalid TakerPays',
)
assert.throws(
() => verify(offer),
ValidationError,
'OfferCreate: invalid TakerPays',
)
})
it(`throws w/ invalid TakerGets`, function () {
@@ -187,5 +204,10 @@ describe('OfferCreate', function () {
ValidationError,
'OfferCreate: invalid TakerGets',
)
assert.throws(
() => verify(offer),
ValidationError,
'OfferCreate: invalid TakerGets',
)
})
})

View File

@@ -3,9 +3,10 @@ import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import {
PaymentTransactionFlags,
verifyPayment,
} from '../../src/models/transactions/payment'
verify,
PaymentTransactionFlags,
} from '../../src/models/transactions'
/**
* PaymentTransaction Verification Testing.
@@ -22,15 +23,26 @@ describe('Payment', function () {
Amount: '1234',
Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
DestinationTag: 1,
Fee: '12',
Flags: 2147483648,
LastLedgerSequence: 65953073,
Sequence: 65923914,
SigningPubKey:
'02F9E33F16DF9507705EC954E3F94EB5F10D1FC4A354606DBE6297DBB1096FE654',
TxnSignature:
'3045022100E3FAE0EDEC3D6A8FF6D81BC9CF8288A61B7EEDE8071E90FF9314CB4621058D10022043545CF631706D700CEE65A1DB83EFDD185413808292D9D90F14D87D3DC2D8CB',
InvoiceID:
'6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B',
Paths: [[{ currency: 'BTC', issuer: 'apsoeijf90wp34fh' }]],
Paths: [
[{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }],
],
SendMax: '100000000',
} as any
})
it(`verifies valid PaymentTransaction`, function () {
assert.doesNotThrow(() => verifyPayment(paymentTransaction))
assert.doesNotThrow(() => verify(paymentTransaction))
})
it(`throws when Amount is missing`, function () {
@@ -40,6 +52,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: missing field Amount',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: missing field Amount',
)
})
it(`throws when Amount is invalid`, function () {
@@ -49,6 +66,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: invalid Amount',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: invalid Amount',
)
})
it(`throws when Destination is missing`, function () {
@@ -58,6 +80,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: missing field Destination',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: missing field Destination',
)
})
it(`throws when Destination is invalid`, function () {
@@ -67,6 +94,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: invalid Destination',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: invalid Destination',
)
})
it(`throws when DestinationTag is not a number`, function () {
@@ -76,6 +108,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: DestinationTag must be a number',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: DestinationTag must be a number',
)
})
it(`throws when InvoiceID is not a string`, function () {
@@ -85,6 +122,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: InvoiceID must be a string',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: InvoiceID must be a string',
)
})
it(`throws when Paths is invalid`, function () {
@@ -94,6 +136,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: invalid Paths',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: invalid Paths',
)
})
it(`throws when SendMax is invalid`, function () {
@@ -103,18 +150,25 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: invalid SendMax',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: invalid SendMax',
)
})
it(`verifies valid DeliverMin with tfPartialPayment flag set as a number`, function () {
paymentTransaction.DeliverMin = '10000'
paymentTransaction.Flags = PaymentTransactionFlags.tfPartialPayment
assert.doesNotThrow(() => verifyPayment(paymentTransaction))
assert.doesNotThrow(() => verify(paymentTransaction))
})
it(`verifies valid DeliverMin with tfPartialPayment flag set as a boolean`, function () {
paymentTransaction.DeliverMin = '10000'
paymentTransaction.Flags = { tfPartialPayment: true }
assert.doesNotThrow(() => verifyPayment(paymentTransaction))
assert.doesNotThrow(() => verify(paymentTransaction))
})
it(`throws when DeliverMin is invalid`, function () {
@@ -125,6 +179,11 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: invalid DeliverMin',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: invalid DeliverMin',
)
})
it(`throws when tfPartialPayment flag is missing with valid DeliverMin`, function () {
@@ -134,5 +193,10 @@ describe('Payment', function () {
ValidationError,
'PaymentTransaction: tfPartialPayment flag required with DeliverMin',
)
assert.throws(
() => verify(paymentTransaction),
ValidationError,
'PaymentTransaction: tfPartialPayment flag required with DeliverMin',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyPaymentChannelClaim } from '../../src/models/transactions/paymentChannelClaim'
import { verifyPaymentChannelClaim } from './../../src/models/transactions/paymentChannelClaim'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* PaymentChannelClaim Transaction Verification Testing.
@@ -14,7 +13,7 @@ describe('PaymentChannelClaim', function () {
beforeEach(function () {
channel = {
Account: 'r...',
Account: 'rB5Ux4Lv2nRx6eeoAAsZmtctnBQ2LiACnk',
TransactionType: 'PaymentChannelClaim',
Channel:
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
@@ -29,6 +28,7 @@ describe('PaymentChannelClaim', function () {
it(`verifies valid PaymentChannelClaim`, function () {
assert.doesNotThrow(() => verifyPaymentChannelClaim(channel))
assert.doesNotThrow(() => verify(channel))
})
it(`verifies valid PaymentChannelClaim w/o optional`, function () {
@@ -38,6 +38,7 @@ describe('PaymentChannelClaim', function () {
delete channel.PublicKey
assert.doesNotThrow(() => verifyPaymentChannelClaim(channel))
assert.doesNotThrow(() => verify(channel))
})
it(`throws w/ missing Channel`, function () {
@@ -48,6 +49,11 @@ describe('PaymentChannelClaim', function () {
ValidationError,
'PaymentChannelClaim: missing Channel',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelClaim: missing Channel',
)
})
it(`throws w/ invalid Channel`, function () {
@@ -58,6 +64,11 @@ describe('PaymentChannelClaim', function () {
ValidationError,
'PaymentChannelClaim: Channel must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelClaim: Channel must be a string',
)
})
it(`throws w/ invalid Balance`, function () {
@@ -68,6 +79,11 @@ describe('PaymentChannelClaim', function () {
ValidationError,
'PaymentChannelClaim: Balance must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelClaim: Balance must be a string',
)
})
it(`throws w/ invalid Amount`, function () {
@@ -78,6 +94,11 @@ describe('PaymentChannelClaim', function () {
ValidationError,
'PaymentChannelClaim: Amount must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelClaim: Amount must be a string',
)
})
it(`throws w/ invalid Signature`, function () {
@@ -88,6 +109,11 @@ describe('PaymentChannelClaim', function () {
ValidationError,
'PaymentChannelClaim: Signature must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelClaim: Signature must be a string',
)
})
it(`throws w/ invalid PublicKey`, function () {
@@ -98,5 +124,10 @@ describe('PaymentChannelClaim', function () {
ValidationError,
'PaymentChannelClaim: PublicKey must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelClaim: PublicKey must be a string',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyPaymentChannelCreate } from '../../src/models/transactions/paymentChannelCreate'
import { verifyPaymentChannelCreate } from './../../src/models/transactions/paymentChannelCreate'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* PaymentChannelCreate Transaction Verification Testing.
@@ -29,6 +28,7 @@ describe('PaymentChannelCreate', function () {
it(`verifies valid PaymentChannelCreate`, function () {
assert.doesNotThrow(() => verifyPaymentChannelCreate(channel))
assert.doesNotThrow(() => verify(channel))
})
it(`verifies valid PaymentChannelCreate w/o optional`, function () {
@@ -37,6 +37,7 @@ describe('PaymentChannelCreate', function () {
delete channel.SourceTag
assert.doesNotThrow(() => verifyPaymentChannelCreate(channel))
assert.doesNotThrow(() => verify(channel))
})
it(`missing Amount`, function () {
@@ -47,6 +48,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: missing Amount',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: missing Amount',
)
})
it(`missing Destination`, function () {
@@ -57,6 +63,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: missing Destination',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: missing Destination',
)
})
it(`missing SettleDelay`, function () {
@@ -67,6 +78,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: missing SettleDelay',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: missing SettleDelay',
)
})
it(`missing PublicKey`, function () {
@@ -77,6 +93,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: missing PublicKey',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: missing PublicKey',
)
})
it(`invalid Amount`, function () {
@@ -87,6 +108,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: Amount must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: Amount must be a string',
)
})
it(`invalid Destination`, function () {
@@ -97,6 +123,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: Destination must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: Destination must be a string',
)
})
it(`invalid SettleDelay`, function () {
@@ -107,6 +138,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: SettleDelay must be a number',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: SettleDelay must be a number',
)
})
it(`invalid PublicKey`, function () {
@@ -117,6 +153,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: PublicKey must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: PublicKey must be a string',
)
})
it(`invalid DestinationTag`, function () {
@@ -127,6 +168,11 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: DestinationTag must be a number',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: DestinationTag must be a number',
)
})
it(`invalid CancelAfter`, function () {
@@ -137,5 +183,10 @@ describe('PaymentChannelCreate', function () {
ValidationError,
'PaymentChannelCreate: CancelAfter must be a number',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelCreate: CancelAfter must be a number',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyPaymentChannelFund } from '../../src/models/transactions/paymentChannelFund'
import { verifyPaymentChannelFund } from './../../src/models/transactions/paymentChannelFund'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* PaymentChannelFund Transaction Verification Testing.
@@ -25,12 +24,14 @@ describe('PaymentChannelFund', function () {
it(`verifies valid PaymentChannelFund`, function () {
assert.doesNotThrow(() => verifyPaymentChannelFund(channel))
assert.doesNotThrow(() => verify(channel))
})
it(`verifies valid PaymentChannelFund w/o optional`, function () {
delete channel.Expiration
assert.doesNotThrow(() => verifyPaymentChannelFund(channel))
assert.doesNotThrow(() => verify(channel))
})
it(`throws w/ missing Amount`, function () {
@@ -41,6 +42,11 @@ describe('PaymentChannelFund', function () {
ValidationError,
'PaymentChannelFund: missing Amount',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelFund: missing Amount',
)
})
it(`throws w/ missing Channel`, function () {
@@ -51,6 +57,11 @@ describe('PaymentChannelFund', function () {
ValidationError,
'PaymentChannelFund: missing Channel',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelFund: missing Channel',
)
})
it(`throws w/ invalid Amount`, function () {
@@ -61,6 +72,11 @@ describe('PaymentChannelFund', function () {
ValidationError,
'PaymentChannelFund: Amount must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelFund: Amount must be a string',
)
})
it(`throws w/ invalid Channel`, function () {
@@ -71,6 +87,11 @@ describe('PaymentChannelFund', function () {
ValidationError,
'PaymentChannelFund: Channel must be a string',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelFund: Channel must be a string',
)
})
it(`throws w/ invalid Expiration`, function () {
@@ -81,5 +102,10 @@ describe('PaymentChannelFund', function () {
ValidationError,
'PaymentChannelFund: Expiration must be a number',
)
assert.throws(
() => verify(channel),
ValidationError,
'PaymentChannelFund: Expiration must be a number',
)
})
})

View File

@@ -2,6 +2,7 @@ import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verify } from '../../src/models/transactions'
import { verifySetRegularKey } from '../../src/models/transactions/setRegularKey'
/**
@@ -24,11 +25,13 @@ describe('SetRegularKey', function () {
it(`verifies valid SetRegularKey`, function () {
assert.doesNotThrow(() => verifySetRegularKey(account))
assert.doesNotThrow(() => verify(account))
})
it(`verifies w/o SetRegularKey`, function () {
account.RegularKey = undefined
assert.doesNotThrow(() => verifySetRegularKey(account))
assert.doesNotThrow(() => verify(account))
})
it(`throws w/ invalid RegularKey`, function () {
@@ -39,5 +42,10 @@ describe('SetRegularKey', function () {
ValidationError,
'SetRegularKey: RegularKey must be a string',
)
assert.throws(
() => verify(account),
ValidationError,
'SetRegularKey: RegularKey must be a string',
)
})
})

View File

@@ -2,6 +2,7 @@ import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verify } from '../../src/models/transactions'
import { verifySignerListSet } from '../../src/models/transactions/signerListSet'
/**
@@ -10,10 +11,10 @@ import { verifySignerListSet } from '../../src/models/transactions/signerListSet
* Providing runtime verification testing for each specific transaction type.
*/
describe('SignerListSet', function () {
let SignerListSetTx
let signerListSetTx
beforeEach(function () {
SignerListSetTx = {
signerListSetTx = {
Flags: 0,
TransactionType: 'SignerListSet',
Account: 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn',
@@ -43,34 +44,50 @@ describe('SignerListSet', function () {
})
it(`verifies valid SignerListSet`, function () {
assert.doesNotThrow(() => verifySignerListSet(SignerListSetTx))
assert.doesNotThrow(() => verifySignerListSet(signerListSetTx))
assert.doesNotThrow(() => verify(signerListSetTx))
})
it(`throws w/ missing SignerQuorum`, function () {
SignerListSetTx.SignerQuorum = undefined
signerListSetTx.SignerQuorum = undefined
assert.throws(
() => verifySignerListSet(SignerListSetTx),
() => verifySignerListSet(signerListSetTx),
ValidationError,
'SignerListSet: missing field SignerQuorum',
)
assert.throws(
() => verify(signerListSetTx),
ValidationError,
'SignerListSet: missing field SignerQuorum',
)
})
it(`throws w/ empty SignerEntries`, function () {
SignerListSetTx.SignerEntries = []
signerListSetTx.SignerEntries = []
assert.throws(
() => verifySignerListSet(SignerListSetTx),
() => verifySignerListSet(signerListSetTx),
ValidationError,
'SignerListSet: need atleast 1 member in SignerEntries',
)
assert.throws(
() => verify(signerListSetTx),
ValidationError,
'SignerListSet: need atleast 1 member in SignerEntries',
)
})
it(`throws w/ invalid SignerEntries`, function () {
SignerListSetTx.SignerEntries = 'khgfgyhujk'
signerListSetTx.SignerEntries = 'khgfgyhujk'
assert.throws(
() => verifySignerListSet(SignerListSetTx),
() => verifySignerListSet(signerListSetTx),
ValidationError,
'SignerListSet: invalid SignerEntries',
)
assert.throws(
() => verify(signerListSetTx),
ValidationError,
'SignerListSet: invalid SignerEntries',
)

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyTicketCreate } from '../../src/models/transactions/ticketCreate'
import { verifyTicketCreate } from './../../src/models/transactions/ticketCreate'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* TicketCreate Transaction Verification Testing.
@@ -22,6 +21,7 @@ describe('TicketCreate', function () {
it('verifies valid TicketCreate', function () {
assert.doesNotThrow(() => verifyTicketCreate(ticketCreate))
assert.doesNotThrow(() => verify(ticketCreate))
})
it('throws when TicketCount is missing', function () {
@@ -31,6 +31,11 @@ describe('TicketCreate', function () {
ValidationError,
'TicketCreate: missing field TicketCount',
)
assert.throws(
() => verify(ticketCreate),
ValidationError,
'TicketCreate: missing field TicketCount',
)
})
it('throws when TicketCount is not a number', function () {
@@ -40,6 +45,11 @@ describe('TicketCreate', function () {
ValidationError,
'TicketCreate: TicketCount must be a number',
)
assert.throws(
() => verify(ticketCreate),
ValidationError,
'TicketCreate: TicketCount must be a number',
)
})
it('throws when TicketCount is not an integer', function () {
@@ -49,6 +59,11 @@ describe('TicketCreate', function () {
ValidationError,
'TicketCreate: TicketCount must be an integer from 1 to 250',
)
assert.throws(
() => verify(ticketCreate),
ValidationError,
'TicketCreate: TicketCount must be an integer from 1 to 250',
)
})
it('throws when TicketCount is < 1', function () {
@@ -58,6 +73,11 @@ describe('TicketCreate', function () {
ValidationError,
'TicketCreate: TicketCount must be an integer from 1 to 250',
)
assert.throws(
() => verify(ticketCreate),
ValidationError,
'TicketCreate: TicketCount must be an integer from 1 to 250',
)
})
it('throws when TicketCount is > 250', function () {
@@ -67,5 +87,10 @@ describe('TicketCreate', function () {
ValidationError,
'TicketCreate: TicketCount must be an integer from 1 to 250',
)
assert.throws(
() => verify(ticketCreate),
ValidationError,
'TicketCreate: TicketCount must be an integer from 1 to 250',
)
})
})

View File

@@ -1,8 +1,7 @@
import { assert } from 'chai'
import { ValidationError } from 'xrpl-local/common/errors'
import { verifyTrustSet } from '../../src/models/transactions/trustSet'
import { verifyTrustSet } from './../../src/models/transactions/trustSet'
import { assert } from 'chai'
import { verify } from '../../src/models/transactions'
/**
* TrustSet Transaction Verification Testing.
@@ -28,6 +27,7 @@ describe('TrustSet', function () {
it('verifies valid TrustSet', function () {
assert.doesNotThrow(() => verifyTrustSet(trustSet))
assert.doesNotThrow(() => verify(trustSet))
})
it('throws when LimitAmount is missing', function () {
@@ -37,6 +37,11 @@ describe('TrustSet', function () {
ValidationError,
'TrustSet: missing field LimitAmount',
)
assert.throws(
() => verify(trustSet),
ValidationError,
'TrustSet: missing field LimitAmount',
)
})
it('throws when LimitAmount is invalid', function () {
@@ -46,6 +51,11 @@ describe('TrustSet', function () {
ValidationError,
'TrustSet: invalid LimitAmount',
)
assert.throws(
() => verify(trustSet),
ValidationError,
'TrustSet: invalid LimitAmount',
)
})
it('throws when QualityIn is not a number', function () {
@@ -55,6 +65,11 @@ describe('TrustSet', function () {
ValidationError,
'TrustSet: QualityIn must be a number',
)
assert.throws(
() => verify(trustSet),
ValidationError,
'TrustSet: QualityIn must be a number',
)
})
it('throws when QualityOut is not a number', function () {
@@ -64,5 +79,10 @@ describe('TrustSet', function () {
ValidationError,
'TrustSet: QualityOut must be a number',
)
assert.throws(
() => verify(trustSet),
ValidationError,
'TrustSet: QualityOut must be a number',
)
})
})