mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-03 20:45:48 +00:00
fix: fix escrow OfferSequence validation (#2474)
* Fix escrow validation * update .nvmrc * fix tests * fix EscrowFinish too * fix test * update HISTORY * fix validation * fix linter issues * forgot to save * change test string
This commit is contained in:
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@@ -0,0 +1 @@
|
||||
*.md
|
||||
@@ -128,6 +128,12 @@ module.exports = {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['src/models/**/*.ts'],
|
||||
rules: {
|
||||
complexity: ['off'],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['.eslintrc.js', 'jest.config.js'],
|
||||
rules: {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
# xrpl.js (ripple-lib) Release History
|
||||
|
||||
Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release.
|
||||
|
||||
## Unreleased
|
||||
|
||||
## Fixed
|
||||
* Fix request model fields related to AMM
|
||||
* Fixed `EscrowCancel` and `EscrowFinish` validation
|
||||
|
||||
## 2.11.0 (2023-08-24)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- required for validateAMMBid */
|
||||
import { ValidationError } from '../../errors'
|
||||
import { AuthAccount, Currency, IssuedCurrencyAmount } from '../common'
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- required for validateAMMDeposit */
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Amount, Currency, IssuedCurrencyAmount } from '../common'
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- required for validateAMMWithdraw */
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Amount, Currency, IssuedCurrencyAmount } from '../common'
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validateAccountSet */
|
||||
|
||||
import { isValidClassicAddress } from 'ripple-address-codec'
|
||||
|
||||
import { ValidationError } from '../../errors'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validateCheckCash */
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Amount } from '../common'
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validateCheckCreate */
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Amount } from '../common'
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/* eslint-disable max-lines-per-function -- Necessary for validateBaseTransaction */
|
||||
/* eslint-disable complexity -- Necessary for validateBaseTransaction */
|
||||
/* eslint-disable max-statements -- Necessary for validateBaseTransaction */
|
||||
import { TRANSACTION_TYPES } from 'ripple-binary-codec'
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validateDepositPreauth */
|
||||
import { ValidationError } from '../../errors'
|
||||
|
||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||
|
||||
@@ -15,7 +15,7 @@ export interface EscrowCancel extends BaseTransaction {
|
||||
* Transaction sequence (or Ticket number) of EscrowCreate transaction that.
|
||||
* created the escrow to cancel.
|
||||
*/
|
||||
OfferSequence: number
|
||||
OfferSequence: number | string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ export interface EscrowCancel extends BaseTransaction {
|
||||
export function validateEscrowCancel(tx: Record<string, unknown>): void {
|
||||
validateBaseTransaction(tx)
|
||||
|
||||
if (tx.Owner === undefined) {
|
||||
if (tx.Owner == null) {
|
||||
throw new ValidationError('EscrowCancel: missing Owner')
|
||||
}
|
||||
|
||||
@@ -35,11 +35,15 @@ export function validateEscrowCancel(tx: Record<string, unknown>): void {
|
||||
throw new ValidationError('EscrowCancel: Owner must be a string')
|
||||
}
|
||||
|
||||
if (tx.OfferSequence === undefined) {
|
||||
if (tx.OfferSequence == null) {
|
||||
throw new ValidationError('EscrowCancel: missing OfferSequence')
|
||||
}
|
||||
|
||||
if (typeof tx.OfferSequence !== 'number') {
|
||||
if (
|
||||
(typeof tx.OfferSequence !== 'number' &&
|
||||
typeof tx.OfferSequence !== 'string') ||
|
||||
Number.isNaN(Number(tx.OfferSequence))
|
||||
) {
|
||||
throw new ValidationError('EscrowCancel: OfferSequence must be a number')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validateEscrowCreate */
|
||||
import { ValidationError } from '../../errors'
|
||||
|
||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||
|
||||
@@ -15,7 +15,7 @@ export interface EscrowFinish extends BaseTransaction {
|
||||
* Transaction sequence of EscrowCreate transaction that created the held.
|
||||
* payment to finish.
|
||||
*/
|
||||
OfferSequence: number
|
||||
OfferSequence: number | string
|
||||
/**
|
||||
* Hex value matching the previously-supplied PREIMAGE-SHA-256.
|
||||
* crypto-condition of the held payment.
|
||||
@@ -37,7 +37,7 @@ export interface EscrowFinish extends BaseTransaction {
|
||||
export function validateEscrowFinish(tx: Record<string, unknown>): void {
|
||||
validateBaseTransaction(tx)
|
||||
|
||||
if (tx.Owner === undefined) {
|
||||
if (tx.Owner == null) {
|
||||
throw new ValidationError('EscrowFinish: missing field Owner')
|
||||
}
|
||||
|
||||
@@ -45,11 +45,15 @@ export function validateEscrowFinish(tx: Record<string, unknown>): void {
|
||||
throw new ValidationError('EscrowFinish: Owner must be a string')
|
||||
}
|
||||
|
||||
if (tx.OfferSequence === undefined) {
|
||||
if (tx.OfferSequence == null) {
|
||||
throw new ValidationError('EscrowFinish: missing field OfferSequence')
|
||||
}
|
||||
|
||||
if (typeof tx.OfferSequence !== 'number') {
|
||||
if (
|
||||
(typeof tx.OfferSequence !== 'number' &&
|
||||
typeof tx.OfferSequence !== 'string') ||
|
||||
Number.isNaN(Number(tx.OfferSequence))
|
||||
) {
|
||||
throw new ValidationError('EscrowFinish: OfferSequence must be a number')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validateOfferCreate */
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Amount } from '../common'
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validatePayment */
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Amount, Path } from '../common'
|
||||
import { isFlagEnabled } from '../utils'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validatePaymentChannelClaim */
|
||||
import { ValidationError } from '../../errors'
|
||||
|
||||
import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable complexity -- Necessary for validatePaymentChannelCreate */
|
||||
import { ValidationError } from '../../errors'
|
||||
|
||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||
|
||||
@@ -36,7 +36,6 @@ const HEX_WALLET_LOCATOR_REGEX = /^[0-9A-Fa-f]{64}$/u
|
||||
* @param tx - An SignerListSet Transaction.
|
||||
* @throws When the SignerListSet is Malformed.
|
||||
*/
|
||||
// eslint-disable-next-line complexity -- validation can be complex
|
||||
export function validateSignerListSet(tx: Record<string, unknown>): void {
|
||||
validateBaseTransaction(tx)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* 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 */
|
||||
|
||||
import { ValidationError } from '../../errors'
|
||||
|
||||
@@ -25,6 +25,13 @@ describe('EscrowCancel', function () {
|
||||
assert.doesNotThrow(() => validate(cancel))
|
||||
})
|
||||
|
||||
it(`Valid EscrowCancel with string OfferSequence`, function () {
|
||||
cancel.OfferSequence = '7'
|
||||
|
||||
assert.doesNotThrow(() => validateEscrowCancel(cancel))
|
||||
assert.doesNotThrow(() => validate(cancel))
|
||||
})
|
||||
|
||||
it(`Invalid EscrowCancel missing owner`, function () {
|
||||
delete cancel.Owner
|
||||
|
||||
@@ -55,7 +62,7 @@ describe('EscrowCancel', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it(`Invalid OfferSequence`, function () {
|
||||
it(`Invalid Owner`, function () {
|
||||
cancel.Owner = 10
|
||||
|
||||
assert.throws(
|
||||
@@ -70,8 +77,8 @@ describe('EscrowCancel', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it(`Invalid owner`, function () {
|
||||
cancel.OfferSequence = '10'
|
||||
it(`Invalid OfferSequence`, function () {
|
||||
cancel.OfferSequence = 'random'
|
||||
|
||||
assert.throws(
|
||||
() => validateEscrowCancel(cancel),
|
||||
|
||||
@@ -35,6 +35,13 @@ describe('EscrowFinish', function () {
|
||||
assert.doesNotThrow(() => validate(escrow))
|
||||
})
|
||||
|
||||
it(`verifies valid EscrowFinish w/string OfferSequence`, function () {
|
||||
escrow.OfferSequence = '7'
|
||||
|
||||
assert.doesNotThrow(() => validateEscrowFinish(escrow))
|
||||
assert.doesNotThrow(() => validate(escrow))
|
||||
})
|
||||
|
||||
it(`throws w/ invalid Owner`, function () {
|
||||
escrow.Owner = 0x15415253
|
||||
|
||||
@@ -51,7 +58,7 @@ describe('EscrowFinish', function () {
|
||||
})
|
||||
|
||||
it(`throws w/ invalid OfferSequence`, function () {
|
||||
escrow.OfferSequence = '10'
|
||||
escrow.OfferSequence = 'random'
|
||||
|
||||
assert.throws(
|
||||
() => validateEscrowFinish(escrow),
|
||||
|
||||
Reference in New Issue
Block a user