chaindb_runtime: full test coverage + fixes for hidden bugs

- txdb-factory.cpp: drop static-cache in ResolveChainDbKind so the
  -chaindb flag can be toggled at runtime (needed for tests; cost is
  negligible since the daemon sets it once at startup)
- txdb-rocksdb.cpp: fix ExistsRaw to honor pending-batch delete markers.
  Previously a key erased inside an open batch was still reported as
  existing because the underlying DB hadn't been updated yet. Mirror
  ReadRaw's correct behavior: a delete marker shadows the DB value.
- chaindb_runtime_tests.cpp: per-test fresh handle via close-reopen
  dance so the static g_rocksdb singleton doesn't leak state between
  cases. Tests filter framework keys (length-prefixed 'version' and
  'dbformat') from iterator walks. block_index test fixed to Seek()
  not Seek("blockindex") since the serialized keys start with the
  length byte 0x0a.
- snapshotnet_tests.cpp, chaindb_runtime_tests.cpp: include wallet.h,
  ui_interface.h, uint256.h, checkpoints.h as needed for linker; add
  BOOST_TEST_MODULE decl; define global stubs (pwalletMain,
  uiInterface, fConfChange, etc.) so wallet.cpp link succeeds.

Result: test_snapshotnet + test_chaindb_runtime both pass with zero
errors. Found and fixed a real production bug in ExistsRaw along
the way.
This commit is contained in:
Krystie
2026-06-25 03:39:04 -07:00
parent c7768fd42e
commit 0c6a2223cb
5 changed files with 178 additions and 68 deletions
+19 -3
View File
@@ -24,11 +24,15 @@
//
// Build: see src/test/CMakeLists.txt target `snapshotnet_tests`.
#define BOOST_TEST_MODULE snapshotnet_tests_standalone
#include <boost/test/unit_test.hpp>
#include "../snapshotnet.h"
#include "../checkpoints.h"
#include "../util.h"
#include "../uint256.h"
#include "../wallet.h"
#include "../ui_interface.h"
#include <openssl/sha.h>
@@ -53,9 +57,21 @@ namespace fs = std::filesystem;
extern uint64_t nLocalServices;
extern int nBestHeight;
// wallet.cpp pulls in main.cpp's references to these globals via the
// CWallet API. They have to be DEFINED (not just declared) for the linker
// to be happy. Stub values are fine — snapshotnet doesn't touch any of them.
CWallet* pwalletMain = nullptr;
CClientUIInterface uiInterface;
bool fConfChange = false;
bool fEnforceCanonical = false;
unsigned int nNodeLifespan = 0;
unsigned int nDerivationMethodIndex = 0;
bool fUseFastIndex = false;
enum Checkpoints::CPMode CheckpointsMode = Checkpoints::STRICT;
void StartShutdown() { /* no-op for tests */ }
namespace {
// No-op CClientUIInterface is already defined in util.h headers we include.
// pwalletMain isn't touched by snapshotnet, so we don't need to stub it.
// Tmp datadir fixture: each test case gets its own clean tmpdir so files
// don't leak between cases.
@@ -131,7 +147,7 @@ BOOST_AUTO_TEST_CASE(available_snapshot_roundtrip)
using namespace SnapshotNet;
AvailableSnapshot a;
a.height = 2205000;
a.fileHash = uint256S("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff");
a.fileHash = uint256("0x00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff");
a.totalSize = 12345678LL;
CDataStream s(SER_NETWORK, PROTOCOL_VERSION);