missing tests + formatting

This commit is contained in:
Valentin Balaschenko
2026-07-09 17:40:58 +01:00
parent f836c4b43e
commit 0d287fd9ba
2 changed files with 51 additions and 8 deletions

View File

@@ -339,8 +339,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
Callback&& replaceCallback)
{
std::scoped_lock<mutex_type> const lock(mutex_);
return canonicalizeImpl(
lock, key, data, policy, std::forward<Callback>(replaceCallback));
return canonicalizeImpl(lock, key, data, policy, std::forward<Callback>(replaceCallback));
}
template <
@@ -690,12 +689,9 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
std::scoped_lock<mutex_type> const lock(mutex_);
auto entry = std::make_shared<T>();
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");

View File

@@ -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<CheckMessageLogs>("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();
}
};