mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add helper to modify Env configs (RIPD-1247)
Add envconfig test helper for manipulating Env config via callables. Create new common modifiers for non-admin config, validator config and one for using different server port values.
This commit is contained in:
committed by
Scott Schurr
parent
09a1d1a593
commit
80d9b0464a
@@ -26,22 +26,6 @@ namespace test {
|
||||
class AccountOffers_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
static
|
||||
std::unique_ptr<Config>
|
||||
makeConfig(bool setup_admin)
|
||||
{
|
||||
auto p = std::make_unique<Config>();
|
||||
setupConfigForUnitTests(*p);
|
||||
// the default config has admin active
|
||||
// ...we remove them if setup_admin is false
|
||||
if (! setup_admin)
|
||||
{
|
||||
(*p)["port_rpc"].set("admin","");
|
||||
(*p)["port_ws"].set("admin","");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
// test helper
|
||||
static bool checkArraySize(Json::Value const& val, unsigned int size)
|
||||
{
|
||||
@@ -60,7 +44,7 @@ public:
|
||||
void testNonAdminMinLimit()
|
||||
{
|
||||
using namespace jtx;
|
||||
Env env(*this, makeConfig(false));
|
||||
Env env {*this, envconfig(no_admin)};
|
||||
Account const gw ("G1");
|
||||
auto const USD_gw = gw["USD"];
|
||||
Account const bob ("bob");
|
||||
@@ -97,10 +81,10 @@ public:
|
||||
BEAST_EXPECT(checkArraySize(jro_l, 10u));
|
||||
}
|
||||
|
||||
void testSequential(bool as_admin)
|
||||
void testSequential(bool asAdmin)
|
||||
{
|
||||
using namespace jtx;
|
||||
Env env(*this, makeConfig(as_admin));
|
||||
Env env {*this, asAdmin ? envconfig() : envconfig(no_admin)};
|
||||
Account const gw ("G1");
|
||||
auto const USD_gw = gw["USD"];
|
||||
Account const bob ("bob");
|
||||
@@ -153,9 +137,9 @@ public:
|
||||
// limit parameter is NOT subject to sane defaults, but with a
|
||||
// non-admin there are pre-configured limit ranges applied. That's
|
||||
// why we have different BEAST_EXPECT()s here for the two scenarios
|
||||
BEAST_EXPECT(checkArraySize(jro_l_1, as_admin ? 1u : 3u));
|
||||
BEAST_EXPECT(as_admin ? checkMarker(jrr_l_1) : (! jrr_l_1.isMember(jss::marker)));
|
||||
if (as_admin)
|
||||
BEAST_EXPECT(checkArraySize(jro_l_1, asAdmin ? 1u : 3u));
|
||||
BEAST_EXPECT(asAdmin ? checkMarker(jrr_l_1) : (! jrr_l_1.isMember(jss::marker)));
|
||||
if (asAdmin)
|
||||
{
|
||||
BEAST_EXPECT(jro[0u] == jro_l_1[0u]);
|
||||
|
||||
@@ -193,8 +177,8 @@ public:
|
||||
jvParams[jss::limit] = 0u;
|
||||
auto const jrr = env.rpc ("json", "account_offers", jvParams.toStyledString())[jss::result];
|
||||
auto const& jro = jrr[jss::offers];
|
||||
BEAST_EXPECT(checkArraySize(jro, as_admin ? 0u : 3u));
|
||||
BEAST_EXPECT(as_admin ? checkMarker(jrr) : (! jrr.isMember(jss::marker)));
|
||||
BEAST_EXPECT(checkArraySize(jro, asAdmin ? 0u : 3u));
|
||||
BEAST_EXPECT(asAdmin ? checkMarker(jrr) : (! jrr.isMember(jss::marker)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1410,16 +1410,7 @@ public:
|
||||
{
|
||||
testcase("BookOffer Limits");
|
||||
using namespace jtx;
|
||||
Env env(*this, [asAdmin]() {
|
||||
auto p = std::make_unique<Config>();
|
||||
setupConfigForUnitTests(*p);
|
||||
if(! asAdmin)
|
||||
{
|
||||
(*p)["port_rpc"].set("admin","");
|
||||
(*p)["port_ws"].set("admin","");
|
||||
}
|
||||
return p;
|
||||
}());
|
||||
Env env {*this, asAdmin ? envconfig() : envconfig(no_admin)};
|
||||
Account gw {"gw"};
|
||||
env.fund(XRP(200000), gw);
|
||||
env.close();
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <ripple/protocol/Feature.h>
|
||||
#include <ripple/rpc/impl/TransactionSign.h>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace ripple {
|
||||
@@ -1934,15 +1935,14 @@ public:
|
||||
|
||||
void testAutoFillEscalatedFees ()
|
||||
{
|
||||
test::jtx::Env env(*this, []()
|
||||
using namespace test::jtx;
|
||||
Env env {*this, envconfig([](std::unique_ptr<Config> cfg)
|
||||
{
|
||||
auto p = std::make_unique<Config>();
|
||||
test::setupConfigForUnitTests(*p);
|
||||
auto& section = p->section("transaction_queue");
|
||||
section.set("minimum_txn_in_ledger_standalone", "3");
|
||||
return p;
|
||||
}(),
|
||||
test::jtx::features(featureFeeEscalation));
|
||||
cfg->section("transaction_queue")
|
||||
.set("minimum_txn_in_ledger_standalone", "3");
|
||||
return cfg;
|
||||
}),
|
||||
test::jtx::features(featureFeeEscalation)};
|
||||
LoadFeeTrack const& feeTrack = env.app().getFeeTrack();
|
||||
|
||||
{
|
||||
|
||||
@@ -26,23 +26,6 @@ namespace ripple {
|
||||
class LedgerData_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
|
||||
static
|
||||
std::unique_ptr<Config>
|
||||
makeConfig(bool setup_admin)
|
||||
{
|
||||
auto p = std::make_unique<Config>();
|
||||
test::setupConfigForUnitTests(*p);
|
||||
// the default config has admin active
|
||||
// ...we remove them if setup_admin is false
|
||||
if (! setup_admin)
|
||||
{
|
||||
(*p)["port_rpc"].set("admin","");
|
||||
(*p)["port_ws"].set("admin","");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
// test helper
|
||||
static bool checkArraySize(Json::Value const& val, unsigned int size)
|
||||
{
|
||||
@@ -58,10 +41,10 @@ public:
|
||||
val[jss::marker].asString().size() > 0;
|
||||
}
|
||||
|
||||
void testCurrentLedgerToLimits(bool as_admin)
|
||||
void testCurrentLedgerToLimits(bool asAdmin)
|
||||
{
|
||||
using namespace test::jtx;
|
||||
Env env {*this, makeConfig(as_admin)};
|
||||
Env env {*this, asAdmin ? envconfig() : envconfig(no_admin)};
|
||||
Account const gw {"gateway"};
|
||||
auto const USD = gw["USD"];
|
||||
env.fund(XRP(100000), gw);
|
||||
@@ -97,14 +80,14 @@ public:
|
||||
boost::lexical_cast<std::string>(jvParams)) [jss::result];
|
||||
BEAST_EXPECT(
|
||||
checkArraySize( jrr[jss::state],
|
||||
(delta > 0 && !as_admin) ? max_limit : max_limit + delta ));
|
||||
(delta > 0 && !asAdmin) ? max_limit : max_limit + delta ));
|
||||
}
|
||||
}
|
||||
|
||||
void testCurrentLedgerBinary()
|
||||
{
|
||||
using namespace test::jtx;
|
||||
Env env { *this, makeConfig(false) };
|
||||
Env env { *this, envconfig(no_admin) };
|
||||
Account const gw { "gateway" };
|
||||
auto const USD = gw["USD"];
|
||||
env.fund(XRP(100000), gw);
|
||||
@@ -192,7 +175,7 @@ public:
|
||||
void testMarkerFollow()
|
||||
{
|
||||
using namespace test::jtx;
|
||||
Env env { *this, makeConfig(false) };
|
||||
Env env { *this, envconfig(no_admin) };
|
||||
Account const gw { "gateway" };
|
||||
auto const USD = gw["USD"];
|
||||
env.fund(XRP(100000), gw);
|
||||
|
||||
@@ -27,17 +27,6 @@ namespace ripple {
|
||||
|
||||
class LedgerRPC_test : public beast::unit_test::suite
|
||||
{
|
||||
static
|
||||
std::unique_ptr<Config>
|
||||
makeNonAdminConfig()
|
||||
{
|
||||
auto p = std::make_unique<Config>();
|
||||
test::setupConfigForUnitTests(*p);
|
||||
(*p)["port_rpc"].set("admin","");
|
||||
(*p)["port_ws"].set("admin","");
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
checkErrorValue(
|
||||
Json::Value const& jv,
|
||||
@@ -184,7 +173,7 @@ class LedgerRPC_test : public beast::unit_test::suite
|
||||
testcase("Ledger Request, Full Option Without Admin");
|
||||
using namespace test::jtx;
|
||||
|
||||
Env env { *this, makeNonAdminConfig() };
|
||||
Env env { *this, envconfig(no_admin) };
|
||||
|
||||
env.close();
|
||||
|
||||
|
||||
@@ -32,17 +32,6 @@ class LedgerRequestRPC_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
|
||||
static
|
||||
std::unique_ptr<Config>
|
||||
makeNonAdminConfig()
|
||||
{
|
||||
auto p = std::make_unique<Config>();
|
||||
test::setupConfigForUnitTests(*p);
|
||||
(*p)["port_rpc"].set("admin","");
|
||||
(*p)["port_ws"].set("admin","");
|
||||
return p;
|
||||
}
|
||||
|
||||
void testLedgerRequest()
|
||||
{
|
||||
using namespace test::jtx;
|
||||
@@ -288,7 +277,7 @@ public:
|
||||
void testNonAdmin()
|
||||
{
|
||||
using namespace test::jtx;
|
||||
Env env { *this, makeNonAdminConfig() };
|
||||
Env env { *this, envconfig(no_admin) };
|
||||
Account const gw { "gateway" };
|
||||
auto const USD = gw["USD"];
|
||||
env.fund(XRP(100000), gw);
|
||||
|
||||
@@ -32,14 +32,7 @@ public:
|
||||
{
|
||||
testcase << "Overload " << (useWS ? "WS" : "HTTP") << " RPC client";
|
||||
using namespace jtx;
|
||||
Env env(*this, []()
|
||||
{
|
||||
auto p = std::make_unique<Config>();
|
||||
setupConfigForUnitTests(*p);
|
||||
(*p)["port_rpc"].set("admin","");
|
||||
(*p)["port_ws"].set("admin","");
|
||||
return p;
|
||||
}());
|
||||
Env env {*this, envconfig(no_admin)};
|
||||
|
||||
Account const alice {"alice"};
|
||||
Account const bob {"bob"};
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ripple {
|
||||
|
||||
namespace test {
|
||||
|
||||
namespace validator {
|
||||
namespace validator_data {
|
||||
static auto const public_key =
|
||||
"nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
)rippleConfig");
|
||||
|
||||
p->loadFromString (boost::str (
|
||||
toLoad % validator::token % validator::public_key));
|
||||
toLoad % validator_data::token % validator_data::public_key));
|
||||
|
||||
setupConfigForUnitTests(*p);
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
BEAST_EXPECT(result[jss::status] == "success");
|
||||
BEAST_EXPECT(result[jss::result].isMember(jss::info));
|
||||
BEAST_EXPECT(result[jss::result][jss::info]
|
||||
[jss::pubkey_validator] == validator::public_key);
|
||||
[jss::pubkey_validator] == validator_data::public_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -312,29 +312,24 @@ public:
|
||||
BEAST_EXPECT(jv[jss::status] == "success");
|
||||
}
|
||||
|
||||
static
|
||||
std::unique_ptr<Config>
|
||||
makeValidatorConfig(std::string const& seed)
|
||||
{
|
||||
auto p = std::make_unique<Config>();
|
||||
setupConfigForUnitTests(*p);
|
||||
|
||||
// If the config has valid validation keys then we run as a validator.
|
||||
p->section(SECTION_VALIDATION_SEED).append(
|
||||
std::vector<std::string>{seed});
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void testValidations()
|
||||
{
|
||||
using namespace jtx;
|
||||
|
||||
// Public key must be derived from the private key
|
||||
std::string const seed = "snpTg5uPtiRG2hE8HHCAF4NzdorKT";
|
||||
Env env {*this, envconfig(validator, "")};
|
||||
auto& cfg = env.app().config();
|
||||
if(! BEAST_EXPECT(cfg.section(SECTION_VALIDATION_SEED).empty()))
|
||||
return;
|
||||
auto const parsedseed = parseBase58<Seed>(
|
||||
cfg.section(SECTION_VALIDATION_SEED).values()[0]);
|
||||
if(! BEAST_EXPECT(parsedseed))
|
||||
return;
|
||||
|
||||
std::string const valPublicKey =
|
||||
"n9KCD2WU48u1WG3neBH6vRSinAxoTwrjLbjUAn6Xq6mCe5YrJv2V";
|
||||
Env env(*this, makeValidatorConfig(seed));
|
||||
toBase58 (TokenType::TOKEN_NODE_PUBLIC,
|
||||
derivePublicKey (KeyType::secp256k1,
|
||||
generateSecretKey (KeyType::secp256k1, *parsedseed)));
|
||||
|
||||
auto wsc = makeWSClient(env.app().config());
|
||||
Json::Value stream;
|
||||
|
||||
@@ -361,7 +356,8 @@ public:
|
||||
[&](auto const& jv)
|
||||
{
|
||||
return jv[jss::type] == "validationReceived" &&
|
||||
jv[jss::validation_public_key] == valPublicKey &&
|
||||
jv[jss::validation_public_key].asString() ==
|
||||
valPublicKey &&
|
||||
jv[jss::ledger_hash] ==
|
||||
to_string(env.closed()->info().hash) &&
|
||||
jv[jss::ledger_index] ==
|
||||
|
||||
Reference in New Issue
Block a user