xrpld
Loading...
Searching...
No Matches
envconfig.cpp
1#include <test/jtx/envconfig.h>
2
3#include <test/jtx/amount.h>
4
5#include <xrpld/core/Config.h>
6
7#include <xrpl/config/Constants.h>
8
9#include <atomic>
10#include <cstdint>
11#include <map>
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace xrpl::test {
17
19
20void
22{
23 using namespace jtx;
24 // Default fees to old values, so tests don't have to worry about changes in
25 // Config.h
26 cfg.fees.referenceFee = UNIT_TEST_REFERENCE_FEE;
27 cfg.fees.accountReserve = XRP(200).value().xrp().drops();
28 cfg.fees.ownerReserve = XRP(50).value().xrp().drops();
29
30 // The Beta API (currently v2) is always available to tests
31 cfg.betaRpcApi = true;
32
37 cfg.setupControl(true, true, true);
40
41 // Using port 0 asks the operating system to allocate an unused port, which
42 // can be obtained after a "bind" call.
43 // Works for all system (Linux, Windows, Unix, Mac).
44 // Check https://man7.org/linux/man-pages/man7/ip.7.html
45 // "ip_local_port_range" section for more info
46 cfg[Sections::kPortPeer].set(Keys::kPort, "0");
47 cfg[Sections::kPortPeer].set(Keys::kProtocol, "peer");
48
52 cfg[Sections::kPortRpc].set(Keys::kPort, "0");
53 cfg[Sections::kPortRpc].set(Keys::kProtocol, "http,ws2");
54
58 cfg[Sections::kPortWs].set(Keys::kPort, "0");
59 cfg[Sections::kPortWs].set(Keys::kProtocol, "ws");
60 cfg.sslVerify = false;
61}
62
63namespace jtx {
64
67{
68 cfg->ledgerHistory = deleteInterval;
69 auto& section = cfg->section(Sections::kNodeDatabase);
70 section.set(Keys::kOnlineDelete, std::to_string(deleteInterval));
71 return cfg;
72}
73
76{
77 (*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "");
78 (*cfg)[Sections::kPortWs].set(Keys::kAdmin, "");
79 return cfg;
80}
81
90
93{
94 (*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "127.0.0.0/8");
95 (*cfg)[Sections::kPortWs].set(Keys::kAdmin, "127.0.0.0/8");
96 return cfg;
97}
98
101{
102 (*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "");
103 (*cfg)[Sections::kPortWs].set(Keys::kAdmin, "");
104 (*cfg)[Sections::kPortRpc].set(Keys::kSecureGateway, "127.0.0.0/8");
105 (*cfg)[Sections::kPortWs].set(Keys::kSecureGateway, "127.0.0.0/8");
106 return cfg;
107}
110{
111 cfg->ioWorkers = 1;
112 return cfg;
113}
114
115constexpr auto kDefaultSeed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
116
119{
120 // If the config has valid validation keys then we run as a validator.
121 cfg->section(Sections::kValidationSeed)
122 .append(std::vector<std::string>{seed.empty() ? kDefaultSeed : seed});
123 return cfg;
124}
125
128{
130 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
131 return cfg;
132}
133
136{
138
139 // Check https://man7.org/linux/man-pages/man7/ip.7.html
140 // "ip_local_port_range" section for using 0 ports
141 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
143 return cfg;
144}
145
149 std::string const& certPath,
150 std::string const& keyPath)
151{
153 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
154 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
155 (*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
156 return cfg;
157}
158
162 std::string const& certPath,
163 std::string const& keyPath,
164 std::string const& clientCAPath)
165{
167 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
168 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
169 (*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
170 (*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, clientCAPath);
171 return cfg;
172}
173
177 std::string const& certPath,
178 std::string const& keyPath,
179 std::string const& certChainPath)
180{
182 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
183 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
184 (*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
185 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCertChain, certChainPath);
186 return cfg;
187}
188
193{
194 auto p = test::jtx::envconfig();
195 auto& section = p->section(Sections::kTransactionQueue);
196 section.set(Keys::kLedgersInQueue, "2");
197 section.set(Keys::kMinimumQueueSize, "2");
198 section.set(Keys::kMinLedgersToComputeSizeLimit, "3");
199 section.set(Keys::kMaxLedgerCountsToStore, "100");
200 section.set(Keys::kRetrySequencePercent, "25");
202
203 for (auto const& [k, v] : extraTxQ)
204 section.set(k, v);
205
206 // Some tests specify different fee settings that are enabled by
207 // a FeeVote
208 if (!extraVoting.empty())
209 {
210 auto& votingSection = p->section(Sections::kVoting);
211 for (auto const& [k, v] : extraVoting)
212 {
213 votingSection.set(k, v);
214 }
215
216 // In order for the vote to occur, we must run as a validator
217 p->section(Sections::kValidationSeed).legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
218 }
219 return p;
220}
221
222} // namespace jtx
223} // namespace xrpl::test
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.
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
T empty(T... args)
std::unique_ptr< Config > addGrpcConfigWithTLSAndCertChain(std::unique_ptr< Config >, std::string const &certPath, std::string const &keyPath, std::string const &certChainPath)
add a grpc address, port and TLS with server cert chain to config
std::unique_ptr< Config > addGrpcConfigWithTLSAndClientCA(std::unique_ptr< Config >, std::string const &certPath, std::string const &keyPath, std::string const &clientCAPath)
add a grpc address, port and TLS certificate/key/client CA paths to config
std::unique_ptr< Config > addGrpcConfigWithTLS(std::unique_ptr< Config >, std::string const &certPath, std::string const &keyPath)
add a grpc address, port and TLS certificate/key paths to config
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
std::unique_ptr< Config > secureGateway(std::unique_ptr< Config >)
Definition envconfig.cpp:83
std::unique_ptr< Config > secureGatewayLocalnet(std::unique_ptr< Config >)
constexpr auto kDefaultSeed
std::unique_ptr< Config > makeConfig(std::map< std::string, std::string > extraTxQ={}, std::map< std::string, std::string > extraVoting={})
std::unique_ptr< Config > singleThreadIo(std::unique_ptr< Config >)
std::unique_ptr< Config > addGrpcConfigWithSecureGateway(std::unique_ptr< Config >, std::string const &secureGateway)
add a grpc address, port and secureGateway to config
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Definition envconfig.h:38
std::unique_ptr< Config > adminLocalnet(std::unique_ptr< Config >)
Definition envconfig.cpp:92
std::unique_ptr< Config > noAdmin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition envconfig.cpp:75
std::unique_ptr< Config > addGrpcConfig(std::unique_ptr< Config >)
add a grpc address and port to config
std::unique_ptr< Config > onlineDelete(std::unique_ptr< Config > cfg, std::uint32_t deleteInterval=8)
adjust config to enable online_delete
Definition envconfig.cpp:66
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition envconfig.cpp:21
char const * getEnvLocalhostAddr()
Definition envconfig.h:16
std::atomic< bool > gEnvUseIPv4
Definition envconfig.cpp:18
XRPAmount accountReserve
The account reserve requirement in drops.
XRPAmount ownerReserve
The per-owned item reserve requirement in drops.
XRPAmount referenceFee
The cost of a reference transaction in drops.
static constexpr auto kProtocol
Definition Constants.h:148
static constexpr auto kMinLedgersToComputeSizeLimit
Definition Constants.h:129
static constexpr auto kRetrySequencePercent
Definition Constants.h:152
static constexpr auto kMaxLedgerCountsToStore
Definition Constants.h:121
static constexpr auto kSslCertChain
Definition Constants.h:162
static constexpr auto kSslKey
Definition Constants.h:166
static constexpr auto kAdmin
Definition Constants.h:86
static constexpr auto kPort
Definition Constants.h:146
static constexpr auto kSslClientCa
Definition Constants.h:165
static constexpr auto kSslCert
Definition Constants.h:161
static constexpr auto kSecureGateway
Definition Constants.h:155
static constexpr auto kType
Definition Constants.h:174
static constexpr auto kIp
Definition Constants.h:114
static constexpr auto kPath
Definition Constants.h:144
static constexpr auto kMinimumQueueSize
Definition Constants.h:132
static constexpr auto kNormalConsensusIncreasePercent
Definition Constants.h:135
static constexpr auto kOnlineDelete
Definition Constants.h:137
static constexpr auto kLedgersInQueue
Definition Constants.h:117
static constexpr auto kPortWs
Definition Constants.h:48
static constexpr auto kImportNodeDatabase
Definition Constants.h:20
static constexpr auto kValidationSeed
Definition Constants.h:67
static constexpr auto kServer
Definition Constants.h:56
static constexpr auto kPortRpc
Definition Constants.h:47
static constexpr auto kTransactionQueue
Definition Constants.h:66
static constexpr auto kNodeDatabase
Definition Constants.h:32
static constexpr auto kDatabasePath
Definition Constants.h:13
static constexpr auto kPortPeer
Definition Constants.h:46
static constexpr auto kPortGrpc
Definition Constants.h:45
static constexpr auto kVoting
Definition Constants.h:78
T to_string(T... args)