rippled
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 {
11namespace test {
12namespace jtx {
13
14class AMM;
15
16enum class Fund { All, Acct, Gw, IOUOnly };
17
19{
24 // For now, just disable SAV entirely, which locks in the small Number
25 // mantissas
26 jtx::testable_amendments() - featureSingleAssetVault - featureLendingProtocol};
27
28 bool noLog = false;
29};
30
31void
32fund(
33 jtx::Env& env,
34 jtx::Account const& gw,
35 std::vector<jtx::Account> const& accounts,
36 std::vector<STAmount> const& amts,
37 Fund how);
38
39void
40fund(
41 jtx::Env& env,
42 jtx::Account const& gw,
43 std::vector<jtx::Account> const& accounts,
44 STAmount const& xrp,
45 std::vector<STAmount> const& amts = {},
46 Fund how = Fund::All);
47
48void
49fund(
50 jtx::Env& env,
51 std::vector<jtx::Account> const& accounts,
52 STAmount const& xrp,
53 std::vector<STAmount> const& amts = {},
54 Fund how = Fund::All);
55
57{
58protected:
68
69public:
71
72 static FeatureBitset
74 {
75 // For now, just disable SAV entirely, which locks in the small Number
76 // mantissas
77 return jtx::testable_amendments() - featureSingleAssetVault - featureLendingProtocol;
78 }
79
80protected:
84 void
85 testAMM(
86 std::function<void(jtx::AMM&, jtx::Env&)>&& cb,
88 std::uint16_t tfee = 0,
91
92 void
93 testAMM(std::function<void(jtx::AMM&, jtx::Env&)>&& cb, TestAMMArg const& arg);
94};
95
97{
98protected:
100 reserve(jtx::Env& env, std::uint32_t count) const;
101
103 ammCrtFee(jtx::Env& env) const;
104
105 /* Path_test */
106 /************************************************/
107 class gate
108 {
109 private:
112 bool signaled_ = false;
113
114 public:
115 // Thread safe, blocks until signaled or period expires.
116 // Returns `true` if signaled.
117 template <class Rep, class Period>
118 bool
120 {
122 auto b = cv_.wait_for(lk, rel_time, [this] { return signaled_; });
123 signaled_ = false;
124 return b;
125 }
126
127 void
129 {
131 signaled_ = true;
132 cv_.notify_all();
133 }
134 };
135
137 pathTestEnv();
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
150 jtx::Env& env,
151 jtx::Account const& src,
152 jtx::Account const& dst,
153 STAmount const& saDstAmount,
154 std::optional<STAmount> const& saSendMax = std::nullopt,
155 std::optional<Currency> const& saSrcCurrency = std::nullopt);
156};
157
158} // namespace jtx
159} // namespace test
160} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
A testsuite class.
Definition suite.h:51
std::string const & arg() const
Return the argument associated with the runner.
Definition suite.h:276
jtx::Account const gw
Definition AMMTest.h:59
static FeatureBitset testable_amendments()
Definition AMMTest.h:73
jtx::Account const bob
Definition AMMTest.h:62
jtx::Account const alice
Definition AMMTest.h:61
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:60
bool wait_for(std::chrono::duration< Rep, Period > const &rel_time)
Definition AMMTest.h:119
std::condition_variable cv_
Definition AMMTest.h:110
XRPAmount ammCrtFee(jtx::Env &env) const
Definition AMMTest.cpp:151
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:171
XRPAmount reserve(jtx::Env &env, std::uint32_t count) const
Definition AMMTest.cpp:145
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:230
Convenience class to test AMM functionality.
Definition AMM.h:104
Immutable cryptographic account descriptor.
Definition Account.h:19
A transaction testing environment.
Definition Env.h:119
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:15
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:76
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::optional< std::pair< STAmount, STAmount > > pool
Definition AMMTest.h:20
std::vector< FeatureBitset > features
Definition AMMTest.h:23