File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -137,3 +137,28 @@ impl<'a> Iterator for TlvStream<'a> {
137
137
}
138
138
}
139
139
}
140
+
141
+ #[ cfg( test) ]
142
+ mod tests {
143
+ use bitcoin:: hashes:: { Hash , sha256} ;
144
+
145
+ #[ test]
146
+ fn calculates_merkle_root_hash ( ) {
147
+ // BOLT 12 test vectors
148
+ macro_rules! tlv1 { ( ) => { "010203e8" } }
149
+ macro_rules! tlv2 { ( ) => { "02080000010000020003" } }
150
+ macro_rules! tlv3 { ( ) => { "03310266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c0351800000000000000010000000000000002" } }
151
+ assert_eq ! (
152
+ super :: root_hash( & hex:: decode( tlv1!( ) ) . unwrap( ) ) ,
153
+ sha256:: Hash :: from_slice( & hex:: decode( "b013756c8fee86503a0b4abdab4cddeb1af5d344ca6fc2fa8b6c08938caa6f93" ) . unwrap( ) ) . unwrap( ) ,
154
+ ) ;
155
+ assert_eq ! (
156
+ super :: root_hash( & hex:: decode( concat!( tlv1!( ) , tlv2!( ) ) ) . unwrap( ) ) ,
157
+ sha256:: Hash :: from_slice( & hex:: decode( "c3774abbf4815aa54ccaa026bff6581f01f3be5fe814c620a252534f434bc0d1" ) . unwrap( ) ) . unwrap( ) ,
158
+ ) ;
159
+ assert_eq ! (
160
+ super :: root_hash( & hex:: decode( concat!( tlv1!( ) , tlv2!( ) , tlv3!( ) ) ) . unwrap( ) ) ,
161
+ sha256:: Hash :: from_slice( & hex:: decode( "ab2e79b1283b0b31e0b035258de23782df6b89a38cfa7237bde69aed1a658c5d" ) . unwrap( ) ) . unwrap( ) ,
162
+ ) ;
163
+ }
164
+ }
You can’t perform that action at this time.
0 commit comments