Cover all TryFrom implementations in Script

Add tests to cover `TryFrom` implementations in `Script`
This commit is contained in:
Jamil Lambert, PhD 2025-03-20 15:14:18 +00:00
parent 6dfa3d8f4d
commit 7e1369b3f1
No known key found for this signature in database
GPG Key ID: 54DC29234AB5D2C0
1 changed files with 36 additions and 0 deletions

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]);