rippled
Loading...
Searching...
No Matches
OversizeMeta_test.cpp
1#include <test/jtx.h>
2
3#include <xrpl/beast/unit_test.h>
4
5namespace xrpl {
6namespace test {
7
8// Make sure "plump" order books don't have problems
10{
11public:
12 static 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, xrpl, 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, xrpl);
61
62//------------------------------------------------------------------------------
63
65{
66public:
67 static 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, xrpl, 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 {
127 len = l2;
128 }
129 }
130 return lo;
131 }
132
133 static void
135 {
136 using namespace jtx;
137 for (std::size_t i = 1; i <= n; ++i)
138 {
139 env(offer("alice", XRP(i), iou(1)));
140 env.close();
141 }
142 }
143
144 bool
146 {
147 using namespace jtx;
148 auto const billion = 1000000000ul;
149 Env env(*this);
150 env.disable_sigs();
151 auto const gw = Account("gateway");
152 auto const USD = gw["USD"];
153 env.fund(XRP(billion), gw, "alice");
154 env.trust(USD(billion), "alice");
155 env(pay(gw, "alice", USD(billion)));
156 createOffers(env, USD, n);
157 env(pay("alice", gw, USD(billion)));
158 env(offer("alice", USD(1), XRP(1)), ter(std::ignore));
159 return env.ter() == tecOVERSIZE;
160 }
161
162 void
163 run() override
164 {
165 auto const result = bfind(100, 9000, [&](std::size_t n) { return oversize(n); });
166 log << "Min oversize offers = " << result << '\n';
167 }
168};
169
170BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(FindOversizeCross, app, xrpl, 50);
171
172} // namespace test
173} // namespace xrpl
A testsuite class.
Definition suite.h:51
log_os< char > log
Logging output stream.
Definition suite.h:147
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.
Immutable cryptographic account descriptor.
Definition Account.h:19
A transaction testing environment.
Definition Env.h:122
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:100
TER ter() const
Return the TER for the last JTx.
Definition Env.h:658
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:270
void disable_sigs()
Turn off signature checks.
Definition Env.h:463
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
Definition Env.cpp:301
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
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:95
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
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tecOVERSIZE
Definition TER.h:292