Skip to main content

md_codec/
test_vectors.rs

1//! Canonical `md` test-vector corpus.
2//!
3//! Used by `md-codec`'s own integration tests, by `md-cli`'s `vectors`
4//! subcommand, and by `md-cli`'s `tests/json_snapshots.rs` /
5//! `tests/template_roundtrip.rs`. Single source of truth: any vector
6//! addition / removal / rename happens here.
7//!
8//! `Vector` is `#[non_exhaustive]` so future fields can be added without a
9//! breaking-change bump: external consumers construct nothing — they only
10//! read `MANIFEST` entries.
11
12/// One entry of the canonical test-vector corpus.
13#[non_exhaustive]
14pub struct Vector {
15    pub name: &'static str,
16    pub template: &'static str,
17    pub keys: &'static [(u8, &'static str)],
18    pub fingerprints: &'static [(u8, [u8; 4])],
19    pub force_chunked: bool,
20}
21
22/// The canonical 10-entry corpus.
23///
24/// `tr_with_leaf` and `sh_wpkh` are intentionally omitted: their round-trip
25/// via the v0.14+ codec is asymmetric (encode requires explicit origin;
26/// decode strips canonical 86'/0'/0' resp. 49'/0'/0'). Coverage for those
27/// wrappers is preserved by `parse::template` unit tests
28/// (`tr_with_one_leaf`, `sh_wpkh_nested`).
29pub const MANIFEST: &[Vector] = &[
30    Vector { name: "wpkh_basic",         template: "wpkh(@0/<0;1>/*)",                                   keys: &[], fingerprints: &[], force_chunked: false },
31    Vector { name: "pkh_basic",          template: "pkh(@0/<0;1>/*)",                                    keys: &[], fingerprints: &[], force_chunked: false },
32    Vector { name: "wsh_multi_2of2",     template: "wsh(multi(2,@0/<0;1>/*,@1/<0;1>/*))",                keys: &[], fingerprints: &[], force_chunked: false },
33    Vector { name: "wsh_multi_2of3",     template: "wsh(multi(2,@0/<0;1>/*,@1/<0;1>/*,@2/<0;1>/*))",     keys: &[], fingerprints: &[], force_chunked: false },
34    Vector { name: "wsh_sortedmulti",    template: "wsh(sortedmulti(2,@0/<0;1>/*,@1/<0;1>/*,@2/<0;1>/*))", keys: &[], fingerprints: &[], force_chunked: false },
35    Vector { name: "tr_keyonly",         template: "tr(@0/<0;1>/*)",                                     keys: &[], fingerprints: &[], force_chunked: false },
36    Vector { name: "sh_wsh_multi",       template: "sh(wsh(multi(2,@0/<0;1>/*,@1/<0;1>/*)))",            keys: &[], fingerprints: &[], force_chunked: false },
37    Vector { name: "wsh_divergent_paths", template: "wsh(multi(2,@0/<0;1>/*,@1/<2;3>/*))",               keys: &[], fingerprints: &[], force_chunked: false },
38    Vector { name: "wsh_with_fingerprints", template: "wsh(multi(2,@0/<0;1>/*,@1/<0;1>/*))",
39        keys: &[],
40        fingerprints: &[(0, [0xDE,0xAD,0xBE,0xEF]), (1, [0xCA,0xFE,0xBA,0xBE])],
41        force_chunked: false },
42    Vector { name: "wsh_multi_chunked",  template: "wsh(multi(3,@0/<0;1>/*,@1/<0;1>/*,@2/<0;1>/*))",     keys: &[], fingerprints: &[], force_chunked: true },
43];