mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 23:55:49 +00:00
* 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>
169 lines
5.6 KiB
TypeScript
169 lines
5.6 KiB
TypeScript
import { assert } from 'chai'
|
|
|
|
import { validate, ValidationError } from '../../src'
|
|
import { validateAMMBid } from '../../src/models/transactions/AMMBid'
|
|
|
|
/**
|
|
* AMMBid Transaction Verification Testing.
|
|
*
|
|
* Providing runtime verification testing for each specific transaction type.
|
|
*/
|
|
describe('AMMBid', function () {
|
|
let bid
|
|
|
|
beforeEach(function () {
|
|
bid = {
|
|
TransactionType: 'AMMBid',
|
|
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
|
|
Asset: {
|
|
currency: 'XRP',
|
|
},
|
|
Asset2: {
|
|
currency: 'ETH',
|
|
issuer: 'rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
|
|
},
|
|
BidMin: '5',
|
|
BidMax: '10',
|
|
AuthAccounts: [
|
|
{
|
|
AuthAccount: {
|
|
Account: 'rNZdsTBP5tH1M6GHC6bTreHAp6ouP8iZSh',
|
|
},
|
|
},
|
|
{
|
|
AuthAccount: {
|
|
Account: 'rfpFv97Dwu89FTyUwPjtpZBbuZxTqqgTmH',
|
|
},
|
|
},
|
|
{
|
|
AuthAccount: {
|
|
Account: 'rzzYHPGb8Pa64oqxCzmuffm122bitq3Vb',
|
|
},
|
|
},
|
|
{
|
|
AuthAccount: {
|
|
Account: 'rhwxHxaHok86fe4LykBom1jSJ3RYQJs1h4',
|
|
},
|
|
},
|
|
],
|
|
Sequence: 1337,
|
|
} as any
|
|
})
|
|
|
|
it(`verifies valid AMMBid`, function () {
|
|
assert.doesNotThrow(() => validateAMMBid(bid))
|
|
assert.doesNotThrow(() => validate(bid))
|
|
})
|
|
|
|
it(`throws w/ missing field Asset`, function () {
|
|
delete bid.Asset
|
|
const errorMessage = 'AMMBid: missing field Asset'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ Asset must be a Currency`, function () {
|
|
bid.Asset = 1234
|
|
const errorMessage = 'AMMBid: Asset must be a Currency'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ missing field Asset2`, function () {
|
|
delete bid.Asset2
|
|
const errorMessage = 'AMMBid: missing field Asset2'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ Asset2 must be a Currency`, function () {
|
|
bid.Asset2 = 1234
|
|
const errorMessage = 'AMMBid: Asset2 must be a Currency'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ BidMin must be an Amount`, function () {
|
|
bid.BidMin = 5
|
|
const errorMessage = 'AMMBid: BidMin must be an Amount'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ BidMax must be an Amount`, function () {
|
|
bid.BidMax = 10
|
|
const errorMessage = 'AMMBid: BidMax must be an Amount'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ AuthAccounts length must not be greater than 4`, function () {
|
|
bid.AuthAccounts.push({
|
|
AuthAccount: {
|
|
Account: 'r3X6noRsvaLapAKCG78zAtWcbhB3sggS1s',
|
|
},
|
|
})
|
|
const errorMessage =
|
|
'AMMBid: AuthAccounts length must not be greater than 4'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ AuthAccounts must be an AuthAccount array`, function () {
|
|
bid.AuthAccounts = 1234
|
|
const errorMessage = 'AMMBid: AuthAccounts must be an AuthAccount array'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ invalid AuthAccounts when AuthAccount is null`, function () {
|
|
bid.AuthAccounts[0] = {
|
|
AuthAccount: null,
|
|
}
|
|
const errorMessage = 'AMMBid: invalid AuthAccounts'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ invalid AuthAccounts when AuthAccount is undefined`, function () {
|
|
bid.AuthAccounts[0] = {
|
|
AuthAccount: undefined,
|
|
}
|
|
const errorMessage = 'AMMBid: invalid AuthAccounts'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ invalid AuthAccounts when AuthAccount is not an object`, function () {
|
|
bid.AuthAccounts[0] = {
|
|
AuthAccount: 1234,
|
|
}
|
|
const errorMessage = 'AMMBid: invalid AuthAccounts'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ invalid AuthAccounts when AuthAccount.Account is not a string`, function () {
|
|
bid.AuthAccounts[0] = {
|
|
AuthAccount: {
|
|
Account: 1234,
|
|
},
|
|
}
|
|
const errorMessage = 'AMMBid: invalid AuthAccounts'
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
|
|
it(`throws w/ AuthAccounts must not include sender's address`, function () {
|
|
bid.AuthAccounts[0] = {
|
|
AuthAccount: {
|
|
Account: bid.Account,
|
|
},
|
|
}
|
|
const errorMessage =
|
|
"AMMBid: AuthAccounts must not include sender's address"
|
|
assert.throws(() => validateAMMBid(bid), ValidationError, errorMessage)
|
|
assert.throws(() => validate(bid), ValidationError, errorMessage)
|
|
})
|
|
})
|