mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-01 00:34:01 +02:00
Merge bitcoin/bitcoin#23118: test: refactor: introduce script_util helper for creating P2PK scripts
429b49378etest: introduce script_util helper for creating P2PK scripts (Sebastian Falbesoner) Pull request description: This PR is a follow-up to #22363, which took use of already existing `script_util` helpers to get rid of manual CScript for the P2{PKH,SH,WPKH,WSH} output types, in order to increase readability and maintainability of the test code. Here the same is done for P2PK scripts by introducing a helper `key_to_p2pk_script` and using it. Note that the helper only accepts ECDSA pubkeys (i.e. ones with a size of 33 or 65 bytes), hence it can't be used for scripts in the form of [x-only-pubkey, OP_CHECKSIG]. ACKs for top commit: brunoerg: Code review ACK429b49378elaanwj: Code review ACK429b49378erajarshimaitra: Concept + tACK429b49378eTree-SHA512: 984aea01eba5f38a328d69905d90a3a36f0a02419ca3e5baf3c8095895fb094e3780c7da16fad5851db3847bdb05ce8cda244ab09b79b8aa9602dfb3c5e0414c
This commit is contained in:
@@ -24,12 +24,14 @@ from test_framework.messages import (
|
||||
from test_framework.script import (
|
||||
CScript,
|
||||
LegacySignatureHash,
|
||||
OP_CHECKSIG,
|
||||
OP_TRUE,
|
||||
OP_NOP,
|
||||
SIGHASH_ALL,
|
||||
)
|
||||
from test_framework.script_util import key_to_p2wpkh_script
|
||||
from test_framework.script_util import (
|
||||
key_to_p2pk_script,
|
||||
key_to_p2wpkh_script,
|
||||
)
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_greater_than_or_equal,
|
||||
@@ -75,7 +77,7 @@ class MiniWallet:
|
||||
self._priv_key = ECKey()
|
||||
self._priv_key.set((1).to_bytes(32, 'big'), True)
|
||||
pub_key = self._priv_key.get_pubkey()
|
||||
self._scriptPubKey = bytes(CScript([pub_key.get_bytes(), OP_CHECKSIG]))
|
||||
self._scriptPubKey = key_to_p2pk_script(pub_key.get_bytes())
|
||||
elif mode == MiniWalletMode.ADDRESS_OP_TRUE:
|
||||
self._address = ADDRESS_BCRT1_P2WSH_OP_TRUE
|
||||
self._scriptPubKey = bytes.fromhex(self._test_node.validateaddress(self._address)['scriptPubKey'])
|
||||
|
||||
Reference in New Issue
Block a user