File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -947,4 +947,26 @@ mod tests {
947947 assert ! ( CheckedHrpstring :: new:: <Bech32 >( valid) . is_ok( ) )
948948 }
949949 }
950+
951+ macro_rules! check_invalid_segwit_addresses {
952+ ( $( $test_name: ident, $reason: literal, $address: literal) ;* $( ; ) ?) => {
953+ $(
954+ #[ test]
955+ fn $test_name( ) {
956+ let res = SegwitHrpstring :: new( $address) ;
957+ if res. is_ok( ) {
958+ panic!( "{} sting should not be valid: {}" , $address, $reason) ;
959+ }
960+ }
961+ ) *
962+ }
963+ }
964+ check_invalid_segwit_addresses ! {
965+ invalid_segwit_address_0, "missing hrp" , "1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq" ;
966+ invalid_segwit_address_1, "missing data-checksum" , "91111" ;
967+ invalid_segwit_address_2, "invalid witness version" , "bc14r0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq" ;
968+ invalid_segwit_address_3, "invalid checksum length" , "bc1q5mdq" ;
969+ invalid_segwit_address_4, "missing data" , "bc1qwf5mdq" ;
970+ invalid_segwit_address_5, "invalid program length" , "bc14r0srrr7xfkvy5l643lydnw9rewf5mdq" ;
971+ }
950972}
You can’t perform that action at this time.
0 commit comments