mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-01 19:35:52 +02:00
[tests] Move deterministic address import to setup_nodes
This requires a small changes to a few tests, but means that deterministic addresses will always be imported (unless setup_nodes behaviour is explicitly overridden).
This commit is contained in:
@@ -168,7 +168,6 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
self.skip_test_if_missing_module()
|
||||
self.setup_chain()
|
||||
self.setup_network()
|
||||
self.import_deterministic_coinbase_privkeys()
|
||||
self.run_test()
|
||||
success = TestStatus.PASSED
|
||||
except JSONRPCException as e:
|
||||
@@ -261,11 +260,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
extra_args = self.extra_args
|
||||
self.add_nodes(self.num_nodes, extra_args)
|
||||
self.start_nodes()
|
||||
self.import_deterministic_coinbase_privkeys()
|
||||
|
||||
def import_deterministic_coinbase_privkeys(self):
|
||||
if self.setup_clean_chain:
|
||||
return
|
||||
|
||||
for n in self.nodes:
|
||||
try:
|
||||
n.getwalletinfo()
|
||||
@@ -273,7 +270,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
assert str(e).startswith('Method not found')
|
||||
continue
|
||||
|
||||
n.importprivkey(n.get_deterministic_priv_key().key)
|
||||
n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
|
||||
|
||||
def run_test(self):
|
||||
"""Tests must override this method to define test logic"""
|
||||
|
||||
@@ -199,21 +199,6 @@ class TestNode():
|
||||
|
||||
def generate(self, nblocks, maxtries=1000000):
|
||||
self.log.debug("TestNode.generate() dispatches `generate` call to `generatetoaddress`")
|
||||
# Try to import the node's deterministic private key. This is a no-op if the private key
|
||||
# has already been imported.
|
||||
try:
|
||||
self.rpc.importprivkey(privkey=self.get_deterministic_priv_key().key, label='coinbase', rescan=False)
|
||||
except JSONRPCException as e:
|
||||
# This may fail if:
|
||||
# - wallet is disabled ('Method not found')
|
||||
# - there are multiple wallets to import to ('Wallet file not specified')
|
||||
# - wallet is locked ('Error: Please enter the wallet passphrase with walletpassphrase first')
|
||||
# Just ignore those errors. We can make this tidier by importing the privkey during TestFramework.setup_nodes
|
||||
# TODO: tidy up deterministic privkey import.
|
||||
assert str(e).startswith('Method not found') or \
|
||||
str(e).startswith('Wallet file not specified') or \
|
||||
str(e).startswith('Error: Please enter the wallet passphrase with walletpassphrase first')
|
||||
|
||||
return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries)
|
||||
|
||||
def get_wallet_rpc(self, wallet_name):
|
||||
|
||||
Reference in New Issue
Block a user