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/TER.h>
21#include <xrpl/protocol/TxFlags.h>
33 Env env{*
this, features};
48 auto const lpIssue = ammAlice.
lptIssue();
69 if (features[fixFrozenLPTokenTransfer])
87 Env env{*
this, features};
91 ammAlice.deposit(
carol_, 1'000);
92 ammAlice.deposit(
bob_, 1'000);
94 auto const lpIssue = ammAlice.lptIssue();
113 if (features[fixFrozenLPTokenTransfer])
177 Env env{*
this, features};
181 ammAlice.deposit(
carol_, 1'000);
182 ammAlice.deposit(
bob_, 1'000);
184 auto const lpIssue = ammAlice.lptIssue();
192 if (features[fixFrozenLPTokenTransfer])
237 Env env{*
this, features};
242 ammAlice1.deposit(
carol_, 10'000'000);
246 ammAlice2.deposit(
carol_, 10'000'000);
247 auto const token1 = ammAlice1.lptIssue();
248 auto const token2 = ammAlice2.lptIssue();
266 if (features[fixFrozenLPTokenTransfer])
298 Env env{*
this, features};
302 ammAlice.deposit(
carol_, 1'000);
303 ammAlice.deposit(
bob_, 1'000);
305 auto const lpIssue = ammAlice.lptIssue();
318 if (features[fixFrozenLPTokenTransfer])
346 Env env{*
this, features};
351 ammAlice.deposit(
carol_, 1'000);
352 ammAlice.deposit(
bob_, 1'000);
354 auto const lpIssue = ammAlice.lptIssue();
372 if (features[fixFrozenLPTokenTransfer])
439 for (
auto const features : {all, all - fixFrozenLPTokenTransfer})
TestcaseT testcase
Memberspace for declaring test cases.
Floating point representation of amounts with high dynamic range.
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 check(AccountID const &id, std::uint32_t seq) noexcept
A Check.
Keylet nftokenOffer(AccountID const &owner, std::uint32_t seq)
An offer from an account to buy or sell an NFT.
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.