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}
92{
93 cfg->IO_WORKERS = 1;
94 return cfg;
95}
96
97auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
98
101{
102 // If the config has valid validation keys then we run as a validator.
103 cfg->section(SECTION_VALIDATION_SEED)
104 .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
105 return cfg;
106}
107
110{
111 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
112 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
113 return cfg;
114}
115
118{
119 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
120
121 // Check https://man7.org/linux/man-pages/man7/ip.7.html
122 // "ip_local_port_range" section for using 0 ports
123 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
124 (*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
125 return cfg;
126}
127
132{
133 auto p = test::jtx::envconfig();
134 auto& section = p->section("transaction_queue");
135 section.set("ledgers_in_queue", "2");
136 section.set("minimum_queue_size", "2");
137 section.set("min_ledgers_to_compute_size_limit", "3");
138 section.set("max_ledger_counts_to_store", "100");
139 section.set("retry_sequence_percent", "25");
140 section.set("normal_consensus_increase_percent", "0");
141
142 for (auto const& [k, v] : extraTxQ)
143 section.set(k, v);
144
145 // Some tests specify different fee settings that are enabled by
146 // a FeeVote
147 if (!extraVoting.empty())
148 {
149 auto& votingSection = p->section("voting");
150 for (auto const& [k, v] : extraVoting)
151 {
152 votingSection.set(k, v);
153 }
154
155 // In order for the vote to occur, we must run as a validator
156 p->section("validation_seed").legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
157 }
158 return p;
159}
160
161} // namespace jtx
162} // namespace test
163} // 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:272
bool SSL_VERIFY
Definition Config.h:200
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition Config.cpp:250
FeeSetup FEES
Definition Config.h:189
T empty(T... args)
std::unique_ptr< Config > single_thread_io(std::unique_ptr< Config >)
Definition envconfig.cpp:91
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:95
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:97
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:34
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
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:16
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
static std::string nodeDatabase()
static std::string importNodeDatabase()
XRPAmount reference_fee
The cost of a reference transaction in drops.
Definition Config.h:51
XRPAmount account_reserve
The account reserve requirement in drops.
Definition Config.h:54
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
Definition Config.h:57