@@ -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