Add validation amount on Remit (#27)

This commit is contained in:
tequ
2025-07-08 01:31:42 +09:00
committed by GitHub
parent 72ed28b1fe
commit 7a79042735
2 changed files with 13 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ import { ValidationError } from '../../errors'
import { AmountEntry, MintURIToken } from '../common/xahau'
import { isHex } from '../utils'
import { BaseTransaction, validateBaseTransaction } from './common'
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
const MAX_URI_LENGTH = 512
const DIGEST_LENGTH = 64
@@ -118,6 +118,10 @@ function checkAmounts(tx: Record<string, unknown>): void {
throw new ValidationError('Remit: invalid Amounts.AmountEntry')
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ignore
if (!isAmount(amount.AmountEntry.Amount)) {
throw new ValidationError('Remit: invalid Amounts.AmountEntry.Amount')
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- ignore
if (typeof amount.AmountEntry.Amount === 'string') {
// eslint-disable-next-line max-depth -- ignore
if (seenXrp) {

View File

@@ -157,6 +157,14 @@ describe('Remit', function () {
'Remit: Duplicate amounts are not allowed',
)
})
it(`throws w/ Bad Amount`, function () {
remit.Amounts = [{ AmountEntry: { Amount: 1234 } }]
assert.throws(
() => validateRemit(remit),
ValidationError,
'Remit: invalid Amounts.AmountEntry.Amount',
)
})
it(`throws w/ Bad URITokenIDs`, function () {
remit.URITokenIDs = {}
assert.throws(