rippled
Loading...
Searching...
No Matches
AMMTest.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2023 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TEST_JTX_AMMTEST_H_INCLUDED
21#define RIPPLE_TEST_JTX_AMMTEST_H_INCLUDED
22
23#include <test/jtx/Account.h>
24#include <test/jtx/amount.h>
25#include <test/jtx/ter.h>
26
27#include <xrpl/beast/unit_test/suite.h>
28#include <xrpl/protocol/Feature.h>
29
30namespace ripple {
31namespace test {
32namespace jtx {
33
34class AMM;
35
36enum class Fund { All, Acct, Gw, IOUOnly };
37
46
47void
48fund(
49 jtx::Env& env,
50 jtx::Account const& gw,
51 std::vector<jtx::Account> const& accounts,
52 std::vector<STAmount> const& amts,
53 Fund how);
54
55void
56fund(
57 jtx::Env& env,
58 jtx::Account const& gw,
59 std::vector<jtx::Account> const& accounts,
60 STAmount const& xrp,
61 std::vector<STAmount> const& amts = {},
62 Fund how = Fund::All);
63
64void
65fund(
66 jtx::Env& env,
67 std::vector<jtx::Account> const& accounts,
68 STAmount const& xrp,
69 std::vector<STAmount> const& amts = {},
70 Fund how = Fund::All);
71
73{
74protected:
84
85public:
87
88protected:
92 void
93 testAMM(
94 std::function<void(jtx::AMM&, jtx::Env&)>&& cb,
96 std::uint16_t tfee = 0,
99
100 void
101 testAMM(
102 std::function<void(jtx::AMM&, jtx::Env&)>&& cb,
103 TestAMMArg const& arg);
104};
105
107{
108protected:
110 reserve(jtx::Env& env, std::uint32_t count) const;
111
113 ammCrtFee(jtx::Env& env) const;
114
115 /* Path_test */
116 /************************************************/
117 class gate
118 {
119 private:
122 bool signaled_ = false;
123
124 public:
125 // Thread safe, blocks until signaled or period expires.
126 // Returns `true` if signaled.
127 template <class Rep, class Period>
128 bool
130 {
132 auto b = cv_.wait_for(lk, rel_time, [this] { return signaled_; });
133 signaled_ = false;
134 return b;
135 }
136
137 void
139 {
141 signaled_ = true;
142 cv_.notify_all();
143 }
144 };
145
147 pathTestEnv();
148
151 jtx::Env& env,
152 jtx::Account const& src,
153 jtx::Account const& dst,
154 STAmount const& saDstAmount,
155 std::optional<STAmount> const& saSendMax = std::nullopt,
156 std::optional<Currency> const& saSrcCurrency = std::nullopt);
157
160 jtx::Env& env,
161 jtx::Account const& src,
162 jtx::Account const& dst,
163 STAmount const& saDstAmount,
164 std::optional<STAmount> const& saSendMax = std::nullopt,
165 std::optional<Currency> const& saSrcCurrency = std::nullopt);
166};
167
168} // namespace jtx
169} // namespace test
170} // namespace ripple
171
172#endif // RIPPLE_TEST_JTX_AMMTEST_H_INCLUDED
Represents a JSON value.
Definition json_value.h:149
A testsuite class.
Definition suite.h:55
std::string const & arg() const
Return the argument associated with the runner.
Definition suite.h:288
jtx::Account const alice
Definition AMMTest.h:77
jtx::Account const gw
Definition AMMTest.h:75
jtx::Account const bob
Definition AMMTest.h:78
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:103
jtx::Account const carol
Definition AMMTest.h:76
bool wait_for(std::chrono::duration< Rep, Period > const &rel_time)
Definition AMMTest.h:129
std::condition_variable cv_
Definition AMMTest.h:120
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:256
XRPAmount ammCrtFee(jtx::Env &env) const
Definition AMMTest.cpp:177
XRPAmount reserve(jtx::Env &env, std::uint32_t count) const
Definition AMMTest.cpp:171
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:197
Convenience class to test AMM functionality.
Definition AMM.h:124
Immutable cryptographic account descriptor.
Definition Account.h:39
A transaction testing environment.
Definition Env.h:121
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:35
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:37
FeatureBitset testable_amendments()
Definition Env.h:74
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::vector< FeatureBitset > features
Definition AMMTest.h:43
std::optional< std::pair< STAmount, STAmount > > pool
Definition AMMTest.h:40