Merge rust-bitcoin/rust-bitcoin#1039: Fix incorrect argument passed to Error::InvalidSegwitV0ProgramLength and add test
24fdb53c9c
Fix incorrect argument passed to Error::InvalidSegwitV0ProgramLength (eunoia_1729) Pull request description: See also: #995, #1038 ACKs for top commit: sanket1729: utACK24fdb53c9c
. Nice catch apoelstra: ACK24fdb53c9c
tcharding: ACK24fdb53c9c
Tree-SHA512: ced78b69054ec81431399a853291c7bad5b1a49d6683b1ac153a0f1449935bb5d75a31e3d86160602064530959a2ddc3c59a2a2ca268252c42a6805253ead9d0
This commit is contained in:
commit
d363cd2ebc
|
@ -401,7 +401,7 @@ impl Payload {
|
|||
Payload::ScriptHash(ScriptHash::from_inner(hash_inner))
|
||||
} else if script.is_witness_program() {
|
||||
if script.witness_version() == Some(WitnessVersion::V0) && !(script.is_v0_p2wpkh() || script.is_v0_p2wsh()) {
|
||||
return Err(Error::InvalidSegwitV0ProgramLength(script.len()));
|
||||
return Err(Error::InvalidSegwitV0ProgramLength(script.len() - 2));
|
||||
}
|
||||
|
||||
Payload::WitnessProgram {
|
||||
|
@ -1430,9 +1430,11 @@ mod tests {
|
|||
fn test_fail_address_from_script() {
|
||||
let bad_p2wpkh = hex_script!("0014dbc5b0a8f9d4353b4b54c3db48846bb15abfec");
|
||||
let bad_p2wsh = hex_script!("00202d4fa2eb233d008cc83206fa2f4f2e60199000f5b857a835e3172323385623");
|
||||
let invalid_segwitv0_script = hex_script!("001161458e330389cd0437ee9fe3641d70cc18");
|
||||
let expected = Err(Error::UnrecognizedScript);
|
||||
|
||||
assert_eq!(Address::from_script(&bad_p2wpkh, Network::Bitcoin), expected);
|
||||
assert_eq!(Address::from_script(&bad_p2wsh, Network::Bitcoin), expected);
|
||||
assert_eq!(Address::from_script(&invalid_segwitv0_script, Network::Bitcoin), Err(Error::InvalidSegwitV0ProgramLength(17)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue