Add LMDB blockchain unit tests (write + read)#7716
Draft
Copilot wants to merge 2 commits intodevelopmentfrom
Draft
Add LMDB blockchain unit tests (write + read)#7716Copilot wants to merge 2 commits intodevelopmentfrom
Copilot wants to merge 2 commits intodevelopmentfrom
Conversation
Co-authored-by: SWvheerden <2579813+SWvheerden@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add unit tests for lmdb functionality
Add LMDB blockchain unit tests (write + read)
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No unit tests existed to verify that the LMDB backend correctly stores and retrieves blockchain data, including reorg scenarios.
Test chain structure
After the reorg: main chain is heights 0–15; B6–B10 become orphans (5 blocks).
Changes
lmdb_tests.rs– new test module with:build_test_blockchain()– creates the chain above usingTestBlockchain. Main-chain blocks B2–B10 each spend the previous coinbase. Fork blocks F6–F15 are coinbase-only. Fork block SMT roots are computed correctly via aMockTreeStoreJMT initialised to the UTXO state at B5, bypassing the DB's tip-only MMR calculation.replay_chain_data()– serialises all blocks to JSON, deserialises, and replays them into a freshBlockchainDatabase<TempDatabase>in identical insertion order.test_lmdb_write– asserts that a JSON-roundtripped replay produces an identical database: matching block hashes for all 16 main-chain heights, identical orphan-pool hashes, UTXO count, and kernel MMR size.test_lmdb_read– exhaustively exercises every backend read operation across all 16 main-chain blocks and 5 orphans:fetch_chain_header,fetch_chain_header_in_all_chains,fetch_block,fetch_block_accumulated_data,fetch_header_accumulated_data,fetch_orphan,fetch_outputs_in_block,fetch_inputs_in_block,fetch_kernels_in_block,fetch_output,fetch_mined_info_by_payref,fetch_outputs_in_block_with_spend_state,fetch_kernel_by_excess_sig,fetch_header_containing_kernel_mmr, andfetch_unspent_output_hash_by_commitment.tests/mod.rs– addsmod lmdb_tests.Known issue
The reorg-trigger assertion (
assert_reorg) uses the wrong counts — F11 (height 11) beats the main chain at height 10, so F6–F10 are orphans and F11 triggers the reorg (assert_reorg(6, 5)), with F12–F15 appended directly. This needs a follow-up fix before the tests will pass.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.