rippled
Loading...
Searching...
No Matches
envconfig.cpp
1#include <test/jtx/amount.h>
2#include <test/jtx/envconfig.h>
3
4#include <xrpld/core/ConfigSections.h>
5
6namespace ripple {
7namespace test {
8
10
11void
13{
14 using namespace jtx;
15 // Default fees to old values, so tests don't have to worry about changes in
16 // Config.h
17 cfg.FEES.reference_fee = UNIT_TEST_REFERENCE_FEE;
18 cfg.FEES.account_reserve = XRP(200).value().xrp().drops();
19 cfg.FEES.owner_reserve = XRP(50).value().xrp().drops();
20
21 // The Beta API (currently v2) is always available to tests
22 cfg.BETA_RPC_API = true;
23
24 cfg.overwrite(ConfigSection::nodeDatabase(), "type", "memory");
25 cfg.overwrite(ConfigSection::nodeDatabase(), "path", "main");
27 cfg.legacy("database_path", "");
28 cfg.setupControl(true, true, true);
29 cfg["server"].append(PORT_PEER);
30 cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
31
32 // Using port 0 asks the operating system to allocate an unused port, which
33 // can be obtained after a "bind" call.
34 // Works for all system (Linux, Windows, Unix, Mac).
35 // Check https://man7.org/linux/man-pages/man7/ip.7.html
36 // "ip_local_port_range" section for more info
37 cfg[PORT_PEER].set("port", "0");
38 cfg[PORT_PEER].set("protocol", "peer");
39
40 cfg["server"].append(PORT_RPC);
41 cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
42 cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
43 cfg[PORT_RPC].set("port", "0");
44 cfg[PORT_RPC].set("protocol", "http,ws2");
45
46 cfg["server"].append(PORT_WS);
47 cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
48 cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
49 cfg[PORT_WS].set("port", "0");
50 cfg[PORT_WS].set("protocol", "ws");
51 cfg.SSL_VERIFY = false;
52}
53
54namespace jtx {
55
58{
59 (*cfg)[PORT_RPC].set("admin", "");
60 (*cfg)[PORT_WS].set("admin", "");
61 return cfg;
62}
63
66{
67 (*cfg)[PORT_RPC].set("admin", "");
68 (*cfg)[PORT_WS].set("admin", "");
69 (*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
70 return cfg;
71}
72
75{
76 (*cfg)[PORT_RPC].set("admin", "127.0.0.0/8");
77 (*cfg)[PORT_WS].set("admin", "127.0.0.0/8");
78 return cfg;
79}
80
83{
84 (*cfg)[PORT_RPC].set("admin", "");
85 (*cfg)[PORT_WS].set("admin", "");
86 (*cfg)[PORT_RPC].set("secure_gateway", "127.0.0.0/8");
87 (*cfg)[PORT_WS].set("secure_gateway", "127.0.0.0/8");
88 return cfg;
89}
90
91auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
92
95{
96 // If the config has valid validation keys then we run as a validator.
97 cfg->section(SECTION_VALIDATION_SEED)
98 .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
99 return cfg;
100}
101
104{
105 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
106 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
107 return cfg;
108}
109
113 std::string const& secureGateway)
114{
115 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
116
117 // Check https://man7.org/linux/man-pages/man7/ip.7.html
118 // "ip_local_port_range" section for using 0 ports
119 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
120 (*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
121 return cfg;
122}
123
128{
129 auto p = test::jtx::envconfig();
130 auto& section = p->section("transaction_queue");
131 section.set("ledgers_in_queue", "2");
132 section.set("minimum_queue_size", "2");
133 section.set("min_ledgers_to_compute_size_limit", "3");
134 section.set("max_ledger_counts_to_store", "100");
135 section.set("retry_sequence_percent", "25");
136 section.set("normal_consensus_increase_percent", "0");
137
138 for (auto const& [k, v] : extraTxQ)
139 section.set(k, v);
140
141 // Some tests specify different fee settings that are enabled by
142 // a FeeVote
143 if (!extraVoting.empty())
144 {
145 auto& votingSection = p->section("voting");
146 for (auto const& [k, v] : extraVoting)
147 {
148 votingSection.set(k, v);
149 }
150
151 // In order for the vote to occur, we must run as a validator
152 p->section("validation_seed").legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
153 }
154 return p;
155}
156
157} // namespace jtx
158} // namespace test
159} // namespace ripple
void deprecatedClearSection(std::string const &section)
Remove all the key/value pairs from the section.
void overwrite(std::string const &section, std::string const &key, std::string const &value)
Overwrite a key/value pair with a command line argument If the section does not exist it is created.
void legacy(std::string const &section, std::string value)
Set a value that is not a key/value pair.
bool BETA_RPC_API
Definition Config.h:268
bool SSL_VERIFY
Definition Config.h:196
FeeSetup FEES
Definition Config.h:185
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition Config.cpp:250
T empty(T... args)
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
Definition envconfig.cpp:94
std::unique_ptr< Config > admin_localnet(std::unique_ptr< Config >)
Definition envconfig.cpp:74
std::unique_ptr< Config > makeConfig(std::map< std::string, std::string > extraTxQ={}, std::map< std::string, std::string > extraVoting={})
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
Definition envconfig.cpp:65
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition envconfig.cpp:57
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:35
std::unique_ptr< Config > addGrpcConfig(std::unique_ptr< Config >)
add a grpc address and port to config
auto constexpr defaultseed
Definition envconfig.cpp:91
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
std::unique_ptr< Config > addGrpcConfigWithSecureGateway(std::unique_ptr< Config >, std::string const &secureGateway)
add a grpc address, port and secure_gateway to config
std::unique_ptr< Config > secure_gateway_localnet(std::unique_ptr< Config >)
Definition envconfig.cpp:82
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition envconfig.cpp:12
std::atomic< bool > envUseIPv4
Definition envconfig.cpp:9
char const * getEnvLocalhostAddr()
Definition envconfig.h:17
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
static std::string nodeDatabase()
static std::string importNodeDatabase()
XRPAmount reference_fee
The cost of a reference transaction in drops.
Definition Config.h:49
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
Definition Config.h:55
XRPAmount account_reserve
The account reserve requirement in drops.
Definition Config.h:52