20 #include <ripple/app/misc/TxQ.h>
21 #include <ripple/protocol/Feature.h>
22 #include <ripple/protocol/jss.h>
24 #include <test/jtx/envconfig.h>
25 #include <boost/algorithm/string/predicate.hpp>
26 #include <ripple/beast/utility/temp_dir.h>
27 #include <ripple/resource/ResourceManager.h>
28 #include <ripple/resource/impl/Entry.h>
29 #include <ripple/resource/impl/Tuning.h>
30 #include <ripple/rpc/impl/Tuning.h>
39 testcase (
"Bad input to noripple_check");
41 using namespace test::jtx;
44 auto const alice = Account {
"alice"};
45 env.fund (XRP(10000), alice);
49 auto const result = env.rpc (
"json",
"noripple_check",
"{}")
51 BEAST_EXPECT (result[jss::error] ==
"invalidParams");
52 BEAST_EXPECT (result[jss::error_message] ==
53 "Missing field 'account'.");
58 params[jss::account] = alice.human();
59 auto const result = env.rpc (
"json",
"noripple_check",
60 boost::lexical_cast<std::string>(params)) [jss::result];
61 BEAST_EXPECT (result[jss::error] ==
"invalidParams");
62 BEAST_EXPECT (result[jss::error_message] ==
63 "Missing field 'role'.");
68 params[jss::account] = alice.human();
69 params[jss::role] =
"not_a_role";
70 auto const result = env.rpc (
"json",
"noripple_check",
71 boost::lexical_cast<std::string>(params)) [jss::result];
72 BEAST_EXPECT (result[jss::error] ==
"invalidParams");
73 BEAST_EXPECT (result[jss::error_message] ==
74 "Invalid field 'role'.");
79 params[jss::account] = alice.human();
80 params[jss::role] =
"user";
81 params[jss::limit] = -1;
82 auto const result = env.rpc (
"json",
"noripple_check",
83 boost::lexical_cast<std::string>(params)) [jss::result];
84 BEAST_EXPECT (result[jss::error] ==
"invalidParams");
85 BEAST_EXPECT (result[jss::error_message] ==
86 "Invalid field 'limit', not unsigned integer.");
91 params[jss::account] = alice.human();
92 params[jss::role] =
"user";
93 params[jss::ledger_hash] = 1;
94 auto const result = env.rpc (
"json",
"noripple_check",
95 boost::lexical_cast<std::string>(params)) [jss::result];
96 BEAST_EXPECT (result[jss::error] ==
"invalidParams");
97 BEAST_EXPECT (result[jss::error_message] ==
98 "ledgerHashNotString");
103 params[jss::account] = Account{
"nobody"}.human();
104 params[jss::role] =
"user";
105 params[jss::ledger] =
"current";
106 auto const result = env.rpc (
"json",
"noripple_check",
107 boost::lexical_cast<std::string>(params)) [jss::result];
108 BEAST_EXPECT (result[jss::error] ==
"actNotFound");
109 BEAST_EXPECT (result[jss::error_message] ==
110 "Account not found.");
116 params[jss::account] =
118 params[jss::role] =
"user";
119 params[jss::ledger] =
"current";
120 auto const result = env.rpc (
"json",
"noripple_check",
121 boost::lexical_cast<std::string>(params)) [jss::result];
122 BEAST_EXPECT (result[jss::error] ==
"badSeed");
123 BEAST_EXPECT (result[jss::error_message] ==
131 testcase <<
"Request noripple_check for " <<
132 (user ?
"user" :
"gateway") <<
" role, expect" <<
133 (problems ?
"" :
" no") <<
" problems";
135 using namespace test::jtx;
138 auto const gw = Account {
"gw"};
139 auto const alice = Account {
"alice"};
141 env.fund (XRP(10000), gw, alice);
142 if ((user && problems) || (!user && !problems))
145 env (trust (alice, gw[
"USD"](100)));
155 params[jss::account] = alice.human();
156 params[jss::role] = (user ?
"user" :
"gateway");
157 params[jss::ledger] =
"current";
158 auto result = env.rpc (
"json",
"noripple_check",
159 boost::lexical_cast<std::string>(params)) [jss::result];
161 auto const pa = result[
"problems"];
162 if (! BEAST_EXPECT (pa.isArray ()))
167 if (! BEAST_EXPECT (pa.size() == 2))
173 boost::starts_with(pa[0u].asString(),
174 "You appear to have set"));
176 boost::starts_with(pa[1u].asString(),
177 "You should probably set"));
182 boost::starts_with(pa[0u].asString(),
183 "You should immediately set"));
185 boost::starts_with(pa[1u].asString(),
186 "You should clear"));
191 BEAST_EXPECT (pa.size() == 0);
196 params[jss::transactions] =
true;
197 result = env.rpc (
"json",
"noripple_check",
198 boost::lexical_cast<std::string>(params)) [jss::result];
199 if (! BEAST_EXPECT (result[jss::transactions].isArray ()))
202 auto const txs = result[jss::transactions];
205 if (! BEAST_EXPECT (txs.size () == (user ? 1 : 2)))
210 BEAST_EXPECT (txs[0u][jss::Account] == alice.human());
211 BEAST_EXPECT (txs[0u][jss::TransactionType] == jss::AccountSet);
215 result[jss::transactions][txs.size()-1][jss::Account] ==
218 result[jss::transactions][txs.size()-1][jss::TransactionType] ==
221 result[jss::transactions][txs.size()-1][jss::LimitAmount] ==
226 BEAST_EXPECT (txs.size () == 0);
234 for (
auto user : {
true,
false})
235 for (
auto problem : {
true,
false})
245 testcase <<
"Check limits in returned data, " <<
246 (admin ?
"admin" :
"non-admin");
248 using namespace test::jtx;
250 Env env {*
this, admin ? envconfig () : envconfig(no_admin)};
252 auto const alice = Account {
"alice"};
253 env.fund (XRP (100000), alice);
257 auto checkBalance = [&env]()
269 auto c = env.app ().getResourceManager ()
270 .newInboundEndpoint (
277 c.entry().local_balance =
279 {steady_clock::now()};
288 auto& txq = env.app().getTxQ();
291 auto const baseFee = env.current()->fees().base;
292 env (pay (env.master, gw, XRP(1000)),
295 txq.getMetrics(*env.current()).openLedgerFeeLevel,
296 baseFee).second + 1),
301 txq.getMetrics(*env.current()).openLedgerFeeLevel,
302 baseFee).second + 1),
304 env (trust (alice, gw[
"USD"](10)),
306 txq.getMetrics(*env.current()).openLedgerFeeLevel,
307 baseFee).second + 1));
313 params[jss::account] = alice.human();
314 params[jss::role] =
"user";
315 params[jss::ledger] =
"current";
316 auto result = env.rpc (
"json",
"noripple_check",
317 boost::lexical_cast<std::string>(params)) [jss::result];
319 BEAST_EXPECT (result[
"problems"].size() == 301);
322 params[jss::limit] = 9;
323 result = env.rpc (
"json",
"noripple_check",
324 boost::lexical_cast<std::string>(params)) [jss::result];
325 BEAST_EXPECT (result[
"problems"].size() == (admin ? 10 : 11));
328 params[jss::limit] = 10;
329 result = env.rpc (
"json",
"noripple_check",
330 boost::lexical_cast<std::string>(params)) [jss::result];
331 BEAST_EXPECT (result[
"problems"].size() == 11);
334 params[jss::limit] = 400;
335 result = env.rpc (
"json",
"noripple_check",
336 boost::lexical_cast<std::string>(params)) [jss::result];
337 BEAST_EXPECT (result[
"problems"].size() == 401);
340 params[jss::limit] = 401;
341 result = env.rpc (
"json",
"noripple_check",
342 boost::lexical_cast<std::string>(params)) [jss::result];
343 BEAST_EXPECT (result[
"problems"].size() == (admin ? 402 : 401));
349 for (
auto admin : {
true,
false})