Skip to content

Commit f211d7b

Browse files
committed
Move test helper function
Move helper function to above the test that uses it. Refactor only, no logic changes.
1 parent f236f45 commit f211d7b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/blockdata/transaction.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,25 +1082,6 @@ mod tests {
10821082
serde_round_trip!(tx);
10831083
}
10841084

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-
11041085
// Test decoding transaction `4be105f158ea44aec57bf12c5817d073a712ab131df6f37786872cfc70734188`
11051086
// from testnet, which is the first BIP144-encoded transaction I encountered.
11061087
#[test]
@@ -1155,6 +1136,25 @@ mod tests {
11551136
assert_eq!(EcdsaSigHashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSigHashType(0x04)));
11561137
}
11571138

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+
11581158
// These test vectors were stolen from libbtc, which is Copyright 2014 Jonas Schnelli MIT
11591159
// They were transformed by replacing {...} with run_test_sighash(...), then the ones containing
11601160
// OP_CODESEPARATOR in their pubkeys were removed

0 commit comments

Comments
 (0)