@@ -21,6 +21,15 @@ use serialization::{Decode, Encode};
2121
2222use super :: { timelock:: OutputTimeLock , Destination } ;
2323
24+ fixed_hash:: construct_fixed_hash! {
25+ #[ derive( Encode , Decode , serde:: Serialize , serde:: Deserialize ) ]
26+ pub struct SecretHash ( 20 ) ;
27+ }
28+
29+ impl rpc_description:: HasValueHint for SecretHash {
30+ const HINT_SER : rpc_description:: ValueHint = rpc_description:: ValueHint :: HEX_STRING ;
31+ }
32+
2433#[ derive( Debug , Clone , PartialEq , Eq , Encode , Decode , serde:: Serialize , serde:: Deserialize ) ]
2534pub struct HashedTimelockContract {
2635 // can be spent either by a specific address that knows the secret
@@ -108,19 +117,24 @@ mod tests {
108117 }
109118
110119 #[ rstest]
111- #[ case( "\" 0000000000000000000000000000000000000000\" " ) ]
112- #[ case( "\" 0000000000000000000000000000000000000001\" " ) ]
113- #[ case( "\" ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd\" " ) ]
114- #[ case( "\" e4732fe6f1ed1cddc2ed4b328fff5224276e3f6f\" " ) ]
115- #[ case( "\" 0103b9683e51e5aba83b8a34c9b98ce67d66136c\" " ) ]
116- fn deserialize_valid ( #[ case] s : String ) {
117- serde_json:: from_str :: < HtlcSecretHash > ( & s) . unwrap ( ) ;
120+ #[ case( "\" 0000000000000000000000000000000000000000\" " , [ 0 ; 20 ] ) ]
121+ #[ case( "\" 0000000000000000000000000000000000000001\" " , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ) ]
122+ #[ case( "\" ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd\" " , [ 0xac , 0x7b , 0x96 , 0x0a , 0x8d , 0x03 , 0x70 , 0x5d , 0x1a , 0xce , 0x08 , 0xb1 , 0xa1 , 0x9d , 0xa3 , 0xfd , 0xcc , 0x99 , 0xdd , 0xbd ] ) ]
123+ #[ case( "\" e4732fe6f1ed1cddc2ed4b328fff5224276e3f6f\" " , [ 0xe4 , 0x73 , 0x2f , 0xe6 , 0xf1 , 0xed , 0x1c , 0xdd , 0xc2 , 0xed , 0x4b , 0x32 , 0x8f , 0xff , 0x52 , 0x24 , 0x27 , 0x6e , 0x3f , 0x6f ] ) ]
124+ #[ case( "\" 0103b9683e51e5aba83b8a34c9b98ce67d66136c\" " , [ 0x01 , 0x03 , 0xb9 , 0x68 , 0x3e , 0x51 , 0xe5 , 0xab , 0xa8 , 0x3b , 0x8a , 0x34 , 0xc9 , 0xb9 , 0x8c , 0xe6 , 0x7d , 0x66 , 0x13 , 0x6c ] ) ]
125+ fn deserialize_valid ( #[ case] str : String , #[ case] expected : [ u8 ; 20 ] ) {
126+ let result = serde_json:: from_str :: < HtlcSecretHash > ( & str) . unwrap ( ) ;
127+ assert_eq ! ( result, HtlcSecretHash :: from_slice( & expected) ) ;
118128 }
119129
120130 #[ rstest]
121- #[ case( "\" 00000000000000000000000000000000000000000000000000000000000000\" " ) ]
122- #[ case( "\" 000000000000000000000000000000000invalid\" " ) ]
123- fn deserialize_invalid ( #[ case] s : String ) {
124- serde_json:: from_str :: < HtlcSecretHash > ( & s) . unwrap_err ( ) ;
131+ #[ case(
132+ "\" 00000000000000000000000000000000000000000000000000000000000000\" " ,
133+ "Invalid input length"
134+ ) ]
135+ #[ case( "\" 000000000000000000000000000000000invalid\" " , "Invalid character" ) ]
136+ fn deserialize_invalid ( #[ case] s : String , #[ case] expected_msg : String ) {
137+ let err = serde_json:: from_str :: < HtlcSecretHash > ( & s) . unwrap_err ( ) ;
138+ assert ! ( err. to_string( ) . contains( & expected_msg) ) ;
125139 }
126140}
0 commit comments