1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! Shared test helpers for integration tests across requirement domains.
//!
//! **Requirement:** [`STR-005`](../docs/requirements/domains/crate_structure/specs/STR-005.md) —
//! temporary RocksDB directories, deterministic [`dig_block::L2Block`] fixtures, small
//! [`dig_blockstore::BlockStoreConfig`], and linear fake chains.
//!
//! ## How integration tests include this module
//!
//! Rust treats each `[[test]]` binary as a separate crate root. Submodules are resolved relative to the
//! test file, so flat `tests/<prefix>_<req#>_tests.rs` crates pull this tree in with:
//! `#[path = "common/mod.rs"] mod common;`
//!
//! **Rationale:** Avoid duplicating genesis/block builders in every domain’s test file; keep
//! determinism explicit (same inputs → same [`L2Block::hash`]) so storage and canonical tests share one
//! definition of “a fake block”.
use PathBuf;
use Bytes32;
use ;
use ;
use BlockStoreConfig;
use TempDir;
/// Creates a temporary directory for a RocksDB-backed [`dig_blockstore::BlockStore`] that is deleted when
/// the returned [`TempDir`] guard is dropped.
///
/// **Proof:** [`STR-005`](../docs/requirements/domains/crate_structure/specs/STR-005.md) “Temporary
/// RocksDB Directory Helper”; cleanup is [`tempfile`](https://docs.rs/tempfile/)’s `Drop` on [`TempDir`].
///
/// # Returns
///
/// `(guard, path)` — keep the guard alive for the lifetime of the store; assign `path` to
/// [`BlockStoreConfig`](dig_blockstore::BlockStoreConfig) `path` when calling [`dig_blockstore::BlockStore::open`].
/// Builds a deterministic [`L2BlockHeader`] from `height`, `parent_hash`, and fixed sentinel roots.
///
/// **Spec:** [`STR-005`](../docs/requirements/domains/crate_structure/specs/STR-005.md) “Test Block
/// Helper” — timestamp scales with height (`height * 10`); other fields use stable protocol constants
/// ([`EMPTY_ROOT`](dig_block::constants::EMPTY_ROOT), [`ZERO_HASH`](dig_block::constants::ZERO_HASH)) so
/// the header hash is a pure function of `(height, parent_hash)` for test purposes.
///
/// **Upstream type:** [`L2BlockHeader::new`](dig_block::L2BlockHeader::new) (DIG [`dig-block`](https://github.com/DIG-Network/dig-block) / BLK-002).
/// Wraps [`test_header`] in an [`L2Block`] with an empty body and default proposer signature.
///
/// **Identity:** [`L2Block::hash`](dig_block::L2Block::hash) delegates to the header; empty spend bundles
/// keep the Merkle roots in the header consistent with the zeroed counts from [`L2BlockHeader::new`].
/// [`BlockStoreConfig`](dig_blockstore::BlockStoreConfig) tuned for fast, isolated unit tests.
///
/// **Normative:** [`STR-005`](../docs/requirements/domains/crate_structure/specs/STR-005.md) — small
/// in-memory cache capacities, reduced RocksDB budgets, **disabled block compression** (`compress_blocks: false`)
/// for cheap genesis / round-trip tests; BlobDB stays **`true`** (aligned with
/// [`BlockStoreConfig::default`]) so [`TYP-003`](../docs/requirements/domains/storage_types/specs/TYP-003.md)
/// CF options match [`dig_blockstore::BlockStore::open_readonly`]’s default-derived descriptors.
///
/// **Related:** Production defaults remain [`BlockStoreConfig::default`](dig_blockstore::BlockStoreConfig::default)
/// ([`TYP-008`](../docs/requirements/domains/storage_types/specs/TYP-008.md)).
/// Builds `n` blocks `[genesis … block_{n-1}]` where each block’s parent hash is the previous block’s
/// [`L2Block::hash`].
///
/// **Algorithm:** [`STR-005`](../docs/requirements/domains/crate_structure/specs/STR-005.md) “Chain
/// Builder” — seed parent with [`Bytes32::default`] (all-zero hash / genesis parent sentinel), then link.
///
/// **`dead_code`:** Each `[[test]]` binary includes this module independently; not every integration crate calls
/// `build_chain`, so we silence `unused` here rather than duplicating helpers per test file.