Merge rust-bitcoin/rust-bitcoin#825: test: Add a test for incorrect message signature in `is_signed_by_address`
e391ce9939
test: Add a test for incorrect message signature (Andrew Ahlers) Pull request description: In response to this comment: https://github.com/rust-bitcoin/rust-bitcoin/pull/819#discussion_r801477961 This should be straightforward. Let me know if there are any style issues. I tried to keep things similar to the existing test while cutting out any extra cruft to keep things small. ACKs for top commit: apoelstra: ACKe391ce9939
Kixunil: ACKe391ce9939
dr-orlovsky: ACKe391ce9939
Tree-SHA512: 47296a7e0b2f45d5e50f507727ae4360686730a386f37dedfd1360b8cdf4b9dd3ce3bb5d05ea630177379ce4109059b6924fa362396b984ebab0ed1754318627
This commit is contained in:
commit
60d941621d
|
@ -349,4 +349,28 @@ mod tests {
|
||||||
Err(MessageSignatureError::UnsupportedAddressType(AddressType::P2sh))
|
Err(MessageSignatureError::UnsupportedAddressType(AddressType::P2sh))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(all(feature = "secp-recovery", feature = "base64"))]
|
||||||
|
fn test_incorrect_message_signature() {
|
||||||
|
use secp256k1;
|
||||||
|
use util::key::PublicKey;
|
||||||
|
|
||||||
|
let secp = secp256k1::Secp256k1::new();
|
||||||
|
let message = "a different message from what was signed";
|
||||||
|
let msg_hash = super::signed_msg_hash(&message);
|
||||||
|
|
||||||
|
// Signature of msg = "rust-bitcoin MessageSignature test"
|
||||||
|
// Signed with pk "UuOGDsfLPr4HIMKQX0ipjJeRaj1geCq3yPUF2COP5ME="
|
||||||
|
let signature_base64 = "IAM2qX24tYx/bdBTIgVLhD8QEAjrPlJpmjB4nZHdRYGIBa4DmVulAcwjPnWe6Q5iEwXH6F0pUCJP/ZeHPWS1h1o=";
|
||||||
|
let pubkey_base64 = "A1FTfMEntPpAty3qkEo0q2Dc1FEycI10a3jmwEFy+Qr6";
|
||||||
|
let signature = super::MessageSignature::from_base64(signature_base64).expect("message signature");
|
||||||
|
|
||||||
|
let pubkey = PublicKey::from_slice(
|
||||||
|
&::base64::decode(&pubkey_base64).expect("base64 string")
|
||||||
|
).expect("pubkey slice");
|
||||||
|
|
||||||
|
let p2pkh = ::Address::p2pkh(&pubkey, ::Network::Bitcoin);
|
||||||
|
assert_eq!(signature.is_signed_by_address(&secp, &p2pkh, msg_hash), Ok(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue