mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 12:03:04 +02:00
test: refactor: introduce generate_keypair
helper with WIF support
In functional tests it is a quite common scenario to generate fresh elliptic curve keypairs, which is currently a bit cumbersome as it involves multiple steps, e.g.: privkey = ECKey() privkey.generate() privkey_wif = bytes_to_wif(privkey.get_bytes()) pubkey = privkey.get_pubkey().get_bytes() Simplify this by providing a new `generate_keypair` helper function that returns the private key either as `ECKey` object or as WIF-string (depending on the boolean `wif` parameter) and the public key as byte-string; these formats are what we mostly need (currently we don't use `ECPubKey` objects from generated keypairs anywhere). With this, most of the affected code blocks following the pattern above can be replaced by one-liners, e.g.: privkey, pubkey = generate_keypair(wif=True) Note that after this commit, the only direct uses of `ECKey` remain in situations where we want to set the private key explicitly, e.g. in MiniWallet (test/functional/test_framework/wallet.py) or the test for the signet miner script (test/functional/tool_signet_miner.py).
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
"""Test dust limit mempool policy (`-dustrelayfee` parameter)"""
|
||||
from decimal import Decimal
|
||||
|
||||
from test_framework.key import ECKey
|
||||
from test_framework.messages import (
|
||||
COIN,
|
||||
CTxOut,
|
||||
@@ -32,6 +31,7 @@ from test_framework.util import (
|
||||
get_fee,
|
||||
)
|
||||
from test_framework.wallet import MiniWallet
|
||||
from test_framework.wallet_util import generate_keypair
|
||||
|
||||
|
||||
DUST_RELAY_TX_FEE = 3000 # default setting [sat/kvB]
|
||||
@@ -74,11 +74,8 @@ class DustRelayFeeTest(BitcoinTestFramework):
|
||||
self.wallet = MiniWallet(self.nodes[0])
|
||||
|
||||
# prepare output scripts of each standard type
|
||||
key = ECKey()
|
||||
key.generate(compressed=False)
|
||||
uncompressed_pubkey = key.get_pubkey().get_bytes()
|
||||
key.generate(compressed=True)
|
||||
pubkey = key.get_pubkey().get_bytes()
|
||||
_, uncompressed_pubkey = generate_keypair(compressed=False)
|
||||
_, pubkey = generate_keypair(compressed=True)
|
||||
|
||||
output_scripts = (
|
||||
(key_to_p2pk_script(uncompressed_pubkey), "P2PK (uncompressed)"),
|
||||
|
Reference in New Issue
Block a user