From 0d287fd9ba4b6dcad38f2a63c0e0621771caf7f7 Mon Sep 17 00:00:00 2001 From: Valentin Balaschenko <13349202+vlntb@users.noreply.github.com> Date: Thu, 9 Jul 2026 17:40:58 +0100 Subject: [PATCH] missing tests + formatting --- include/xrpl/basics/TaggedCache.ipp | 12 +++----- src/test/app/LedgerHistory_test.cpp | 47 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index 734342fe8f..9396c344fe 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -339,8 +339,7 @@ TaggedCache const lock(mutex_); - return canonicalizeImpl( - lock, key, data, policy, std::forward(replaceCallback)); + return canonicalizeImpl(lock, key, data, policy, std::forward(replaceCallback)); } template < @@ -690,12 +689,9 @@ TaggedCache const lock(mutex_); auto entry = std::make_shared(); - canonicalizeImpl( - lock, - key, - entry, - detail::ReplaceDynamically{}, - [](SharedPointerType const&) { return false; }); + canonicalizeImpl(lock, key, entry, detail::ReplaceDynamically{}, [](SharedPointerType const&) { + return false; + }); XRPL_ASSERT( entry != nullptr, "xrpl::TaggedCache::fetchAndModify : entry present after canonicalize"); diff --git a/src/test/app/LedgerHistory_test.cpp b/src/test/app/LedgerHistory_test.cpp index 428f7be064..d993210908 100644 --- a/src/test/app/LedgerHistory_test.cpp +++ b/src/test/app/LedgerHistory_test.cpp @@ -231,6 +231,52 @@ public: BEAST_EXPECT(found); } + + // Reverse order: validatedLedger arrives first, then builtLedger + // detects the mismatch. Covers the mismatch branch in builtLedger. + { + bool found = false; + Env env{ + *this, + envconfig(), + std::make_unique("MISMATCH on close time", &found)}; + LedgerHistory lh{beast::insight::NullCollector::make(), env.app()}; + auto const genesis = makeLedger({}, env, lh, 0s); + auto const ledgerA = makeLedger(genesis, env, lh, 4s); + auto const ledgerB = makeLedger(genesis, env, lh, 40s); + + uint256 const dummyTxHash{1}; + lh.validatedLedger(ledgerB, dummyTxHash); + lh.builtLedger(ledgerA, dummyTxHash, {}); + + BEAST_EXPECT(found); + } + } + + void + testFixIndex() + { + testcase("LedgerHistory fixIndex"); + using namespace jtx; + using namespace std::chrono; + + Env env{*this}; + LedgerHistory lh{beast::insight::NullCollector::make(), env.app()}; + + auto const genesis = makeLedger({}, env, lh, 0s); + auto const ledger1 = makeLedger(genesis, env, lh, 4s); + lh.insert(ledger1, true); + + // Unknown index: returns true, no repair. + BEAST_EXPECT(lh.fixIndex(999, ledger1->header().hash)); + + // Known index with the same hash: returns true, no repair. + BEAST_EXPECT(lh.fixIndex(ledger1->header().seq, ledger1->header().hash)); + + // Known index with a different hash: returns false and repairs. + uint256 const bogusHash{42}; + BEAST_EXPECT(!lh.fixIndex(ledger1->header().seq, bogusHash)); + BEAST_EXPECT(lh.getLedgerHash(ledger1->header().seq) == bogusHash); } void @@ -238,6 +284,7 @@ public: { testHashIndexInvariant(); testHandleMismatch(); + testFixIndex(); } };