1#include <test/jtx/AMM.h>
2#include <test/jtx/AMMTest.h>
3#include <test/jtx/Env.h>
4#include <test/jtx/TestHelpers.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/check.h>
7#include <test/jtx/offer.h>
8#include <test/jtx/owners.h>
9#include <test/jtx/pay.h>
10#include <test/jtx/sendmax.h>
11#include <test/jtx/ter.h>
12#include <test/jtx/token.h>
13#include <test/jtx/trust.h>
14#include <test/jtx/txflags.h>
16#include <xrpl/basics/base_uint.h>
17#include <xrpl/beast/unit_test/suite.h>
18#include <xrpl/protocol/Feature.h>
19#include <xrpl/protocol/Indexes.h>
20#include <xrpl/protocol/SeqProxy.h>
21#include <xrpl/protocol/TER.h>
22#include <xrpl/protocol/TxFlags.h>
34 Env env{*
this, features};
49 auto const lpIssue = ammAlice.
lptIssue();
70 if (features[fixFrozenLPTokenTransfer])
88 Env env{*
this, features};
92 ammAlice.deposit(
carol_, 1'000);
93 ammAlice.deposit(
bob_, 1'000);
95 auto const lpIssue = ammAlice.lptIssue();
114 if (features[fixFrozenLPTokenTransfer])
178 Env env{*
this, features};
182 ammAlice.deposit(
carol_, 1'000);
183 ammAlice.deposit(
bob_, 1'000);
185 auto const lpIssue = ammAlice.lptIssue();
193 if (features[fixFrozenLPTokenTransfer])
238 Env env{*
this, features};
243 ammAlice1.deposit(
carol_, 10'000'000);
247 ammAlice2.deposit(
carol_, 10'000'000);
248 auto const token1 = ammAlice1.lptIssue();
249 auto const token2 = ammAlice2.lptIssue();
267 if (features[fixFrozenLPTokenTransfer])
299 Env env{*
this, features};
303 ammAlice.deposit(
carol_, 1'000);
304 ammAlice.deposit(
bob_, 1'000);
306 auto const lpIssue = ammAlice.lptIssue();
319 if (features[fixFrozenLPTokenTransfer])
347 Env env{*
this, features};
352 ammAlice.deposit(
carol_, 1'000);
353 ammAlice.deposit(
bob_, 1'000);
355 auto const lpIssue = ammAlice.lptIssue();
374 if (features[fixFrozenLPTokenTransfer])
442 for (
auto const features : {all, all - fixFrozenLPTokenTransfer})
TestcaseT testcase
Memberspace for declaring test cases.
Floating point representation of amounts with high dynamic range.
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
void run() override
Runs the suite.
void testOfferCrossing(FeatureBitset features)
void testOfferCreation(FeatureBitset features)
void testDirectStep(FeatureBitset features)
void testBookStep(FeatureBitset features)
void testCheck(FeatureBitset features)
void testNFTOffers(FeatureBitset features)
jtx::Account const alice_
jtx::Account const carol_
Convenience class to test AMM functionality.
IOUAmount deposit(std::optional< Account > const &account, LPToken tokens, std::optional< STAmount > const &asset1InDetails=std::nullopt, std::optional< std::uint32_t > const &flags=std::nullopt, std::optional< Ter > const &ter=std::nullopt)
bool expectBalances(STAmount const &asset1, STAmount const &asset2, IOUAmount const &lpt, std::optional< AccountID > const &account=std::nullopt) const
Verify the AMM balances.
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Sets the SendMax on a JTx.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Sets the optional Owner on an NFTokenOffer.
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Keylet check(AccountID const &id, SeqProxy const &seq) noexcept
A Check.
json::Value create(A const &account, A const &dest, STAmount const &sendMax)
Create a check.
json::Value cash(jtx::Account const &dest, uint256 const &checkId, STAmount const &amount)
Cash a check requiring that a specific amount be delivered.
json::Value mint(jtx::Account const &account, std::uint32_t nfTokenTaxon)
Mint an NFToken.
json::Value createOffer(jtx::Account const &account, uint256 const &nftokenID, STAmount const &amount)
Create an NFTokenOffer.
json::Value acceptBuyOffer(jtx::Account const &account, uint256 const &offerIndex)
Accept an NFToken buy offer.
json::Value acceptSellOffer(jtx::Account const &account, uint256 const &offerIndex)
Accept an NFToken sell offer.
uint256 getNextID(jtx::Env const &env, jtx::Account const &issuer, std::uint32_t nfTokenTaxon, std::uint16_t flags, std::uint16_t xferFee)
Get the next NFTokenID that will be issued.
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
std::vector< STAmount > fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
bool expectOffers(Env &env, AccountID const &account, std::uint16_t size, std::vector< Amounts > const &toMatch)
bool expectHolding(Env &env, AccountID const &account, STAmount const &value, bool defaultLimits)
XrpT const XRP
Converts to XRP Issue or STAmount.
FeatureBitset testableAmendments()
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.