diff --git a/src/test/app/LedgerMaster_test.cpp b/src/test/app/LedgerMaster_test.cpp index 19664616b1..d41868c76c 100644 --- a/src/test/app/LedgerMaster_test.cpp +++ b/src/test/app/LedgerMaster_test.cpp @@ -21,6 +21,7 @@ #include #include +#include namespace ripple { namespace test { @@ -119,6 +120,83 @@ class LedgerMaster_test : public beast::unit_test::suite } } + void + testCompleteLedgerRange(FeatureBitset features) + { + testcase("Complete Ledger operations"); + + using namespace test::jtx; + + auto const deleteInterval = 8; + + Env env{*this, envconfig([](auto cfg) { + return online_delete(std::move(cfg), deleteInterval); + })}; + + auto const alice = Account("alice"); + env.fund(XRP(1000), alice); + env.close(); + + auto& lm = env.app().getLedgerMaster(); + LedgerIndex minSeq = 2; + LedgerIndex maxSeq = env.closed()->info().seq; + auto& store = env.app().getSHAMapStore(); + LedgerIndex lastRotated = store.getLastRotated(); + BEAST_EXPECTS(maxSeq == 3, to_string(maxSeq)); + BEAST_EXPECTS( + lm.getCompleteLedgers() == "2-3", lm.getCompleteLedgers()); + BEAST_EXPECTS(lastRotated == 3, to_string(lastRotated)); + BEAST_EXPECT(lm.missingFromCompleteLedgerRange(minSeq, maxSeq) == 0); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq + 1, maxSeq - 1) == 0); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq - 1, maxSeq + 1) == 2); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq - 2, maxSeq - 2) == 2); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq + 2, maxSeq + 2) == 2); + + // Close enough ledgers to rotate a few times + for (int i = 0; i < 24; ++i) + { + for (int t = 0; t < 3; ++t) + { + env(noop(alice)); + } + env.close(); + store.rendezvous(); + + ++maxSeq; + + if (maxSeq == lastRotated + deleteInterval) + { + minSeq = lastRotated; + lastRotated = maxSeq; + } + BEAST_EXPECTS( + env.closed()->info().seq == maxSeq, + to_string(env.closed()->info().seq)); + BEAST_EXPECTS( + store.getLastRotated() == lastRotated, + to_string(store.getLastRotated())); + std::stringstream expectedRange; + expectedRange << minSeq << "-" << maxSeq; + BEAST_EXPECTS( + lm.getCompleteLedgers() == expectedRange.str(), + lm.getCompleteLedgers()); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq, maxSeq) == 0); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq + 1, maxSeq - 1) == 0); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq - 1, maxSeq + 1) == 2); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq - 2, maxSeq - 2) == 2); + BEAST_EXPECT( + lm.missingFromCompleteLedgerRange(minSeq + 2, maxSeq + 2) == 2); + } + } + public: void run() override @@ -132,6 +210,7 @@ public: testWithFeats(FeatureBitset features) { testTxnIdFromIndex(features); + testCompleteLedgerRange(features); } }; diff --git a/src/test/app/SHAMapStore_test.cpp b/src/test/app/SHAMapStore_test.cpp index 1e0ec4bcf0..ea4aff70e4 100644 --- a/src/test/app/SHAMapStore_test.cpp +++ b/src/test/app/SHAMapStore_test.cpp @@ -39,10 +39,7 @@ class SHAMapStore_test : public beast::unit_test::suite static auto onlineDelete(std::unique_ptr cfg) { - cfg->LEDGER_HISTORY = deleteInterval; - auto& section = cfg->section(ConfigSection::nodeDatabase()); - section.set("online_delete", std::to_string(deleteInterval)); - return cfg; + return online_delete(std::move(cfg), deleteInterval); } static auto diff --git a/src/test/jtx/envconfig.h b/src/test/jtx/envconfig.h index f22c5743e7..94384ce448 100644 --- a/src/test/jtx/envconfig.h +++ b/src/test/jtx/envconfig.h @@ -77,6 +77,17 @@ envconfig(F&& modfunc, Args&&... args) return modfunc(envconfig(), std::forward(args)...); } +/// @brief adjust config to enable online_delete +/// +/// @param cfg config instance to be modified +/// +/// @param deleteInterval how many new ledgers should be available before +/// rotating. Defaults to 8, because the standalone minimum is 8. +/// +/// @return unique_ptr to Config instance +std::unique_ptr +online_delete(std::unique_ptr cfg, std::uint32_t deleteInterval = 8); + /// @brief adjust config so no admin ports are enabled /// /// this is intended for use with envconfig, as in diff --git a/src/test/jtx/impl/envconfig.cpp b/src/test/jtx/impl/envconfig.cpp index dd9c735465..9ee60d7788 100644 --- a/src/test/jtx/impl/envconfig.cpp +++ b/src/test/jtx/impl/envconfig.cpp @@ -72,6 +72,15 @@ setupConfigForUnitTests(Config& cfg) namespace jtx { +std::unique_ptr +online_delete(std::unique_ptr cfg, std::uint32_t deleteInterval) +{ + cfg->LEDGER_HISTORY = deleteInterval; + auto& section = cfg->section(ConfigSection::nodeDatabase()); + section.set("online_delete", std::to_string(deleteInterval)); + return cfg; +} + std::unique_ptr no_admin(std::unique_ptr cfg) {