From 0de755bb0bf7df2bf4e54a9108fe634b84d51555 Mon Sep 17 00:00:00 2001 From: Omar Khan Date: Tue, 30 Aug 2022 16:49:48 -0400 Subject: [PATCH] update EPrice validation error message and add missing tests --- .../src/models/transactions/AMMDeposit.ts | 2 +- .../src/models/transactions/AMMWithdraw.ts | 2 +- packages/xrpl/test/models/AMMDeposit.ts | 38 +++++++++++++++++++ packages/xrpl/test/models/AMMWithdraw.ts | 38 +++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/src/models/transactions/AMMDeposit.ts b/packages/xrpl/src/models/transactions/AMMDeposit.ts index d74620ad..086381e0 100644 --- a/packages/xrpl/src/models/transactions/AMMDeposit.ts +++ b/packages/xrpl/src/models/transactions/AMMDeposit.ts @@ -94,6 +94,6 @@ export function validateAMMDeposit(tx: Record): 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') } } diff --git a/packages/xrpl/src/models/transactions/AMMWithdraw.ts b/packages/xrpl/src/models/transactions/AMMWithdraw.ts index 2556e0e3..1c777f78 100644 --- a/packages/xrpl/src/models/transactions/AMMWithdraw.ts +++ b/packages/xrpl/src/models/transactions/AMMWithdraw.ts @@ -96,6 +96,6 @@ export function validateAMMWithdraw(tx: Record): 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') } } diff --git a/packages/xrpl/test/models/AMMDeposit.ts b/packages/xrpl/test/models/AMMDeposit.ts index ea81e8cf..e926646a 100644 --- a/packages/xrpl/test/models/AMMDeposit.ts +++ b/packages/xrpl/test/models/AMMDeposit.ts @@ -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', + ) + }) }) diff --git a/packages/xrpl/test/models/AMMWithdraw.ts b/packages/xrpl/test/models/AMMWithdraw.ts index 1f5e6c20..5f8eca42 100644 --- a/packages/xrpl/test/models/AMMWithdraw.ts +++ b/packages/xrpl/test/models/AMMWithdraw.ts @@ -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', + ) + }) })