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