tests: Use script hash methods
We have methods to convert a script to a `WScritpHash` and `ScriptHash`, no need to do this manually, let alone use the `psbt::Serialize` trait to do so.
This commit is contained in:
parent
ff08caf17c
commit
013dffa65d
|
@ -9,8 +9,7 @@ use super::*;
|
||||||
use crate::blockdata::opcodes;
|
use crate::blockdata::opcodes;
|
||||||
use crate::consensus::encode::{deserialize, serialize};
|
use crate::consensus::encode::{deserialize, serialize};
|
||||||
use crate::crypto::key::{PublicKey, XOnlyPublicKey};
|
use crate::crypto::key::{PublicKey, XOnlyPublicKey};
|
||||||
use crate::hash_types::{PubkeyHash, ScriptHash, WPubkeyHash, WScriptHash};
|
use crate::hash_types::{PubkeyHash, WPubkeyHash};
|
||||||
use crate::psbt::serialize::Serialize;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
@ -213,12 +212,12 @@ fn script_generators() {
|
||||||
assert!(ScriptBuf::new_v0_p2wpkh(&wpubkey_hash).is_v0_p2wpkh());
|
assert!(ScriptBuf::new_v0_p2wpkh(&wpubkey_hash).is_v0_p2wpkh());
|
||||||
|
|
||||||
let script = Builder::new().push_opcode(OP_NUMEQUAL).push_verify().into_script();
|
let script = Builder::new().push_opcode(OP_NUMEQUAL).push_verify().into_script();
|
||||||
let script_hash = ScriptHash::hash(&script.serialize());
|
let script_hash = script.script_hash();
|
||||||
let p2sh = ScriptBuf::new_p2sh(&script_hash);
|
let p2sh = ScriptBuf::new_p2sh(&script_hash);
|
||||||
assert!(p2sh.is_p2sh());
|
assert!(p2sh.is_p2sh());
|
||||||
assert_eq!(script.to_p2sh(), p2sh);
|
assert_eq!(script.to_p2sh(), p2sh);
|
||||||
|
|
||||||
let wscript_hash = WScriptHash::hash(&script.serialize());
|
let wscript_hash = script.wscript_hash();
|
||||||
let p2wsh = ScriptBuf::new_v0_p2wsh(&wscript_hash);
|
let p2wsh = ScriptBuf::new_v0_p2wsh(&wscript_hash);
|
||||||
assert!(p2wsh.is_v0_p2wsh());
|
assert!(p2wsh.is_v0_p2wsh());
|
||||||
assert_eq!(script.to_v0_p2wsh(), p2wsh);
|
assert_eq!(script.to_v0_p2wsh(), p2wsh);
|
||||||
|
|
Loading…
Reference in New Issue