Repository: unionlabs/union
File: lib/ics23/test-suite/src/main.rs (Rust)

Code before:
    }
}

const IAVL_SPEC: unionlabs::cosmos::ics23::proof_spec::ProofSpec = ProofSpec {
    leaf_spec: LeafOp {
        hash: HashOp::Sha256,
        prehash_key: HashOp::NoHash,
        prehash_value: HashOp::Sha256,
        length: unionlabs::cosmos::ics23::length_op::LengthOp::VarProto,
        prefix: std::borrow::Cow::Borrowed(&[0]),
    },
    inner_spec: unionlabs::cosmos::ics23::inner_spec::InnerSpec {
        child_order: Cow::Borrowed(promote!(&[PositiveI32AsUsize]: &[
            result_unwrap!(PositiveI32AsUsize::new(0)),
            result_unwrap!(PositiveI32AsUsize::new(1)),
        ])),
        child_size: result_unwrap!(PositiveI32AsUsize::new(33)),
        min_prefix_length: result_unwrap!(PositiveI32AsUsize::new(4)),
        max_prefix_length: result_unwrap!(PositiveI32AsUsize::new(12)),
        empty_child: Cow::Borrowed(&[0; 0]),
        hash: HashOp::Sha256,
    },
    min_depth: None,
    max_depth: None,
    prehash_key_before_comparison: false,
};

// from: proof.go
// IavlSpec constrains the format from proofs-iavl (iavl merkle proofs)
// var IavlSpec = &ProofSpec{
// 	LeafSpec: &LeafOp{
// 		Prefix:       []byte{0},
// 		PrehashKey:   HashOp_NO_HASH,
// 		Hash:         HashOp_SHA256,
// 		PrehashValue: HashOp_SHA256,
// 		Length:       LengthOp_VAR_PROTO,
// 	},
// 	InnerSpec: &InnerSpec{
// 		ChildOrder:      []int32{0, 1},
// 		MinPrefixLength: 4,
// 		MaxPrefixLength: 12,
// 		ChildSize:       33, // (with length byte)
// 		EmptyChild:      nil,
// 		Hash:            HashOp_SHA256,
// 	},
// }

const TENDERMINT_SPEC: unionlabs::cosmos::ics23::proof_spec::ProofSpec = ProofSpec {
    leaf_spec: LeafOp {
        hash: HashOp::Sha256,
        prehash_key: HashOp::NoHash,

Review comment (suggestion):
you should be able to import these from the ics23 library: https://github.com/unionlabs/union/blob/84940c5ad4bbb8112af7cf87ae6591d9d38e5f2f/lib/ics23/src/proof_specs.rs#L14-L38

Code after:
        .iter()
        .flat_map(|spec_type| {
            FILENAMES.iter().map(|file_name| {
                let name = format!("{} - {}", spec_type.name(), file_name);
                let spec = spec_type.proof_spec();

                let path = app.testdata_dir.join(spec_type.path()).join(file_name);
                let data = read_json::<VectorTestData>(path);

                VectorTest { name, data, spec }
            })
        })
        .collect();

    for test in tests {
        eprint!("test vectors: {}...", &test);
        test.run()?;
        eprintln!("OK");
    }

    Ok(())
}

#[derive(Debug, Deserialize)]
struct VectorTest {
    name: String,
    data: VectorTestData,
    spec: ProofSpec,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
struct VectorTestData {
    #[serde(with = "::serde_utils::hex_upper_unprefixed")]
    key: Vec<u8>,
    #[serde(with = "::serde_utils::hex_upper_unprefixed")]
    proof: Vec<u8>,
    #[serde(with = "::serde_utils::hex_upper_unprefixed")]
    root: Vec<u8>,
    #[serde(with = "::serde_utils::hex_upper_unprefixed")]
    value: Vec<u8>,
}

impl Display for VectorTest {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.name.as_str())
    }
}

impl TestCase for VectorTest {
    fn run(self) -> anyhow::Result<()> {