-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathenvconfig.cpp
More file actions
163 lines (139 loc) · 4.84 KB
/
envconfig.cpp
File metadata and controls
163 lines (139 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <test/jtx/amount.h>
#include <test/jtx/envconfig.h>
#include <xrpld/core/ConfigSections.h>
namespace xrpl {
namespace test {
std::atomic<bool> envUseIPv4{false};
void
setupConfigForUnitTests(Config& cfg)
{
using namespace jtx;
// 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;
cfg.FEES.account_reserve = XRP(200).value().xrp().drops();
cfg.FEES.owner_reserve = XRP(50).value().xrp().drops();
// The Beta API (currently v2) is always available to tests
cfg.BETA_RPC_API = true;
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", getEnvLocalhostAddr());
// Using port 0 asks the operating system to allocate an unused port, which
// can be obtained after a "bind" call.
// Works for all system (Linux, Windows, Unix, Mac).
// Check https://man7.org/linux/man-pages/man7/ip.7.html
// "ip_local_port_range" section for more info
cfg[PORT_PEER].set("port", "0");
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("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("port", "0");
cfg[PORT_WS].set("protocol", "ws");
cfg.SSL_VERIFY = false;
}
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;
}
std::unique_ptr<Config>
secure_gateway(std::unique_ptr<Config> cfg)
{
(*cfg)[PORT_RPC].set("admin", "");
(*cfg)[PORT_WS].set("admin", "");
(*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
return cfg;
}
std::unique_ptr<Config>
admin_localnet(std::unique_ptr<Config> cfg)
{
(*cfg)[PORT_RPC].set("admin", "127.0.0.0/8");
(*cfg)[PORT_WS].set("admin", "127.0.0.0/8");
return cfg;
}
std::unique_ptr<Config>
secure_gateway_localnet(std::unique_ptr<Config> cfg)
{
(*cfg)[PORT_RPC].set("admin", "");
(*cfg)[PORT_WS].set("admin", "");
(*cfg)[PORT_RPC].set("secure_gateway", "127.0.0.0/8");
(*cfg)[PORT_WS].set("secure_gateway", "127.0.0.0/8");
return cfg;
}
std::unique_ptr<Config>
single_thread_io(std::unique_ptr<Config> cfg)
{
cfg->IO_WORKERS = 1;
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>
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,
std::map<std::string, std::string> extraVoting)
{
auto p = test::jtx::envconfig();
auto& section = p->section("transaction_queue");
section.set("ledgers_in_queue", "2");
section.set("minimum_queue_size", "2");
section.set("min_ledgers_to_compute_size_limit", "3");
section.set("max_ledger_counts_to_store", "100");
section.set("retry_sequence_percent", "25");
section.set("normal_consensus_increase_percent", "0");
for (auto const& [k, v] : extraTxQ)
section.set(k, v);
// Some tests specify different fee settings that are enabled by
// a FeeVote
if (!extraVoting.empty())
{
auto& votingSection = p->section("voting");
for (auto const& [k, v] : extraVoting)
{
votingSection.set(k, v);
}
// In order for the vote to occur, we must run as a validator
p->section("validation_seed").legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
}
return p;
}
} // namespace jtx
} // namespace test
} // namespace xrpl