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 xrpl {
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).append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
98 return cfg;
99}
100
103{
104 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
105 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
106 return cfg;
107}
108
111{
112 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
113
114 // Check https://man7.org/linux/man-pages/man7/ip.7.html
115 // "ip_local_port_range" section for using 0 ports
116 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
117 (*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
118 return cfg;
119}
120
123{
124 auto p = test::jtx::envconfig();
125 auto& section = p->section("transaction_queue");
126 section.set("ledgers_in_queue", "2");
127 section.set("minimum_queue_size", "2");
128 section.set("min_ledgers_to_compute_size_limit", "3");
129 section.set("max_ledger_counts_to_store", "100");
130 section.set("retry_sequence_percent", "25");
131 section.set("normal_consensus_increase_percent", "0");
132
133 for (auto const& [k, v] : extraTxQ)
134 section.set(k, v);
135
136 // Some tests specify different fee settings that are enabled by
137 // a FeeVote
138 if (!extraVoting.empty())
139 {
140 auto& votingSection = p->section("voting");
141 for (auto const& [k, v] : extraVoting)
142 {
143 votingSection.set(k, v);
144 }
145
146 // In order for the vote to occur, we must run as a validator
147 p->section("validation_seed").legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
148 }
149 return p;
150}
151
152} // namespace jtx
153} // namespace test
154} // namespace xrpl
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
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition Config.cpp:244
FeeSetup FEES
Definition Config.h:185
T empty(T... args)
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
Definition envconfig.cpp:65
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:90
std::unique_ptr< Config > makeConfig(std::map< std::string, std::string > extraTxQ={}, std::map< std::string, std::string > extraVoting={})
std::unique_ptr< Config > admin_localnet(std::unique_ptr< Config >)
Definition envconfig.cpp:74
auto constexpr defaultseed
Definition envconfig.cpp:91
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 > 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
std::unique_ptr< Config > secure_gateway_localnet(std::unique_ptr< Config >)
Definition envconfig.cpp:82
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 > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition envconfig.cpp:57
std::atomic< bool > envUseIPv4
Definition envconfig.cpp:9
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition envconfig.cpp:12
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 account_reserve
The account reserve requirement in drops.
Definition Config.h:52
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
Definition Config.h:55