mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-29 23:15:49 +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
@@ -4461,6 +4461,8 @@
|
|||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\test\jtx\Env.h">
|
<ClInclude Include="..\..\src\test\jtx\Env.h">
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\test\jtx\envconfig.h">
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\test\jtx\Env_ss.h">
|
<ClInclude Include="..\..\src\test\jtx\Env_ss.h">
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClCompile Include="..\..\src\test\jtx\Env_test.cpp">
|
<ClCompile Include="..\..\src\test\jtx\Env_test.cpp">
|
||||||
@@ -4491,6 +4493,10 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\test\jtx\impl\envconfig.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\test\jtx\impl\fee.cpp">
|
<ClCompile Include="..\..\src\test\jtx\impl\fee.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -5199,6 +5199,9 @@
|
|||||||
<ClInclude Include="..\..\src\test\jtx\Env.h">
|
<ClInclude Include="..\..\src\test\jtx\Env.h">
|
||||||
<Filter>test\jtx</Filter>
|
<Filter>test\jtx</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\test\jtx\envconfig.h">
|
||||||
|
<Filter>test\jtx</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\test\jtx\Env_ss.h">
|
<ClInclude Include="..\..\src\test\jtx\Env_ss.h">
|
||||||
<Filter>test\jtx</Filter>
|
<Filter>test\jtx</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -5226,6 +5229,9 @@
|
|||||||
<ClCompile Include="..\..\src\test\jtx\impl\Env.cpp">
|
<ClCompile Include="..\..\src\test\jtx\impl\Env.cpp">
|
||||||
<Filter>test\jtx\impl</Filter>
|
<Filter>test\jtx\impl</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\test\jtx\impl\envconfig.cpp">
|
||||||
|
<Filter>test\jtx\impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\test\jtx\impl\fee.cpp">
|
<ClCompile Include="..\..\src\test\jtx\impl\fee.cpp">
|
||||||
<Filter>test\jtx\impl</Filter>
|
<Filter>test\jtx\impl</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ class LedgerLoad_test : public beast::unit_test::suite
|
|||||||
auto ledgerConfig(std::string const& ledger, Config::StartUpType type)
|
auto ledgerConfig(std::string const& ledger, Config::StartUpType type)
|
||||||
{
|
{
|
||||||
assert(! dbPath_.empty());
|
assert(! dbPath_.empty());
|
||||||
auto p = std::make_unique<Config>();
|
auto p = test::jtx::envconfig();
|
||||||
test::setupConfigForUnitTests(*p);
|
|
||||||
p->START_LEDGER = ledger;
|
p->START_LEDGER = ledger;
|
||||||
p->START_UP = type;
|
p->START_UP = type;
|
||||||
p->legacy("database_path", dbPath_.string());
|
p->legacy("database_path", dbPath_.string());
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <BeastConfig.h>
|
#include <BeastConfig.h>
|
||||||
#include <test/jtx.h>
|
#include <test/jtx.h>
|
||||||
|
#include <test/jtx/envconfig.h>
|
||||||
#include <ripple/app/tx/apply.h>
|
#include <ripple/app/tx/apply.h>
|
||||||
#include <ripple/basics/StringUtilities.h>
|
#include <ripple/basics/StringUtilities.h>
|
||||||
#include <ripple/json/json_reader.h>
|
#include <ripple/json/json_reader.h>
|
||||||
@@ -164,14 +165,12 @@ struct Regression_test : public beast::unit_test::suite
|
|||||||
{
|
{
|
||||||
testcase("Autofilled fee should use the escalated fee");
|
testcase("Autofilled fee should use the escalated fee");
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, []()
|
Env env(*this, envconfig([](std::unique_ptr<Config> cfg)
|
||||||
{
|
{
|
||||||
auto p = std::make_unique<Config>();
|
cfg->section("transaction_queue")
|
||||||
setupConfigForUnitTests(*p);
|
.set("minimum_txn_in_ledger_standalone", "3");
|
||||||
auto& section = p->section("transaction_queue");
|
return cfg;
|
||||||
section.set("minimum_txn_in_ledger_standalone", "3");
|
}),
|
||||||
return p;
|
|
||||||
}(),
|
|
||||||
features(featureFeeEscalation));
|
features(featureFeeEscalation));
|
||||||
Env_ss envs(env);
|
Env_ss envs(env);
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <ripple/core/SociDB.h>
|
#include <ripple/core/SociDB.h>
|
||||||
#include <ripple/protocol/JsonFields.h>
|
#include <ripple/protocol/JsonFields.h>
|
||||||
#include <test/jtx.h>
|
#include <test/jtx.h>
|
||||||
|
#include <test/jtx/envconfig.h>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
namespace test {
|
namespace test {
|
||||||
@@ -34,26 +35,24 @@ class SHAMapStore_test : public beast::unit_test::suite
|
|||||||
static auto const deleteInterval = 8;
|
static auto const deleteInterval = 8;
|
||||||
|
|
||||||
static
|
static
|
||||||
std::unique_ptr<Config>
|
auto
|
||||||
makeConfig()
|
onlineDelete(std::unique_ptr<Config> cfg)
|
||||||
{
|
{
|
||||||
auto p = std::make_unique<Config>();
|
cfg->LEDGER_HISTORY = deleteInterval;
|
||||||
setupConfigForUnitTests(*p);
|
auto& section = cfg->section(ConfigSection::nodeDatabase());
|
||||||
p->LEDGER_HISTORY = deleteInterval;
|
|
||||||
auto& section = p->section(ConfigSection::nodeDatabase());
|
|
||||||
section.set("online_delete", to_string(deleteInterval));
|
section.set("online_delete", to_string(deleteInterval));
|
||||||
//section.set("age_threshold", "60");
|
//section.set("age_threshold", "60");
|
||||||
return p;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
std::unique_ptr<Config>
|
auto
|
||||||
makeConfigAdvisory()
|
advisoryDelete(std::unique_ptr<Config> cfg)
|
||||||
{
|
{
|
||||||
auto p = makeConfig();
|
cfg = onlineDelete(std::move(cfg));
|
||||||
auto& section = p->section(ConfigSection::nodeDatabase());
|
cfg->section(ConfigSection::nodeDatabase())
|
||||||
section.set("advisory_delete", "1");
|
.set("advisory_delete", "1");
|
||||||
return p;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool goodLedger(jtx::Env& env, Json::Value const& json,
|
bool goodLedger(jtx::Env& env, Json::Value const& json,
|
||||||
@@ -211,7 +210,7 @@ public:
|
|||||||
testcase("clearPrior");
|
testcase("clearPrior");
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
|
|
||||||
Env env(*this, makeConfig());
|
Env env(*this, envconfig(onlineDelete));
|
||||||
|
|
||||||
auto& store = env.app().getSHAMapStore();
|
auto& store = env.app().getSHAMapStore();
|
||||||
env.fund(XRP(10000), noripple("alice"));
|
env.fund(XRP(10000), noripple("alice"));
|
||||||
@@ -397,7 +396,7 @@ public:
|
|||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
Env env(*this, makeConfig());
|
Env env(*this, envconfig(onlineDelete));
|
||||||
auto& store = env.app().getSHAMapStore();
|
auto& store = env.app().getSHAMapStore();
|
||||||
|
|
||||||
auto ledgerSeq = waitForReady(env);
|
auto ledgerSeq = waitForReady(env);
|
||||||
@@ -466,7 +465,7 @@ public:
|
|||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
// Same config with advisory_delete enabled
|
// Same config with advisory_delete enabled
|
||||||
Env env(*this, makeConfigAdvisory());
|
Env env(*this, envconfig(advisoryDelete));
|
||||||
auto& store = env.app().getSHAMapStore();
|
auto& store = env.app().getSHAMapStore();
|
||||||
|
|
||||||
auto ledgerSeq = waitForReady(env);
|
auto ledgerSeq = waitForReady(env);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <ripple/basics/Log.h>
|
#include <ripple/basics/Log.h>
|
||||||
#include <ripple/basics/mulDiv.h>
|
#include <ripple/basics/mulDiv.h>
|
||||||
#include <test/jtx/TestSuite.h>
|
#include <test/jtx/TestSuite.h>
|
||||||
|
#include <test/jtx/envconfig.h>
|
||||||
#include <ripple/protocol/ErrorCodes.h>
|
#include <ripple/protocol/ErrorCodes.h>
|
||||||
#include <ripple/protocol/Feature.h>
|
#include <ripple/protocol/Feature.h>
|
||||||
#include <ripple/protocol/JsonFields.h>
|
#include <ripple/protocol/JsonFields.h>
|
||||||
@@ -98,8 +99,7 @@ class TxQ_test : public beast::unit_test::suite
|
|||||||
std::unique_ptr<Config>
|
std::unique_ptr<Config>
|
||||||
makeConfig(std::map<std::string, std::string> extra = {})
|
makeConfig(std::map<std::string, std::string> extra = {})
|
||||||
{
|
{
|
||||||
auto p = std::make_unique<Config>();
|
auto p = test::jtx::envconfig();
|
||||||
setupConfigForUnitTests(*p);
|
|
||||||
auto& section = p->section("transaction_queue");
|
auto& section = p->section("transaction_queue");
|
||||||
section.set("ledgers_in_queue", "2");
|
section.set("ledgers_in_queue", "2");
|
||||||
section.set("min_ledgers_to_compute_size_limit", "3");
|
section.set("min_ledgers_to_compute_size_limit", "3");
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <test/jtx/Account.h>
|
#include <test/jtx/Account.h>
|
||||||
#include <test/jtx/amount.h>
|
#include <test/jtx/amount.h>
|
||||||
|
#include <test/jtx/envconfig.h>
|
||||||
#include <test/jtx/JTx.h>
|
#include <test/jtx/JTx.h>
|
||||||
#include <test/jtx/require.h>
|
#include <test/jtx/require.h>
|
||||||
#include <test/jtx/tags.h>
|
#include <test/jtx/tags.h>
|
||||||
@@ -54,13 +55,6 @@
|
|||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
extern
|
|
||||||
void
|
|
||||||
setupConfigForUnitTests (Config& config);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace jtx {
|
namespace jtx {
|
||||||
|
|
||||||
/** Designate accounts as no-ripple in Env::fund */
|
/** Designate accounts as no-ripple in Env::fund */
|
||||||
@@ -152,12 +146,7 @@ public:
|
|||||||
template <class... Args>
|
template <class... Args>
|
||||||
Env (beast::unit_test::suite& suite_,
|
Env (beast::unit_test::suite& suite_,
|
||||||
Args&&... args)
|
Args&&... args)
|
||||||
: Env(suite_, []()
|
: Env(suite_, envconfig(), std::forward<Args>(args)...)
|
||||||
{
|
|
||||||
auto p = std::make_unique<Config>();
|
|
||||||
setupConfigForUnitTests(*p);
|
|
||||||
return p;
|
|
||||||
}(), std::forward<Args>(args)...)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
111
src/test/jtx/envconfig.h
Normal file
111
src/test/jtx/envconfig.h
Normal file
@@ -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 <ripple/core/Config.h>
|
||||||
|
|
||||||
|
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<Config>
|
||||||
|
envconfig()
|
||||||
|
{
|
||||||
|
auto p = std::make_unique<Config>();
|
||||||
|
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 <class F, class... Args>
|
||||||
|
std::unique_ptr<Config>
|
||||||
|
envconfig(F&& modfunc, Args&&... args)
|
||||||
|
{
|
||||||
|
return modfunc(envconfig(), std::forward<Args>(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<Config>
|
||||||
|
no_admin(std::unique_ptr<Config>);
|
||||||
|
|
||||||
|
/// @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<Config>
|
||||||
|
validator(std::unique_ptr<Config>, 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<Config>
|
||||||
|
port_increment(std::unique_ptr<Config>, int);
|
||||||
|
|
||||||
|
} // jtx
|
||||||
|
} // test
|
||||||
|
} // ripple
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -35,7 +35,6 @@
|
|||||||
#include <ripple/app/misc/TxQ.h>
|
#include <ripple/app/misc/TxQ.h>
|
||||||
#include <ripple/basics/contract.h>
|
#include <ripple/basics/contract.h>
|
||||||
#include <ripple/basics/Slice.h>
|
#include <ripple/basics/Slice.h>
|
||||||
#include <ripple/core/ConfigSections.h>
|
|
||||||
#include <ripple/json/to_string.h>
|
#include <ripple/json/to_string.h>
|
||||||
#include <ripple/net/HTTPClient.h>
|
#include <ripple/net/HTTPClient.h>
|
||||||
#include <ripple/net/RPCCall.h>
|
#include <ripple/net/RPCCall.h>
|
||||||
@@ -54,33 +53,6 @@
|
|||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
namespace test {
|
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 {
|
namespace jtx {
|
||||||
|
|
||||||
class SuiteSink : public beast::Journal::Sink
|
class SuiteSink : public beast::Journal::Sink
|
||||||
|
|||||||
89
src/test/jtx/impl/envconfig.cpp
Normal file
89
src/test/jtx/impl/envconfig.cpp
Normal file
@@ -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 <test/jtx/envconfig.h>
|
||||||
|
#include <test/jtx/Env.h>
|
||||||
|
#include <ripple/core/ConfigSections.h>
|
||||||
|
|
||||||
|
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<Config>
|
||||||
|
no_admin(std::unique_ptr<Config> cfg)
|
||||||
|
{
|
||||||
|
(*cfg)["port_rpc"].set("admin","");
|
||||||
|
(*cfg)["port_ws"].set("admin","");
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
|
||||||
|
|
||||||
|
std::unique_ptr<Config>
|
||||||
|
validator(std::unique_ptr<Config> 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<std::string>{seed.empty() ? defaultseed : seed});
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Config>
|
||||||
|
port_increment(std::unique_ptr<Config> cfg, int increment)
|
||||||
|
{
|
||||||
|
for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"})
|
||||||
|
{
|
||||||
|
Section& s = (*cfg)[sectionName];
|
||||||
|
auto const port = s.get<std::int32_t>("port");
|
||||||
|
if (port)
|
||||||
|
{
|
||||||
|
s.set ("port", std::to_string(*port + increment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // jtx
|
||||||
|
} // test
|
||||||
|
} // ripple
|
||||||
@@ -687,27 +687,9 @@ class View_test
|
|||||||
eA.close();
|
eA.close();
|
||||||
auto const rdViewA4 = eA.closed();
|
auto const rdViewA4 = eA.closed();
|
||||||
|
|
||||||
// The two Env's can't share the same ports, so edit the config
|
// The two Env's can't share the same ports, so modifiy the config
|
||||||
// of the second Env.
|
// of the second Env to use higher port numbers
|
||||||
auto getConfigWithNewPorts = [this] ()
|
Env eB {*this, envconfig(port_increment, 5)};
|
||||||
{
|
|
||||||
auto cfg = std::make_unique<Config>();
|
|
||||||
setupConfigForUnitTests(*cfg);
|
|
||||||
|
|
||||||
for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"})
|
|
||||||
{
|
|
||||||
Section& s = (*cfg)[sectionName];
|
|
||||||
auto const port = s.get<std::int32_t>("port");
|
|
||||||
BEAST_EXPECT(port);
|
|
||||||
if (port)
|
|
||||||
{
|
|
||||||
constexpr int portIncr = 5;
|
|
||||||
s.set ("port", std::to_string(*port + portIncr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cfg;
|
|
||||||
};
|
|
||||||
Env eB(*this, getConfigWithNewPorts());
|
|
||||||
|
|
||||||
// Make ledgers that are incompatible with the first ledgers. Note
|
// Make ledgers that are incompatible with the first ledgers. Note
|
||||||
// that bob is funded before alice.
|
// that bob is funded before alice.
|
||||||
@@ -802,25 +784,11 @@ class View_test
|
|||||||
class GetAmendments_test
|
class GetAmendments_test
|
||||||
: public beast::unit_test::suite
|
: public beast::unit_test::suite
|
||||||
{
|
{
|
||||||
static
|
|
||||||
std::unique_ptr<Config>
|
|
||||||
makeValidatorConfig()
|
|
||||||
{
|
|
||||||
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>{"shUwVw52ofnCUX5m7kPTKzJdr4HEH"});
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
testGetAmendments()
|
testGetAmendments()
|
||||||
{
|
{
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, makeValidatorConfig());
|
Env env {*this, envconfig(validator, "")};
|
||||||
|
|
||||||
// Start out with no amendments.
|
// Start out with no amendments.
|
||||||
auto majorities = getMajorityAmendments (*env.closed());
|
auto majorities = getMajorityAmendments (*env.closed());
|
||||||
|
|||||||
@@ -26,22 +26,6 @@ namespace test {
|
|||||||
class AccountOffers_test : public beast::unit_test::suite
|
class AccountOffers_test : public beast::unit_test::suite
|
||||||
{
|
{
|
||||||
public:
|
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
|
// test helper
|
||||||
static bool checkArraySize(Json::Value const& val, unsigned int size)
|
static bool checkArraySize(Json::Value const& val, unsigned int size)
|
||||||
{
|
{
|
||||||
@@ -60,7 +44,7 @@ public:
|
|||||||
void testNonAdminMinLimit()
|
void testNonAdminMinLimit()
|
||||||
{
|
{
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, makeConfig(false));
|
Env env {*this, envconfig(no_admin)};
|
||||||
Account const gw ("G1");
|
Account const gw ("G1");
|
||||||
auto const USD_gw = gw["USD"];
|
auto const USD_gw = gw["USD"];
|
||||||
Account const bob ("bob");
|
Account const bob ("bob");
|
||||||
@@ -97,10 +81,10 @@ public:
|
|||||||
BEAST_EXPECT(checkArraySize(jro_l, 10u));
|
BEAST_EXPECT(checkArraySize(jro_l, 10u));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testSequential(bool as_admin)
|
void testSequential(bool asAdmin)
|
||||||
{
|
{
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, makeConfig(as_admin));
|
Env env {*this, asAdmin ? envconfig() : envconfig(no_admin)};
|
||||||
Account const gw ("G1");
|
Account const gw ("G1");
|
||||||
auto const USD_gw = gw["USD"];
|
auto const USD_gw = gw["USD"];
|
||||||
Account const bob ("bob");
|
Account const bob ("bob");
|
||||||
@@ -153,9 +137,9 @@ public:
|
|||||||
// limit parameter is NOT subject to sane defaults, but with a
|
// limit parameter is NOT subject to sane defaults, but with a
|
||||||
// non-admin there are pre-configured limit ranges applied. That's
|
// non-admin there are pre-configured limit ranges applied. That's
|
||||||
// why we have different BEAST_EXPECT()s here for the two scenarios
|
// why we have different BEAST_EXPECT()s here for the two scenarios
|
||||||
BEAST_EXPECT(checkArraySize(jro_l_1, as_admin ? 1u : 3u));
|
BEAST_EXPECT(checkArraySize(jro_l_1, asAdmin ? 1u : 3u));
|
||||||
BEAST_EXPECT(as_admin ? checkMarker(jrr_l_1) : (! jrr_l_1.isMember(jss::marker)));
|
BEAST_EXPECT(asAdmin ? checkMarker(jrr_l_1) : (! jrr_l_1.isMember(jss::marker)));
|
||||||
if (as_admin)
|
if (asAdmin)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(jro[0u] == jro_l_1[0u]);
|
BEAST_EXPECT(jro[0u] == jro_l_1[0u]);
|
||||||
|
|
||||||
@@ -193,8 +177,8 @@ public:
|
|||||||
jvParams[jss::limit] = 0u;
|
jvParams[jss::limit] = 0u;
|
||||||
auto const jrr = env.rpc ("json", "account_offers", jvParams.toStyledString())[jss::result];
|
auto const jrr = env.rpc ("json", "account_offers", jvParams.toStyledString())[jss::result];
|
||||||
auto const& jro = jrr[jss::offers];
|
auto const& jro = jrr[jss::offers];
|
||||||
BEAST_EXPECT(checkArraySize(jro, as_admin ? 0u : 3u));
|
BEAST_EXPECT(checkArraySize(jro, asAdmin ? 0u : 3u));
|
||||||
BEAST_EXPECT(as_admin ? checkMarker(jrr) : (! jrr.isMember(jss::marker)));
|
BEAST_EXPECT(asAdmin ? checkMarker(jrr) : (! jrr.isMember(jss::marker)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1410,16 +1410,7 @@ public:
|
|||||||
{
|
{
|
||||||
testcase("BookOffer Limits");
|
testcase("BookOffer Limits");
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, [asAdmin]() {
|
Env env {*this, asAdmin ? envconfig() : envconfig(no_admin)};
|
||||||
auto p = std::make_unique<Config>();
|
|
||||||
setupConfigForUnitTests(*p);
|
|
||||||
if(! asAdmin)
|
|
||||||
{
|
|
||||||
(*p)["port_rpc"].set("admin","");
|
|
||||||
(*p)["port_ws"].set("admin","");
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}());
|
|
||||||
Account gw {"gw"};
|
Account gw {"gw"};
|
||||||
env.fund(XRP(200000), gw);
|
env.fund(XRP(200000), gw);
|
||||||
env.close();
|
env.close();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <ripple/protocol/Feature.h>
|
#include <ripple/protocol/Feature.h>
|
||||||
#include <ripple/rpc/impl/TransactionSign.h>
|
#include <ripple/rpc/impl/TransactionSign.h>
|
||||||
#include <test/jtx.h>
|
#include <test/jtx.h>
|
||||||
|
#include <test/jtx/envconfig.h>
|
||||||
#include <ripple/beast/unit_test.h>
|
#include <ripple/beast/unit_test.h>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
@@ -1934,15 +1935,14 @@ public:
|
|||||||
|
|
||||||
void testAutoFillEscalatedFees ()
|
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>();
|
cfg->section("transaction_queue")
|
||||||
test::setupConfigForUnitTests(*p);
|
.set("minimum_txn_in_ledger_standalone", "3");
|
||||||
auto& section = p->section("transaction_queue");
|
return cfg;
|
||||||
section.set("minimum_txn_in_ledger_standalone", "3");
|
}),
|
||||||
return p;
|
test::jtx::features(featureFeeEscalation)};
|
||||||
}(),
|
|
||||||
test::jtx::features(featureFeeEscalation));
|
|
||||||
LoadFeeTrack const& feeTrack = env.app().getFeeTrack();
|
LoadFeeTrack const& feeTrack = env.app().getFeeTrack();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,23 +26,6 @@ namespace ripple {
|
|||||||
class LedgerData_test : public beast::unit_test::suite
|
class LedgerData_test : public beast::unit_test::suite
|
||||||
{
|
{
|
||||||
public:
|
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
|
// test helper
|
||||||
static bool checkArraySize(Json::Value const& val, unsigned int size)
|
static bool checkArraySize(Json::Value const& val, unsigned int size)
|
||||||
{
|
{
|
||||||
@@ -58,10 +41,10 @@ public:
|
|||||||
val[jss::marker].asString().size() > 0;
|
val[jss::marker].asString().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testCurrentLedgerToLimits(bool as_admin)
|
void testCurrentLedgerToLimits(bool asAdmin)
|
||||||
{
|
{
|
||||||
using namespace test::jtx;
|
using namespace test::jtx;
|
||||||
Env env {*this, makeConfig(as_admin)};
|
Env env {*this, asAdmin ? envconfig() : envconfig(no_admin)};
|
||||||
Account const gw {"gateway"};
|
Account const gw {"gateway"};
|
||||||
auto const USD = gw["USD"];
|
auto const USD = gw["USD"];
|
||||||
env.fund(XRP(100000), gw);
|
env.fund(XRP(100000), gw);
|
||||||
@@ -97,14 +80,14 @@ public:
|
|||||||
boost::lexical_cast<std::string>(jvParams)) [jss::result];
|
boost::lexical_cast<std::string>(jvParams)) [jss::result];
|
||||||
BEAST_EXPECT(
|
BEAST_EXPECT(
|
||||||
checkArraySize( jrr[jss::state],
|
checkArraySize( jrr[jss::state],
|
||||||
(delta > 0 && !as_admin) ? max_limit : max_limit + delta ));
|
(delta > 0 && !asAdmin) ? max_limit : max_limit + delta ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testCurrentLedgerBinary()
|
void testCurrentLedgerBinary()
|
||||||
{
|
{
|
||||||
using namespace test::jtx;
|
using namespace test::jtx;
|
||||||
Env env { *this, makeConfig(false) };
|
Env env { *this, envconfig(no_admin) };
|
||||||
Account const gw { "gateway" };
|
Account const gw { "gateway" };
|
||||||
auto const USD = gw["USD"];
|
auto const USD = gw["USD"];
|
||||||
env.fund(XRP(100000), gw);
|
env.fund(XRP(100000), gw);
|
||||||
@@ -192,7 +175,7 @@ public:
|
|||||||
void testMarkerFollow()
|
void testMarkerFollow()
|
||||||
{
|
{
|
||||||
using namespace test::jtx;
|
using namespace test::jtx;
|
||||||
Env env { *this, makeConfig(false) };
|
Env env { *this, envconfig(no_admin) };
|
||||||
Account const gw { "gateway" };
|
Account const gw { "gateway" };
|
||||||
auto const USD = gw["USD"];
|
auto const USD = gw["USD"];
|
||||||
env.fund(XRP(100000), gw);
|
env.fund(XRP(100000), gw);
|
||||||
|
|||||||
@@ -27,17 +27,6 @@ namespace ripple {
|
|||||||
|
|
||||||
class LedgerRPC_test : public beast::unit_test::suite
|
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
|
void
|
||||||
checkErrorValue(
|
checkErrorValue(
|
||||||
Json::Value const& jv,
|
Json::Value const& jv,
|
||||||
@@ -184,7 +173,7 @@ class LedgerRPC_test : public beast::unit_test::suite
|
|||||||
testcase("Ledger Request, Full Option Without Admin");
|
testcase("Ledger Request, Full Option Without Admin");
|
||||||
using namespace test::jtx;
|
using namespace test::jtx;
|
||||||
|
|
||||||
Env env { *this, makeNonAdminConfig() };
|
Env env { *this, envconfig(no_admin) };
|
||||||
|
|
||||||
env.close();
|
env.close();
|
||||||
|
|
||||||
|
|||||||
@@ -32,17 +32,6 @@ class LedgerRequestRPC_test : public beast::unit_test::suite
|
|||||||
{
|
{
|
||||||
public:
|
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()
|
void testLedgerRequest()
|
||||||
{
|
{
|
||||||
using namespace test::jtx;
|
using namespace test::jtx;
|
||||||
@@ -288,7 +277,7 @@ public:
|
|||||||
void testNonAdmin()
|
void testNonAdmin()
|
||||||
{
|
{
|
||||||
using namespace test::jtx;
|
using namespace test::jtx;
|
||||||
Env env { *this, makeNonAdminConfig() };
|
Env env { *this, envconfig(no_admin) };
|
||||||
Account const gw { "gateway" };
|
Account const gw { "gateway" };
|
||||||
auto const USD = gw["USD"];
|
auto const USD = gw["USD"];
|
||||||
env.fund(XRP(100000), gw);
|
env.fund(XRP(100000), gw);
|
||||||
|
|||||||
@@ -32,14 +32,7 @@ public:
|
|||||||
{
|
{
|
||||||
testcase << "Overload " << (useWS ? "WS" : "HTTP") << " RPC client";
|
testcase << "Overload " << (useWS ? "WS" : "HTTP") << " RPC client";
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, []()
|
Env env {*this, envconfig(no_admin)};
|
||||||
{
|
|
||||||
auto p = std::make_unique<Config>();
|
|
||||||
setupConfigForUnitTests(*p);
|
|
||||||
(*p)["port_rpc"].set("admin","");
|
|
||||||
(*p)["port_ws"].set("admin","");
|
|
||||||
return p;
|
|
||||||
}());
|
|
||||||
|
|
||||||
Account const alice {"alice"};
|
Account const alice {"alice"};
|
||||||
Account const bob {"bob"};
|
Account const bob {"bob"};
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace ripple {
|
|||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
namespace validator {
|
namespace validator_data {
|
||||||
static auto const public_key =
|
static auto const public_key =
|
||||||
"nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
|
"nHBt9fsb4849WmZiCds4r5TXyBeQjqnH5kzPtqgMAQMgi39YZRPa";
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
)rippleConfig");
|
)rippleConfig");
|
||||||
|
|
||||||
p->loadFromString (boost::str (
|
p->loadFromString (boost::str (
|
||||||
toLoad % validator::token % validator::public_key));
|
toLoad % validator_data::token % validator_data::public_key));
|
||||||
|
|
||||||
setupConfigForUnitTests(*p);
|
setupConfigForUnitTests(*p);
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
BEAST_EXPECT(result[jss::status] == "success");
|
BEAST_EXPECT(result[jss::status] == "success");
|
||||||
BEAST_EXPECT(result[jss::result].isMember(jss::info));
|
BEAST_EXPECT(result[jss::result].isMember(jss::info));
|
||||||
BEAST_EXPECT(result[jss::result][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");
|
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()
|
void testValidations()
|
||||||
{
|
{
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
|
|
||||||
// Public key must be derived from the private key
|
Env env {*this, envconfig(validator, "")};
|
||||||
std::string const seed = "snpTg5uPtiRG2hE8HHCAF4NzdorKT";
|
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 =
|
std::string const valPublicKey =
|
||||||
"n9KCD2WU48u1WG3neBH6vRSinAxoTwrjLbjUAn6Xq6mCe5YrJv2V";
|
toBase58 (TokenType::TOKEN_NODE_PUBLIC,
|
||||||
Env env(*this, makeValidatorConfig(seed));
|
derivePublicKey (KeyType::secp256k1,
|
||||||
|
generateSecretKey (KeyType::secp256k1, *parsedseed)));
|
||||||
|
|
||||||
auto wsc = makeWSClient(env.app().config());
|
auto wsc = makeWSClient(env.app().config());
|
||||||
Json::Value stream;
|
Json::Value stream;
|
||||||
|
|
||||||
@@ -361,7 +356,8 @@ public:
|
|||||||
[&](auto const& jv)
|
[&](auto const& jv)
|
||||||
{
|
{
|
||||||
return jv[jss::type] == "validationReceived" &&
|
return jv[jss::type] == "validationReceived" &&
|
||||||
jv[jss::validation_public_key] == valPublicKey &&
|
jv[jss::validation_public_key].asString() ==
|
||||||
|
valPublicKey &&
|
||||||
jv[jss::ledger_hash] ==
|
jv[jss::ledger_hash] ==
|
||||||
to_string(env.closed()->info().hash) &&
|
to_string(env.closed()->info().hash) &&
|
||||||
jv[jss::ledger_index] ==
|
jv[jss::ledger_index] ==
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <ripple/rpc/ServerHandler.h>
|
#include <ripple/rpc/ServerHandler.h>
|
||||||
#include <ripple/json/json_reader.h>
|
#include <ripple/json/json_reader.h>
|
||||||
#include <test/jtx.h>
|
#include <test/jtx.h>
|
||||||
|
#include <test/jtx/envconfig.h>
|
||||||
#include <test/jtx/WSClient.h>
|
#include <test/jtx/WSClient.h>
|
||||||
#include <test/jtx/JSONRPCClient.h>
|
#include <test/jtx/JSONRPCClient.h>
|
||||||
#include <ripple/core/DeadlineTimer.h>
|
#include <ripple/core/DeadlineTimer.h>
|
||||||
@@ -45,8 +46,7 @@ class ServerStatus_test :
|
|||||||
{
|
{
|
||||||
auto const section_name =
|
auto const section_name =
|
||||||
boost::starts_with(proto, "h") ? "port_rpc" : "port_ws";
|
boost::starts_with(proto, "h") ? "port_rpc" : "port_ws";
|
||||||
auto p = std::make_unique<Config>();
|
auto p = jtx::envconfig();
|
||||||
setupConfigForUnitTests(*p);
|
|
||||||
|
|
||||||
p->overwrite(section_name, "protocol", proto);
|
p->overwrite(section_name, "protocol", proto);
|
||||||
if(! admin)
|
if(! admin)
|
||||||
@@ -274,13 +274,11 @@ class ServerStatus_test :
|
|||||||
{
|
{
|
||||||
testcase("WS client to http server fails");
|
testcase("WS client to http server fails");
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, []()
|
Env env {*this, envconfig([](std::unique_ptr<Config> cfg)
|
||||||
{
|
{
|
||||||
auto p = std::make_unique<Config>();
|
cfg->section("port_ws").set("protocol", "http,https");
|
||||||
setupConfigForUnitTests(*p);
|
return cfg;
|
||||||
p->section("port_ws").set("protocol", "http,https");
|
})};
|
||||||
return p;
|
|
||||||
}());
|
|
||||||
|
|
||||||
//non-secure request
|
//non-secure request
|
||||||
{
|
{
|
||||||
@@ -308,14 +306,12 @@ class ServerStatus_test :
|
|||||||
{
|
{
|
||||||
testcase("Status request");
|
testcase("Status request");
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
Env env(*this, []()
|
Env env {*this, envconfig([](std::unique_ptr<Config> cfg)
|
||||||
{
|
{
|
||||||
auto p = std::make_unique<Config>();
|
cfg->section("port_rpc").set("protocol", "ws2,wss2");
|
||||||
setupConfigForUnitTests(*p);
|
cfg->section("port_ws").set("protocol", "http");
|
||||||
p->section("port_rpc").set("protocol", "ws2,wss2");
|
return cfg;
|
||||||
p->section("port_ws").set("protocol", "http");
|
})};
|
||||||
return p;
|
|
||||||
}());
|
|
||||||
|
|
||||||
//non-secure request
|
//non-secure request
|
||||||
{
|
{
|
||||||
@@ -345,13 +341,11 @@ class ServerStatus_test :
|
|||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
using namespace boost::asio;
|
using namespace boost::asio;
|
||||||
using namespace beast::http;
|
using namespace beast::http;
|
||||||
Env env(*this, []()
|
Env env {*this, envconfig([](std::unique_ptr<Config> cfg)
|
||||||
{
|
{
|
||||||
auto p = std::make_unique<Config>();
|
cfg->section("port_ws").set("protocol", "ws2");
|
||||||
setupConfigForUnitTests(*p);
|
return cfg;
|
||||||
p->section("port_ws").set("protocol", "ws2");
|
})};
|
||||||
return p;
|
|
||||||
}());
|
|
||||||
|
|
||||||
auto const port = env.app().config()["port_ws"].
|
auto const port = env.app().config()["port_ws"].
|
||||||
get<std::uint16_t>("port");
|
get<std::uint16_t>("port");
|
||||||
@@ -395,6 +389,9 @@ class ServerStatus_test :
|
|||||||
std::string const& server_protocol,
|
std::string const& server_protocol,
|
||||||
boost::asio::yield_context& yield)
|
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 " <<
|
testcase << "Connect fails: " << client_protocol << " client to " <<
|
||||||
server_protocol << " server";
|
server_protocol << " server";
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
@@ -402,12 +399,6 @@ class ServerStatus_test :
|
|||||||
|
|
||||||
beast::http::response<beast::http::string_body> resp;
|
beast::http::response<beast::http::string_body> resp;
|
||||||
boost::system::error_code ec;
|
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"))
|
if(boost::starts_with(client_protocol, "h"))
|
||||||
{
|
{
|
||||||
doHTTPRequest(
|
doHTTPRequest(
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <test/jtx/impl/balance.cpp>
|
#include <test/jtx/impl/balance.cpp>
|
||||||
#include <test/jtx/impl/delivermin.cpp>
|
#include <test/jtx/impl/delivermin.cpp>
|
||||||
#include <test/jtx/impl/Env.cpp>
|
#include <test/jtx/impl/Env.cpp>
|
||||||
|
#include <test/jtx/impl/envconfig.cpp>
|
||||||
#include <test/jtx/impl/fee.cpp>
|
#include <test/jtx/impl/fee.cpp>
|
||||||
#include <test/jtx/impl/flags.cpp>
|
#include <test/jtx/impl/flags.cpp>
|
||||||
#include <test/jtx/impl/jtx_json.cpp>
|
#include <test/jtx/impl/jtx_json.cpp>
|
||||||
|
|||||||
Reference in New Issue
Block a user