mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-30 16:05:51 +00:00
Fix tests, remove unused functions
This commit is contained in:
@@ -45,7 +45,7 @@ getRandomIPv4Loopback()
|
||||
// (except 127.0.0.0 and 127.255.255.255 that are reserved), which we should
|
||||
// use as the majority of our tests use IPv4. On macOS only 127.0.0.1 is
|
||||
// available as loopback address, unless the loopback interface is aliased
|
||||
// to more addresses, e.g. `sudo ifconfig lo0 alias 127.0.0.* up`.
|
||||
// to more addresses, e.g. `sudo ifconfig lo0 alias 127.0.0.2 up` etc.
|
||||
#if defined(__clang__) && defined(__APPLE__)
|
||||
return 0x7F000001; // 127.0.0.1
|
||||
#else
|
||||
@@ -142,27 +142,6 @@ std::unique_ptr<Config> secure_gateway_localnet(std::unique_ptr<Config>);
|
||||
std::unique_ptr<Config>
|
||||
validator(std::unique_ptr<Config>, std::string const&);
|
||||
|
||||
/// @brief add a grpc address and port to config
|
||||
///
|
||||
/// This is intended for use with envconfig, for tests that require a grpc
|
||||
/// server. If this function is not called, grpc server will not start
|
||||
///
|
||||
///
|
||||
/// @param cfg config instance to be modified
|
||||
std::unique_ptr<Config> addGrpcConfig(std::unique_ptr<Config>);
|
||||
|
||||
/// @brief add a grpc address, port and secure_gateway to config
|
||||
///
|
||||
/// This is intended for use with envconfig, for tests that require a grpc
|
||||
/// server. If this function is not called, grpc server will not start
|
||||
///
|
||||
///
|
||||
/// @param cfg config instance to be modified
|
||||
std::unique_ptr<Config>
|
||||
addGrpcConfigWithSecureGateway(
|
||||
std::unique_ptr<Config>,
|
||||
std::string const& secureGateway);
|
||||
|
||||
std::unique_ptr<Config>
|
||||
makeConfig(
|
||||
std::map<std::string, std::string> extraTxQ = {},
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/JSONRPCClient.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
|
||||
#include <xrpl/json/json_reader.h>
|
||||
#include <xrpl/json/to_string.h>
|
||||
@@ -54,8 +55,17 @@ class JSONRPCClient : public AbstractClient
|
||||
continue;
|
||||
using namespace boost::asio::ip;
|
||||
if (pp.ip && pp.ip->is_unspecified())
|
||||
*pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()}
|
||||
: address{address_v4::loopback()};
|
||||
{
|
||||
if (pp.ip->is_v6())
|
||||
{
|
||||
*pp.ip = address{address_v6::loopback()};
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const loopback_v4 = getRandomIPv4Loopback();
|
||||
*pp.ip = address{address_v4(loopback_v4)};
|
||||
}
|
||||
}
|
||||
|
||||
if (!pp.port)
|
||||
Throw<std::runtime_error>("Use fixConfigPorts with auto ports");
|
||||
|
||||
@@ -31,6 +31,10 @@ void
|
||||
setupConfigForUnitTests(Config& cfg)
|
||||
{
|
||||
using namespace jtx;
|
||||
|
||||
// Use the loopback address for IPv4 or IPv6, as appropriate.
|
||||
auto const& localhost = getEnvLocalhostAddr();
|
||||
|
||||
// Default fees to old values, so tests don't have to worry about changes in
|
||||
// Config.h
|
||||
cfg.FEES.reference_fee = UNIT_TEST_REFERENCE_FEE;
|
||||
@@ -46,7 +50,7 @@ setupConfigForUnitTests(Config& cfg)
|
||||
cfg.legacy("database_path", "");
|
||||
cfg.setupControl(true, true, true);
|
||||
cfg["server"].append(PORT_PEER);
|
||||
cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_PEER].set("ip", localhost);
|
||||
|
||||
// Using port 0 asks the operating system to allocate an unused port, which
|
||||
// can be obtained after a "bind" call.
|
||||
@@ -57,14 +61,14 @@ setupConfigForUnitTests(Config& cfg)
|
||||
cfg[PORT_PEER].set("protocol", "peer");
|
||||
|
||||
cfg["server"].append(PORT_RPC);
|
||||
cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("ip", localhost);
|
||||
cfg[PORT_RPC].set("admin", localhost);
|
||||
cfg[PORT_RPC].set("port", "0");
|
||||
cfg[PORT_RPC].set("protocol", "http,ws2");
|
||||
|
||||
cfg["server"].append(PORT_WS);
|
||||
cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("ip", localhost);
|
||||
cfg[PORT_WS].set("admin", localhost);
|
||||
cfg[PORT_WS].set("port", "0");
|
||||
cfg[PORT_WS].set("protocol", "ws");
|
||||
cfg.SSL_VERIFY = false;
|
||||
@@ -83,9 +87,11 @@ no_admin(std::unique_ptr<Config> cfg)
|
||||
std::unique_ptr<Config>
|
||||
secure_gateway(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
// Use the same IP address as assigned to the other IP fields.
|
||||
auto const localhost = (*cfg)[PORT_PEER].get<std::string>("ip");
|
||||
(*cfg)[PORT_RPC].set("admin", "");
|
||||
(*cfg)[PORT_WS].set("admin", "");
|
||||
(*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
|
||||
(*cfg)[PORT_RPC].set("secure_gateway", *localhost);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -118,28 +124,6 @@ validator(std::unique_ptr<Config> cfg, std::string const& seed)
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
addGrpcConfig(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
addGrpcConfigWithSecureGateway(
|
||||
std::unique_ptr<Config> cfg,
|
||||
std::string const& secureGateway)
|
||||
{
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
|
||||
// Check https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
// "ip_local_port_range" section for using 0 ports
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
makeConfig(
|
||||
std::map<std::string, std::string> extraTxQ,
|
||||
|
||||
@@ -80,14 +80,17 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
|
||||
if (proto == "https")
|
||||
{
|
||||
// Use the same IP address as assigned to the other IP address
|
||||
// fields.
|
||||
auto const localhost = (*p)[PORT_PEER].get<std::string>("ip");
|
||||
// this port is here to allow the env to create its internal client,
|
||||
// which requires an http endpoint to talk to. In the connection
|
||||
// failure test, this endpoint should never be used
|
||||
(*p)["server"].append("port_alt");
|
||||
(*p)["port_alt"].set("ip", getEnvLocalhostAddr());
|
||||
(*p)["port_alt"].set("ip", *localhost);
|
||||
(*p)["port_alt"].set("port", "7099");
|
||||
(*p)["port_alt"].set("protocol", "http");
|
||||
(*p)["port_alt"].set("admin", getEnvLocalhostAddr());
|
||||
(*p)["port_alt"].set("admin", *localhost);
|
||||
}
|
||||
|
||||
return p;
|
||||
|
||||
@@ -466,37 +466,37 @@ public:
|
||||
messages.find("Missing 'protocol' in [port_rpc]") !=
|
||||
std::string::npos);
|
||||
|
||||
except(
|
||||
[&] // this creates a standard test config without the server
|
||||
// section
|
||||
{
|
||||
Env env{
|
||||
*this,
|
||||
envconfig([](std::unique_ptr<Config> cfg) {
|
||||
cfg = std::make_unique<Config>();
|
||||
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)["port_peer"].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)["port_peer"].set("port", "8080");
|
||||
(*cfg)["port_peer"].set("protocol", "peer");
|
||||
(*cfg)["port_rpc"].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)["port_rpc"].set("port", "8081");
|
||||
(*cfg)["port_rpc"].set("protocol", "http,ws2");
|
||||
(*cfg)["port_rpc"].set("admin", getEnvLocalhostAddr());
|
||||
(*cfg)["port_ws"].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)["port_ws"].set("port", "8082");
|
||||
(*cfg)["port_ws"].set("protocol", "ws");
|
||||
(*cfg)["port_ws"].set("admin", getEnvLocalhostAddr());
|
||||
return cfg;
|
||||
}),
|
||||
std::make_unique<CaptureLogs>(&messages)};
|
||||
});
|
||||
except([&] // this creates a standard test config without the server
|
||||
// section
|
||||
{
|
||||
Env env{
|
||||
*this,
|
||||
envconfig([](std::unique_ptr<Config> cfg) {
|
||||
auto const& localhost = getEnvLocalhostAddr();
|
||||
cfg = std::make_unique<Config>();
|
||||
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)["port_peer"].set("ip", localhost);
|
||||
(*cfg)["port_peer"].set("port", "8080");
|
||||
(*cfg)["port_peer"].set("protocol", "peer");
|
||||
(*cfg)["port_rpc"].set("ip", localhost);
|
||||
(*cfg)["port_rpc"].set("port", "8081");
|
||||
(*cfg)["port_rpc"].set("protocol", "http,ws2");
|
||||
(*cfg)["port_rpc"].set("admin", localhost);
|
||||
(*cfg)["port_ws"].set("ip", localhost);
|
||||
(*cfg)["port_ws"].set("port", "8082");
|
||||
(*cfg)["port_ws"].set("protocol", "ws");
|
||||
(*cfg)["port_ws"].set("admin", localhost);
|
||||
return cfg;
|
||||
}),
|
||||
std::make_unique<CaptureLogs>(&messages)};
|
||||
});
|
||||
BEAST_EXPECT(
|
||||
messages.find("Required section [server] is missing") !=
|
||||
std::string::npos);
|
||||
|
||||
Reference in New Issue
Block a user