add negative TradingFee check

This commit is contained in:
Omar Khan
2022-08-30 19:09:55 -04:00
parent 6a06412b2d
commit 85b8a3930b
2 changed files with 13 additions and 4 deletions

View File

@@ -68,9 +68,9 @@ export function validateAMMInstanceCreate(tx: Record<string, unknown>): void {
throw new ValidationError('AMMInstanceCreate: TradingFee must be a number')
}
if (tx.TradingFee > AMM_MAX_TRADING_FEE) {
if (tx.TradingFee < 0 || tx.TradingFee > AMM_MAX_TRADING_FEE) {
throw new ValidationError(
`AMMInstanceCreate: TradingFee must not be greater than ${AMM_MAX_TRADING_FEE}`,
`AMMInstanceCreate: TradingFee must be between 0 and ${AMM_MAX_TRADING_FEE}`,
)
}
}

View File

@@ -82,12 +82,21 @@ describe('AMMInstanceCreate', function () {
)
})
it(`throws w/ TradingFee must not be greater than 65000`, function () {
it(`throws when TradingFee is greater than 65000`, function () {
instanceCreate.TradingFee = 65001
assert.throws(
() => validate(instanceCreate),
ValidationError,
`AMMInstanceCreate: TradingFee must not be greater than 65000`,
`AMMInstanceCreate: TradingFee must be between 0 and 65000`,
)
})
it(`throws when TradingFee is a negative number`, function () {
instanceCreate.TradingFee = -1
assert.throws(
() => validate(instanceCreate),
ValidationError,
`AMMInstanceCreate: TradingFee must be between 0 and 65000`,
)
})
})