1+ #[ cfg( feature = "smtc" ) ]
12use std:: convert:: TryInto ;
23
34use crate :: * ;
45use blake2b_rs:: { Blake2b , Blake2bBuilder } ;
56use default_store:: DefaultStore ;
7+ #[ cfg( feature = "smtc" ) ]
68use hex:: decode;
79use proptest:: prelude:: * ;
810use traits:: Hasher ;
911
12+ #[ cfg( feature = "smtc" ) ]
1013fn str_to_h256 ( src : & str ) -> H256 {
1114 let src = decode ( src) . unwrap ( ) ;
1215 assert ! ( src. len( ) == 32 ) ;
1316 let data: [ u8 ; 32 ] = src. try_into ( ) . unwrap ( ) ;
1417 H256 :: from ( data)
1518}
1619
20+ #[ cfg( feature = "smtc" ) ]
1721fn str_to_vec ( src : & str ) -> Vec < u8 > {
1822 decode ( src) . unwrap ( )
1923}
2024
25+ #[ cfg( feature = "smtc" ) ]
2126#[ test]
2227fn test_ckb_smt_verify1 ( ) {
2328 let key = str_to_h256 ( "381dc5391dab099da5e28acd1ad859a051cf18ace804d037f12819c6fbc0e18b" ) ;
@@ -33,6 +38,7 @@ fn test_ckb_smt_verify1() {
3338 assert ! ( smt. verify( & root_hash, & proof) . is_ok( ) ) ;
3439}
3540
41+ #[ cfg( feature = "smtc" ) ]
3642#[ test]
3743fn test_ckb_smt_verify2 ( ) {
3844 let key = str_to_h256 ( "a9bb945be71f0bd2757d33d2465b6387383da42f321072e47472f0c9c7428a8a" ) ;
@@ -48,6 +54,7 @@ fn test_ckb_smt_verify2() {
4854 assert ! ( smt. verify( & root_hash, & proof) . is_ok( ) ) ;
4955}
5056
57+ #[ cfg( feature = "smtc" ) ]
5158#[ test]
5259fn test_ckb_smt_verify3 ( ) {
5360 let key = str_to_h256 ( "e8c0265680a02b680b6cbc880348f062b825b28e237da7169aded4bcac0a04e5" ) ;
@@ -63,6 +70,7 @@ fn test_ckb_smt_verify3() {
6370 assert ! ( smt. verify( & root_hash, & proof) . is_ok( ) ) ;
6471}
6572
73+ #[ cfg( feature = "smtc" ) ]
6674#[ test]
6775fn test_ckb_smt_verify_invalid ( ) {
6876 let key = str_to_h256 ( "e8c0265680a02b680b6cbc880348f062b825b28e237da7169aded4bcac0a04e5" ) ;
@@ -136,11 +144,14 @@ proptest! {
136144 . verify:: <CkbBlake2bHasher >( tree. root( ) , vec![ ( key, value) ] )
137145 . expect( "verify compiled one proof" ) ) ;
138146
139- let compiled_proof_bin: Vec <u8 > = compiled_proof. into( ) ;
140- let smt_state = SMTBuilder :: new( ) ;
141- let smt_state = smt_state. insert( & key, & value) . unwrap( ) ;
142- let smt = smt_state. build( ) . unwrap( ) ;
143- smt. verify( tree. root( ) , & compiled_proof_bin) . expect( "verify with c" ) ;
147+ #[ cfg( feature = "smtc" ) ]
148+ {
149+ let compiled_proof_bin: Vec <u8 > = compiled_proof. into( ) ;
150+ let smt_state = SMTBuilder :: new( ) ;
151+ let smt_state = smt_state. insert( & key, & value) . unwrap( ) ;
152+ let smt = smt_state. build( ) . unwrap( ) ;
153+ smt. verify( tree. root( ) , & compiled_proof_bin) . expect( "verify with c" ) ;
154+ }
144155 }
145156 }
146157}
0 commit comments