rippled
Loading...
Searching...
No Matches
AMMTest.h
1#ifndef XRPL_TEST_JTX_AMMTEST_H_INCLUDED
2#define XRPL_TEST_JTX_AMMTEST_H_INCLUDED
3
4#include <test/jtx/Account.h>
5#include <test/jtx/amount.h>
6#include <test/jtx/ter.h>
7
8#include <xrpl/beast/unit_test/suite.h>
9#include <xrpl/protocol/Feature.h>
10
11namespace ripple {
12namespace test {
13namespace jtx {
14
15class AMM;
16
17enum class Fund { All, Acct, Gw, IOUOnly };
18
27
28void
29fund(
30 jtx::Env& env,
31 jtx::Account const& gw,
32 std::vector<jtx::Account> const& accounts,
33 std::vector<STAmount> const& amts,
34 Fund how);
35
36void
37fund(
38 jtx::Env& env,
39 jtx::Account const& gw,
40 std::vector<jtx::Account> const& accounts,
41 STAmount const& xrp,
42 std::vector<STAmount> const& amts = {},
43 Fund how = Fund::All);
44
45void
46fund(
47 jtx::Env& env,
48 std::vector<jtx::Account> const& accounts,
49 STAmount const& xrp,
50 std::vector<STAmount> const& amts = {},
51 Fund how = Fund::All);
52
54{
55protected:
65
66public:
68
69protected:
73 void
74 testAMM(
75 std::function<void(jtx::AMM&, jtx::Env&)>&& cb,
77 std::uint16_t tfee = 0,
80
81 void
82 testAMM(
83 std::function<void(jtx::AMM&, jtx::Env&)>&& cb,
84 TestAMMArg const& arg);
85};
86
88{
89protected:
91 reserve(jtx::Env& env, std::uint32_t count) const;
92
94 ammCrtFee(jtx::Env& env) const;
95
96 /* Path_test */
97 /************************************************/
98 class gate
99 {
100 private:
103 bool signaled_ = false;
104
105 public:
106 // Thread safe, blocks until signaled or period expires.
107 // Returns `true` if signaled.
108 template <class Rep, class Period>
109 bool
111 {
113 auto b = cv_.wait_for(lk, rel_time, [this] { return signaled_; });
114 signaled_ = false;
115 return b;
116 }
117
118 void
120 {
122 signaled_ = true;
123 cv_.notify_all();
124 }
125 };
126
128 pathTestEnv();
129
132 jtx::Env& env,
133 jtx::Account const& src,
134 jtx::Account const& dst,
135 STAmount const& saDstAmount,
136 std::optional<STAmount> const& saSendMax = std::nullopt,
137 std::optional<Currency> const& saSrcCurrency = std::nullopt);
138
141 jtx::Env& env,
142 jtx::Account const& src,
143 jtx::Account const& dst,
144 STAmount const& saDstAmount,
145 std::optional<STAmount> const& saSendMax = std::nullopt,
146 std::optional<Currency> const& saSrcCurrency = std::nullopt);
147};
148
149} // namespace jtx
150} // namespace test
151} // namespace ripple
152
153#endif // XRPL_TEST_JTX_AMMTEST_H_INCLUDED
Represents a JSON value.
Definition json_value.h:130
A testsuite class.
Definition suite.h:52
std::string const & arg() const
Return the argument associated with the runner.
Definition suite.h:285
jtx::Account const alice
Definition AMMTest.h:58
jtx::Account const gw
Definition AMMTest.h:56
jtx::Account const bob
Definition AMMTest.h:59
void testAMM(std::function< void(jtx::AMM &, jtx::Env &)> &&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={testable_amendments()})
testAMM() funds 30,000XRP and 30,000IOU for each non-XRP asset to Alice and Carol
Definition AMMTest.cpp:84
jtx::Account const carol
Definition AMMTest.h:57
bool wait_for(std::chrono::duration< Rep, Period > const &rel_time)
Definition AMMTest.h:110
std::condition_variable cv_
Definition AMMTest.h:101
std::tuple< STPathSet, STAmount, STAmount > find_paths(jtx::Env &env, jtx::Account const &src, jtx::Account const &dst, STAmount const &saDstAmount, std::optional< STAmount > const &saSendMax=std::nullopt, std::optional< Currency > const &saSrcCurrency=std::nullopt)
Definition AMMTest.cpp:237
XRPAmount ammCrtFee(jtx::Env &env) const
Definition AMMTest.cpp:158
XRPAmount reserve(jtx::Env &env, std::uint32_t count) const
Definition AMMTest.cpp:152
Json::Value find_paths_request(jtx::Env &env, jtx::Account const &src, jtx::Account const &dst, STAmount const &saDstAmount, std::optional< STAmount > const &saSendMax=std::nullopt, std::optional< Currency > const &saSrcCurrency=std::nullopt)
Definition AMMTest.cpp:178
Convenience class to test AMM functionality.
Definition AMM.h:105
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:102
Converts to IOU Issue or STAmount.
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:16
T is_same_v
void fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
Definition AMMTest.cpp:18
FeatureBitset testable_amendments()
Definition Env.h:55
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::vector< FeatureBitset > features
Definition AMMTest.h:24
std::optional< std::pair< STAmount, STAmount > > pool
Definition AMMTest.h:21