Skip to content

Commit 3a83a01

Browse files
committed
[tests] move generate_wif_key to wallet_util.py
generate_wif_key is a wallet utility function. Move it from the EC key module to the wallet util module.
1 parent b216b0b commit 3a83a01

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

test/functional/rpc_createmultisig.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
from test_framework.authproxy import JSONRPCException
1313
from test_framework.descriptors import descsum_create, drop_origins
14-
from test_framework.key import ECPubKey, ECKey, bytes_to_wif
14+
from test_framework.key import ECPubKey, ECKey
1515
from test_framework.test_framework import BitcoinTestFramework
1616
from test_framework.util import (
1717
assert_raises_rpc_error,
1818
assert_equal,
1919
)
20+
from test_framework.wallet_util import bytes_to_wif
2021

2122
class RpcCreateMultiSigTest(BitcoinTestFramework):
2223
def set_test_params(self):

test/functional/test_framework/key.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
anything but tests."""
99
import random
1010

11-
from .address import byte_to_base58
12-
1311
def modinv(a, n):
1412
"""Compute the modular inverse of a modulo n
1513
@@ -386,14 +384,3 @@ def sign_ecdsa(self, msg, low_s=True):
386384
rb = r.to_bytes((r.bit_length() + 8) // 8, 'big')
387385
sb = s.to_bytes((s.bit_length() + 8) // 8, 'big')
388386
return b'\x30' + bytes([4 + len(rb) + len(sb), 2, len(rb)]) + rb + bytes([2, len(sb)]) + sb
389-
390-
def bytes_to_wif(b, compressed=True):
391-
if compressed:
392-
b += b'\x01'
393-
return byte_to_base58(b, 239)
394-
395-
def generate_wif_key():
396-
# Makes a WIF privkey for imports
397-
k = ECKey()
398-
k.generate()
399-
return bytes_to_wif(k.get_bytes(), k.is_compressed)

test/functional/test_framework/wallet_util.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
from collections import namedtuple
77

88
from test_framework.address import (
9+
byte_to_base58,
910
key_to_p2pkh,
1011
key_to_p2sh_p2wpkh,
1112
key_to_p2wpkh,
1213
script_to_p2sh,
1314
script_to_p2sh_p2wsh,
1415
script_to_p2wsh,
1516
)
16-
from test_framework.key import (
17-
bytes_to_wif,
18-
ECKey,
19-
)
17+
from test_framework.key import ECKey
2018
from test_framework.script import (
2119
CScript,
2220
OP_0,
@@ -120,3 +118,14 @@ def test_address(node, address, **kwargs):
120118
raise AssertionError("key {} unexpectedly returned in getaddressinfo.".format(key))
121119
elif addr_info[key] != value:
122120
raise AssertionError("key {} value {} did not match expected value {}".format(key, addr_info[key], value))
121+
122+
def bytes_to_wif(b, compressed=True):
123+
if compressed:
124+
b += b'\x01'
125+
return byte_to_base58(b, 239)
126+
127+
def generate_wif_key():
128+
# Makes a WIF privkey for imports
129+
k = ECKey()
130+
k.generate()
131+
return bytes_to_wif(k.get_bytes(), k.is_compressed)

0 commit comments

Comments
 (0)