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 // Reserves held at pre-2021 mainnet values; many tests carry balance
25 // expectations built on them. Extension limits are deliberately unset --
26 // tests inherit the FeeSetup defaults, or set [voting].
27 cfg.fees.referenceFee = UNIT_TEST_REFERENCE_FEE;
28 cfg.fees.accountReserve = XRP(200).value().xrp().drops();
29 cfg.fees.ownerReserve = XRP(50).value().xrp().drops();
30
31 // The Beta API (currently v2) is always available to tests
32 cfg.betaRpcApi = true;
33
38 cfg.setupControl(true, true, true);
41
42 // Using port 0 asks the operating system to allocate an unused port, which
43 // can be obtained after a "bind" call.
44 // Works for all system (Linux, Windows, Unix, Mac).
45 // Check https://man7.org/linux/man-pages/man7/ip.7.html
46 // "ip_local_port_range" section for more info
47 cfg[Sections::kPortPeer].set(Keys::kPort, "0");
48 cfg[Sections::kPortPeer].set(Keys::kProtocol, "peer");
49
53 cfg[Sections::kPortRpc].set(Keys::kPort, "0");
54 cfg[Sections::kPortRpc].set(Keys::kProtocol, "http,ws2");
55
59 cfg[Sections::kPortWs].set(Keys::kPort, "0");
60 cfg[Sections::kPortWs].set(Keys::kProtocol, "ws");
61 cfg.sslVerify = false;
62}
63
64namespace jtx {
65
68{
69 cfg->ledgerHistory = deleteInterval;
70 auto& section = cfg->section(Sections::kNodeDatabase);
71 section.set(Keys::kOnlineDelete, std::to_string(deleteInterval));
72 return cfg;
73}
74
77{
78 (*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "");
79 (*cfg)[Sections::kPortWs].set(Keys::kAdmin, "");
80 return cfg;
81}
82
91
94{
95 (*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "127.0.0.0/8");
96 (*cfg)[Sections::kPortWs].set(Keys::kAdmin, "127.0.0.0/8");
97 return cfg;
98}
99
102{
103 (*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "");
104 (*cfg)[Sections::kPortWs].set(Keys::kAdmin, "");
105 (*cfg)[Sections::kPortRpc].set(Keys::kSecureGateway, "127.0.0.0/8");
106 (*cfg)[Sections::kPortWs].set(Keys::kSecureGateway, "127.0.0.0/8");
107 return cfg;
108}
111{
112 cfg->ioWorkers = 1;
113 return cfg;
114}
115
116constexpr auto kDefaultSeed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
117
120{
121 // If the config has valid validation keys then we run as a validator.
122 cfg->section(Sections::kValidationSeed)
123 .append(std::vector<std::string>{seed.empty() ? kDefaultSeed : seed});
124 return cfg;
125}
126
129{
131 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
132 return cfg;
133}
134
137{
139
140 // Check https://man7.org/linux/man-pages/man7/ip.7.html
141 // "ip_local_port_range" section for using 0 ports
142 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
144 return cfg;
145}
146
150 std::string const& certPath,
151 std::string const& keyPath)
152{
154 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
155 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
156 (*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
157 return cfg;
158}
159
163 std::string const& certPath,
164 std::string const& keyPath,
165 std::string const& clientCAPath)
166{
168 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
169 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
170 (*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
171 (*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, clientCAPath);
172 return cfg;
173}
174
178 std::string const& certPath,
179 std::string const& keyPath,
180 std::string const& certChainPath)
181{
183 (*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
184 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
185 (*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
186 (*cfg)[Sections::kPortGrpc].set(Keys::kSslCertChain, certChainPath);
187 return cfg;
188}
189
194{
195 auto p = test::jtx::envconfig();
196 auto& section = p->section(Sections::kTransactionQueue);
197 section.set(Keys::kLedgersInQueue, "2");
198 section.set(Keys::kMinimumQueueSize, "2");
199 section.set(Keys::kMinLedgersToComputeSizeLimit, "3");
200 section.set(Keys::kMaxLedgerCountsToStore, "100");
201 section.set(Keys::kRetrySequencePercent, "25");
203
204 for (auto const& [k, v] : extraTxQ)
205 section.set(k, v);
206
207 // Some tests specify different fee settings that are enabled by
208 // a FeeVote
209 if (!extraVoting.empty())
210 {
211 auto& votingSection = p->section(Sections::kVoting);
212 for (auto const& [k, v] : extraVoting)
213 {
214 votingSection.set(k, v);
215 }
216
217 // In order for the vote to occur, we must run as a validator
218 p->section(Sections::kValidationSeed).legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
219 }
220 return p;
221}
222
223} // namespace jtx
224} // 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:84
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:93
std::unique_ptr< Config > noAdmin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition envconfig.cpp:76
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:67
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:151
static constexpr auto kMinLedgersToComputeSizeLimit
Definition Constants.h:132
static constexpr auto kRetrySequencePercent
Definition Constants.h:155
static constexpr auto kMaxLedgerCountsToStore
Definition Constants.h:124
static constexpr auto kSslCertChain
Definition Constants.h:165
static constexpr auto kSslKey
Definition Constants.h:169
static constexpr auto kAdmin
Definition Constants.h:86
static constexpr auto kPort
Definition Constants.h:149
static constexpr auto kSslClientCa
Definition Constants.h:168
static constexpr auto kSslCert
Definition Constants.h:164
static constexpr auto kSecureGateway
Definition Constants.h:158
static constexpr auto kType
Definition Constants.h:177
static constexpr auto kIp
Definition Constants.h:117
static constexpr auto kPath
Definition Constants.h:147
static constexpr auto kMinimumQueueSize
Definition Constants.h:135
static constexpr auto kNormalConsensusIncreasePercent
Definition Constants.h:138
static constexpr auto kOnlineDelete
Definition Constants.h:140
static constexpr auto kLedgersInQueue
Definition Constants.h:120
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)