refactor: Change config section and key string literals into constants (#7095)

Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com>
This commit is contained in:
Bart
2026-06-09 10:58:21 -04:00
committed by GitHub
parent c9769d1add
commit c552eb333f
83 changed files with 1262 additions and 1029 deletions

View File

@@ -29,6 +29,7 @@
#include <xrpl/beast/unit_test/suite.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/config/Constants.h>
#include <xrpl/json/json_value.h>
#include <xrpl/json/to_string.h>
#include <xrpl/ledger/ApplyView.h>
@@ -167,7 +168,7 @@ public:
using namespace std::chrono;
testcase("queue sequence");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto alice = Account("alice");
auto bob = Account("bob");
@@ -380,7 +381,7 @@ public:
using namespace jtx;
testcase("queue ticket");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto alice = Account("alice");
@@ -618,7 +619,7 @@ public:
using namespace jtx;
testcase("queue tec");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "2"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "2"}}));
auto alice = Account("alice");
auto gw = Account("gw");
@@ -655,7 +656,7 @@ public:
using namespace std::chrono;
testcase("local tx retry");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "2"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "2"}}));
auto alice = Account("alice");
auto bob = Account("bob");
@@ -708,7 +709,7 @@ public:
using namespace std::chrono;
testcase("last ledger sequence");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "2"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "2"}}));
auto alice = Account("alice");
auto bob = Account("bob");
@@ -830,7 +831,7 @@ public:
using namespace std::chrono;
testcase("zero transaction fee");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "2"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "2"}}));
auto alice = Account("alice");
auto bob = Account("bob");
@@ -957,7 +958,7 @@ public:
using namespace jtx;
testcase("queued tx fails");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "2"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "2"}}));
auto alice = Account("alice");
auto bob = Account("bob");
@@ -1009,8 +1010,8 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "3"}},
{{"account_reserve", "200"}, {"owner_reserve", "50"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "3"}},
{{Keys::kAccountReserve, "200"}, {Keys::kOwnerReserve, "50"}}));
auto alice = Account("alice");
auto bob = Account("bob");
@@ -1258,7 +1259,7 @@ public:
using namespace std::chrono;
testcase("tie breaking");
auto cfg = makeConfig({{"minimum_txn_in_ledger_standalone", "4"}});
auto cfg = makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "4"}});
cfg->fees.referenceFee = 10;
Env env(*this, std::move(cfg));
@@ -1471,7 +1472,7 @@ public:
using namespace jtx;
testcase("acct tx id");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "1"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "1"}}));
auto alice = Account("alice");
@@ -1511,10 +1512,10 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "2"},
{"minimum_txn_in_ledger", "5"},
{"target_txn_in_ledger", "4"},
{"maximum_txn_in_ledger", "5"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "2"},
{Keys::kMinimumTxnInLedger, "5"},
{Keys::kTargetTxnInLedger, "4"},
{Keys::kMaximumTxnInLedger, "5"}}));
auto const baseFee = env.current()->fees().base.drops();
auto alice = Account("alice");
@@ -1555,10 +1556,10 @@ public:
Env const env(
*this,
makeConfig(
{{"minimum_txn_in_ledger", "200"},
{"minimum_txn_in_ledger_standalone", "200"},
{"target_txn_in_ledger", "4"},
{"maximum_txn_in_ledger", "5"}}));
{{Keys::kMinimumTxnInLedger, "200"},
{Keys::kMinimumTxnInLedgerStandalone, "200"},
{Keys::kTargetTxnInLedger, "4"},
{Keys::kMaximumTxnInLedger, "5"}}));
// should throw
fail();
}
@@ -1576,10 +1577,10 @@ public:
Env const env(
*this,
makeConfig(
{{"minimum_txn_in_ledger", "200"},
{"minimum_txn_in_ledger_standalone", "2"},
{"target_txn_in_ledger", "4"},
{"maximum_txn_in_ledger", "5"}}));
{{Keys::kMinimumTxnInLedger, "200"},
{Keys::kMinimumTxnInLedgerStandalone, "2"},
{Keys::kTargetTxnInLedger, "4"},
{Keys::kMaximumTxnInLedger, "5"}}));
// should throw
fail();
}
@@ -1597,10 +1598,10 @@ public:
Env const env(
*this,
makeConfig(
{{"minimum_txn_in_ledger", "2"},
{"minimum_txn_in_ledger_standalone", "200"},
{"target_txn_in_ledger", "4"},
{"maximum_txn_in_ledger", "5"}}));
{{Keys::kMinimumTxnInLedger, "2"},
{Keys::kMinimumTxnInLedgerStandalone, "200"},
{Keys::kTargetTxnInLedger, "4"},
{Keys::kMaximumTxnInLedger, "5"}}));
// should throw
fail();
}
@@ -1624,8 +1625,8 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "3"}},
{{"account_reserve", "200"}, {"owner_reserve", "50"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "3"}},
{{Keys::kAccountReserve, "200"}, {Keys::kOwnerReserve, "50"}}));
auto alice = Account("alice");
auto bob = Account("bob");
@@ -1716,7 +1717,7 @@ public:
auto queued = Ter(terQUEUED);
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const baseFee = env.current()->fees().base.drops();
checkMetrics(*this, env, 0, std::nullopt, 0, 3);
@@ -1845,7 +1846,7 @@ public:
auto queued = Ter(terQUEUED);
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const baseFee = env.current()->fees().base.drops();
checkMetrics(*this, env, 0, std::nullopt, 0, 3);
@@ -1996,8 +1997,8 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "3"}},
{{"account_reserve", "200"}, {"owner_reserve", "50"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "3"}},
{{Keys::kAccountReserve, "200"}, {Keys::kOwnerReserve, "50"}}));
auto alice = Account("alice");
auto charlie = Account("charlie");
@@ -2399,7 +2400,7 @@ public:
auto queued = Ter(terQUEUED);
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const baseFee = env.current()->fees().base.drops();
checkMetrics(*this, env, 0, std::nullopt, 0, 3);
@@ -2568,9 +2569,9 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "1"},
{"ledgers_in_queue", "10"},
{"maximum_txn_per_account", "20"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "1"},
{Keys::kLedgersInQueue, "10"},
{Keys::kMaximumTxnPerAccount, "20"}}));
auto const baseFee = env.current()->fees().base.drops();
@@ -2650,9 +2651,9 @@ public:
testcase("full queue gap handling");
auto cfg = makeConfig(
{{"minimum_txn_in_ledger_standalone", "1"},
{"ledgers_in_queue", "10"},
{"maximum_txn_per_account", "11"}});
{{Keys::kMinimumTxnInLedgerStandalone, "1"},
{Keys::kLedgersInQueue, "10"},
{Keys::kMaximumTxnPerAccount, "11"}});
cfg->fees.referenceFee = 10;
Env env(*this, std::move(cfg));
@@ -2777,7 +2778,7 @@ public:
{
testcase("Autofilled sequence should account for TxQ");
using namespace jtx;
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "6"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "6"}}));
auto const baseFee = env.current()->fees().base.drops();
EnvSs envs(env);
auto const& txQ = env.app().getTxQ();
@@ -2911,7 +2912,7 @@ public:
using namespace jtx;
testcase("account info");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const baseFee = env.current()->fees().base.drops();
EnvSs envs(env);
@@ -3181,7 +3182,7 @@ public:
using namespace jtx;
testcase("server info");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const baseFee = env.current()->fees().base.drops();
EnvSs envs(env);
@@ -3407,7 +3408,7 @@ public:
using namespace jtx;
testcase("server subscribe");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const baseFee = env.current()->fees().base.drops();
json::Value stream;
@@ -3546,7 +3547,7 @@ public:
using namespace jtx;
testcase("clear queued acct txs");
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const baseFee = env.current()->fees().base.drops();
auto alice = Account("alice");
auto bob = Account("bob");
@@ -3756,11 +3757,11 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "3"},
{"normal_consensus_increase_percent", "25"},
{"slow_consensus_decrease_percent", "50"},
{"target_txn_in_ledger", "10"},
{"maximum_txn_per_account", "200"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "3"},
{Keys::kNormalConsensusIncreasePercent, "25"},
{Keys::kSlowConsensusDecreasePercent, "50"},
{Keys::kTargetTxnInLedger, "10"},
{Keys::kMaximumTxnPerAccount, "200"}}));
auto alice = Account("alice");
checkMetrics(*this, env, 0, std::nullopt, 0, 3);
@@ -3842,11 +3843,11 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "3"},
{"normal_consensus_increase_percent", "150"},
{"slow_consensus_decrease_percent", "150"},
{"target_txn_in_ledger", "10"},
{"maximum_txn_per_account", "200"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "3"},
{Keys::kNormalConsensusIncreasePercent, "150"},
{Keys::kSlowConsensusDecreasePercent, "150"},
{Keys::kTargetTxnInLedger, "10"},
{Keys::kMaximumTxnPerAccount, "200"}}));
auto alice = Account("alice");
checkMetrics(*this, env, 0, std::nullopt, 0, 3);
@@ -3899,7 +3900,7 @@ public:
testcase("Sequence in queue and open ledger");
using namespace jtx;
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto const alice = Account("alice");
@@ -3962,7 +3963,7 @@ public:
testcase("Ticket in queue and open ledger");
using namespace jtx;
Env env(*this, makeConfig({{"minimum_txn_in_ledger_standalone", "3"}}));
Env env(*this, makeConfig({{Keys::kMinimumTxnInLedgerStandalone, "3"}}));
auto alice = Account("alice");
@@ -4063,15 +4064,16 @@ public:
static constexpr int kLedgersInQueue = 30;
auto cfg = makeConfig(
{{"minimum_txn_in_ledger_standalone", "1"},
{"ledgers_in_queue", std::to_string(kLedgersInQueue)},
{"maximum_txn_per_account", "10"}},
{{"account_reserve", "1000"}, {"owner_reserve", "50"}});
{{Keys::kMinimumTxnInLedgerStandalone, "1"},
{Keys::kLedgersInQueue, std::to_string(kLedgersInQueue)},
{Keys::kMaximumTxnPerAccount, "10"}},
{{Keys::kAccountReserve, "1000"}, {Keys::kOwnerReserve, "50"}});
auto& votingSection = cfg->section("voting");
votingSection.set("account_reserve", std::to_string(cfg->fees.referenceFee.drops() * 100));
auto& votingSection = cfg->section(Sections::kVoting);
votingSection.set(
Keys::kAccountReserve, std::to_string(cfg->fees.referenceFee.drops() * 100));
votingSection.set("reference_fee", std::to_string(cfg->fees.referenceFee.drops()));
votingSection.set(Keys::kReferenceFee, std::to_string(cfg->fees.referenceFee.drops()));
Env env(*this, std::move(cfg));
@@ -4228,10 +4230,10 @@ public:
Account const fiona("fiona");
auto cfg = makeConfig(
{{"minimum_txn_in_ledger_standalone", "5"},
{"ledgers_in_queue", "5"},
{"maximum_txn_per_account", "30"},
{"minimum_queue_size", "50"}});
{{Keys::kMinimumTxnInLedgerStandalone, "5"},
{Keys::kLedgersInQueue, "5"},
{Keys::kMaximumTxnPerAccount, "30"},
{Keys::kMinimumQueueSize, "50"}});
Env env(*this, std::move(cfg));
auto const baseFee = env.current()->fees().base.drops();
@@ -4437,10 +4439,10 @@ public:
auto usd = gw["USD"];
auto cfg = makeConfig(
{{"minimum_txn_in_ledger_standalone", "5"},
{"ledgers_in_queue", "5"},
{"maximum_txn_per_account", "30"},
{"minimum_queue_size", "50"}});
{{Keys::kMinimumTxnInLedgerStandalone, "5"},
{Keys::kLedgersInQueue, "5"},
{Keys::kMaximumTxnPerAccount, "30"},
{Keys::kMinimumQueueSize, "50"}});
Env env(*this, std::move(cfg));
@@ -4537,8 +4539,10 @@ public:
Env env(
*this,
makeConfig(
{{"minimum_txn_in_ledger_standalone", "3"}},
{{"reference_fee", "0"}, {"account_reserve", "0"}, {"owner_reserve", "0"}}));
{{Keys::kMinimumTxnInLedgerStandalone, "3"}},
{{Keys::kReferenceFee, "0"},
{Keys::kAccountReserve, "0"},
{Keys::kOwnerReserve, "0"}}));
checkMetrics(*this, env, 0, std::nullopt, 0, 3);