diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index f6284c697..e979d82a3 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -4461,6 +4461,8 @@ + + @@ -4491,6 +4493,10 @@ True True + + True + True + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 6a688f3b9..7a877baab 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -5199,6 +5199,9 @@ test\jtx + + test\jtx + test\jtx @@ -5226,6 +5229,9 @@ test\jtx\impl + + test\jtx\impl + test\jtx\impl diff --git a/src/test/app/LedgerLoad_test.cpp b/src/test/app/LedgerLoad_test.cpp index e74dbfaec..cd9a33ec5 100644 --- a/src/test/app/LedgerLoad_test.cpp +++ b/src/test/app/LedgerLoad_test.cpp @@ -40,8 +40,7 @@ class LedgerLoad_test : public beast::unit_test::suite auto ledgerConfig(std::string const& ledger, Config::StartUpType type) { assert(! dbPath_.empty()); - auto p = std::make_unique(); - test::setupConfigForUnitTests(*p); + auto p = test::jtx::envconfig(); p->START_LEDGER = ledger; p->START_UP = type; p->legacy("database_path", dbPath_.string()); diff --git a/src/test/app/Regression_test.cpp b/src/test/app/Regression_test.cpp index 9c80c1024..debf65c50 100644 --- a/src/test/app/Regression_test.cpp +++ b/src/test/app/Regression_test.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -164,14 +165,12 @@ struct Regression_test : public beast::unit_test::suite { testcase("Autofilled fee should use the escalated fee"); using namespace jtx; - Env env(*this, []() + Env env(*this, envconfig([](std::unique_ptr cfg) { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - auto& section = p->section("transaction_queue"); - section.set("minimum_txn_in_ledger_standalone", "3"); - return p; - }(), + cfg->section("transaction_queue") + .set("minimum_txn_in_ledger_standalone", "3"); + return cfg; + }), features(featureFeeEscalation)); Env_ss envs(env); diff --git a/src/test/app/SHAMapStore_test.cpp b/src/test/app/SHAMapStore_test.cpp index 0d6c3318e..aa1fb07f9 100644 --- a/src/test/app/SHAMapStore_test.cpp +++ b/src/test/app/SHAMapStore_test.cpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace ripple { namespace test { @@ -34,26 +35,24 @@ class SHAMapStore_test : public beast::unit_test::suite static auto const deleteInterval = 8; static - std::unique_ptr - makeConfig() + auto + onlineDelete(std::unique_ptr cfg) { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - p->LEDGER_HISTORY = deleteInterval; - auto& section = p->section(ConfigSection::nodeDatabase()); + cfg->LEDGER_HISTORY = deleteInterval; + auto& section = cfg->section(ConfigSection::nodeDatabase()); section.set("online_delete", to_string(deleteInterval)); //section.set("age_threshold", "60"); - return p; + return cfg; } static - std::unique_ptr - makeConfigAdvisory() + auto + advisoryDelete(std::unique_ptr cfg) { - auto p = makeConfig(); - auto& section = p->section(ConfigSection::nodeDatabase()); - section.set("advisory_delete", "1"); - return p; + cfg = onlineDelete(std::move(cfg)); + cfg->section(ConfigSection::nodeDatabase()) + .set("advisory_delete", "1"); + return cfg; } bool goodLedger(jtx::Env& env, Json::Value const& json, @@ -211,7 +210,7 @@ public: testcase("clearPrior"); using namespace jtx; - Env env(*this, makeConfig()); + Env env(*this, envconfig(onlineDelete)); auto& store = env.app().getSHAMapStore(); env.fund(XRP(10000), noripple("alice")); @@ -397,7 +396,7 @@ public: using namespace jtx; using namespace std::chrono_literals; - Env env(*this, makeConfig()); + Env env(*this, envconfig(onlineDelete)); auto& store = env.app().getSHAMapStore(); auto ledgerSeq = waitForReady(env); @@ -466,7 +465,7 @@ public: using namespace std::chrono_literals; // Same config with advisory_delete enabled - Env env(*this, makeConfigAdvisory()); + Env env(*this, envconfig(advisoryDelete)); auto& store = env.app().getSHAMapStore(); auto ledgerSeq = waitForReady(env); diff --git a/src/test/app/TxQ_test.cpp b/src/test/app/TxQ_test.cpp index 14e84fa38..0a8a8a168 100644 --- a/src/test/app/TxQ_test.cpp +++ b/src/test/app/TxQ_test.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -98,8 +99,7 @@ class TxQ_test : public beast::unit_test::suite std::unique_ptr makeConfig(std::map extra = {}) { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); + auto p = test::jtx::envconfig(); auto& section = p->section("transaction_queue"); section.set("ledgers_in_queue", "2"); section.set("min_ledgers_to_compute_size_limit", "3"); diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index c1d6d0b19..cad23d1e7 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -54,13 +55,6 @@ namespace ripple { namespace test { - -extern -void -setupConfigForUnitTests (Config& config); - -//------------------------------------------------------------------------------ - namespace jtx { /** Designate accounts as no-ripple in Env::fund */ @@ -152,12 +146,7 @@ public: template Env (beast::unit_test::suite& suite_, Args&&... args) - : Env(suite_, []() - { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - return p; - }(), std::forward(args)...) + : Env(suite_, envconfig(), std::forward(args)...) { } diff --git a/src/test/jtx/envconfig.h b/src/test/jtx/envconfig.h new file mode 100644 index 000000000..dd9d5be2b --- /dev/null +++ b/src/test/jtx/envconfig.h @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012-2017 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_TEST_JTX_ENVCONFIG_H_INCLUDED +#define RIPPLE_TEST_JTX_ENVCONFIG_H_INCLUDED + +#include + +namespace ripple { +namespace test { + +/// @brief initializes a config object for use with jtx::Env +/// +/// @param config the configuration object to be initialized +extern +void +setupConfigForUnitTests (Config& config); + +namespace jtx { + +/// @brief creates and initializes a default +/// configuration for jtx::Env +/// +/// @return unique_ptr to Config instance +inline +std::unique_ptr +envconfig() +{ + auto p = std::make_unique(); + setupConfigForUnitTests(*p); + return p; +} + +/// @brief creates and initializes a default configuration for jtx::Env and +/// invokes the provided function/lambda with the configuration object. +/// +/// @param modfunc callable function or lambda to modify the default config. +/// The first argument to the function must be std::unique_ptr to +/// ripple::Config. The function takes ownership of the unique_ptr and +/// relinquishes ownership by returning a unique_ptr. +/// +/// @param args additional arguments that will be passed to +/// the config modifier function (optional) +/// +/// @return unique_ptr to Config instance +template +std::unique_ptr +envconfig(F&& modfunc, Args&&... args) +{ + return modfunc(envconfig(), std::forward(args)...); +} + +/// @brief adjust config so no admin ports are enabled +/// +/// this is intended for use with envconfig, as in +/// envconfig(no_admin) +/// +/// @param cfg config instance to be modified +/// +/// @return unique_ptr to Config instance +std::unique_ptr +no_admin(std::unique_ptr); + +/// @brief adjust configuration with params needed to be a validator +/// +/// this is intended for use with envconfig, as in +/// envconfig(validator, myseed) +/// +/// @param cfg config instance to be modified +/// @param seed seed string for use in secret key generation. A fixed default +/// value will be used if this string is empty +/// +/// @return unique_ptr to Config instance +std::unique_ptr +validator(std::unique_ptr, std::string const&); + +/// @brief adjust the default configured server ports by a specified value +/// +/// This is intended for use with envconfig, as in +/// envconfig(port_increment, 5) +/// +/// @param cfg config instance to be modified +/// @param int amount by which to increment the existing server port +/// values in the config +/// +/// @return unique_ptr to Config instance +std::unique_ptr +port_increment(std::unique_ptr, int); + +} // jtx +} // test +} // ripple + +#endif + diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index b9a0660e0..0227014e2 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -54,33 +53,6 @@ namespace ripple { namespace test { - -void -setupConfigForUnitTests (Config& cfg) -{ - cfg.overwrite (ConfigSection::nodeDatabase (), "type", "memory"); - cfg.overwrite (ConfigSection::nodeDatabase (), "path", "main"); - cfg.deprecatedClearSection (ConfigSection::importNodeDatabase ()); - cfg.legacy("database_path", ""); - cfg.setupControl(true, true, true); - cfg["server"].append("port_peer"); - cfg["port_peer"].set("ip", "127.0.0.1"); - cfg["port_peer"].set("port", "8080"); - cfg["port_peer"].set("protocol", "peer"); - cfg["server"].append("port_rpc"); - cfg["port_rpc"].set("ip", "127.0.0.1"); - cfg["port_rpc"].set("port", "8081"); - cfg["port_rpc"].set("protocol", "http,ws2"); - cfg["port_rpc"].set("admin", "127.0.0.1"); - cfg["server"].append("port_ws"); - cfg["port_ws"].set("ip", "127.0.0.1"); - cfg["port_ws"].set("port", "8082"); - cfg["port_ws"].set("protocol", "ws"); - cfg["port_ws"].set("admin", "127.0.0.1"); -} - -//------------------------------------------------------------------------------ - namespace jtx { class SuiteSink : public beast::Journal::Sink diff --git a/src/test/jtx/impl/envconfig.cpp b/src/test/jtx/impl/envconfig.cpp new file mode 100644 index 000000000..14bdccf70 --- /dev/null +++ b/src/test/jtx/impl/envconfig.cpp @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012-2017 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include + +namespace ripple { +namespace test { + +void +setupConfigForUnitTests (Config& cfg) +{ + cfg.overwrite (ConfigSection::nodeDatabase (), "type", "memory"); + cfg.overwrite (ConfigSection::nodeDatabase (), "path", "main"); + cfg.deprecatedClearSection (ConfigSection::importNodeDatabase ()); + cfg.legacy("database_path", ""); + cfg.setupControl(true, true, true); + cfg["server"].append("port_peer"); + cfg["port_peer"].set("ip", "127.0.0.1"); + cfg["port_peer"].set("port", "8080"); + cfg["port_peer"].set("protocol", "peer"); + cfg["server"].append("port_rpc"); + cfg["port_rpc"].set("ip", "127.0.0.1"); + cfg["port_rpc"].set("port", "8081"); + cfg["port_rpc"].set("protocol", "http,ws2"); + cfg["port_rpc"].set("admin", "127.0.0.1"); + cfg["server"].append("port_ws"); + cfg["port_ws"].set("ip", "127.0.0.1"); + cfg["port_ws"].set("port", "8082"); + cfg["port_ws"].set("protocol", "ws"); + cfg["port_ws"].set("admin", "127.0.0.1"); +} + +namespace jtx { + +std::unique_ptr +no_admin(std::unique_ptr cfg) +{ + (*cfg)["port_rpc"].set("admin",""); + (*cfg)["port_ws"].set("admin",""); + return cfg; +} + +auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH"; + +std::unique_ptr +validator(std::unique_ptr cfg, std::string const& seed) +{ + // If the config has valid validation keys then we run as a validator. + cfg->section(SECTION_VALIDATION_SEED).append( + std::vector{seed.empty() ? defaultseed : seed}); + return cfg; +} + +std::unique_ptr +port_increment(std::unique_ptr cfg, int increment) +{ + for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"}) + { + Section& s = (*cfg)[sectionName]; + auto const port = s.get("port"); + if (port) + { + s.set ("port", std::to_string(*port + increment)); + } + } + return cfg; +} + +} // jtx +} // test +} // ripple diff --git a/src/test/ledger/View_test.cpp b/src/test/ledger/View_test.cpp index beca88216..4c698a146 100644 --- a/src/test/ledger/View_test.cpp +++ b/src/test/ledger/View_test.cpp @@ -687,27 +687,9 @@ class View_test eA.close(); auto const rdViewA4 = eA.closed(); - // The two Env's can't share the same ports, so edit the config - // of the second Env. - auto getConfigWithNewPorts = [this] () - { - auto cfg = std::make_unique(); - setupConfigForUnitTests(*cfg); - - for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"}) - { - Section& s = (*cfg)[sectionName]; - auto const port = s.get("port"); - BEAST_EXPECT(port); - if (port) - { - constexpr int portIncr = 5; - s.set ("port", std::to_string(*port + portIncr)); - } - } - return cfg; - }; - Env eB(*this, getConfigWithNewPorts()); + // The two Env's can't share the same ports, so modifiy the config + // of the second Env to use higher port numbers + Env eB {*this, envconfig(port_increment, 5)}; // Make ledgers that are incompatible with the first ledgers. Note // that bob is funded before alice. @@ -802,25 +784,11 @@ class View_test class GetAmendments_test : public beast::unit_test::suite { - static - std::unique_ptr - makeValidatorConfig() - { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - - // If the config has valid validation keys then we run as a validator. - p->section(SECTION_VALIDATION_SEED).append( - std::vector{"shUwVw52ofnCUX5m7kPTKzJdr4HEH"}); - - return p; - } - void testGetAmendments() { using namespace jtx; - Env env(*this, makeValidatorConfig()); + Env env {*this, envconfig(validator, "")}; // Start out with no amendments. auto majorities = getMajorityAmendments (*env.closed()); diff --git a/src/test/rpc/AccountOffers_test.cpp b/src/test/rpc/AccountOffers_test.cpp index aafaaf9fa..7d76dc64c 100644 --- a/src/test/rpc/AccountOffers_test.cpp +++ b/src/test/rpc/AccountOffers_test.cpp @@ -26,22 +26,6 @@ namespace test { class AccountOffers_test : public beast::unit_test::suite { public: - static - std::unique_ptr - makeConfig(bool setup_admin) - { - auto p = std::make_unique(); - 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))); } } diff --git a/src/test/rpc/Book_test.cpp b/src/test/rpc/Book_test.cpp index f61130482..51cc15892 100644 --- a/src/test/rpc/Book_test.cpp +++ b/src/test/rpc/Book_test.cpp @@ -1410,16 +1410,7 @@ public: { testcase("BookOffer Limits"); using namespace jtx; - Env env(*this, [asAdmin]() { - auto p = std::make_unique(); - 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(); diff --git a/src/test/rpc/JSONRPC_test.cpp b/src/test/rpc/JSONRPC_test.cpp index 9863eafdb..d828c4406 100644 --- a/src/test/rpc/JSONRPC_test.cpp +++ b/src/test/rpc/JSONRPC_test.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include 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 cfg) { - auto p = std::make_unique(); - 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(); { diff --git a/src/test/rpc/LedgerData_test.cpp b/src/test/rpc/LedgerData_test.cpp index 48c0a5145..8546930f6 100644 --- a/src/test/rpc/LedgerData_test.cpp +++ b/src/test/rpc/LedgerData_test.cpp @@ -26,23 +26,6 @@ namespace ripple { class LedgerData_test : public beast::unit_test::suite { public: - - static - std::unique_ptr - makeConfig(bool setup_admin) - { - auto p = std::make_unique(); - 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(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); diff --git a/src/test/rpc/LedgerRPC_test.cpp b/src/test/rpc/LedgerRPC_test.cpp index d5800aa42..4714a66bb 100644 --- a/src/test/rpc/LedgerRPC_test.cpp +++ b/src/test/rpc/LedgerRPC_test.cpp @@ -27,17 +27,6 @@ namespace ripple { class LedgerRPC_test : public beast::unit_test::suite { - static - std::unique_ptr - makeNonAdminConfig() - { - auto p = std::make_unique(); - 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(); diff --git a/src/test/rpc/LedgerRequestRPC_test.cpp b/src/test/rpc/LedgerRequestRPC_test.cpp index af7b00f32..d6212fbc0 100644 --- a/src/test/rpc/LedgerRequestRPC_test.cpp +++ b/src/test/rpc/LedgerRequestRPC_test.cpp @@ -32,17 +32,6 @@ class LedgerRequestRPC_test : public beast::unit_test::suite { public: - static - std::unique_ptr - makeNonAdminConfig() - { - auto p = std::make_unique(); - 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); diff --git a/src/test/rpc/RPCOverload_test.cpp b/src/test/rpc/RPCOverload_test.cpp index 93975e4b6..4c5037f1b 100644 --- a/src/test/rpc/RPCOverload_test.cpp +++ b/src/test/rpc/RPCOverload_test.cpp @@ -32,14 +32,7 @@ public: { testcase << "Overload " << (useWS ? "WS" : "HTTP") << " RPC client"; using namespace jtx; - Env env(*this, []() - { - auto p = std::make_unique(); - 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"}; diff --git a/src/test/rpc/ServerInfo_test.cpp b/src/test/rpc/ServerInfo_test.cpp index 55d46ba75..87367887c 100644 --- a/src/test/rpc/ServerInfo_test.cpp +++ b/src/test/rpc/ServerInfo_test.cpp @@ -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); } } diff --git a/src/test/rpc/Subscribe_test.cpp b/src/test/rpc/Subscribe_test.cpp index b9255cdf8..419258e94 100644 --- a/src/test/rpc/Subscribe_test.cpp +++ b/src/test/rpc/Subscribe_test.cpp @@ -312,29 +312,24 @@ public: BEAST_EXPECT(jv[jss::status] == "success"); } - static - std::unique_ptr - makeValidatorConfig(std::string const& seed) - { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - - // If the config has valid validation keys then we run as a validator. - p->section(SECTION_VALIDATION_SEED).append( - std::vector{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( + 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] == diff --git a/src/test/server/ServerStatus_test.cpp b/src/test/server/ServerStatus_test.cpp index 6ca72f107..94d238571 100644 --- a/src/test/server/ServerStatus_test.cpp +++ b/src/test/server/ServerStatus_test.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -45,8 +46,7 @@ class ServerStatus_test : { auto const section_name = boost::starts_with(proto, "h") ? "port_rpc" : "port_ws"; - auto p = std::make_unique(); - setupConfigForUnitTests(*p); + auto p = jtx::envconfig(); p->overwrite(section_name, "protocol", proto); if(! admin) @@ -274,13 +274,11 @@ class ServerStatus_test : { testcase("WS client to http server fails"); using namespace jtx; - Env env(*this, []() + Env env {*this, envconfig([](std::unique_ptr cfg) { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - p->section("port_ws").set("protocol", "http,https"); - return p; - }()); + cfg->section("port_ws").set("protocol", "http,https"); + return cfg; + })}; //non-secure request { @@ -308,14 +306,12 @@ class ServerStatus_test : { testcase("Status request"); using namespace jtx; - Env env(*this, []() + Env env {*this, envconfig([](std::unique_ptr cfg) { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - p->section("port_rpc").set("protocol", "ws2,wss2"); - p->section("port_ws").set("protocol", "http"); - return p; - }()); + cfg->section("port_rpc").set("protocol", "ws2,wss2"); + cfg->section("port_ws").set("protocol", "http"); + return cfg; + })}; //non-secure request { @@ -345,13 +341,11 @@ class ServerStatus_test : using namespace jtx; using namespace boost::asio; using namespace beast::http; - Env env(*this, []() + Env env {*this, envconfig([](std::unique_ptr cfg) { - auto p = std::make_unique(); - setupConfigForUnitTests(*p); - p->section("port_ws").set("protocol", "ws2"); - return p; - }()); + cfg->section("port_ws").set("protocol", "ws2"); + return cfg; + })}; auto const port = env.app().config()["port_ws"]. get("port"); @@ -395,6 +389,9 @@ class ServerStatus_test : std::string const& server_protocol, boost::asio::yield_context& yield) { + // The essence of this test is to have a client and server configured + // out-of-phase with respect to ssl (secure client and insecure server + // or vice-versa) testcase << "Connect fails: " << client_protocol << " client to " << server_protocol << " server"; using namespace jtx; @@ -402,12 +399,6 @@ class ServerStatus_test : beast::http::response resp; boost::system::error_code ec; - // The essence of this test is to have a client and server configured - // out-of-phase with respect to ssl (secure client and insecure server - // or vice-versa) - as such, here is a config to pass to - // WSClient/JSONRPCClient that configures it for a protocol that - // doesn't match the actual server - auto cfg = makeConfig(client_protocol); if(boost::starts_with(client_protocol, "h")) { doHTTPRequest( diff --git a/src/test/unity/support_unity.cpp b/src/test/unity/support_unity.cpp index f836da53e..ae7bca6d3 100644 --- a/src/test/unity/support_unity.cpp +++ b/src/test/unity/support_unity.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include