Merge rust-bitcoin/rust-bitcoin#4327: primitives: Add tests to improve coverage

7e1369b3f1 Cover all TryFrom implementations in Script (Jamil Lambert, PhD)
6dfa3d8f4d Update test to increase coverage (Jamil Lambert, PhD)

Pull request description:

  Update test in borrowed to cover the `default` implementation of `Script`.

  Add tests to cover all `TryFrom` implementations in `Script`

ACKs for top commit:
  apoelstra:
    ACK 7e1369b3f1a7789b2757951c2e3ff58937442200; successfully ran local tests
  tcharding:
    ACK 7e1369b3f1

Tree-SHA512: 766b8eb63abbb1f10670f42b3789a8a4d4d73470ade13f14a1140d4cdd93b49d79865645d49f404774d8ff7aeb22b68059275902dc063d2baaf79fc8a89dca95
This commit is contained in:
merge-script 2025-04-14 13:53:01 +00:00
commit 0089b535ea
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 37 additions and 1 deletions

View File

@ -195,7 +195,7 @@ mod tests {
#[test]
fn script_is_empty() {
let script = Script::new();
let script: &Script = Default::default();
assert!(script.is_empty());
let script = Script::from_bytes(&[1, 2, 3]);

View File

@ -707,6 +707,23 @@ mod tests {
assert!(ScriptHash::try_from(script).is_err());
}
#[test]
fn try_from_scriptbuf_ref_for_scripthash() {
let script = ScriptBuf::from(vec![0x51; 520]);
assert!(ScriptHash::try_from(&script).is_ok());
let script = ScriptBuf::from(vec![0x51; 521]);
assert!(ScriptHash::try_from(&script).is_err());
}
#[test]
fn try_from_script_for_scripthash() {
let script = Script::from_bytes(&[0x51; 520]);
assert!(ScriptHash::try_from(script).is_ok());
let script = Script::from_bytes(&[0x51; 521]);
assert!(ScriptHash::try_from(script).is_err());
}
#[test]
fn try_from_scriptbuf_for_wscript_hash() {
let script = ScriptBuf::from(vec![0x51; 10_000]);
@ -716,6 +733,25 @@ mod tests {
assert!(WScriptHash::try_from(script).is_err());
}
#[test]
fn try_from_scriptbuf_ref_for_wscript_hash() {
let script = ScriptBuf::from(vec![0x51; 10_000]);
assert!(WScriptHash::try_from(&script).is_ok());
let script = ScriptBuf::from(vec![0x51; 10_001]);
assert!(WScriptHash::try_from(&script).is_err());
}
#[test]
fn try_from_script_for_wscript_hash() {
let script = Script::from_bytes(&[0x51; 10_000]);
assert!(WScriptHash::try_from(script).is_ok());
let script = Script::from_bytes(&[0x51; 10_001]);
assert!(WScriptHash::try_from(script).is_err());
}
#[test]
fn script_display() {
let script = Script::from_bytes(&[0xa1, 0xb2, 0xc3]);