update EPrice validation error message and add missing tests

This commit is contained in:
Omar Khan
2022-08-30 16:49:48 -04:00
parent ed7760c555
commit 0de755bb0b
4 changed files with 78 additions and 2 deletions

View File

@@ -94,6 +94,6 @@ export function validateAMMDeposit(tx: Record<string, unknown>): void {
}
if (tx.EPrice != null && typeof tx.EPrice !== 'string') {
throw new ValidationError('AMMDeposit: EPrice must be a string')
throw new ValidationError('AMMDeposit: EPrice must be an Amount')
}
}

View File

@@ -96,6 +96,6 @@ export function validateAMMWithdraw(tx: Record<string, unknown>): void {
}
if (tx.EPrice != null && typeof tx.EPrice !== 'string') {
throw new ValidationError('AMMWithdraw: EPrice must be a string')
throw new ValidationError('AMMWithdraw: EPrice must be an Amount')
}
}

View File

@@ -88,4 +88,42 @@ describe('AMMDeposit', function () {
'AMMDeposit: must set Asset1In with EPrice',
)
})
it(`throws w/ LPToken must be an IssuedCurrencyAmount`, function () {
deposit.LPToken = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: LPToken must be an IssuedCurrencyAmount',
)
})
it(`throws w/ Asset1In must be an Amount`, function () {
deposit.Asset1In = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: Asset1In must be an Amount',
)
})
it(`throws w/ Asset2In must be an Amount`, function () {
deposit.Asset1In = '1000'
deposit.Asset2In = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: Asset2In must be an Amount',
)
})
it(`throws w/ EPrice must be an Amount`, function () {
deposit.Asset1In = '1000'
deposit.EPrice = 1234
assert.throws(
() => validate(deposit),
ValidationError,
'AMMDeposit: EPrice must be an Amount',
)
})
})

View File

@@ -88,4 +88,42 @@ describe('AMMWithdraw', function () {
'AMMWithdraw: must set Asset1Out with EPrice',
)
})
it(`throws w/ LPToken must be an IssuedCurrencyAmount`, function () {
withdraw.LPToken = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: LPToken must be an IssuedCurrencyAmount',
)
})
it(`throws w/ Asset1Out must be an Amount`, function () {
withdraw.Asset1Out = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: Asset1Out must be an Amount',
)
})
it(`throws w/ Asset2Out must be an Amount`, function () {
withdraw.Asset1Out = '1000'
withdraw.Asset2Out = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: Asset2Out must be an Amount',
)
})
it(`throws w/ EPrice must be an Amount`, function () {
withdraw.Asset1Out = '1000'
withdraw.EPrice = 1234
assert.throws(
() => validate(withdraw),
ValidationError,
'AMMWithdraw: EPrice must be an Amount',
)
})
})