Skip to content

test: DB roundtrip tests for storage/blockchain and storage/txpool - #3

Open
orrinfrazier wants to merge 1 commit into
mainfrom
fix/S08-1-storage-roundtrip-tests
Open

test: DB roundtrip tests for storage/blockchain and storage/txpool#3
orrinfrazier wants to merge 1 commit into
mainfrom
fix/S08-1-storage-roundtrip-tests

Conversation

@orrinfrazier

@orrinfrazier orrinfrazier commented May 24, 2026

Copy link
Copy Markdown
Owner

Closes #13

Summary

Adds the first direct roundtrip tests for the storage layer's DB ops. storage/blockchain had only the compact_history proptest and storage/txpool had none — the read/write logic in ops/{block,tx,output}.rs and ops/{key_images,tx_read,tx_write}.rs was untested. Implements issues/S08-1-storage-roundtrip-tests.md.

Why

Storage is the chain-integrity layer where a bug means permanent corruption. This was the largest test-coverage gap before a confident public release.

Key design note: positional tapes

The block_infos/tx_infos tapes are positional (tape index == block height). The real mainnet-height fixtures (BLOCK_V1_TX2@202609, etc.) therefore can't be round-tripped by height in an empty DB. Two complementary harnesses are used:

  • Real fixtures → height-independent fidelity: get_tx real pruned+prunable reassembly (V1 via v1_prunable_blobs, V2 via pruning stripe), pre-RCT + RCT output lookups, and get_block via a captured BlockInfo.
  • Synthetic miner-only genesis chain → natural height-keyed lifecycle: get_block by height/hash, get_block_complete_entry (pruned + non-pruned), chain_height/top_block_height, and pop_block restoring prior state. Needs no consensus machinery (mirrors cuprated's reorg-test block generation).

Changes

  • storage/blockchain/src/ops/tests.rs (new) — 4 tests: fixture block roundtrip (0-tx/V1/V2), V1 tx+output, V2 tx+output, synthetic-chain lifecycle + pop.
  • storage/txpool/src/ops/tests.rs (new) — 3 tests: add/get roundtrip (V1+V2, stem flag), key-image double-spend rejection, remove + re-insert.
  • Wired both #[cfg(test)] mod tests;; added cuprate-test-utils + tempfile to storage/blockchain dev-deps (txpool already had them).

Testing

  • cargo test -p cuprate-blockchain -p cuprate-txpool — 8 pass (5 blockchain incl. the pre-existing proptest, 3 txpool).
  • cargo clippy -p cuprate-blockchain -p cuprate-txpool --all-targets --all-features -- -D warnings — clean.
  • cargo fmt --check — clean.

Acceptance criteria

  • storage/blockchain ops have direct roundtrip tests for block/tx/output read+write
  • storage/txpool ops have add/read/key-image tests
  • cargo test -p cuprate-blockchain -p cuprate-txpool exercises real DB operations

storage/blockchain had a single test (the compact_history proptest) and
storage/txpool had none; the DB read/write ops were untested. Add in-crate
#[cfg(test)] roundtrip modules that open a temporary fjall DB and exercise the
real ops.

The block_infos/tx_infos tapes are positional (tape index == block height), so
the real mainnet-height fixtures cannot be round-tripped by height in an empty
DB. Two complementary harnesses are used:

- blockchain: real fixtures (V1, V2, 0-tx) for height-independent tx/output/block
  blob fidelity (get_tx pruned+prunable reassembly, output lookups, get_block via
  a captured BlockInfo), plus a synthetic miner-only genesis chain for the natural
  height-keyed lifecycle (get_block by height/hash, get_block_complete_entry
  pruned+non-pruned, chain_height/top_block_height, pop_block restores state).
- txpool: add/get roundtrip (V1 + V2, stem flag), key-image double-spend
  rejection, and remove + re-insert.

Adds cuprate-test-utils + tempfile to storage/blockchain dev-dependencies
(storage/txpool already had them).
@orrinfrazier
orrinfrazier force-pushed the fix/S08-1-storage-roundtrip-tests branch from ae39f48 to c6e3fca Compare July 28, 2026 23:17
@github-actions github-actions Bot added A-storage Area: Related to storage. A-workspace Area: Changes to a root workspace file or general repo file. A-dependency labels Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-dependency A-storage Area: Related to storage. A-workspace Area: Changes to a root workspace file or general repo file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testing: DB roundtrip tests for storage/blockchain and storage/txpool

1 participant