Skip to content

Commit 648c72e

Browse files
committed
test: vesper serialization
1 parent 32dea7b commit 648c72e

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

commit_verify/src/id.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,14 @@ impl From<Sha256> for StrictHash {
418418
}
419419

420420
#[cfg(test)]
421-
mod tests {
421+
pub(crate) mod tests {
422422
#![cfg_attr(coverage_nightly, coverage(off))]
423423
use super::*;
424424

425425
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
426426
#[derive(StrictType, StrictEncode, StrictDecode)]
427427
#[strict_type(lib = "Test")]
428-
struct DumbConceal(u8);
428+
pub struct DumbConceal(u8);
429429

430430
impl Conceal for DumbConceal {
431431
type Concealed = DumbHash;
@@ -437,14 +437,14 @@ mod tests {
437437
#[strict_type(lib = "Test")]
438438
#[derive(CommitEncode)]
439439
#[commit_encode(crate = self, strategy = strict, id = StrictHash)]
440-
struct DumbHash(u8);
440+
pub struct DumbHash(u8);
441441

442442
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
443443
#[derive(StrictType, StrictEncode, StrictDecode)]
444444
#[strict_type(lib = "Test")]
445445
#[derive(CommitEncode)]
446446
#[commit_encode(crate = self, strategy = strict, id = MerkleHash)]
447-
struct DumbMerkle(u8);
447+
pub struct DumbMerkle(u8);
448448

449449
#[test]
450450
fn commit_engine_strict() {

commit_verify/src/vesper.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,69 @@ impl CommitLayout {
202202
}
203203
}
204204
}
205+
206+
#[cfg(test)]
207+
mod tests {
208+
#![cfg_attr(coverage_nightly, coverage(off))]
209+
210+
use amplify::confinement::{LargeString, SmallOrdMap, SmallOrdSet};
211+
use strict_encoding::{StrictDecode, StrictEncode};
212+
213+
use super::*;
214+
use crate::id::tests::*;
215+
use crate::{CommitEncode, CommitEngine, CommitmentLayout, StrictHash};
216+
217+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
218+
#[derive(StrictType, StrictEncode, StrictDecode)]
219+
#[strict_type(lib = "Test")]
220+
struct NamedWrapper<T: Default + StrictEncode + StrictDecode>(T);
221+
222+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
223+
#[derive(StrictType, StrictEncode, StrictDecode)]
224+
#[strict_type(lib = "Test")]
225+
struct Test {
226+
serialized: NamedWrapper<LargeString>,
227+
concealed: DumbConceal,
228+
hash: DumbHash,
229+
merkle_list: TinyVec<DumbMerkle>,
230+
set: SmallOrdSet<DumbHash>,
231+
map: SmallOrdMap<u8, u64>,
232+
}
233+
impl CommitEncode for Test {
234+
type CommitmentId = StrictHash;
235+
fn commit_encode(&self, e: &mut CommitEngine) {
236+
e.commit_to_serialized(&self.serialized);
237+
e.commit_to_concealed(&self.concealed);
238+
e.commit_to_hash(&self.hash);
239+
e.commit_to_merkle(&self.merkle_list);
240+
e.commit_to_linear_set(&self.set);
241+
e.commit_to_linear_map(&self.map);
242+
}
243+
}
244+
245+
#[test]
246+
fn display() {
247+
let layout = Test::commitment_layout();
248+
assert_eq!(
249+
layout
250+
.to_vesper()
251+
.display()
252+
.to_string()
253+
.replace(" \n", "\n"),
254+
r#"commitment StrictHash: for Test, hasher SHA256, tagged urn:ubideco:strict-types:value-hash#2024-02-10
255+
serialize NamedWrapperConfinedString04294967295
256+
conceal DumbConceal: to DumbHash
257+
serialize DumbHash
258+
hash DumbHash
259+
serialize DumbHash
260+
merklize DumbMerkle
261+
serialize DumbMerkle
262+
set DumbHash: len 0..<2^16
263+
element DumbHash
264+
map U64: len 0..<2^16
265+
mapKey U8
266+
mapValue U64
267+
"#
268+
);
269+
}
270+
}

0 commit comments

Comments
 (0)