Files
xahau.js/packages/xrpl/test/models/AMMCreate.test.ts
Omar Khan 5581474627 feat: add AMM support (#2071)
* update definitions.json

* add AMMInstanceCreate

* renamed LPTokens to LPToken in definitions.json

* update HISTORY.md

* add amm_info RPC command

* add AMMDeposit

* use null check for missing fields

* add AMMWithdraw

* add AMMVote

* fix lint error

* add max trading fee check to AMMVote

* refactor MAX_TRADING_FEE to be in one place

* add AMMBid

* add AuthAccount interface to AMMBid

* refactor tests

* add AMMID to AMMInfoResponse

* update amm_info docstrings

* fix EPrice type to be Amount

* update EPrice validation error message and add missing tests

* update definitions to fix AMM in LEDGER_ENTRY_TYPES

* add missing test case Asset1In and Asset2In valid

* add missing test case Asset1Out and Asset2Out valid

* add negative FeeVal check

* update HISTORY.md to specify XLS-30

* update wording on AMMDeposit & AMMWithdraw validation errors

* add negative TradingFee check

* fix ammInfo response

* add AMMID as optional param in ammInfo response

* fix EPrice validation checks in AMMDeposit & AMMWithdraw

* add VoteSlots as optional param in AMMInfoResponse

* update VoteEntry interface

* fix deposit and withdraw tests

* fix AMMBid ValidationError

* update definitions.json with different AuthAccounts number

* Change amm_info asset parameters to Currency type

* API name changes with updated definitions.json

* rename amm_info param asset1 -> asset

* fix typo

* change AMM_MAX_TRADING_FEE to 1%

* Use Asset/Asset2 instead of AMMID for Deposit/Withdraw/Bid/Vote

* add Deposit/Withdraw flags

* rename FeeVal -> TradingFee in VoteEntry

* rename MinBidPrice -> BidMin and MaxBidPrice -> BidMax

* update definitions to change Asset & Asset2 nth values to 3 & 4

* update definitions

* add Issue type and tests for Asset/Asset2

* remove AMMID from amm_info and use Issue type

* update amm_info fields

* fix lint errors

* update unit tests

* add AMM codec-fixtures

* update Issue type

* add one asset and withdraw all tests

* refactor amm_info response fields to match AMMDevnet

* update definitions.json with refactored error codes

* update ammInfo.ts response model

* remove invalid fields from ammInfo.ts response model

* update time_interval description

* rename test model names and fix lint errors

* add Owner Reserve Fee for AMMCreate transaction

* add missing asset_frozen field

* replace Issue with IssuedCurrency

* refactor: convert flags to number

* update asset pair to use Currency type

* refactor isIssue to isCurrency

* add AMM ledger entry object, lsfAMM flag, amm fields to LedgerEntryRequest

* update definitions.json

* WIP defintions

* update codec-fixtures

* fix definitions test

* update DiscountedFee definition

* update definitions

* update codec-fixtures

* update definitions

* update unit tests

* update amm_info response

* sort imports/exports

* update jsdoc

* update amm_info jsdoc

* update jsdoc

* convert caution to all caps

* add validation for AuthAccounts

* refactor and export interfaces

* use Currency type

* update definitions

* add AMMDelete

* rename Issue to Currency in error message

* mark asset frozen as optional fields

* refactor isAuthAccounts

* add AMMDelete jsdoc

* rename to validateAuthAccounts

* fix typo

* fix typo in unit test

---------

Co-authored-by: Caleb Kniffen <ckniffen@ripple.com>
2023-08-17 22:42:32 -04:00

122 lines
3.5 KiB
TypeScript

import { assert } from 'chai'
import { validate, ValidationError } from '../../src'
import { validateAMMCreate } from '../../src/models/transactions/AMMCreate'
/**
* AMMCreate Transaction Verification Testing.
*
* Providing runtime verification testing for each specific transaction type.
*/
describe('AMMCreate', function () {
let ammCreate
beforeEach(function () {
ammCreate = {
TransactionType: 'AMMCreate',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Amount: '1000',
Amount2: {
currency: 'USD',
issuer: 'rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9',
value: '1000',
},
TradingFee: 12,
Sequence: 1337,
} as any
})
it(`verifies valid AMMCreate`, function () {
assert.doesNotThrow(() => validateAMMCreate(ammCreate))
assert.doesNotThrow(() => validate(ammCreate))
})
it(`throws w/ missing Amount`, function () {
delete ammCreate.Amount
const errorMessage = 'AMMCreate: missing field Amount'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
it(`throws w/ Amount must be an Amount`, function () {
ammCreate.Amount = 1000
const errorMessage = 'AMMCreate: Amount must be an Amount'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
it(`throws w/ missing Amount2`, function () {
delete ammCreate.Amount2
const errorMessage = 'AMMCreate: missing field Amount2'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
it(`throws w/ Amount2 must be an Amount`, function () {
ammCreate.Amount2 = 1000
const errorMessage = 'AMMCreate: Amount2 must be an Amount'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
it(`throws w/ missing TradingFee`, function () {
delete ammCreate.TradingFee
const errorMessage = 'AMMCreate: missing field TradingFee'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
it(`throws w/ TradingFee must be a number`, function () {
ammCreate.TradingFee = '12'
const errorMessage = 'AMMCreate: TradingFee must be a number'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
it(`throws when TradingFee is greater than 1000`, function () {
ammCreate.TradingFee = 1001
const errorMessage = 'AMMCreate: TradingFee must be between 0 and 1000'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
it(`throws when TradingFee is a negative number`, function () {
ammCreate.TradingFee = -1
const errorMessage = 'AMMCreate: TradingFee must be between 0 and 1000'
assert.throws(
() => validateAMMCreate(ammCreate),
ValidationError,
errorMessage,
)
assert.throws(() => validate(ammCreate), ValidationError, errorMessage)
})
})