mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -18,222 +18,229 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/app/misc/TxQ.h>
|
||||
#include <ripple/beast/utility/temp_dir.h>
|
||||
#include <ripple/protocol/Feature.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <ripple/beast/utility/temp_dir.h>
|
||||
#include <ripple/resource/ResourceManager.h>
|
||||
#include <ripple/resource/impl/Entry.h>
|
||||
#include <ripple/resource/impl/Tuning.h>
|
||||
#include <ripple/rpc/impl/Tuning.h>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class NoRippleCheck_test : public beast::unit_test::suite
|
||||
{
|
||||
void
|
||||
testBadInput ()
|
||||
testBadInput()
|
||||
{
|
||||
testcase ("Bad input to noripple_check");
|
||||
testcase("Bad input to noripple_check");
|
||||
|
||||
using namespace test::jtx;
|
||||
Env env {*this};
|
||||
Env env{*this};
|
||||
|
||||
auto const alice = Account {"alice"};
|
||||
env.fund (XRP(10000), alice);
|
||||
env.close ();
|
||||
auto const alice = Account{"alice"};
|
||||
env.fund(XRP(10000), alice);
|
||||
env.close();
|
||||
|
||||
{ // missing account field
|
||||
auto const result = env.rpc ("json", "noripple_check", "{}")
|
||||
[jss::result];
|
||||
BEAST_EXPECT (result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT (result[jss::error_message] ==
|
||||
"Missing field 'account'.");
|
||||
{ // missing account field
|
||||
auto const result =
|
||||
env.rpc("json", "noripple_check", "{}")[jss::result];
|
||||
BEAST_EXPECT(result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
result[jss::error_message] == "Missing field 'account'.");
|
||||
}
|
||||
|
||||
{ // missing role field
|
||||
{ // missing role field
|
||||
Json::Value params;
|
||||
params[jss::account] = alice.human();
|
||||
auto const result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT (result[jss::error_message] ==
|
||||
"Missing field 'role'.");
|
||||
auto const result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(result[jss::error_message] == "Missing field 'role'.");
|
||||
}
|
||||
|
||||
{ // invalid role field
|
||||
{ // invalid role field
|
||||
Json::Value params;
|
||||
params[jss::account] = alice.human();
|
||||
params[jss::role] = "not_a_role";
|
||||
auto const result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT (result[jss::error_message] ==
|
||||
"Invalid field 'role'.");
|
||||
auto const result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(result[jss::error_message] == "Invalid field 'role'.");
|
||||
}
|
||||
|
||||
{ // invalid limit
|
||||
{ // invalid limit
|
||||
Json::Value params;
|
||||
params[jss::account] = alice.human();
|
||||
params[jss::role] = "user";
|
||||
params[jss::limit] = -1;
|
||||
auto const result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT (result[jss::error_message] ==
|
||||
auto const result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(
|
||||
result[jss::error_message] ==
|
||||
"Invalid field 'limit', not unsigned integer.");
|
||||
}
|
||||
|
||||
{ // invalid ledger (hash)
|
||||
{ // invalid ledger (hash)
|
||||
Json::Value params;
|
||||
params[jss::account] = alice.human();
|
||||
params[jss::role] = "user";
|
||||
params[jss::ledger_hash] = 1;
|
||||
auto const result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT (result[jss::error_message] ==
|
||||
"ledgerHashNotString");
|
||||
auto const result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result[jss::error] == "invalidParams");
|
||||
BEAST_EXPECT(result[jss::error_message] == "ledgerHashNotString");
|
||||
}
|
||||
|
||||
{ // account not found
|
||||
{ // account not found
|
||||
Json::Value params;
|
||||
params[jss::account] = Account{"nobody"}.human();
|
||||
params[jss::role] = "user";
|
||||
params[jss::ledger] = "current";
|
||||
auto const result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result[jss::error] == "actNotFound");
|
||||
BEAST_EXPECT (result[jss::error_message] ==
|
||||
"Account not found.");
|
||||
auto const result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result[jss::error] == "actNotFound");
|
||||
BEAST_EXPECT(result[jss::error_message] == "Account not found.");
|
||||
}
|
||||
|
||||
{ // passing an account private key will cause
|
||||
// parsing as a seed to fail
|
||||
{ // passing an account private key will cause
|
||||
// parsing as a seed to fail
|
||||
Json::Value params;
|
||||
params[jss::account] =
|
||||
toBase58 (TokenType::NodePrivate, alice.sk());
|
||||
params[jss::account] = toBase58(TokenType::NodePrivate, alice.sk());
|
||||
params[jss::role] = "user";
|
||||
params[jss::ledger] = "current";
|
||||
auto const result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result[jss::error] == "badSeed");
|
||||
BEAST_EXPECT (result[jss::error_message] ==
|
||||
"Disallowed seed.");
|
||||
auto const result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result[jss::error] == "badSeed");
|
||||
BEAST_EXPECT(result[jss::error_message] == "Disallowed seed.");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testBasic (bool user, bool problems)
|
||||
testBasic(bool user, bool problems)
|
||||
{
|
||||
testcase << "Request noripple_check for " <<
|
||||
(user ? "user" : "gateway") << " role, expect" <<
|
||||
(problems ? "" : " no") << " problems";
|
||||
testcase << "Request noripple_check for " << (user ? "user" : "gateway")
|
||||
<< " role, expect" << (problems ? "" : " no") << " problems";
|
||||
|
||||
using namespace test::jtx;
|
||||
Env env {*this};
|
||||
Env env{*this};
|
||||
|
||||
auto const gw = Account {"gw"};
|
||||
auto const alice = Account {"alice"};
|
||||
auto const gw = Account{"gw"};
|
||||
auto const alice = Account{"alice"};
|
||||
|
||||
env.fund (XRP(10000), gw, alice);
|
||||
env.fund(XRP(10000), gw, alice);
|
||||
if ((user && problems) || (!user && !problems))
|
||||
{
|
||||
env (fset (alice, asfDefaultRipple));
|
||||
env (trust (alice, gw["USD"](100)));
|
||||
env(fset(alice, asfDefaultRipple));
|
||||
env(trust(alice, gw["USD"](100)));
|
||||
}
|
||||
else
|
||||
{
|
||||
env (fclear (alice, asfDefaultRipple));
|
||||
env (trust (alice, gw["USD"](100), gw, tfSetNoRipple));
|
||||
env(fclear(alice, asfDefaultRipple));
|
||||
env(trust(alice, gw["USD"](100), gw, tfSetNoRipple));
|
||||
}
|
||||
env.close ();
|
||||
env.close();
|
||||
|
||||
Json::Value params;
|
||||
params[jss::account] = alice.human();
|
||||
params[jss::role] = (user ? "user" : "gateway");
|
||||
params[jss::ledger] = "current";
|
||||
auto result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
auto result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
|
||||
auto const pa = result["problems"];
|
||||
if (! BEAST_EXPECT (pa.isArray ()))
|
||||
if (!BEAST_EXPECT(pa.isArray()))
|
||||
return;
|
||||
|
||||
if (problems)
|
||||
{
|
||||
if (! BEAST_EXPECT (pa.size() == 2))
|
||||
if (!BEAST_EXPECT(pa.size() == 2))
|
||||
return;
|
||||
|
||||
if (user)
|
||||
{
|
||||
BEAST_EXPECT (
|
||||
boost::starts_with(pa[0u].asString(),
|
||||
"You appear to have set"));
|
||||
BEAST_EXPECT (
|
||||
boost::starts_with(pa[1u].asString(),
|
||||
"You should probably set"));
|
||||
BEAST_EXPECT(boost::starts_with(
|
||||
pa[0u].asString(), "You appear to have set"));
|
||||
BEAST_EXPECT(boost::starts_with(
|
||||
pa[1u].asString(), "You should probably set"));
|
||||
}
|
||||
else
|
||||
{
|
||||
BEAST_EXPECT (
|
||||
boost::starts_with(pa[0u].asString(),
|
||||
"You should immediately set"));
|
||||
BEAST_EXPECT(boost::starts_with(
|
||||
pa[0u].asString(), "You should immediately set"));
|
||||
BEAST_EXPECT(
|
||||
boost::starts_with(pa[1u].asString(),
|
||||
"You should clear"));
|
||||
boost::starts_with(pa[1u].asString(), "You should clear"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BEAST_EXPECT (pa.size() == 0);
|
||||
BEAST_EXPECT(pa.size() == 0);
|
||||
}
|
||||
|
||||
// now make a second request asking for the relevant transactions this
|
||||
// time.
|
||||
params[jss::transactions] = true;
|
||||
result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
if (! BEAST_EXPECT (result[jss::transactions].isArray ()))
|
||||
result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
if (!BEAST_EXPECT(result[jss::transactions].isArray()))
|
||||
return;
|
||||
|
||||
auto const txs = result[jss::transactions];
|
||||
if (problems)
|
||||
{
|
||||
if (! BEAST_EXPECT (txs.size () == (user ? 1 : 2)))
|
||||
if (!BEAST_EXPECT(txs.size() == (user ? 1 : 2)))
|
||||
return;
|
||||
|
||||
if (! user)
|
||||
if (!user)
|
||||
{
|
||||
BEAST_EXPECT (txs[0u][jss::Account] == alice.human());
|
||||
BEAST_EXPECT (txs[0u][jss::TransactionType] == jss::AccountSet);
|
||||
BEAST_EXPECT(txs[0u][jss::Account] == alice.human());
|
||||
BEAST_EXPECT(txs[0u][jss::TransactionType] == jss::AccountSet);
|
||||
}
|
||||
|
||||
BEAST_EXPECT (
|
||||
result[jss::transactions][txs.size()-1][jss::Account] ==
|
||||
BEAST_EXPECT(
|
||||
result[jss::transactions][txs.size() - 1][jss::Account] ==
|
||||
alice.human());
|
||||
BEAST_EXPECT (
|
||||
result[jss::transactions][txs.size()-1][jss::TransactionType] ==
|
||||
jss::TrustSet);
|
||||
BEAST_EXPECT (
|
||||
result[jss::transactions][txs.size()-1][jss::LimitAmount] ==
|
||||
gw["USD"](100).value ().getJson (JsonOptions::none));
|
||||
BEAST_EXPECT(
|
||||
result[jss::transactions][txs.size() - 1]
|
||||
[jss::TransactionType] == jss::TrustSet);
|
||||
BEAST_EXPECT(
|
||||
result[jss::transactions][txs.size() - 1][jss::LimitAmount] ==
|
||||
gw["USD"](100).value().getJson(JsonOptions::none));
|
||||
}
|
||||
else
|
||||
{
|
||||
BEAST_EXPECT (txs.size () == 0);
|
||||
BEAST_EXPECT(txs.size() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testBadInput ();
|
||||
testBadInput();
|
||||
for (auto user : {true, false})
|
||||
for (auto problem : {true, false})
|
||||
testBasic (user, problem);
|
||||
testBasic(user, problem);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -242,20 +249,19 @@ class NoRippleCheckLimits_test : public beast::unit_test::suite
|
||||
void
|
||||
testLimits(bool admin)
|
||||
{
|
||||
testcase << "Check limits in returned data, " <<
|
||||
(admin ? "admin" : "non-admin");
|
||||
testcase << "Check limits in returned data, "
|
||||
<< (admin ? "admin" : "non-admin");
|
||||
|
||||
using namespace test::jtx;
|
||||
|
||||
Env env {*this, admin ? envconfig () : envconfig(no_admin)};
|
||||
Env env{*this, admin ? envconfig() : envconfig(no_admin)};
|
||||
|
||||
auto const alice = Account {"alice"};
|
||||
env.fund (XRP (100000), alice);
|
||||
env (fset (alice, asfDefaultRipple));
|
||||
env.close ();
|
||||
auto const alice = Account{"alice"};
|
||||
env.fund(XRP(100000), alice);
|
||||
env(fset(alice, asfDefaultRipple));
|
||||
env.close();
|
||||
|
||||
auto checkBalance = [&env]()
|
||||
{
|
||||
auto checkBalance = [&env]() {
|
||||
// this is endpoint drop prevention. Non admin ports will drop
|
||||
// requests if they are coming too fast, so we manipulate the
|
||||
// resource manager here to reset the enpoint balance (for
|
||||
@@ -266,45 +272,49 @@ class NoRippleCheckLimits_test : public beast::unit_test::suite
|
||||
using namespace ripple::Resource;
|
||||
using namespace std::chrono;
|
||||
using namespace beast::IP;
|
||||
auto c = env.app ().getResourceManager ()
|
||||
.newInboundEndpoint (
|
||||
Endpoint::from_string (test::getEnvLocalhostAddr()));
|
||||
auto c = env.app().getResourceManager().newInboundEndpoint(
|
||||
Endpoint::from_string(test::getEnvLocalhostAddr()));
|
||||
|
||||
// if we go above the warning threshold, reset
|
||||
if (c.balance() > warningThreshold)
|
||||
{
|
||||
using ct = beast::abstract_clock <steady_clock>;
|
||||
using ct = beast::abstract_clock<steady_clock>;
|
||||
c.entry().local_balance =
|
||||
DecayingSample <decayWindowSeconds, ct>
|
||||
{steady_clock::now()};
|
||||
DecayingSample<decayWindowSeconds, ct>{steady_clock::now()};
|
||||
}
|
||||
};
|
||||
|
||||
for (auto i = 0; i < ripple::RPC::Tuning::noRippleCheck.rmax + 5; ++i)
|
||||
{
|
||||
if (! admin)
|
||||
if (!admin)
|
||||
checkBalance();
|
||||
|
||||
auto& txq = env.app().getTxQ();
|
||||
auto const gw = Account {"gw" + std::to_string(i)};
|
||||
auto const gw = Account{"gw" + std::to_string(i)};
|
||||
env.memoize(gw);
|
||||
auto const baseFee = env.current()->fees().base;
|
||||
env (pay (env.master, gw, XRP(1000)),
|
||||
seq (autofill),
|
||||
fee (toDrops(
|
||||
txq.getMetrics(*env.current()).openLedgerFeeLevel,
|
||||
baseFee).second + 1),
|
||||
sig (autofill));
|
||||
env (fset (gw, asfDefaultRipple),
|
||||
seq (autofill),
|
||||
fee (toDrops(
|
||||
txq.getMetrics(*env.current()).openLedgerFeeLevel,
|
||||
baseFee).second + 1),
|
||||
sig (autofill));
|
||||
env (trust (alice, gw["USD"](10)),
|
||||
fee (toDrops(
|
||||
txq.getMetrics(*env.current()).openLedgerFeeLevel,
|
||||
baseFee).second + 1));
|
||||
env(pay(env.master, gw, XRP(1000)),
|
||||
seq(autofill),
|
||||
fee(toDrops(
|
||||
txq.getMetrics(*env.current()).openLedgerFeeLevel,
|
||||
baseFee)
|
||||
.second +
|
||||
1),
|
||||
sig(autofill));
|
||||
env(fset(gw, asfDefaultRipple),
|
||||
seq(autofill),
|
||||
fee(toDrops(
|
||||
txq.getMetrics(*env.current()).openLedgerFeeLevel,
|
||||
baseFee)
|
||||
.second +
|
||||
1),
|
||||
sig(autofill));
|
||||
env(trust(alice, gw["USD"](10)),
|
||||
fee(toDrops(
|
||||
txq.getMetrics(*env.current()).openLedgerFeeLevel,
|
||||
baseFee)
|
||||
.second +
|
||||
1));
|
||||
env.close();
|
||||
}
|
||||
|
||||
@@ -313,51 +323,61 @@ class NoRippleCheckLimits_test : public beast::unit_test::suite
|
||||
params[jss::account] = alice.human();
|
||||
params[jss::role] = "user";
|
||||
params[jss::ledger] = "current";
|
||||
auto result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
auto result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
|
||||
BEAST_EXPECT (result["problems"].size() == 301);
|
||||
BEAST_EXPECT(result["problems"].size() == 301);
|
||||
|
||||
// one below minimum
|
||||
params[jss::limit] = 9;
|
||||
result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result["problems"].size() == (admin ? 10 : 11));
|
||||
result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result["problems"].size() == (admin ? 10 : 11));
|
||||
|
||||
// at minimum
|
||||
params[jss::limit] = 10;
|
||||
result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result["problems"].size() == 11);
|
||||
result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result["problems"].size() == 11);
|
||||
|
||||
// at max
|
||||
params[jss::limit] = 400;
|
||||
result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result["problems"].size() == 401);
|
||||
result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result["problems"].size() == 401);
|
||||
|
||||
// at max+1
|
||||
params[jss::limit] = 401;
|
||||
result = env.rpc ("json", "noripple_check",
|
||||
boost::lexical_cast<std::string>(params)) [jss::result];
|
||||
BEAST_EXPECT (result["problems"].size() == (admin ? 402 : 401));
|
||||
result = env.rpc(
|
||||
"json",
|
||||
"noripple_check",
|
||||
boost::lexical_cast<std::string>(params))[jss::result];
|
||||
BEAST_EXPECT(result["problems"].size() == (admin ? 402 : 401));
|
||||
}
|
||||
|
||||
public:
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
for (auto admin : {true, false})
|
||||
testLimits (admin);
|
||||
testLimits(admin);
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(NoRippleCheck, app, ripple);
|
||||
|
||||
// These tests that deal with limit amounts are slow because of the
|
||||
// offer/account setup, so making them manual -- the additional coverage provided
|
||||
// by them is minimal
|
||||
// offer/account setup, so making them manual -- the additional coverage
|
||||
// provided by them is minimal
|
||||
|
||||
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(NoRippleCheckLimits, app, ripple, 1);
|
||||
|
||||
} // ripple
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user