xrpld
Loading...
Searching...
No Matches
AMMTest.h
1#pragma once
2
3#include <test/jtx/Account.h>
4#include <test/jtx/amount.h>
5#include <test/jtx/ter.h>
6
7#include <xrpl/beast/unit_test/suite.h>
8#include <xrpl/protocol/Feature.h>
9
10namespace xrpl::test::jtx {
11
12class AMM;
13
14enum class Fund { All, Acct, Gw, TokenOnly };
15
17{
22 // For now, just disable SAV entirely, which locks in the small Number
23 // mantissas
24 jtx::testableAmendments() - featureSingleAssetVault - featureLendingProtocol};
25
26 bool noLog = false;
27};
28
29// A hint to testAMM() or fund() to create/fund MPT.
30// A distinct MPT is created if both AMM assets
31// are MPT. The actual MPT asset can be accessed
32// via AMM::operator[](0|1).
33inline static auto gAmmmpt = MPT("AMM");
34
35[[maybe_unused]] std::vector<STAmount>
36fund(
37 jtx::Env& env,
38 jtx::Account const& gw,
39 std::vector<jtx::Account> const& accounts,
40 std::vector<STAmount> const& amts,
41 Fund how);
42
43[[maybe_unused]] std::vector<STAmount>
44fund(
45 jtx::Env& env,
46 jtx::Account const& gw,
47 std::vector<jtx::Account> const& accounts,
48 STAmount const& xrp,
49 std::vector<STAmount> const& amts = {},
50 Fund how = Fund::All);
51
52[[maybe_unused]] std::vector<STAmount>
53fund(
54 jtx::Env& env,
55 std::vector<jtx::Account> const& accounts,
56 STAmount const& xrp,
57 std::vector<STAmount> const& amts = {},
58 Fund how = Fund::All,
59 std::optional<Account> const& mptIssuer = std::nullopt);
60
68
70{
71protected:
76 jtx::IOU const USD; // NOLINT(readability-identifier-naming)
77 jtx::IOU const EUR; // NOLINT(readability-identifier-naming)
78 jtx::IOU const GBP; // NOLINT(readability-identifier-naming)
79 jtx::IOU const BTC; // NOLINT(readability-identifier-naming)
80 jtx::IOU const BAD; // NOLINT(readability-identifier-naming)
81
82public:
84
85 static FeatureBitset
87 {
88 // For now, just disable SAV entirely, which locks in the small Number
89 // mantissas
90 return jtx::testableAmendments() - featureSingleAssetVault - featureLendingProtocol;
91 }
92
93protected:
97 void
98 testAMM(
99 std::function<void(jtx::AMM&, jtx::Env&)> const& cb,
100 std::optional<std::pair<STAmount, STAmount>> const& pool = std::nullopt,
101 std::uint16_t tfee = 0,
102 std::optional<jtx::Ter> const& ter = std::nullopt,
103 std::vector<FeatureBitset> const& features = {testableAmendments()});
104
105 void
106 testAMM(std::function<void(jtx::AMM&, jtx::Env&)> const& cb, TestAMMArg const& arg);
107};
108
110{
111protected:
112 static XRPAmount
113 reserve(jtx::Env& env, std::uint32_t count);
114
115 static XRPAmount
116 ammCrtFee(jtx::Env& env);
117
118 /* Path_test */
119 /************************************************/
120 class Gate
121 {
122 private:
125 bool signaled_ = false;
126
127 public:
128 // Thread safe, blocks until signaled or period expires.
129 // Returns `true` if signaled.
130 template <class Rep, class Period>
131 bool
133 {
135 auto b = cv_.wait_for(lk, relTime, [this] { return signaled_; });
136 signaled_ = false;
137 return b;
138 }
139
140 void
142 {
143 std::scoped_lock const lk(mutex_);
144 signaled_ = true;
145 cv_.notify_all();
146 }
147 };
148
150 pathTestEnv();
151};
152
153} // namespace xrpl::test::jtx
A testsuite class.
Definition suite.h:50
std::string const & arg() const
Return the argument associated with the runner.
Definition suite.h:278
jtx::Account const alice_
Definition AMMTest.h:74
void testAMM(std::function< void(jtx::AMM &, jtx::Env &)> const &cb, std::optional< std::pair< STAmount, STAmount > > const &pool=std::nullopt, std::uint16_t tfee=0, std::optional< jtx::Ter > const &ter=std::nullopt, std::vector< FeatureBitset > const &features={testableAmendments()})
testAMM() funds 30,000XRP and 30,000IOU for each non-XRP asset to Alice and Carol
Definition AMMTest.cpp:120
jtx::Account const gw_
Definition AMMTest.h:72
static FeatureBitset testableAmendments()
Definition AMMTest.h:86
jtx::Account const carol_
Definition AMMTest.h:73
jtx::Account const bob_
Definition AMMTest.h:75
bool waitFor(std::chrono::duration< Rep, Period > const &relTime)
Definition AMMTest.h:132
std::condition_variable cv_
Definition AMMTest.h:123
static XRPAmount reserve(jtx::Env &env, std::uint32_t count)
Definition AMMTest.cpp:198
static XRPAmount ammCrtFee(jtx::Env &env)
Definition AMMTest.cpp:204
Convenience class to test AMM functionality.
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
A transaction testing environment.
Definition Env.h:143
Converts to IOU Issue or STAmount.
Converts to MPT Issue or STAmount.
std::vector< STAmount > fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
Definition AMMTest.cpp:34
FeatureBitset testableAmendments()
Definition Env.h:76
static auto gAmmmpt
Definition AMMTest.h:33
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:48
std::optional< jtx::Ter > ter
Definition AMMTest.h:20
std::optional< std::pair< STAmount, STAmount > > pool
Definition AMMTest.h:18
std::vector< FeatureBitset > features
Definition AMMTest.h:21
std::optional< std::pair< STAmount, STAmount > > const & pool
Definition AMMTest.h:63
std::optional< jtx::Ter > const & ter
Definition AMMTest.h:65
std::vector< FeatureBitset > const & features
Definition AMMTest.h:66