From 8ef2483e151fb648445a8a7ccd6f1da693c42ff8 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 18:45:34 -0400 Subject: [PATCH] add negative FeeVal check --- packages/xrpl/src/models/transactions/AMMVote.ts | 4 ++-- packages/xrpl/test/models/AMMVote.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMVote.ts b/packages/xrpl/src/models/transactions/AMMVote.ts index 621ce232..270a4141 100644 --- a/packages/xrpl/src/models/transactions/AMMVote.ts +++ b/packages/xrpl/src/models/transactions/AMMVote.ts @@ -51,9 +51,9 @@ export function validateAMMVote(tx: Record): void { throw new ValidationError('AMMVote: FeeVal must be a number') } - if (tx.FeeVal > AMM_MAX_TRADING_FEE) { + if (tx.FeeVal < 0 || tx.FeeVal > AMM_MAX_TRADING_FEE) { throw new ValidationError( - `AMMVote: FeeVal must not be greater than ${AMM_MAX_TRADING_FEE}`, + `AMMVote: FeeVal must be between 0 and ${AMM_MAX_TRADING_FEE}`, ) } } diff --git a/packages/xrpl/test/models/AMMVote.ts b/packages/xrpl/test/models/AMMVote.ts index 9e7d6c09..b7ae2852 100644 --- a/packages/xrpl/test/models/AMMVote.ts +++ b/packages/xrpl/test/models/AMMVote.ts @@ -59,12 +59,21 @@ describe('AMMVote', function () { ) }) - it(`throws w/ FeeVal must not be greater than 65000`, function () { + it(`throws when FeeVal is greater than AMM_MAX_TRADING_FEE`, function () { vote.FeeVal = 65001 assert.throws( () => validate(vote), ValidationError, - 'AMMVote: FeeVal must not be greater than 65000', + 'AMMVote: FeeVal must be between 0 and 65000', + ) + }) + + it(`throws when FeeVal is a negative number`, function () { + vote.FeeVal = -1 + assert.throws( + () => validate(vote), + ValidationError, + 'AMMVote: FeeVal must be between 0 and 65000', ) }) })