@@ -1082,25 +1082,6 @@ mod tests {
1082
1082
serde_round_trip ! ( tx) ;
1083
1083
}
1084
1084
1085
- fn run_test_sighash ( tx : & str , script : & str , input_index : usize , hash_type : i32 , expected_result : & str ) {
1086
- let tx: Transaction = deserialize ( & Vec :: from_hex ( tx) . unwrap ( ) [ ..] ) . unwrap ( ) ;
1087
- let script = Script :: from ( Vec :: from_hex ( script) . unwrap ( ) ) ;
1088
- let mut raw_expected = Vec :: from_hex ( expected_result) . unwrap ( ) ;
1089
- raw_expected. reverse ( ) ;
1090
- let expected_result = SigHash :: from_slice ( & raw_expected[ ..] ) . unwrap ( ) ;
1091
-
1092
- let actual_result = if raw_expected[ 0 ] % 2 == 0 {
1093
- // tx.signature_hash and cache.legacy_signature_hash are the same, this if helps to test
1094
- // both the codepaths without repeating the test code
1095
- tx. signature_hash ( input_index, & script, hash_type as u32 )
1096
- } else {
1097
- let cache = SigHashCache :: new ( & tx) ;
1098
- cache. legacy_signature_hash ( input_index, & script, hash_type as u32 ) . unwrap ( )
1099
- } ;
1100
-
1101
- assert_eq ! ( actual_result, expected_result) ;
1102
- }
1103
-
1104
1085
// Test decoding transaction `4be105f158ea44aec57bf12c5817d073a712ab131df6f37786872cfc70734188`
1105
1086
// from testnet, which is the first BIP144-encoded transaction I encountered.
1106
1087
#[ test]
@@ -1155,6 +1136,25 @@ mod tests {
1155
1136
assert_eq ! ( EcdsaSigHashType :: from_u32_standard( nonstandard_hashtype) , Err ( NonStandardSigHashType ( 0x04 ) ) ) ;
1156
1137
}
1157
1138
1139
+ fn run_test_sighash ( tx : & str , script : & str , input_index : usize , hash_type : i32 , expected_result : & str ) {
1140
+ let tx: Transaction = deserialize ( & Vec :: from_hex ( tx) . unwrap ( ) [ ..] ) . unwrap ( ) ;
1141
+ let script = Script :: from ( Vec :: from_hex ( script) . unwrap ( ) ) ;
1142
+ let mut raw_expected = Vec :: from_hex ( expected_result) . unwrap ( ) ;
1143
+ raw_expected. reverse ( ) ;
1144
+ let expected_result = SigHash :: from_slice ( & raw_expected[ ..] ) . unwrap ( ) ;
1145
+
1146
+ let actual_result = if raw_expected[ 0 ] % 2 == 0 {
1147
+ // tx.signature_hash and cache.legacy_signature_hash are the same, this if helps to test
1148
+ // both the codepaths without repeating the test code
1149
+ tx. signature_hash ( input_index, & script, hash_type as u32 )
1150
+ } else {
1151
+ let cache = SigHashCache :: new ( & tx) ;
1152
+ cache. legacy_signature_hash ( input_index, & script, hash_type as u32 ) . unwrap ( )
1153
+ } ;
1154
+
1155
+ assert_eq ! ( actual_result, expected_result) ;
1156
+ }
1157
+
1158
1158
// These test vectors were stolen from libbtc, which is Copyright 2014 Jonas Schnelli MIT
1159
1159
// They were transformed by replacing {...} with run_test_sighash(...), then the ones containing
1160
1160
// OP_CODESEPARATOR in their pubkeys were removed
0 commit comments