update validation error response

This commit is contained in:
Denis Angell
2023-02-15 13:23:56 -05:00
parent 81f09ba043
commit d890b81924
5 changed files with 13 additions and 13 deletions

View File

@@ -2,7 +2,7 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import { BaseTransaction, validateBaseTransaction } from './common'
import { BaseTransaction, isAmount, validateBaseTransaction } from './common'
/**
* Sequester amount until the escrow process either finishes or is canceled.
@@ -56,8 +56,8 @@ export function validateEscrowCreate(tx: Record<string, unknown>): void {
throw new ValidationError('EscrowCreate: missing field Amount')
}
if (typeof tx.Amount !== 'string') {
throw new ValidationError('EscrowCreate: Amount must be a string')
if (typeof tx.Amount !== 'string' && !isAmount(tx.Amount)) {
throw new ValidationError('EscrowCreate: Amount must be an Amount')
}
if (tx.Destination === undefined) {

View File

@@ -82,12 +82,12 @@ describe('EscrowCreate', function () {
assert.throws(
() => validateEscrowCreate(escrow),
ValidationError,
'EscrowCreate: Amount must be a string',
'EscrowCreate: Amount must be an Amount',
)
assert.throws(
() => validate(escrow),
ValidationError,
'EscrowCreate: Amount must be a string',
'EscrowCreate: Amount must be an Amount',
)
})

View File

@@ -77,12 +77,12 @@ describe('PaymentChannelClaim', function () {
assert.throws(
() => validatePaymentChannelClaim(channel),
ValidationError,
'PaymentChannelClaim: invalid Balance',
'PaymentChannelClaim: Balance must be an Amount',
)
assert.throws(
() => validate(channel),
ValidationError,
'PaymentChannelClaim: invalid Balance',
'PaymentChannelClaim: Balance must be an Amount',
)
})
@@ -92,12 +92,12 @@ describe('PaymentChannelClaim', function () {
assert.throws(
() => validatePaymentChannelClaim(channel),
ValidationError,
'PaymentChannelClaim: invalid Amount',
'PaymentChannelClaim: Amount must be an Amount',
)
assert.throws(
() => validate(channel),
ValidationError,
'PaymentChannelClaim: invalid Amount',
'PaymentChannelClaim: Amount must be an Amount',
)
})

View File

@@ -106,12 +106,12 @@ describe('PaymentChannelCreate', function () {
assert.throws(
() => validatePaymentChannelCreate(channel),
ValidationError,
'PaymentChannelCreate: invalid Amount',
'PaymentChannelCreate: Amount must be an Amount',
)
assert.throws(
() => validate(channel),
ValidationError,
'PaymentChannelCreate: invalid Amount',
'PaymentChannelCreate: Amount must be an Amount',
)
})

View File

@@ -70,12 +70,12 @@ describe('PaymentChannelFund', function () {
assert.throws(
() => validatePaymentChannelFund(channel),
ValidationError,
'PaymentChannelFund: invalid Amount',
'PaymentChannelFund: Amount must be an Amount',
)
assert.throws(
() => validate(channel),
ValidationError,
'PaymentChannelFund: invalid Amount',
'PaymentChannelFund: Amount must be an Amount',
)
})