add negative FeeVal check

This commit is contained in:
Omar Khan
2022-08-30 18:45:34 -04:00
parent 6150d33a61
commit 8ef2483e15
2 changed files with 13 additions and 4 deletions

View File

@@ -51,9 +51,9 @@ export function validateAMMVote(tx: Record<string, unknown>): 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}`,
)
}
}

View File

@@ -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',
)
})
})