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