xrpld
Loading...
Searching...
No Matches
OversizeMeta_test.cpp
1
2#include <test/jtx/Env.h>
3#include <test/jtx/amount.h>
4#include <test/jtx/offer.h>
5#include <test/jtx/owners.h> // IWYU pragma: keep
6#include <test/jtx/pay.h>
7#include <test/jtx/ter.h>
8
9#include <xrpl/beast/unit_test/suite.h>
10#include <xrpl/protocol/TER.h>
11
12#include <cstddef>
13#include <tuple>
14
15namespace xrpl::test {
16
17// Make sure "plump" order books don't have problems
19{
20public:
21 static void
23 {
24 using namespace jtx;
25 for (std::size_t i = 1; i <= n; ++i)
26 {
27 env(offer("alice", XRP(i), iou(1)));
28 env.close();
29 }
30 }
31
32 void
34 {
35 using namespace jtx;
36 auto const billion = 1000000000ul;
37 Env env(*this);
38 env.disableSigs();
39 auto const gw = Account("gateway");
40 auto const usd = gw["USD"];
41 env.fund(XRP(billion), gw, "alice");
42 env.trust(usd(billion), "alice");
43 env(pay(gw, "alice", usd(billion)));
44 createOffers(env, usd, n);
45 }
46
47 void
48 run() override
49 {
50 test(10000);
51 }
52};
53
55
56//------------------------------------------------------------------------------
57
58// Ensure that unsigned transactions succeed during automatic test runs.
60{
61public:
62 void
63 run() override
64 {
65 test(1);
66 }
67};
68
70
71//------------------------------------------------------------------------------
72
74{
75public:
76 static void
78 {
79 using namespace jtx;
80 for (std::size_t i = 1; i <= n; ++i)
81 {
82 env(offer("alice", XRP(1), iou(1)));
83 env.close();
84 }
85 }
86
87 void
89 {
90 std::size_t const n = 9000;
91 using namespace jtx;
92 auto const billion = 1000000000ul;
93 Env env(*this);
94 env.disableSigs();
95 auto const gw = Account("gateway");
96 auto const usd = gw["USD"];
97 env.fund(XRP(billion), gw, "alice");
98 env.trust(usd(billion), "alice");
99 env(pay(gw, "alice", usd(billion)));
100 createOffers(env, usd, n);
101 env(pay("alice", gw, usd(billion)));
102 env(offer("alice", usd(1), XRP(1)));
103 }
104
105 void
106 run() override
107 {
108 test();
109 }
110};
111
113
114//------------------------------------------------------------------------------
115
117{
118public:
119 // Return lowest x in [lo, hi] for which f(x)==true
120 template <class Function>
121 static std::size_t
122 bfind(std::size_t lo, std::size_t hi, Function&& f)
123 {
124 auto len = hi - lo;
125 while (len != 0)
126 {
127 auto l2 = len / 2;
128 auto m = lo + l2;
129 if (!f(m))
130 {
131 lo = ++m;
132 len -= l2 + 1;
133 }
134 else
135 {
136 len = l2;
137 }
138 }
139 return lo;
140 }
141
142 static void
144 {
145 using namespace jtx;
146 for (std::size_t i = 1; i <= n; ++i)
147 {
148 env(offer("alice", XRP(i), iou(1)));
149 env.close();
150 }
151 }
152
153 bool
155 {
156 using namespace jtx;
157 auto const billion = 1000000000ul;
158 Env env(*this);
159 env.disableSigs();
160 auto const gw = Account("gateway");
161 auto const usd = gw["USD"];
162 env.fund(XRP(billion), gw, "alice");
163 env.trust(usd(billion), "alice");
164 env(pay(gw, "alice", usd(billion)));
165 createOffers(env, usd, n);
166 env(pay("alice", gw, usd(billion)));
167 env(offer("alice", usd(1), XRP(1)), Ter(std::ignore));
168 return env.ter() == tecOVERSIZE;
169 }
170
171 void
172 run() override
173 {
174 auto const result = bfind(100, 9000, [&](std::size_t n) { return oversize(n); });
175 log << "Min oversize offers = " << result << '\n';
176 }
177};
178
179BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(FindOversizeCross, app, xrpl, 50);
180
181} // namespace xrpl::test
A testsuite class.
Definition suite.h:50
LogOs< char > log
Logging output stream.
Definition suite.h:146
static void createOffers(jtx::Env &env, jtx::IOU const &iou, std::size_t n)
void run() override
Runs the suite.
static std::size_t bfind(std::size_t lo, std::size_t hi, Function &&f)
void run() override
Runs the suite.
static void createOffers(jtx::Env &env, jtx::IOU const &iou, std::size_t n)
static void createOffers(jtx::Env &env, jtx::IOU const &iou, std::size_t n)
void run() override
Runs the suite.
void run() override
Runs the suite.
A transaction testing environment.
Definition Env.h:143
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
TER ter() const
Return the TER for the last JTx.
Definition Env.h:675
void disableSigs()
Turn off signature checks.
Definition Env.h:487
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:296
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:327
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:13
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:14
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(CrossingLimits, app, xrpl, 10)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tecOVERSIZE
Definition TER.h:309