Merge #18788: tests: Update more tests to work with descriptor wallets
c7b7e0a692
tests: Make only desc wallets for wallet_multwallet.py --descriptors (Andrew Chow)d4b67ad214
Avoid creating legacy wallets in wallet_importdescriptors.py (Andrew Chow)6c9c12bf87
Update feature_backwards_compatibility for descriptor wallets (Andrew Chow)9a4c631e1c
Update wallet_labels.py to not require descriptors=False (Andrew Chow)242aed7cc1
tests: Add a --legacy-wallet that is mutually exclusive with --descriptors (Andrew Chow)388053e172
Disable some tests for tool_wallet when descriptors (Andrew Chow)47d3243160
Make raw multisig tests legacy wallet only in rpc_rawtransaction.py (Andrew Chow)59d3da5bce
Do addmultisigaddress tests in legacy wallet mode in wallet_address_types.py (Andrew Chow)25bc5dccbf
Use importdescriptors when in descriptor wallet mode in wallet_createwallet.py (Andrew Chow)0bd1860300
Avoid dumpprivkey and watchonly behavior in rpc_signrawtransaction.py (Andrew Chow)08067aebfd
Add script equivalent of functions in address.py (Andrew Chow)86968882a8
Add descriptor wallet output to tool_wallet.py (Andrew Chow)3457679870
Use separate watchonly wallet for multisig in feature_nulldummy.py (Andrew Chow)a42652ec10
Move import and watchonly tests to be legacy wallet only in wallet_balance.py (Andrew Chow)4b871909d6
Use importdescriptors for descriptor wallets in wallet_bumpfee.py (Andrew Chow)c2711e4230
Avoid dumpprivkey in wallet_listsinceblock.py (Andrew Chow)553dbf9af4
Make import tests in wallet_listtransactions.py legacy wallet only (Andrew Chow)dc81418fd0
Use a separate watchonly wallet in rpc_fundrawtransaction.py (Andrew Chow)a357111047
Update wallet_importprunedfunds to avoid dumpprivkey (Andrew Chow) Pull request description: I went through all the tests and checked whether they passed with descriptor wallets. This partially informed some changes in #16528. Some tests needed changes to work with descriptor wallets. These were primarily due to import and watchonly behavior. There are some tests and test cases that only test legacy wallet behavior so those tests won't be run with descriptor wallets. This PR updates more tests to have to the `--descriptors` switch in `test_runner.py`. Additionally a mutually exclusive `--legacy-wallet` option has been added to force legacy wallets. This does nothing currently but will be useful in the future when descriptor wallets are the default. For the tests that rely on legacy wallet behavior, this option is being set so that we don't forget in the future. Those tests are `feature_segwit.py`, `wallet_watchonly.py`, `wallet_implicitsegwit.py`, `wallet_import_with_label.py`, and `wallet_import_with_label.py`. If you invert the `--descriptors`/`--legacy-wallet` default so that descriptor wallets are the default, all tests (besides the legacy wallet specific ones) will pass. ACKs for top commit: MarcoFalke: review ACKc7b7e0a692
🎿 laanwj: ACKc7b7e0a692
Tree-SHA512: 2f4e87815005d1d0a2543ea7947f7cd7593d8cf5312228ef85f8e096f19739b225769961943049cb44f6f07a35b8de988e2246ab9aca5bb5a0b2e62694d5637d
This commit is contained in:
commit
ef4c7c4e0b
20 changed files with 694 additions and 365 deletions
|
@ -27,6 +27,7 @@ from test_framework.descriptors import descsum_create
|
||||||
|
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# w1: regular wallet, created on master: update this test when default
|
# w1: regular wallet, created on master: update this test when default
|
||||||
# wallets can no longer be opened by older versions.
|
# wallets can no longer be opened by older versions.
|
||||||
node_master.rpc.createwallet(wallet_name="w1")
|
node_master.createwallet(wallet_name="w1")
|
||||||
wallet = node_master.get_wallet_rpc("w1")
|
wallet = node_master.get_wallet_rpc("w1")
|
||||||
info = wallet.getwalletinfo()
|
info = wallet.getwalletinfo()
|
||||||
assert info['private_keys_enabled']
|
assert info['private_keys_enabled']
|
||||||
|
@ -127,7 +128,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
# w2: wallet with private keys disabled, created on master: update this
|
# w2: wallet with private keys disabled, created on master: update this
|
||||||
# test when default wallets private keys disabled can no longer be
|
# test when default wallets private keys disabled can no longer be
|
||||||
# opened by older versions.
|
# opened by older versions.
|
||||||
node_master.rpc.createwallet(wallet_name="w2", disable_private_keys=True)
|
node_master.createwallet(wallet_name="w2", disable_private_keys=True)
|
||||||
wallet = node_master.get_wallet_rpc("w2")
|
wallet = node_master.get_wallet_rpc("w2")
|
||||||
info = wallet.getwalletinfo()
|
info = wallet.getwalletinfo()
|
||||||
assert info['private_keys_enabled'] == False
|
assert info['private_keys_enabled'] == False
|
||||||
|
@ -149,7 +150,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# w3: blank wallet, created on master: update this
|
# w3: blank wallet, created on master: update this
|
||||||
# test when default blank wallets can no longer be opened by older versions.
|
# test when default blank wallets can no longer be opened by older versions.
|
||||||
node_master.rpc.createwallet(wallet_name="w3", blank=True)
|
node_master.createwallet(wallet_name="w3", blank=True)
|
||||||
wallet = node_master.get_wallet_rpc("w3")
|
wallet = node_master.get_wallet_rpc("w3")
|
||||||
info = wallet.getwalletinfo()
|
info = wallet.getwalletinfo()
|
||||||
assert info['private_keys_enabled']
|
assert info['private_keys_enabled']
|
||||||
|
@ -215,6 +216,8 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
os.path.join(node_v19_wallets_dir, wallet)
|
os.path.join(node_v19_wallets_dir, wallet)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# Descriptor wallets break compatibility, only run this test for legacy wallet
|
||||||
# Open the wallets in v0.19
|
# Open the wallets in v0.19
|
||||||
node_v19.loadwallet("w1")
|
node_v19.loadwallet("w1")
|
||||||
wallet = node_v19.get_wallet_rpc("w1")
|
wallet = node_v19.get_wallet_rpc("w1")
|
||||||
|
@ -277,6 +280,26 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
assert info['private_keys_enabled']
|
assert info['private_keys_enabled']
|
||||||
assert info['keypoolsize'] == 0
|
assert info['keypoolsize'] == 0
|
||||||
|
|
||||||
|
node_v17.loadwallet("w1")
|
||||||
|
wallet = node_v17.get_wallet_rpc("w1")
|
||||||
|
info = wallet.getwalletinfo()
|
||||||
|
assert info['private_keys_enabled']
|
||||||
|
assert info['keypoolsize'] > 0
|
||||||
|
|
||||||
|
node_v17.loadwallet("w2")
|
||||||
|
wallet = node_v17.get_wallet_rpc("w2")
|
||||||
|
info = wallet.getwalletinfo()
|
||||||
|
assert info['private_keys_enabled'] == False
|
||||||
|
assert info['keypoolsize'] == 0
|
||||||
|
else:
|
||||||
|
# Descriptor wallets appear to be corrupted wallets to old software
|
||||||
|
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node_v19.loadwallet, "w1")
|
||||||
|
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node_v19.loadwallet, "w2")
|
||||||
|
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node_v19.loadwallet, "w3")
|
||||||
|
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node_v18.loadwallet, "w1")
|
||||||
|
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node_v18.loadwallet, "w2")
|
||||||
|
assert_raises_rpc_error(-4, "Wallet file verification failed: wallet.dat corrupt, salvage failed", node_v18.loadwallet, "w3")
|
||||||
|
|
||||||
# Open the wallets in v0.17
|
# Open the wallets in v0.17
|
||||||
node_v17.loadwallet("w1_v18")
|
node_v17.loadwallet("w1_v18")
|
||||||
wallet = node_v17.get_wallet_rpc("w1_v18")
|
wallet = node_v17.get_wallet_rpc("w1_v18")
|
||||||
|
@ -284,24 +307,12 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
assert info['private_keys_enabled']
|
assert info['private_keys_enabled']
|
||||||
assert info['keypoolsize'] > 0
|
assert info['keypoolsize'] > 0
|
||||||
|
|
||||||
node_v17.loadwallet("w1")
|
|
||||||
wallet = node_v17.get_wallet_rpc("w1")
|
|
||||||
info = wallet.getwalletinfo()
|
|
||||||
assert info['private_keys_enabled']
|
|
||||||
assert info['keypoolsize'] > 0
|
|
||||||
|
|
||||||
node_v17.loadwallet("w2_v18")
|
node_v17.loadwallet("w2_v18")
|
||||||
wallet = node_v17.get_wallet_rpc("w2_v18")
|
wallet = node_v17.get_wallet_rpc("w2_v18")
|
||||||
info = wallet.getwalletinfo()
|
info = wallet.getwalletinfo()
|
||||||
assert info['private_keys_enabled'] == False
|
assert info['private_keys_enabled'] == False
|
||||||
assert info['keypoolsize'] == 0
|
assert info['keypoolsize'] == 0
|
||||||
|
|
||||||
node_v17.loadwallet("w2")
|
|
||||||
wallet = node_v17.get_wallet_rpc("w2")
|
|
||||||
info = wallet.getwalletinfo()
|
|
||||||
assert info['private_keys_enabled'] == False
|
|
||||||
assert info['keypoolsize'] == 0
|
|
||||||
|
|
||||||
# RPC loadwallet failure causes bitcoind to exit, in addition to the RPC
|
# RPC loadwallet failure causes bitcoind to exit, in addition to the RPC
|
||||||
# call failure, so the following test won't work:
|
# call failure, so the following test won't work:
|
||||||
# assert_raises_rpc_error(-4, "Wallet loading failed.", node_v17.loadwallet, 'w3_v18')
|
# assert_raises_rpc_error(-4, "Wallet loading failed.", node_v17.loadwallet, 'w3_v18')
|
||||||
|
@ -309,9 +320,17 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||||
# Instead, we stop node and try to launch it with the wallet:
|
# Instead, we stop node and try to launch it with the wallet:
|
||||||
self.stop_node(4)
|
self.stop_node(4)
|
||||||
node_v17.assert_start_raises_init_error(["-wallet=w3_v18"], "Error: Error loading w3_v18: Wallet requires newer version of Bitcoin Core")
|
node_v17.assert_start_raises_init_error(["-wallet=w3_v18"], "Error: Error loading w3_v18: Wallet requires newer version of Bitcoin Core")
|
||||||
|
if self.options.descriptors:
|
||||||
|
# Descriptor wallets appear to be corrupted wallets to old software
|
||||||
|
node_v17.assert_start_raises_init_error(["-wallet=w1"], "Error: wallet.dat corrupt, salvage failed")
|
||||||
|
node_v17.assert_start_raises_init_error(["-wallet=w2"], "Error: wallet.dat corrupt, salvage failed")
|
||||||
|
node_v17.assert_start_raises_init_error(["-wallet=w3"], "Error: wallet.dat corrupt, salvage failed")
|
||||||
|
else:
|
||||||
node_v17.assert_start_raises_init_error(["-wallet=w3"], "Error: Error loading w3: Wallet requires newer version of Bitcoin Core")
|
node_v17.assert_start_raises_init_error(["-wallet=w3"], "Error: Error loading w3: Wallet requires newer version of Bitcoin Core")
|
||||||
self.start_node(4)
|
self.start_node(4)
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# Descriptor wallets break compatibility, only run this test for legacy wallets
|
||||||
# Open most recent wallet in v0.16 (no loadwallet RPC)
|
# Open most recent wallet in v0.16 (no loadwallet RPC)
|
||||||
self.restart_node(5, extra_args=["-wallet=w2"])
|
self.restart_node(5, extra_args=["-wallet=w2"])
|
||||||
wallet = node_v16.get_wallet_rpc("w2")
|
wallet = node_v16.get_wallet_rpc("w2")
|
||||||
|
|
|
@ -51,10 +51,18 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
self.skip_if_no_wallet()
|
self.skip_if_no_wallet()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.address = self.nodes[0].getnewaddress()
|
self.nodes[0].createwallet(wallet_name='wmulti', disable_private_keys=True)
|
||||||
self.ms_address = self.nodes[0].addmultisigaddress(1, [self.address])['address']
|
wmulti = self.nodes[0].get_wallet_rpc('wmulti')
|
||||||
self.wit_address = self.nodes[0].getnewaddress(address_type='p2sh-segwit')
|
w0 = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
|
||||||
self.wit_ms_address = self.nodes[0].addmultisigaddress(1, [self.address], '', 'p2sh-segwit')['address']
|
self.address = w0.getnewaddress()
|
||||||
|
self.pubkey = w0.getaddressinfo(self.address)['pubkey']
|
||||||
|
self.ms_address = wmulti.addmultisigaddress(1, [self.pubkey])['address']
|
||||||
|
self.wit_address = w0.getnewaddress(address_type='p2sh-segwit')
|
||||||
|
self.wit_ms_address = wmulti.addmultisigaddress(1, [self.pubkey], '', 'p2sh-segwit')['address']
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# Legacy wallets need to import these so that they are watched by the wallet. This is unnecssary (and does not need to be tested) for descriptor wallets
|
||||||
|
wmulti.importaddress(self.ms_address)
|
||||||
|
wmulti.importaddress(self.wit_ms_address)
|
||||||
|
|
||||||
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
|
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
|
||||||
coinbase_txid = []
|
coinbase_txid = []
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"""Test the fundrawtransaction RPC."""
|
"""Test the fundrawtransaction RPC."""
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from test_framework.descriptors import descsum_create
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
|
@ -100,17 +101,19 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]})
|
rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]})
|
||||||
assert_equal(rawmatch["changepos"], -1)
|
assert_equal(rawmatch["changepos"], -1)
|
||||||
|
|
||||||
|
self.nodes[3].createwallet(wallet_name="wwatch", disable_private_keys=True)
|
||||||
|
wwatch = self.nodes[3].get_wallet_rpc('wwatch')
|
||||||
watchonly_address = self.nodes[0].getnewaddress()
|
watchonly_address = self.nodes[0].getnewaddress()
|
||||||
watchonly_pubkey = self.nodes[0].getaddressinfo(watchonly_address)["pubkey"]
|
watchonly_pubkey = self.nodes[0].getaddressinfo(watchonly_address)["pubkey"]
|
||||||
self.watchonly_amount = Decimal(200)
|
self.watchonly_amount = Decimal(200)
|
||||||
self.nodes[3].importpubkey(watchonly_pubkey, "", True)
|
wwatch.importpubkey(watchonly_pubkey, "", True)
|
||||||
self.watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, self.watchonly_amount)
|
self.watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, self.watchonly_amount)
|
||||||
|
|
||||||
# Lock UTXO so nodes[0] doesn't accidentally spend it
|
# Lock UTXO so nodes[0] doesn't accidentally spend it
|
||||||
self.watchonly_vout = find_vout_for_address(self.nodes[0], self.watchonly_txid, watchonly_address)
|
self.watchonly_vout = find_vout_for_address(self.nodes[0], self.watchonly_txid, watchonly_address)
|
||||||
self.nodes[0].lockunspent(False, [{"txid": self.watchonly_txid, "vout": self.watchonly_vout}])
|
self.nodes[0].lockunspent(False, [{"txid": self.watchonly_txid, "vout": self.watchonly_vout}])
|
||||||
|
|
||||||
self.nodes[0].sendtoaddress(self.nodes[3].getnewaddress(), self.watchonly_amount / 10)
|
self.nodes[0].sendtoaddress(self.nodes[3].get_wallet_rpc(self.default_wallet_name).getnewaddress(), self.watchonly_amount / 10)
|
||||||
|
|
||||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5)
|
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5)
|
||||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
|
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
|
||||||
|
@ -119,6 +122,8 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
self.nodes[0].generate(1)
|
self.nodes[0].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
|
wwatch.unloadwallet()
|
||||||
|
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
self.log.info("Test fundrawtxn")
|
self.log.info("Test fundrawtxn")
|
||||||
inputs = [ ]
|
inputs = [ ]
|
||||||
|
@ -406,7 +411,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
addr1Obj = self.nodes[1].getaddressinfo(addr1)
|
addr1Obj = self.nodes[1].getaddressinfo(addr1)
|
||||||
addr2Obj = self.nodes[1].getaddressinfo(addr2)
|
addr2Obj = self.nodes[1].getaddressinfo(addr2)
|
||||||
|
|
||||||
mSigObj = self.nodes[1].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])['address']
|
mSigObj = self.nodes[3].createmultisig(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])['address']
|
||||||
|
|
||||||
inputs = []
|
inputs = []
|
||||||
outputs = {mSigObj:1.1}
|
outputs = {mSigObj:1.1}
|
||||||
|
@ -438,7 +443,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
addr4Obj = self.nodes[1].getaddressinfo(addr4)
|
addr4Obj = self.nodes[1].getaddressinfo(addr4)
|
||||||
addr5Obj = self.nodes[1].getaddressinfo(addr5)
|
addr5Obj = self.nodes[1].getaddressinfo(addr5)
|
||||||
|
|
||||||
mSigObj = self.nodes[1].addmultisigaddress(
|
mSigObj = self.nodes[1].createmultisig(
|
||||||
4,
|
4,
|
||||||
[
|
[
|
||||||
addr1Obj['pubkey'],
|
addr1Obj['pubkey'],
|
||||||
|
@ -464,7 +469,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def test_spend_2of2(self):
|
def test_spend_2of2(self):
|
||||||
"""Spend a 2-of-2 multisig transaction over fundraw."""
|
"""Spend a 2-of-2 multisig transaction over fundraw."""
|
||||||
self.log.info("Test fundrawtxn spending 2-of-2 multisig")
|
self.log.info("Test fundpsbt spending 2-of-2 multisig")
|
||||||
|
|
||||||
# Create 2-of-2 addr.
|
# Create 2-of-2 addr.
|
||||||
addr1 = self.nodes[2].getnewaddress()
|
addr1 = self.nodes[2].getnewaddress()
|
||||||
|
@ -473,13 +478,18 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
addr1Obj = self.nodes[2].getaddressinfo(addr1)
|
addr1Obj = self.nodes[2].getaddressinfo(addr1)
|
||||||
addr2Obj = self.nodes[2].getaddressinfo(addr2)
|
addr2Obj = self.nodes[2].getaddressinfo(addr2)
|
||||||
|
|
||||||
mSigObj = self.nodes[2].addmultisigaddress(
|
self.nodes[2].createwallet(wallet_name='wmulti', disable_private_keys=True)
|
||||||
|
wmulti = self.nodes[2].get_wallet_rpc('wmulti')
|
||||||
|
w2 = self.nodes[2].get_wallet_rpc(self.default_wallet_name)
|
||||||
|
mSigObj = wmulti.addmultisigaddress(
|
||||||
2,
|
2,
|
||||||
[
|
[
|
||||||
addr1Obj['pubkey'],
|
addr1Obj['pubkey'],
|
||||||
addr2Obj['pubkey'],
|
addr2Obj['pubkey'],
|
||||||
]
|
]
|
||||||
)['address']
|
)['address']
|
||||||
|
if not self.options.descriptors:
|
||||||
|
wmulti.importaddress(mSigObj)
|
||||||
|
|
||||||
# Send 1.2 BTC to msig addr.
|
# Send 1.2 BTC to msig addr.
|
||||||
self.nodes[0].sendtoaddress(mSigObj, 1.2)
|
self.nodes[0].sendtoaddress(mSigObj, 1.2)
|
||||||
|
@ -489,22 +499,39 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
oldBalance = self.nodes[1].getbalance()
|
oldBalance = self.nodes[1].getbalance()
|
||||||
inputs = []
|
inputs = []
|
||||||
outputs = {self.nodes[1].getnewaddress():1.1}
|
outputs = {self.nodes[1].getnewaddress():1.1}
|
||||||
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
|
funded_psbt = wmulti.walletcreatefundedpsbt(inputs=inputs, outputs=outputs, options={'changeAddress': w2.getrawchangeaddress()})['psbt']
|
||||||
fundedTx = self.nodes[2].fundrawtransaction(rawtx)
|
|
||||||
|
|
||||||
signedTx = self.nodes[2].signrawtransactionwithwallet(fundedTx['hex'])
|
signed_psbt = w2.walletprocesspsbt(funded_psbt)
|
||||||
self.nodes[2].sendrawtransaction(signedTx['hex'])
|
final_psbt = w2.finalizepsbt(signed_psbt['psbt'])
|
||||||
|
self.nodes[2].sendrawtransaction(final_psbt['hex'])
|
||||||
self.nodes[2].generate(1)
|
self.nodes[2].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
# Make sure funds are received at node1.
|
# Make sure funds are received at node1.
|
||||||
assert_equal(oldBalance+Decimal('1.10000000'), self.nodes[1].getbalance())
|
assert_equal(oldBalance+Decimal('1.10000000'), self.nodes[1].getbalance())
|
||||||
|
|
||||||
|
wmulti.unloadwallet()
|
||||||
|
|
||||||
def test_locked_wallet(self):
|
def test_locked_wallet(self):
|
||||||
self.log.info("Test fundrawtxn with locked wallet")
|
self.log.info("Test fundrawtxn with locked wallet and hardened derivation")
|
||||||
|
|
||||||
self.nodes[1].encryptwallet("test")
|
self.nodes[1].encryptwallet("test")
|
||||||
|
|
||||||
|
if self.options.descriptors:
|
||||||
|
self.nodes[1].walletpassphrase('test', 10)
|
||||||
|
self.nodes[1].importdescriptors([{
|
||||||
|
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPdYeeZbPSKd2KYLmeVKtcFA7kqCxDvDR13MQ6us8HopUR2wLcS2ZKPhLyKsqpDL2FtL73LMHcgoCL7DXsciA8eX8nbjCR2eG/0h/*h)'),
|
||||||
|
'timestamp': 'now',
|
||||||
|
'active': True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPdYeeZbPSKd2KYLmeVKtcFA7kqCxDvDR13MQ6us8HopUR2wLcS2ZKPhLyKsqpDL2FtL73LMHcgoCL7DXsciA8eX8nbjCR2eG/1h/*h)'),
|
||||||
|
'timestamp': 'now',
|
||||||
|
'active': True,
|
||||||
|
'internal': True
|
||||||
|
}])
|
||||||
|
self.nodes[1].walletlock()
|
||||||
|
|
||||||
# Drain the keypool.
|
# Drain the keypool.
|
||||||
self.nodes[1].getnewaddress()
|
self.nodes[1].getnewaddress()
|
||||||
self.nodes[1].getrawchangeaddress()
|
self.nodes[1].getrawchangeaddress()
|
||||||
|
@ -621,7 +648,25 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
outputs = {self.nodes[2].getnewaddress(): self.watchonly_amount / 2}
|
outputs = {self.nodes[2].getnewaddress(): self.watchonly_amount / 2}
|
||||||
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
|
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
|
||||||
|
|
||||||
result = self.nodes[3].fundrawtransaction(rawtx, {'includeWatching': True })
|
self.nodes[3].loadwallet('wwatch')
|
||||||
|
wwatch = self.nodes[3].get_wallet_rpc('wwatch')
|
||||||
|
# Setup change addresses for the watchonly wallet
|
||||||
|
desc_import = [{
|
||||||
|
"desc": descsum_create("wpkh(tpubD6NzVbkrYhZ4YNXVQbNhMK1WqguFsUXceaVJKbmno2aZ3B6QfbMeraaYvnBSGpV3vxLyTTK9DYT1yoEck4XUScMzXoQ2U2oSmE2JyMedq3H/1/*)"),
|
||||||
|
"timestamp": "now",
|
||||||
|
"internal": True,
|
||||||
|
"active": True,
|
||||||
|
"keypool": True,
|
||||||
|
"range": [0, 100],
|
||||||
|
"watchonly": True,
|
||||||
|
}]
|
||||||
|
if self.options.descriptors:
|
||||||
|
wwatch.importdescriptors(desc_import)
|
||||||
|
else:
|
||||||
|
wwatch.importmulti(desc_import)
|
||||||
|
|
||||||
|
# Backward compatibility test (2nd params is includeWatching)
|
||||||
|
result = wwatch.fundrawtransaction(rawtx, True)
|
||||||
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
|
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
|
||||||
assert_equal(len(res_dec["vin"]), 1)
|
assert_equal(len(res_dec["vin"]), 1)
|
||||||
assert_equal(res_dec["vin"][0]["txid"], self.watchonly_txid)
|
assert_equal(res_dec["vin"][0]["txid"], self.watchonly_txid)
|
||||||
|
@ -629,6 +674,8 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
assert "fee" in result.keys()
|
assert "fee" in result.keys()
|
||||||
assert_greater_than(result["changepos"], -1)
|
assert_greater_than(result["changepos"], -1)
|
||||||
|
|
||||||
|
wwatch.unloadwallet()
|
||||||
|
|
||||||
def test_all_watched_funds(self):
|
def test_all_watched_funds(self):
|
||||||
self.log.info("Test fundrawtxn using entirety of watched funds")
|
self.log.info("Test fundrawtxn using entirety of watched funds")
|
||||||
|
|
||||||
|
@ -636,17 +683,19 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
outputs = {self.nodes[2].getnewaddress(): self.watchonly_amount}
|
outputs = {self.nodes[2].getnewaddress(): self.watchonly_amount}
|
||||||
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
|
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
|
||||||
|
|
||||||
# Backward compatibility test (2nd param is includeWatching).
|
self.nodes[3].loadwallet('wwatch')
|
||||||
result = self.nodes[3].fundrawtransaction(rawtx, True)
|
wwatch = self.nodes[3].get_wallet_rpc('wwatch')
|
||||||
|
w3 = self.nodes[3].get_wallet_rpc(self.default_wallet_name)
|
||||||
|
result = wwatch.fundrawtransaction(rawtx, {'includeWatching': True, 'changeAddress': w3.getrawchangeaddress(), 'subtractFeeFromOutputs': [0]})
|
||||||
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
|
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
|
||||||
assert_equal(len(res_dec["vin"]), 2)
|
assert_equal(len(res_dec["vin"]), 1)
|
||||||
assert res_dec["vin"][0]["txid"] == self.watchonly_txid or res_dec["vin"][1]["txid"] == self.watchonly_txid
|
assert res_dec["vin"][0]["txid"] == self.watchonly_txid
|
||||||
|
|
||||||
assert_greater_than(result["fee"], 0)
|
assert_greater_than(result["fee"], 0)
|
||||||
assert_greater_than(result["changepos"], -1)
|
assert_equal(result["changepos"], -1)
|
||||||
assert_equal(result["fee"] + res_dec["vout"][result["changepos"]]["value"], self.watchonly_amount / 10)
|
assert_equal(result["fee"] + res_dec["vout"][0]["value"], self.watchonly_amount)
|
||||||
|
|
||||||
signedtx = self.nodes[3].signrawtransactionwithwallet(result["hex"])
|
signedtx = wwatch.signrawtransactionwithwallet(result["hex"])
|
||||||
assert not signedtx["complete"]
|
assert not signedtx["complete"]
|
||||||
signedtx = self.nodes[0].signrawtransactionwithwallet(signedtx["hex"])
|
signedtx = self.nodes[0].signrawtransactionwithwallet(signedtx["hex"])
|
||||||
assert signedtx["complete"]
|
assert signedtx["complete"]
|
||||||
|
@ -654,6 +703,8 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
self.nodes[0].generate(1)
|
self.nodes[0].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
|
wwatch.unloadwallet()
|
||||||
|
|
||||||
def test_option_feerate(self):
|
def test_option_feerate(self):
|
||||||
self.log.info("Test fundrawtxn feeRate option")
|
self.log.info("Test fundrawtxn feeRate option")
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
|
find_vout_for_address,
|
||||||
hex_str_to_bytes,
|
hex_str_to_bytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -242,6 +243,9 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
self.nodes[0].reconsiderblock(block1)
|
self.nodes[0].reconsiderblock(block1)
|
||||||
assert_equal(self.nodes[0].getbestblockhash(), block2)
|
assert_equal(self.nodes[0].getbestblockhash(), block2)
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# The traditional multisig workflow does not work with descriptor wallets so these are legacy only.
|
||||||
|
# The multisig workflow with descriptor wallets uses PSBTs and is tested elsewhere, no need to do them here.
|
||||||
#########################
|
#########################
|
||||||
# RAW TX MULTISIG TESTS #
|
# RAW TX MULTISIG TESTS #
|
||||||
#########################
|
#########################
|
||||||
|
@ -369,9 +373,20 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
decrawtx = self.nodes[0].decoderawtransaction(encrawtx, False) # decode as non-witness transaction
|
decrawtx = self.nodes[0].decoderawtransaction(encrawtx, False) # decode as non-witness transaction
|
||||||
assert_equal(decrawtx['vout'][0]['value'], Decimal('1.00000000'))
|
assert_equal(decrawtx['vout'][0]['value'], Decimal('1.00000000'))
|
||||||
|
|
||||||
|
# Basic signrawtransaction test
|
||||||
|
addr = self.nodes[1].getnewaddress()
|
||||||
|
txid = self.nodes[0].sendtoaddress(addr, 10)
|
||||||
|
self.nodes[0].generate(1)
|
||||||
|
self.sync_all()
|
||||||
|
vout = find_vout_for_address(self.nodes[1], txid, addr)
|
||||||
|
rawTx = self.nodes[1].createrawtransaction([{'txid': txid, 'vout': vout}], {self.nodes[1].getnewaddress(): 9.999})
|
||||||
|
rawTxSigned = self.nodes[1].signrawtransactionwithwallet(rawTx)
|
||||||
|
txId = self.nodes[1].sendrawtransaction(rawTxSigned['hex'])
|
||||||
|
self.nodes[0].generate(1)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
# getrawtransaction tests
|
# getrawtransaction tests
|
||||||
# 1. valid parameters - only supply txid
|
# 1. valid parameters - only supply txid
|
||||||
txId = rawTx["txid"]
|
|
||||||
assert_equal(self.nodes[0].getrawtransaction(txId), rawTxSigned['hex'])
|
assert_equal(self.nodes[0].getrawtransaction(txId), rawTxSigned['hex'])
|
||||||
|
|
||||||
# 2. valid parameters - supply txid and 0 for non-verbose
|
# 2. valid parameters - supply txid and 0 for non-verbose
|
||||||
|
|
|
@ -5,10 +5,13 @@
|
||||||
"""Test transaction signing using the signrawtransaction* RPCs."""
|
"""Test transaction signing using the signrawtransaction* RPCs."""
|
||||||
|
|
||||||
from test_framework.address import check_script, script_to_p2sh
|
from test_framework.address import check_script, script_to_p2sh
|
||||||
|
from test_framework.key import ECKey
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal, assert_raises_rpc_error, find_vout_for_address, hex_str_to_bytes
|
from test_framework.util import assert_equal, assert_raises_rpc_error, find_vout_for_address, hex_str_to_bytes
|
||||||
from test_framework.messages import sha256
|
from test_framework.messages import sha256
|
||||||
from test_framework.script import CScript, OP_0, OP_CHECKSIG
|
from test_framework.script import CScript, OP_0, OP_CHECKSIG
|
||||||
|
from test_framework.script_util import key_to_p2pkh_script, script_to_p2sh_p2wsh_script, script_to_p2wsh_script
|
||||||
|
from test_framework.wallet_util import bytes_to_wif
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
@ -151,21 +154,24 @@ class SignRawTransactionsTest(BitcoinTestFramework):
|
||||||
def witness_script_test(self):
|
def witness_script_test(self):
|
||||||
self.log.info("Test signing transaction to P2SH-P2WSH addresses without wallet")
|
self.log.info("Test signing transaction to P2SH-P2WSH addresses without wallet")
|
||||||
# Create a new P2SH-P2WSH 1-of-1 multisig address:
|
# Create a new P2SH-P2WSH 1-of-1 multisig address:
|
||||||
embedded_address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())
|
eckey = ECKey()
|
||||||
embedded_privkey = self.nodes[1].dumpprivkey(embedded_address["address"])
|
eckey.generate()
|
||||||
p2sh_p2wsh_address = self.nodes[1].addmultisigaddress(1, [embedded_address["pubkey"]], "", "p2sh-segwit")
|
embedded_privkey = bytes_to_wif(eckey.get_bytes())
|
||||||
|
embedded_pubkey = eckey.get_pubkey().get_bytes().hex()
|
||||||
|
p2sh_p2wsh_address = self.nodes[1].createmultisig(1, [embedded_pubkey], "p2sh-segwit")
|
||||||
# send transaction to P2SH-P2WSH 1-of-1 multisig address
|
# send transaction to P2SH-P2WSH 1-of-1 multisig address
|
||||||
self.nodes[0].generate(101)
|
self.nodes[0].generate(101)
|
||||||
self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999)
|
self.nodes[0].sendtoaddress(p2sh_p2wsh_address["address"], 49.999)
|
||||||
self.nodes[0].generate(1)
|
self.nodes[0].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
# Find the UTXO for the transaction node[1] should have received, check witnessScript matches
|
# Get the UTXO info from scantxoutset
|
||||||
unspent_output = self.nodes[1].listunspent(0, 999999, [p2sh_p2wsh_address["address"]])[0]
|
unspent_output = self.nodes[1].scantxoutset('start', [p2sh_p2wsh_address['descriptor']])['unspents'][0]
|
||||||
assert_equal(unspent_output["witnessScript"], p2sh_p2wsh_address["redeemScript"])
|
spk = script_to_p2sh_p2wsh_script(p2sh_p2wsh_address['redeemScript']).hex()
|
||||||
p2sh_redeemScript = CScript([OP_0, sha256(hex_str_to_bytes(p2sh_p2wsh_address["redeemScript"]))])
|
unspent_output['witnessScript'] = p2sh_p2wsh_address['redeemScript']
|
||||||
assert_equal(unspent_output["redeemScript"], p2sh_redeemScript.hex())
|
unspent_output['redeemScript'] = script_to_p2wsh_script(unspent_output['witnessScript']).hex()
|
||||||
|
assert_equal(spk, unspent_output['scriptPubKey'])
|
||||||
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
|
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
|
||||||
spending_tx = self.nodes[0].createrawtransaction([unspent_output], {self.nodes[1].getnewaddress(): Decimal("49.998")})
|
spending_tx = self.nodes[0].createrawtransaction([unspent_output], {self.nodes[1].get_wallet_rpc(self.default_wallet_name).getnewaddress(): Decimal("49.998")})
|
||||||
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [unspent_output])
|
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [unspent_output])
|
||||||
# Check the signing completed successfully
|
# Check the signing completed successfully
|
||||||
assert 'complete' in spending_tx_signed
|
assert 'complete' in spending_tx_signed
|
||||||
|
@ -177,11 +183,13 @@ class SignRawTransactionsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def verify_txn_with_witness_script(self, tx_type):
|
def verify_txn_with_witness_script(self, tx_type):
|
||||||
self.log.info("Test with a {} script as the witnessScript".format(tx_type))
|
self.log.info("Test with a {} script as the witnessScript".format(tx_type))
|
||||||
embedded_addr_info = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress('', 'legacy'))
|
eckey = ECKey()
|
||||||
embedded_privkey = self.nodes[1].dumpprivkey(embedded_addr_info['address'])
|
eckey.generate()
|
||||||
|
embedded_privkey = bytes_to_wif(eckey.get_bytes())
|
||||||
|
embedded_pubkey = eckey.get_pubkey().get_bytes().hex()
|
||||||
witness_script = {
|
witness_script = {
|
||||||
'P2PKH': embedded_addr_info['scriptPubKey'],
|
'P2PKH': key_to_p2pkh_script(embedded_pubkey).hex(),
|
||||||
'P2PK': CScript([hex_str_to_bytes(embedded_addr_info['pubkey']), OP_CHECKSIG]).hex()
|
'P2PK': CScript([hex_str_to_bytes(embedded_pubkey), OP_CHECKSIG]).hex()
|
||||||
}.get(tx_type, "Invalid tx_type")
|
}.get(tx_type, "Invalid tx_type")
|
||||||
redeem_script = CScript([OP_0, sha256(check_script(witness_script))]).hex()
|
redeem_script = CScript([OP_0, sha256(check_script(witness_script))]).hex()
|
||||||
addr = script_to_p2sh(redeem_script)
|
addr = script_to_p2sh(redeem_script)
|
||||||
|
|
|
@ -162,9 +162,8 @@ def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, script_pub_key=C
|
||||||
|
|
||||||
def create_transaction(node, txid, to_address, *, amount):
|
def create_transaction(node, txid, to_address, *, amount):
|
||||||
""" Return signed transaction spending the first output of the
|
""" Return signed transaction spending the first output of the
|
||||||
input txid. Note that the node must be able to sign for the
|
input txid. Note that the node must have a wallet that can
|
||||||
output that is being spent, and the node must not be running
|
sign for the output that is being spent.
|
||||||
multiple wallets.
|
|
||||||
"""
|
"""
|
||||||
raw_tx = create_raw_transaction(node, txid, to_address, amount=amount)
|
raw_tx = create_raw_transaction(node, txid, to_address, amount=amount)
|
||||||
tx = CTransaction()
|
tx = CTransaction()
|
||||||
|
@ -173,14 +172,18 @@ def create_transaction(node, txid, to_address, *, amount):
|
||||||
|
|
||||||
def create_raw_transaction(node, txid, to_address, *, amount):
|
def create_raw_transaction(node, txid, to_address, *, amount):
|
||||||
""" Return raw signed transaction spending the first output of the
|
""" Return raw signed transaction spending the first output of the
|
||||||
input txid. Note that the node must be able to sign for the
|
input txid. Note that the node must have a wallet that can sign
|
||||||
output that is being spent, and the node must not be running
|
for the output that is being spent.
|
||||||
multiple wallets.
|
|
||||||
"""
|
"""
|
||||||
rawtx = node.createrawtransaction(inputs=[{"txid": txid, "vout": 0}], outputs={to_address: amount})
|
psbt = node.createpsbt(inputs=[{"txid": txid, "vout": 0}], outputs={to_address: amount})
|
||||||
signresult = node.signrawtransactionwithwallet(rawtx)
|
for _ in range(2):
|
||||||
assert_equal(signresult["complete"], True)
|
for w in node.listwallets():
|
||||||
return signresult['hex']
|
wrpc = node.get_wallet_rpc(w)
|
||||||
|
signed_psbt = wrpc.walletprocesspsbt(psbt)
|
||||||
|
psbt = signed_psbt['psbt']
|
||||||
|
final_psbt = node.finalizepsbt(psbt)
|
||||||
|
assert_equal(final_psbt["complete"], True)
|
||||||
|
return final_psbt['hex']
|
||||||
|
|
||||||
def get_legacy_sigopcount_block(block, accurate=True):
|
def get_legacy_sigopcount_block(block, accurate=True):
|
||||||
count = 0
|
count = 0
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Useful Script constants and utils."""
|
"""Useful Script constants and utils."""
|
||||||
from test_framework.script import CScript
|
from test_framework.script import CScript, hash160, sha256, OP_0, OP_DUP, OP_HASH160, OP_CHECKSIG, OP_EQUAL, OP_EQUALVERIFY
|
||||||
|
from test_framework.util import hex_str_to_bytes
|
||||||
|
|
||||||
# To prevent a "tx-size-small" policy rule error, a transaction has to have a
|
# To prevent a "tx-size-small" policy rule error, a transaction has to have a
|
||||||
# non-witness size of at least 82 bytes (MIN_STANDARD_TX_NONWITNESS_SIZE in
|
# non-witness size of at least 82 bytes (MIN_STANDARD_TX_NONWITNESS_SIZE in
|
||||||
|
@ -24,3 +25,59 @@ from test_framework.script import CScript
|
||||||
# met.
|
# met.
|
||||||
DUMMY_P2WPKH_SCRIPT = CScript([b'a' * 21])
|
DUMMY_P2WPKH_SCRIPT = CScript([b'a' * 21])
|
||||||
DUMMY_2_P2WPKH_SCRIPT = CScript([b'b' * 21])
|
DUMMY_2_P2WPKH_SCRIPT = CScript([b'b' * 21])
|
||||||
|
|
||||||
|
def keyhash_to_p2pkh_script(hash, main = False):
|
||||||
|
assert len(hash) == 20
|
||||||
|
return CScript([OP_DUP, OP_HASH160, hash, OP_EQUALVERIFY, OP_CHECKSIG])
|
||||||
|
|
||||||
|
def scripthash_to_p2sh_script(hash, main = False):
|
||||||
|
assert len(hash) == 20
|
||||||
|
return CScript([OP_HASH160, hash, OP_EQUAL])
|
||||||
|
|
||||||
|
def key_to_p2pkh_script(key, main = False):
|
||||||
|
key = check_key(key)
|
||||||
|
return keyhash_to_p2pkh_script(hash160(key), main)
|
||||||
|
|
||||||
|
def script_to_p2sh_script(script, main = False):
|
||||||
|
script = check_script(script)
|
||||||
|
return scripthash_to_p2sh_script(hash160(script), main)
|
||||||
|
|
||||||
|
def key_to_p2sh_p2wpkh_script(key, main = False):
|
||||||
|
key = check_key(key)
|
||||||
|
p2shscript = CScript([OP_0, hash160(key)])
|
||||||
|
return script_to_p2sh_script(p2shscript, main)
|
||||||
|
|
||||||
|
def program_to_witness_script(version, program, main = False):
|
||||||
|
if isinstance(program, str):
|
||||||
|
program = hex_str_to_bytes(program)
|
||||||
|
assert 0 <= version <= 16
|
||||||
|
assert 2 <= len(program) <= 40
|
||||||
|
assert version > 0 or len(program) in [20, 32]
|
||||||
|
return CScript([version, program])
|
||||||
|
|
||||||
|
def script_to_p2wsh_script(script, main = False):
|
||||||
|
script = check_script(script)
|
||||||
|
return program_to_witness_script(0, sha256(script), main)
|
||||||
|
|
||||||
|
def key_to_p2wpkh_script(key, main = False):
|
||||||
|
key = check_key(key)
|
||||||
|
return program_to_witness_script(0, hash160(key), main)
|
||||||
|
|
||||||
|
def script_to_p2sh_p2wsh_script(script, main = False):
|
||||||
|
script = check_script(script)
|
||||||
|
p2shscript = CScript([OP_0, sha256(script)])
|
||||||
|
return script_to_p2sh_script(p2shscript, main)
|
||||||
|
|
||||||
|
def check_key(key):
|
||||||
|
if isinstance(key, str):
|
||||||
|
key = hex_str_to_bytes(key) # Assuming this is hex string
|
||||||
|
if isinstance(key, bytes) and (len(key) == 33 or len(key) == 65):
|
||||||
|
return key
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def check_script(script):
|
||||||
|
if isinstance(script, str):
|
||||||
|
script = hex_str_to_bytes(script) # Assuming this is hex string
|
||||||
|
if isinstance(script, bytes) or isinstance(script, CScript):
|
||||||
|
return script
|
||||||
|
assert False
|
||||||
|
|
|
@ -183,9 +183,14 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||||
help="run nodes under the valgrind memory error detector: expect at least a ~10x slowdown, valgrind 3.14 or later required")
|
help="run nodes under the valgrind memory error detector: expect at least a ~10x slowdown, valgrind 3.14 or later required")
|
||||||
parser.add_argument("--randomseed", type=int,
|
parser.add_argument("--randomseed", type=int,
|
||||||
help="set a random seed for deterministically reproducing a previous test run")
|
help="set a random seed for deterministically reproducing a previous test run")
|
||||||
parser.add_argument("--descriptors", default=False, action="store_true",
|
|
||||||
help="Run test using a descriptor wallet")
|
|
||||||
parser.add_argument('--timeout-factor', dest="timeout_factor", type=float, default=1.0, help='adjust test timeouts by a factor. Setting it to 0 disables all timeouts')
|
parser.add_argument('--timeout-factor', dest="timeout_factor", type=float, default=1.0, help='adjust test timeouts by a factor. Setting it to 0 disables all timeouts')
|
||||||
|
|
||||||
|
group = parser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument("--descriptors", default=False, action="store_true",
|
||||||
|
help="Run test using a descriptor wallet", dest='descriptors')
|
||||||
|
group.add_argument("--legacy-wallet", default=False, action="store_false",
|
||||||
|
help="Run test using legacy wallets", dest='descriptors')
|
||||||
|
|
||||||
self.add_options(parser)
|
self.add_options(parser)
|
||||||
self.options = parser.parse_args()
|
self.options = parser.parse_args()
|
||||||
self.options.previous_releases_path = previous_releases_path
|
self.options.previous_releases_path = previous_releases_path
|
||||||
|
|
|
@ -95,8 +95,9 @@ BASE_SCRIPTS = [
|
||||||
'feature_maxuploadtarget.py',
|
'feature_maxuploadtarget.py',
|
||||||
'feature_block.py',
|
'feature_block.py',
|
||||||
'rpc_fundrawtransaction.py',
|
'rpc_fundrawtransaction.py',
|
||||||
|
'rpc_fundrawtransaction.py --descriptors',
|
||||||
'p2p_compactblocks.py',
|
'p2p_compactblocks.py',
|
||||||
'feature_segwit.py',
|
'feature_segwit.py --legacy-wallet',
|
||||||
# vv Tests less than 2m vv
|
# vv Tests less than 2m vv
|
||||||
'wallet_basic.py',
|
'wallet_basic.py',
|
||||||
'wallet_basic.py --descriptors',
|
'wallet_basic.py --descriptors',
|
||||||
|
@ -106,19 +107,24 @@ BASE_SCRIPTS = [
|
||||||
'p2p_timeouts.py',
|
'p2p_timeouts.py',
|
||||||
'p2p_tx_download.py',
|
'p2p_tx_download.py',
|
||||||
'mempool_updatefromblock.py',
|
'mempool_updatefromblock.py',
|
||||||
'wallet_dump.py',
|
'wallet_dump.py --legacy-wallet',
|
||||||
'wallet_listtransactions.py',
|
'wallet_listtransactions.py',
|
||||||
|
'wallet_listtransactions.py --descriptors',
|
||||||
'feature_taproot.py',
|
'feature_taproot.py',
|
||||||
# vv Tests less than 60s vv
|
# vv Tests less than 60s vv
|
||||||
'p2p_sendheaders.py',
|
'p2p_sendheaders.py',
|
||||||
'wallet_importmulti.py',
|
'wallet_importmulti.py --legacy-wallet',
|
||||||
'mempool_limit.py',
|
'mempool_limit.py',
|
||||||
'rpc_txoutproof.py',
|
'rpc_txoutproof.py',
|
||||||
'wallet_listreceivedby.py',
|
'wallet_listreceivedby.py',
|
||||||
|
'wallet_listreceivedby.py --descriptors',
|
||||||
'wallet_abandonconflict.py',
|
'wallet_abandonconflict.py',
|
||||||
|
'wallet_abandonconflict.py --descriptors',
|
||||||
'feature_csv_activation.py',
|
'feature_csv_activation.py',
|
||||||
'rpc_rawtransaction.py',
|
'rpc_rawtransaction.py',
|
||||||
|
'rpc_rawtransaction.py --descriptors',
|
||||||
'wallet_address_types.py',
|
'wallet_address_types.py',
|
||||||
|
'wallet_address_types.py --descriptors',
|
||||||
'feature_bip68_sequence.py',
|
'feature_bip68_sequence.py',
|
||||||
'p2p_feefilter.py',
|
'p2p_feefilter.py',
|
||||||
'feature_reindex.py',
|
'feature_reindex.py',
|
||||||
|
@ -132,6 +138,7 @@ BASE_SCRIPTS = [
|
||||||
'mempool_resurrect.py',
|
'mempool_resurrect.py',
|
||||||
'wallet_txn_doublespend.py --mineblock',
|
'wallet_txn_doublespend.py --mineblock',
|
||||||
'tool_wallet.py',
|
'tool_wallet.py',
|
||||||
|
'tool_wallet.py --descriptors',
|
||||||
'wallet_txn_clone.py',
|
'wallet_txn_clone.py',
|
||||||
'wallet_txn_clone.py --segwit',
|
'wallet_txn_clone.py --segwit',
|
||||||
'rpc_getchaintips.py',
|
'rpc_getchaintips.py',
|
||||||
|
@ -147,8 +154,9 @@ BASE_SCRIPTS = [
|
||||||
'wallet_multiwallet.py --usecli',
|
'wallet_multiwallet.py --usecli',
|
||||||
'wallet_createwallet.py',
|
'wallet_createwallet.py',
|
||||||
'wallet_createwallet.py --usecli',
|
'wallet_createwallet.py --usecli',
|
||||||
'wallet_watchonly.py',
|
'wallet_createwallet.py --descriptors',
|
||||||
'wallet_watchonly.py --usecli',
|
'wallet_watchonly.py --legacy-wallet',
|
||||||
|
'wallet_watchonly.py --usecli --legacy-wallet',
|
||||||
'wallet_reorgsrestore.py',
|
'wallet_reorgsrestore.py',
|
||||||
'interface_http.py',
|
'interface_http.py',
|
||||||
'interface_rpc.py',
|
'interface_rpc.py',
|
||||||
|
@ -158,13 +166,16 @@ BASE_SCRIPTS = [
|
||||||
'rpc_whitelist.py',
|
'rpc_whitelist.py',
|
||||||
'feature_proxy.py',
|
'feature_proxy.py',
|
||||||
'rpc_signrawtransaction.py',
|
'rpc_signrawtransaction.py',
|
||||||
|
'rpc_signrawtransaction.py --descriptors',
|
||||||
'wallet_groups.py',
|
'wallet_groups.py',
|
||||||
'p2p_addrv2_relay.py',
|
'p2p_addrv2_relay.py',
|
||||||
|
'wallet_groups.py --descriptors',
|
||||||
'p2p_disconnect_ban.py',
|
'p2p_disconnect_ban.py',
|
||||||
'rpc_decodescript.py',
|
'rpc_decodescript.py',
|
||||||
'rpc_blockchain.py',
|
'rpc_blockchain.py',
|
||||||
'rpc_deprecated.py',
|
'rpc_deprecated.py',
|
||||||
'wallet_disable.py',
|
'wallet_disable.py',
|
||||||
|
'wallet_disable.py --descriptors',
|
||||||
'p2p_addr_relay.py',
|
'p2p_addr_relay.py',
|
||||||
'p2p_getaddr_caching.py',
|
'p2p_getaddr_caching.py',
|
||||||
'p2p_getdata.py',
|
'p2p_getdata.py',
|
||||||
|
@ -184,7 +195,9 @@ BASE_SCRIPTS = [
|
||||||
'feature_assumevalid.py',
|
'feature_assumevalid.py',
|
||||||
'example_test.py',
|
'example_test.py',
|
||||||
'wallet_txn_doublespend.py',
|
'wallet_txn_doublespend.py',
|
||||||
|
'wallet_txn_doublespend.py --descriptors',
|
||||||
'feature_backwards_compatibility.py',
|
'feature_backwards_compatibility.py',
|
||||||
|
'feature_backwards_compatibility.py --descriptors',
|
||||||
'wallet_txn_clone.py --mineblock',
|
'wallet_txn_clone.py --mineblock',
|
||||||
'feature_notifications.py',
|
'feature_notifications.py',
|
||||||
'rpc_getblockfilter.py',
|
'rpc_getblockfilter.py',
|
||||||
|
@ -197,17 +210,20 @@ BASE_SCRIPTS = [
|
||||||
'feature_versionbits_warning.py',
|
'feature_versionbits_warning.py',
|
||||||
'rpc_preciousblock.py',
|
'rpc_preciousblock.py',
|
||||||
'wallet_importprunedfunds.py',
|
'wallet_importprunedfunds.py',
|
||||||
|
'wallet_importprunedfunds.py --descriptors',
|
||||||
'p2p_leak_tx.py',
|
'p2p_leak_tx.py',
|
||||||
'p2p_eviction.py',
|
'p2p_eviction.py',
|
||||||
'rpc_signmessage.py',
|
'rpc_signmessage.py',
|
||||||
'rpc_generateblock.py',
|
'rpc_generateblock.py',
|
||||||
'rpc_generate.py',
|
'rpc_generate.py',
|
||||||
'wallet_balance.py',
|
'wallet_balance.py',
|
||||||
|
'wallet_balance.py --descriptors',
|
||||||
'feature_nulldummy.py',
|
'feature_nulldummy.py',
|
||||||
|
'feature_nulldummy.py --descriptors',
|
||||||
'mempool_accept.py',
|
'mempool_accept.py',
|
||||||
'mempool_expiry.py',
|
'mempool_expiry.py',
|
||||||
'wallet_import_rescan.py',
|
'wallet_import_rescan.py --legacy-wallet',
|
||||||
'wallet_import_with_label.py',
|
'wallet_import_with_label.py --legacy-wallet',
|
||||||
'wallet_importdescriptors.py --descriptors',
|
'wallet_importdescriptors.py --descriptors',
|
||||||
'wallet_upgradewallet.py',
|
'wallet_upgradewallet.py',
|
||||||
'rpc_bind.py --ipv4',
|
'rpc_bind.py --ipv4',
|
||||||
|
@ -216,9 +232,11 @@ BASE_SCRIPTS = [
|
||||||
'mining_basic.py',
|
'mining_basic.py',
|
||||||
'feature_signet.py',
|
'feature_signet.py',
|
||||||
'wallet_bumpfee.py',
|
'wallet_bumpfee.py',
|
||||||
'wallet_implicitsegwit.py',
|
'wallet_bumpfee.py --descriptors',
|
||||||
|
'wallet_implicitsegwit.py --legacy-wallet',
|
||||||
'rpc_named_arguments.py',
|
'rpc_named_arguments.py',
|
||||||
'wallet_listsinceblock.py',
|
'wallet_listsinceblock.py',
|
||||||
|
'wallet_listsinceblock.py --descriptors',
|
||||||
'p2p_leak.py',
|
'p2p_leak.py',
|
||||||
'wallet_encryption.py',
|
'wallet_encryption.py',
|
||||||
'wallet_encryption.py --descriptors',
|
'wallet_encryption.py --descriptors',
|
||||||
|
@ -226,16 +244,20 @@ BASE_SCRIPTS = [
|
||||||
'feature_cltv.py',
|
'feature_cltv.py',
|
||||||
'rpc_uptime.py',
|
'rpc_uptime.py',
|
||||||
'wallet_resendwallettransactions.py',
|
'wallet_resendwallettransactions.py',
|
||||||
|
'wallet_resendwallettransactions.py --descriptors',
|
||||||
'wallet_fallbackfee.py',
|
'wallet_fallbackfee.py',
|
||||||
|
'wallet_fallbackfee.py --descriptors',
|
||||||
'rpc_dumptxoutset.py',
|
'rpc_dumptxoutset.py',
|
||||||
'feature_minchainwork.py',
|
'feature_minchainwork.py',
|
||||||
'rpc_estimatefee.py',
|
'rpc_estimatefee.py',
|
||||||
'rpc_getblockstats.py',
|
'rpc_getblockstats.py',
|
||||||
'wallet_create_tx.py',
|
'wallet_create_tx.py',
|
||||||
'wallet_send.py',
|
'wallet_send.py',
|
||||||
|
'wallet_create_tx.py --descriptors',
|
||||||
'p2p_fingerprint.py',
|
'p2p_fingerprint.py',
|
||||||
'feature_uacomment.py',
|
'feature_uacomment.py',
|
||||||
'wallet_coinbase_category.py',
|
'wallet_coinbase_category.py',
|
||||||
|
'wallet_coinbase_category.py --descriptors',
|
||||||
'feature_filelock.py',
|
'feature_filelock.py',
|
||||||
'feature_loadblock.py',
|
'feature_loadblock.py',
|
||||||
'p2p_dos_header_tree.py',
|
'p2p_dos_header_tree.py',
|
||||||
|
|
|
@ -71,8 +71,11 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
self.assert_raises_tool_error('Error: two methods provided (info and create). Only one method should be provided.', 'info', 'create')
|
self.assert_raises_tool_error('Error: two methods provided (info and create). Only one method should be provided.', 'info', 'create')
|
||||||
self.assert_raises_tool_error('Error parsing command line arguments: Invalid parameter -foo', '-foo')
|
self.assert_raises_tool_error('Error parsing command line arguments: Invalid parameter -foo', '-foo')
|
||||||
locked_dir = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets")
|
locked_dir = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets")
|
||||||
|
error = 'Error initializing wallet database environment "{}"!'.format(locked_dir)
|
||||||
|
if self.options.descriptors:
|
||||||
|
error = "SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another bitcoind?"
|
||||||
self.assert_raises_tool_error(
|
self.assert_raises_tool_error(
|
||||||
'Error initializing wallet database environment "{}"!'.format(locked_dir),
|
error,
|
||||||
'-wallet=' + self.default_wallet_name,
|
'-wallet=' + self.default_wallet_name,
|
||||||
'info',
|
'info',
|
||||||
)
|
)
|
||||||
|
@ -95,6 +98,20 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
# shasum_before = self.wallet_shasum()
|
# shasum_before = self.wallet_shasum()
|
||||||
timestamp_before = self.wallet_timestamp()
|
timestamp_before = self.wallet_timestamp()
|
||||||
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
|
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
|
||||||
|
if self.options.descriptors:
|
||||||
|
out = textwrap.dedent('''\
|
||||||
|
Wallet info
|
||||||
|
===========
|
||||||
|
Name: default_wallet
|
||||||
|
Format: sqlite
|
||||||
|
Descriptors: yes
|
||||||
|
Encrypted: no
|
||||||
|
HD (hd seed available): yes
|
||||||
|
Keypool Size: 6
|
||||||
|
Transactions: 0
|
||||||
|
Address Book: 1
|
||||||
|
''')
|
||||||
|
else:
|
||||||
out = textwrap.dedent('''\
|
out = textwrap.dedent('''\
|
||||||
Wallet info
|
Wallet info
|
||||||
===========
|
===========
|
||||||
|
@ -138,6 +155,20 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
shasum_before = self.wallet_shasum()
|
shasum_before = self.wallet_shasum()
|
||||||
timestamp_before = self.wallet_timestamp()
|
timestamp_before = self.wallet_timestamp()
|
||||||
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
|
self.log.debug('Wallet file timestamp before calling info: {}'.format(timestamp_before))
|
||||||
|
if self.options.descriptors:
|
||||||
|
out = textwrap.dedent('''\
|
||||||
|
Wallet info
|
||||||
|
===========
|
||||||
|
Name: default_wallet
|
||||||
|
Format: sqlite
|
||||||
|
Descriptors: yes
|
||||||
|
Encrypted: no
|
||||||
|
HD (hd seed available): yes
|
||||||
|
Keypool Size: 6
|
||||||
|
Transactions: 1
|
||||||
|
Address Book: 1
|
||||||
|
''')
|
||||||
|
else:
|
||||||
out = textwrap.dedent('''\
|
out = textwrap.dedent('''\
|
||||||
Wallet info
|
Wallet info
|
||||||
===========
|
===========
|
||||||
|
@ -230,8 +261,11 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
# Warning: The following tests are order-dependent.
|
# Warning: The following tests are order-dependent.
|
||||||
self.test_tool_wallet_info()
|
self.test_tool_wallet_info()
|
||||||
self.test_tool_wallet_info_after_transaction()
|
self.test_tool_wallet_info_after_transaction()
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# TODO: Wallet tool needs more create options at which point these can be enabled.
|
||||||
self.test_tool_wallet_create_on_existing_wallet()
|
self.test_tool_wallet_create_on_existing_wallet()
|
||||||
self.test_getwalletinfo_on_different_wallet()
|
self.test_getwalletinfo_on_different_wallet()
|
||||||
|
# Salvage is a legacy wallet only thing
|
||||||
self.test_salvage()
|
self.test_salvage()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -228,6 +228,9 @@ class AddressTypeTest(BitcoinTestFramework):
|
||||||
compressed_1 = "0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52"
|
compressed_1 = "0296b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52"
|
||||||
compressed_2 = "037211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073"
|
compressed_2 = "037211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073"
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# Tests for addmultisigaddress's address type behavior is only for legacy wallets.
|
||||||
|
# Descriptor wallets do not have addmultsigaddress so these tests are not needed for those.
|
||||||
# addmultisigaddress with at least 1 uncompressed key should return a legacy address.
|
# addmultisigaddress with at least 1 uncompressed key should return a legacy address.
|
||||||
for node in range(4):
|
for node in range(4):
|
||||||
self.test_address(node, self.nodes[node].addmultisigaddress(2, [uncompressed_1, uncompressed_2])['address'], True, 'legacy')
|
self.test_address(node, self.nodes[node].addmultisigaddress(2, [uncompressed_1, uncompressed_2])['address'], True, 'legacy')
|
||||||
|
@ -239,7 +242,11 @@ class AddressTypeTest(BitcoinTestFramework):
|
||||||
self.test_address(2, self.nodes[2].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'p2sh-segwit')
|
self.test_address(2, self.nodes[2].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'p2sh-segwit')
|
||||||
self.test_address(3, self.nodes[3].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'bech32')
|
self.test_address(3, self.nodes[3].addmultisigaddress(2, [compressed_1, compressed_2])['address'], True, 'bech32')
|
||||||
|
|
||||||
for explicit_type, multisig, from_node in itertools.product([False, True], [False, True], range(4)):
|
do_multisigs = [False]
|
||||||
|
if not self.options.descriptors:
|
||||||
|
do_multisigs.append(True)
|
||||||
|
|
||||||
|
for explicit_type, multisig, from_node in itertools.product([False, True], do_multisigs, range(4)):
|
||||||
address_type = None
|
address_type = None
|
||||||
if explicit_type and not multisig:
|
if explicit_type and not multisig:
|
||||||
if from_node == 1:
|
if from_node == 1:
|
||||||
|
|
|
@ -57,6 +57,8 @@ class WalletTest(BitcoinTestFramework):
|
||||||
self.skip_if_no_wallet()
|
self.skip_if_no_wallet()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# Tests legacy watchonly behavior which is not present (and does not need to be tested) in descriptor wallets
|
||||||
self.nodes[0].importaddress(ADDRESS_WATCHONLY)
|
self.nodes[0].importaddress(ADDRESS_WATCHONLY)
|
||||||
# Check that nodes don't own any UTXOs
|
# Check that nodes don't own any UTXOs
|
||||||
assert_equal(len(self.nodes[0].listunspent()), 0)
|
assert_equal(len(self.nodes[0].listunspent()), 0)
|
||||||
|
@ -73,6 +75,8 @@ class WalletTest(BitcoinTestFramework):
|
||||||
self.nodes[1].generatetoaddress(101, ADDRESS_WATCHONLY)
|
self.nodes[1].generatetoaddress(101, ADDRESS_WATCHONLY)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# Tests legacy watchonly behavior which is not present (and does not need to be tested) in descriptor wallets
|
||||||
assert_equal(self.nodes[0].getbalances()['mine']['trusted'], 50)
|
assert_equal(self.nodes[0].getbalances()['mine']['trusted'], 50)
|
||||||
assert_equal(self.nodes[0].getwalletinfo()['balance'], 50)
|
assert_equal(self.nodes[0].getwalletinfo()['balance'], 50)
|
||||||
assert_equal(self.nodes[1].getbalances()['mine']['trusted'], 50)
|
assert_equal(self.nodes[1].getbalances()['mine']['trusted'], 50)
|
||||||
|
@ -86,9 +90,13 @@ class WalletTest(BitcoinTestFramework):
|
||||||
self.log.info("Test getbalance with different arguments")
|
self.log.info("Test getbalance with different arguments")
|
||||||
assert_equal(self.nodes[0].getbalance("*"), 50)
|
assert_equal(self.nodes[0].getbalance("*"), 50)
|
||||||
assert_equal(self.nodes[0].getbalance("*", 1), 50)
|
assert_equal(self.nodes[0].getbalance("*", 1), 50)
|
||||||
assert_equal(self.nodes[0].getbalance("*", 1, True), 100)
|
|
||||||
assert_equal(self.nodes[0].getbalance(minconf=1), 50)
|
assert_equal(self.nodes[0].getbalance(minconf=1), 50)
|
||||||
|
if not self.options.descriptors:
|
||||||
assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 100)
|
assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 100)
|
||||||
|
assert_equal(self.nodes[0].getbalance("*", 1, True), 100)
|
||||||
|
else:
|
||||||
|
assert_equal(self.nodes[0].getbalance(minconf=0, include_watchonly=True), 50)
|
||||||
|
assert_equal(self.nodes[0].getbalance("*", 1, True), 50)
|
||||||
assert_equal(self.nodes[1].getbalance(minconf=0, include_watchonly=True), 50)
|
assert_equal(self.nodes[1].getbalance(minconf=0, include_watchonly=True), 50)
|
||||||
|
|
||||||
# Send 40 BTC from 0 to 1 and 60 BTC from 1 to 0.
|
# Send 40 BTC from 0 to 1 and 60 BTC from 1 to 0.
|
||||||
|
@ -156,6 +164,8 @@ class WalletTest(BitcoinTestFramework):
|
||||||
expected_balances_1 = {'mine': {'immature': Decimal('0E-8'),
|
expected_balances_1 = {'mine': {'immature': Decimal('0E-8'),
|
||||||
'trusted': Decimal('0E-8'), # node 1's send had an unsafe input
|
'trusted': Decimal('0E-8'), # node 1's send had an unsafe input
|
||||||
'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent
|
'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent
|
||||||
|
if self.options.descriptors:
|
||||||
|
del expected_balances_0["watchonly"]
|
||||||
assert_equal(self.nodes[0].getbalances(), expected_balances_0)
|
assert_equal(self.nodes[0].getbalances(), expected_balances_0)
|
||||||
assert_equal(self.nodes[1].getbalances(), expected_balances_1)
|
assert_equal(self.nodes[1].getbalances(), expected_balances_1)
|
||||||
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions
|
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions
|
||||||
|
|
|
@ -184,7 +184,7 @@ def test_segwit_bumpfee_succeeds(self, rbf_node, dest_address):
|
||||||
# which spends it, and make sure bumpfee can be called on it.
|
# which spends it, and make sure bumpfee can be called on it.
|
||||||
|
|
||||||
segwit_in = next(u for u in rbf_node.listunspent() if u["amount"] == Decimal("0.001"))
|
segwit_in = next(u for u in rbf_node.listunspent() if u["amount"] == Decimal("0.001"))
|
||||||
segwit_out = rbf_node.getaddressinfo(rbf_node.getnewaddress(address_type='p2sh-segwit'))
|
segwit_out = rbf_node.getaddressinfo(rbf_node.getnewaddress(address_type='bech32'))
|
||||||
segwitid = send_to_witness(
|
segwitid = send_to_witness(
|
||||||
use_p2wsh=False,
|
use_p2wsh=False,
|
||||||
node=rbf_node,
|
node=rbf_node,
|
||||||
|
@ -365,7 +365,7 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
|
||||||
rbf_node.createwallet(wallet_name="signer", disable_private_keys=False, blank=True)
|
rbf_node.createwallet(wallet_name="signer", disable_private_keys=False, blank=True)
|
||||||
signer = rbf_node.get_wallet_rpc("signer")
|
signer = rbf_node.get_wallet_rpc("signer")
|
||||||
assert signer.getwalletinfo()['private_keys_enabled']
|
assert signer.getwalletinfo()['private_keys_enabled']
|
||||||
result = signer.importmulti([{
|
reqs = [{
|
||||||
"desc": priv_rec_desc,
|
"desc": priv_rec_desc,
|
||||||
"timestamp": 0,
|
"timestamp": 0,
|
||||||
"range": [0,1],
|
"range": [0,1],
|
||||||
|
@ -378,7 +378,11 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
|
||||||
"range": [0, 0],
|
"range": [0, 0],
|
||||||
"internal": True,
|
"internal": True,
|
||||||
"keypool": False
|
"keypool": False
|
||||||
}])
|
}]
|
||||||
|
if self.options.descriptors:
|
||||||
|
result = signer.importdescriptors(reqs)
|
||||||
|
else:
|
||||||
|
result = signer.importmulti(reqs)
|
||||||
assert_equal(result, [{'success': True}, {'success': True}])
|
assert_equal(result, [{'success': True}, {'success': True}])
|
||||||
|
|
||||||
# Create another wallet with just the public keys, which creates PSBTs
|
# Create another wallet with just the public keys, which creates PSBTs
|
||||||
|
@ -386,21 +390,27 @@ def test_watchonly_psbt(self, peer_node, rbf_node, dest_address):
|
||||||
watcher = rbf_node.get_wallet_rpc("watcher")
|
watcher = rbf_node.get_wallet_rpc("watcher")
|
||||||
assert not watcher.getwalletinfo()['private_keys_enabled']
|
assert not watcher.getwalletinfo()['private_keys_enabled']
|
||||||
|
|
||||||
result = watcher.importmulti([{
|
reqs = [{
|
||||||
"desc": pub_rec_desc,
|
"desc": pub_rec_desc,
|
||||||
"timestamp": 0,
|
"timestamp": 0,
|
||||||
"range": [0, 10],
|
"range": [0, 10],
|
||||||
"internal": False,
|
"internal": False,
|
||||||
"keypool": True,
|
"keypool": True,
|
||||||
"watchonly": True
|
"watchonly": True,
|
||||||
|
"active": True,
|
||||||
}, {
|
}, {
|
||||||
"desc": pub_change_desc,
|
"desc": pub_change_desc,
|
||||||
"timestamp": 0,
|
"timestamp": 0,
|
||||||
"range": [0, 10],
|
"range": [0, 10],
|
||||||
"internal": True,
|
"internal": True,
|
||||||
"keypool": True,
|
"keypool": True,
|
||||||
"watchonly": True
|
"watchonly": True,
|
||||||
}])
|
"active": True,
|
||||||
|
}]
|
||||||
|
if self.options.descriptors:
|
||||||
|
result = watcher.importdescriptors(reqs)
|
||||||
|
else:
|
||||||
|
result = watcher.importmulti(reqs)
|
||||||
assert_equal(result, [{'success': True}, {'success': True}])
|
assert_equal(result, [{'success': True}, {'success': True}])
|
||||||
|
|
||||||
funding_address1 = watcher.getnewaddress(address_type='bech32')
|
funding_address1 = watcher.getnewaddress(address_type='bech32')
|
||||||
|
|
|
@ -5,11 +5,15 @@
|
||||||
"""Test createwallet arguments.
|
"""Test createwallet arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from test_framework.address import key_to_p2wpkh
|
||||||
|
from test_framework.descriptors import descsum_create
|
||||||
|
from test_framework.key import ECKey
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet_util import bytes_to_wif, generate_wif_key
|
||||||
|
|
||||||
class CreateWalletTest(BitcoinTestFramework):
|
class CreateWalletTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -35,10 +39,14 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||||
w1.importpubkey(w0.getaddressinfo(address1)['pubkey'])
|
w1.importpubkey(w0.getaddressinfo(address1)['pubkey'])
|
||||||
|
|
||||||
self.log.info('Test that private keys cannot be imported')
|
self.log.info('Test that private keys cannot be imported')
|
||||||
addr = w0.getnewaddress('', 'legacy')
|
eckey = ECKey()
|
||||||
privkey = w0.dumpprivkey(addr)
|
eckey.generate()
|
||||||
|
privkey = bytes_to_wif(eckey.get_bytes())
|
||||||
assert_raises_rpc_error(-4, 'Cannot import private keys to a wallet with private keys disabled', w1.importprivkey, privkey)
|
assert_raises_rpc_error(-4, 'Cannot import private keys to a wallet with private keys disabled', w1.importprivkey, privkey)
|
||||||
result = w1.importmulti([{'scriptPubKey': {'address': addr}, 'timestamp': 'now', 'keys': [privkey]}])
|
if self.options.descriptors:
|
||||||
|
result = w1.importdescriptors([{'desc': descsum_create('wpkh(' + privkey + ')'), 'timestamp': 'now'}])
|
||||||
|
else:
|
||||||
|
result = w1.importmulti([{'scriptPubKey': {'address': key_to_p2wpkh(eckey.get_pubkey().get_bytes())}, 'timestamp': 'now', 'keys': [privkey]}])
|
||||||
assert not result[0]['success']
|
assert not result[0]['success']
|
||||||
assert 'warning' not in result[0]
|
assert 'warning' not in result[0]
|
||||||
assert_equal(result[0]['error']['code'], -4)
|
assert_equal(result[0]['error']['code'], -4)
|
||||||
|
@ -58,11 +66,24 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w3.getnewaddress)
|
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w3.getnewaddress)
|
||||||
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w3.getrawchangeaddress)
|
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w3.getrawchangeaddress)
|
||||||
# Import private key
|
# Import private key
|
||||||
w3.importprivkey(w0.dumpprivkey(address1))
|
w3.importprivkey(generate_wif_key())
|
||||||
# Imported private keys are currently ignored by the keypool
|
# Imported private keys are currently ignored by the keypool
|
||||||
assert_equal(w3.getwalletinfo()['keypoolsize'], 0)
|
assert_equal(w3.getwalletinfo()['keypoolsize'], 0)
|
||||||
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w3.getnewaddress)
|
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w3.getnewaddress)
|
||||||
# Set the seed
|
# Set the seed
|
||||||
|
if self.options.descriptors:
|
||||||
|
w3.importdescriptors([{
|
||||||
|
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPcwuZGKp8TeWppSuLMiLe2d9PupB14QpPeQsqoj3LneJLhGHH13xESfvASyd4EFLJvLrG8b7DrLxEuV7hpF9uUc6XruKA1Wq/0h/*)'),
|
||||||
|
'timestamp': 'now',
|
||||||
|
'active': True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPcwuZGKp8TeWppSuLMiLe2d9PupB14QpPeQsqoj3LneJLhGHH13xESfvASyd4EFLJvLrG8b7DrLxEuV7hpF9uUc6XruKA1Wq/1h/*)'),
|
||||||
|
'timestamp': 'now',
|
||||||
|
'active': True,
|
||||||
|
'internal': True
|
||||||
|
}])
|
||||||
|
else:
|
||||||
w3.sethdseed()
|
w3.sethdseed()
|
||||||
assert_equal(w3.getwalletinfo()['keypoolsize'], 1)
|
assert_equal(w3.getwalletinfo()['keypoolsize'], 1)
|
||||||
w3.getnewaddress()
|
w3.getnewaddress()
|
||||||
|
@ -80,6 +101,19 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w4.getrawchangeaddress)
|
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w4.getrawchangeaddress)
|
||||||
# Now set a seed and it should work. Wallet should also be encrypted
|
# Now set a seed and it should work. Wallet should also be encrypted
|
||||||
w4.walletpassphrase('pass', 60)
|
w4.walletpassphrase('pass', 60)
|
||||||
|
if self.options.descriptors:
|
||||||
|
w4.importdescriptors([{
|
||||||
|
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPcwuZGKp8TeWppSuLMiLe2d9PupB14QpPeQsqoj3LneJLhGHH13xESfvASyd4EFLJvLrG8b7DrLxEuV7hpF9uUc6XruKA1Wq/0h/*)'),
|
||||||
|
'timestamp': 'now',
|
||||||
|
'active': True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPcwuZGKp8TeWppSuLMiLe2d9PupB14QpPeQsqoj3LneJLhGHH13xESfvASyd4EFLJvLrG8b7DrLxEuV7hpF9uUc6XruKA1Wq/1h/*)'),
|
||||||
|
'timestamp': 'now',
|
||||||
|
'active': True,
|
||||||
|
'internal': True
|
||||||
|
}])
|
||||||
|
else:
|
||||||
w4.sethdseed()
|
w4.sethdseed()
|
||||||
w4.getnewaddress()
|
w4.getnewaddress()
|
||||||
w4.getrawchangeaddress()
|
w4.getrawchangeaddress()
|
||||||
|
@ -111,13 +145,14 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||||
w6.walletpassphrase('thisisapassphrase', 60)
|
w6.walletpassphrase('thisisapassphrase', 60)
|
||||||
w6.signmessage(w6.getnewaddress('', 'legacy'), "test")
|
w6.signmessage(w6.getnewaddress('', 'legacy'), "test")
|
||||||
w6.keypoolrefill(1)
|
w6.keypoolrefill(1)
|
||||||
# There should only be 1 key
|
# There should only be 1 key for legacy, 3 for descriptors
|
||||||
walletinfo = w6.getwalletinfo()
|
walletinfo = w6.getwalletinfo()
|
||||||
assert_equal(walletinfo['keypoolsize'], 1)
|
keys = 3 if self.options.descriptors else 1
|
||||||
assert_equal(walletinfo['keypoolsize_hd_internal'], 1)
|
assert_equal(walletinfo['keypoolsize'], keys)
|
||||||
|
assert_equal(walletinfo['keypoolsize_hd_internal'], keys)
|
||||||
# Allow empty passphrase, but there should be a warning
|
# Allow empty passphrase, but there should be a warning
|
||||||
resp = self.nodes[0].createwallet(wallet_name='w7', disable_private_keys=False, blank=False, passphrase='')
|
resp = self.nodes[0].createwallet(wallet_name='w7', disable_private_keys=False, blank=False, passphrase='')
|
||||||
assert_equal(resp['warning'], 'Empty string given as passphrase, wallet will not be encrypted.')
|
assert 'Empty string given as passphrase, wallet will not be encrypted.' in resp['warning']
|
||||||
w7 = node.get_wallet_rpc('w7')
|
w7 = node.get_wallet_rpc('w7')
|
||||||
assert_raises_rpc_error(-15, 'Error: running with an unencrypted wallet, but walletpassphrase was called.', w7.walletpassphrase, '', 60)
|
assert_raises_rpc_error(-15, 'Error: running with an unencrypted wallet, but walletpassphrase was called.', w7.walletpassphrase, '', 60)
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
|
||||||
["-addresstype=bech32", "-keypool=5"]
|
["-addresstype=bech32", "-keypool=5"]
|
||||||
]
|
]
|
||||||
self.setup_clean_chain = True
|
self.setup_clean_chain = True
|
||||||
|
self.wallet_names = []
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
def skip_test_if_missing_module(self):
|
||||||
self.skip_if_no_wallet()
|
self.skip_if_no_wallet()
|
||||||
|
@ -59,7 +60,7 @@ class ImportDescriptorsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.log.info('Setting up wallets')
|
self.log.info('Setting up wallets')
|
||||||
self.nodes[0].createwallet(wallet_name='w0', disable_private_keys=False)
|
self.nodes[0].createwallet(wallet_name='w0', disable_private_keys=False, descriptors=True)
|
||||||
w0 = self.nodes[0].get_wallet_rpc('w0')
|
w0 = self.nodes[0].get_wallet_rpc('w0')
|
||||||
|
|
||||||
self.nodes[1].createwallet(wallet_name='w1', disable_private_keys=True, blank=True, descriptors=True)
|
self.nodes[1].createwallet(wallet_name='w1', disable_private_keys=True, blank=True, descriptors=True)
|
||||||
|
|
|
@ -5,11 +5,14 @@
|
||||||
"""Test the importprunedfunds and removeprunedfunds RPCs."""
|
"""Test the importprunedfunds and removeprunedfunds RPCs."""
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from test_framework.address import key_to_p2wpkh
|
||||||
|
from test_framework.key import ECKey
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet_util import bytes_to_wif
|
||||||
|
|
||||||
class ImportPrunedFundsTest(BitcoinTestFramework):
|
class ImportPrunedFundsTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -30,8 +33,11 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
|
||||||
# pubkey
|
# pubkey
|
||||||
address2 = self.nodes[0].getnewaddress()
|
address2 = self.nodes[0].getnewaddress()
|
||||||
# privkey
|
# privkey
|
||||||
address3 = self.nodes[0].getnewaddress()
|
eckey = ECKey()
|
||||||
address3_privkey = self.nodes[0].dumpprivkey(address3) # Using privkey
|
eckey.generate()
|
||||||
|
address3_privkey = bytes_to_wif(eckey.get_bytes())
|
||||||
|
address3 = key_to_p2wpkh(eckey.get_pubkey().get_bytes())
|
||||||
|
self.nodes[0].importprivkey(address3_privkey)
|
||||||
|
|
||||||
# Check only one address
|
# Check only one address
|
||||||
address_info = self.nodes[0].getaddressinfo(address1)
|
address_info = self.nodes[0].getaddressinfo(address1)
|
||||||
|
@ -80,37 +86,44 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
|
||||||
assert_equal(balance1, Decimal(0))
|
assert_equal(balance1, Decimal(0))
|
||||||
|
|
||||||
# Import with affiliated address with no rescan
|
# Import with affiliated address with no rescan
|
||||||
self.nodes[1].importaddress(address=address2, rescan=False)
|
self.nodes[1].createwallet('wwatch', disable_private_keys=True)
|
||||||
self.nodes[1].importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2)
|
wwatch = self.nodes[1].get_wallet_rpc('wwatch')
|
||||||
assert [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid2]
|
wwatch.importaddress(address=address2, rescan=False)
|
||||||
|
wwatch.importprunedfunds(rawtransaction=rawtxn2, txoutproof=proof2)
|
||||||
|
assert [tx for tx in wwatch.listtransactions(include_watchonly=True) if tx['txid'] == txnid2]
|
||||||
|
|
||||||
# Import with private key with no rescan
|
# Import with private key with no rescan
|
||||||
self.nodes[1].importprivkey(privkey=address3_privkey, rescan=False)
|
w1 = self.nodes[1].get_wallet_rpc(self.default_wallet_name)
|
||||||
self.nodes[1].importprunedfunds(rawtxn3, proof3)
|
w1.importprivkey(privkey=address3_privkey, rescan=False)
|
||||||
assert [tx for tx in self.nodes[1].listtransactions() if tx['txid'] == txnid3]
|
w1.importprunedfunds(rawtxn3, proof3)
|
||||||
balance3 = self.nodes[1].getbalance()
|
assert [tx for tx in w1.listtransactions() if tx['txid'] == txnid3]
|
||||||
|
balance3 = w1.getbalance()
|
||||||
assert_equal(balance3, Decimal('0.025'))
|
assert_equal(balance3, Decimal('0.025'))
|
||||||
|
|
||||||
# Addresses Test - after import
|
# Addresses Test - after import
|
||||||
address_info = self.nodes[1].getaddressinfo(address1)
|
address_info = w1.getaddressinfo(address1)
|
||||||
assert_equal(address_info['iswatchonly'], False)
|
assert_equal(address_info['iswatchonly'], False)
|
||||||
assert_equal(address_info['ismine'], False)
|
assert_equal(address_info['ismine'], False)
|
||||||
address_info = self.nodes[1].getaddressinfo(address2)
|
address_info = wwatch.getaddressinfo(address2)
|
||||||
|
if self.options.descriptors:
|
||||||
|
assert_equal(address_info['iswatchonly'], False)
|
||||||
|
assert_equal(address_info['ismine'], True)
|
||||||
|
else:
|
||||||
assert_equal(address_info['iswatchonly'], True)
|
assert_equal(address_info['iswatchonly'], True)
|
||||||
assert_equal(address_info['ismine'], False)
|
assert_equal(address_info['ismine'], False)
|
||||||
address_info = self.nodes[1].getaddressinfo(address3)
|
address_info = w1.getaddressinfo(address3)
|
||||||
assert_equal(address_info['iswatchonly'], False)
|
assert_equal(address_info['iswatchonly'], False)
|
||||||
assert_equal(address_info['ismine'], True)
|
assert_equal(address_info['ismine'], True)
|
||||||
|
|
||||||
# Remove transactions
|
# Remove transactions
|
||||||
assert_raises_rpc_error(-8, "Transaction does not exist in wallet.", self.nodes[1].removeprunedfunds, txnid1)
|
assert_raises_rpc_error(-8, "Transaction does not exist in wallet.", w1.removeprunedfunds, txnid1)
|
||||||
assert not [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid1]
|
assert not [tx for tx in w1.listtransactions(include_watchonly=True) if tx['txid'] == txnid1]
|
||||||
|
|
||||||
self.nodes[1].removeprunedfunds(txnid2)
|
wwatch.removeprunedfunds(txnid2)
|
||||||
assert not [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid2]
|
assert not [tx for tx in wwatch.listtransactions(include_watchonly=True) if tx['txid'] == txnid2]
|
||||||
|
|
||||||
self.nodes[1].removeprunedfunds(txnid3)
|
w1.removeprunedfunds(txnid3)
|
||||||
assert not [tx for tx in self.nodes[1].listtransactions(include_watchonly=True) if tx['txid'] == txnid3]
|
assert not [tx for tx in w1.listtransactions(include_watchonly=True) if tx['txid'] == txnid3]
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ImportPrunedFundsTest().main()
|
ImportPrunedFundsTest().main()
|
||||||
|
|
|
@ -135,7 +135,7 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||||
change_label(node, labels[2].addresses[0], labels[2], labels[2])
|
change_label(node, labels[2].addresses[0], labels[2], labels[2])
|
||||||
|
|
||||||
self.log.info('Check watchonly labels')
|
self.log.info('Check watchonly labels')
|
||||||
node.createwallet(wallet_name='watch_only', disable_private_keys=True, descriptors=False)
|
node.createwallet(wallet_name='watch_only', disable_private_keys=True)
|
||||||
wallet_watch_only = node.get_wallet_rpc('watch_only')
|
wallet_watch_only = node.get_wallet_rpc('watch_only')
|
||||||
BECH32_VALID = {
|
BECH32_VALID = {
|
||||||
'✔️_VER15_PROG40': 'bcrt10qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqn2cjv3',
|
'✔️_VER15_PROG40': 'bcrt10qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqn2cjv3',
|
||||||
|
@ -156,7 +156,7 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||||
ad = BECH32_INVALID[l]
|
ad = BECH32_INVALID[l]
|
||||||
assert_raises_rpc_error(
|
assert_raises_rpc_error(
|
||||||
-5,
|
-5,
|
||||||
"Invalid Bitcoin address or script",
|
"Address is not valid" if self.options.descriptors else "Invalid Bitcoin address or script",
|
||||||
lambda: wallet_watch_only.importaddress(label=l, rescan=False, address=ad),
|
lambda: wallet_watch_only.importaddress(label=l, rescan=False, address=ad),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test the listsinceblock RPC."""
|
"""Test the listsinceblock RPC."""
|
||||||
|
|
||||||
|
from test_framework.address import key_to_p2wpkh
|
||||||
|
from test_framework.key import ECKey
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.messages import BIP125_SEQUENCE_NUMBER
|
from test_framework.messages import BIP125_SEQUENCE_NUMBER
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
|
@ -11,6 +13,7 @@ from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet_util import bytes_to_wif
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
@ -181,15 +184,21 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
|
||||||
|
# share utxo between nodes[1] and nodes[2]
|
||||||
|
eckey = ECKey()
|
||||||
|
eckey.generate()
|
||||||
|
privkey = bytes_to_wif(eckey.get_bytes())
|
||||||
|
address = key_to_p2wpkh(eckey.get_pubkey().get_bytes())
|
||||||
|
self.nodes[2].sendtoaddress(address, 10)
|
||||||
|
self.nodes[2].generate(6)
|
||||||
|
self.nodes[2].importprivkey(privkey)
|
||||||
|
utxos = self.nodes[2].listunspent()
|
||||||
|
utxo = [u for u in utxos if u["address"] == address][0]
|
||||||
|
self.nodes[1].importprivkey(privkey)
|
||||||
|
|
||||||
# Split network into two
|
# Split network into two
|
||||||
self.split_network()
|
self.split_network()
|
||||||
|
|
||||||
# share utxo between nodes[1] and nodes[2]
|
|
||||||
utxos = self.nodes[2].listunspent()
|
|
||||||
utxo = utxos[0]
|
|
||||||
privkey = self.nodes[2].dumpprivkey(utxo['address'])
|
|
||||||
self.nodes[1].importprivkey(privkey)
|
|
||||||
|
|
||||||
# send from nodes[1] using utxo to nodes[0]
|
# send from nodes[1] using utxo to nodes[0]
|
||||||
change = '%.8f' % (float(utxo['amount']) - 1.0003)
|
change = '%.8f' % (float(utxo['amount']) - 1.0003)
|
||||||
recipient_dict = {
|
recipient_dict = {
|
||||||
|
|
|
@ -91,6 +91,8 @@ class ListTransactionsTest(BitcoinTestFramework):
|
||||||
{"category": "receive", "amount": Decimal("0.44")},
|
{"category": "receive", "amount": Decimal("0.44")},
|
||||||
{"txid": txid})
|
{"txid": txid})
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# include_watchonly is a legacy wallet feature, so don't test it for descriptor wallets
|
||||||
pubkey = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['pubkey']
|
pubkey = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['pubkey']
|
||||||
multisig = self.nodes[1].createmultisig(1, [pubkey])
|
multisig = self.nodes[1].createmultisig(1, [pubkey])
|
||||||
self.nodes[0].importaddress(multisig["redeemScript"], "watchonly", False, True)
|
self.nodes[0].importaddress(multisig["redeemScript"], "watchonly", False, True)
|
||||||
|
|
|
@ -82,8 +82,8 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
# directory paths) can be loaded
|
# directory paths) can be loaded
|
||||||
# create another dummy wallet for use in testing backups later
|
# create another dummy wallet for use in testing backups later
|
||||||
self.start_node(0)
|
self.start_node(0)
|
||||||
node.createwallet("empty", descriptors=False)
|
node.createwallet("empty")
|
||||||
node.createwallet("plain", descriptors=False)
|
node.createwallet("plain")
|
||||||
node.createwallet("created")
|
node.createwallet("created")
|
||||||
self.stop_nodes()
|
self.stop_nodes()
|
||||||
empty_wallet = os.path.join(self.options.tmpdir, 'empty.dat')
|
empty_wallet = os.path.join(self.options.tmpdir, 'empty.dat')
|
||||||
|
@ -101,20 +101,29 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
# sub/w5 - to verify relative wallet path is created correctly
|
# sub/w5 - to verify relative wallet path is created correctly
|
||||||
# extern/w6 - to verify absolute wallet path is created correctly
|
# extern/w6 - to verify absolute wallet path is created correctly
|
||||||
# w7_symlink - to verify symlinked wallet path is initialized correctly
|
# w7_symlink - to verify symlinked wallet path is initialized correctly
|
||||||
# w8 - to verify existing wallet file is loaded correctly
|
# w8 - to verify existing wallet file is loaded correctly. Not tested for SQLite wallets as this is a deprecated BDB behavior.
|
||||||
# '' - to verify default wallet file is created correctly
|
# '' - to verify default wallet file is created correctly
|
||||||
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', self.default_wallet_name]
|
to_create = ['w1', 'w2', 'w3', 'w', 'sub/w5', 'w7_symlink']
|
||||||
|
in_wallet_dir = to_create.copy() # Wallets in the wallet dir
|
||||||
|
in_wallet_dir.append('w7') # w7 is not loaded or created, but will be listed by listwalletdir because w7_symlink
|
||||||
|
to_create.append(os.path.join(self.options.tmpdir, 'extern/w6')) # External, not in the wallet dir, so we need to avoid adding it to in_wallet_dir
|
||||||
|
to_load = [self.default_wallet_name]
|
||||||
|
if not self.options.descriptors:
|
||||||
|
to_load.append('w8')
|
||||||
|
wallet_names = to_create + to_load # Wallet names loaded in the wallet
|
||||||
|
in_wallet_dir += to_load # The loaded wallets are also in the wallet dir
|
||||||
self.start_node(0)
|
self.start_node(0)
|
||||||
for wallet_name in wallet_names[:-2]:
|
for wallet_name in to_create:
|
||||||
self.nodes[0].createwallet(wallet_name, descriptors=False)
|
self.nodes[0].createwallet(wallet_name)
|
||||||
for wallet_name in wallet_names[-2:]:
|
for wallet_name in to_load:
|
||||||
self.nodes[0].loadwallet(wallet_name)
|
self.nodes[0].loadwallet(wallet_name)
|
||||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8'])
|
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), sorted(in_wallet_dir))
|
||||||
|
|
||||||
assert_equal(set(node.listwallets()), set(wallet_names))
|
assert_equal(set(node.listwallets()), set(wallet_names))
|
||||||
|
|
||||||
# should raise rpc error if wallet path can't be created
|
# should raise rpc error if wallet path can't be created
|
||||||
assert_raises_rpc_error(-1, "boost::filesystem::create_directory:", self.nodes[0].createwallet, "w8/bad", descriptors=False)
|
err_code = -4 if self.options.descriptors else -1
|
||||||
|
assert_raises_rpc_error(err_code, "boost::filesystem::create_directory:", self.nodes[0].createwallet, "w8/bad")
|
||||||
|
|
||||||
# check that all requested wallets were created
|
# check that all requested wallets were created
|
||||||
self.stop_node(0)
|
self.stop_node(0)
|
||||||
|
@ -128,8 +137,11 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
# should not initialize if there are duplicate wallets
|
# should not initialize if there are duplicate wallets
|
||||||
self.nodes[0].assert_start_raises_init_error(['-wallet=w1', '-wallet=w1'], 'Error: Error loading wallet w1. Duplicate -wallet filename specified.')
|
self.nodes[0].assert_start_raises_init_error(['-wallet=w1', '-wallet=w1'], 'Error: Error loading wallet w1. Duplicate -wallet filename specified.')
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
|
# Only BDB doesn't open duplicate wallet files. SQLite does not have this limitation. While this may be desired in the future, it is not necessary
|
||||||
# should not initialize if one wallet is a copy of another
|
# should not initialize if one wallet is a copy of another
|
||||||
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy'))
|
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy'))
|
||||||
|
in_wallet_dir.append('w8_copy')
|
||||||
exp_stderr = r"BerkeleyDatabase: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
|
exp_stderr = r"BerkeleyDatabase: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
|
||||||
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
|
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
|
||||||
|
|
||||||
|
@ -167,7 +179,10 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir')
|
competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir')
|
||||||
os.mkdir(competing_wallet_dir)
|
os.mkdir(competing_wallet_dir)
|
||||||
self.restart_node(0, ['-nowallet', '-walletdir=' + competing_wallet_dir])
|
self.restart_node(0, ['-nowallet', '-walletdir=' + competing_wallet_dir])
|
||||||
self.nodes[0].createwallet(self.default_wallet_name, descriptors=False)
|
self.nodes[0].createwallet(self.default_wallet_name)
|
||||||
|
if self.options.descriptors:
|
||||||
|
exp_stderr = r"Error: SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another bitcoind?"
|
||||||
|
else:
|
||||||
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\S*\"!"
|
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\S*\"!"
|
||||||
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
|
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
|
||||||
|
|
||||||
|
@ -175,7 +190,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
for wallet_name in wallet_names:
|
for wallet_name in wallet_names:
|
||||||
self.nodes[0].loadwallet(wallet_name)
|
self.nodes[0].loadwallet(wallet_name)
|
||||||
|
|
||||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy'])
|
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), sorted(in_wallet_dir))
|
||||||
|
|
||||||
wallets = [wallet(w) for w in wallet_names]
|
wallets = [wallet(w) for w in wallet_names]
|
||||||
wallet_bad = wallet("bad")
|
wallet_bad = wallet("bad")
|
||||||
|
@ -266,13 +281,17 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Fail to load duplicate wallets
|
# Fail to load duplicate wallets
|
||||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", "wallet.dat")
|
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", "wallet.dat")
|
||||||
|
if self.options.descriptors:
|
||||||
|
assert_raises_rpc_error(-4, "Wallet file verification failed. SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another bitcoind?", self.nodes[0].loadwallet, wallet_names[0])
|
||||||
|
else:
|
||||||
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, wallet_names[0])
|
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, wallet_names[0])
|
||||||
|
|
||||||
|
# This tests the default wallet that BDB makes, so SQLite wallet doesn't need to test this
|
||||||
# Fail to load duplicate wallets by different ways (directory and filepath)
|
# Fail to load duplicate wallets by different ways (directory and filepath)
|
||||||
if not self.options.descriptors:
|
|
||||||
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallet.dat")
|
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallet.dat")
|
||||||
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, 'wallet.dat')
|
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, 'wallet.dat')
|
||||||
|
|
||||||
|
# Only BDB doesn't open duplicate wallet files. SQLite does not have this limitation. While this may be desired in the future, it is not necessary
|
||||||
# Fail to load if one wallet is a copy of another
|
# Fail to load if one wallet is a copy of another
|
||||||
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
|
||||||
|
|
||||||
|
@ -296,6 +315,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Successfully create a wallet with a new name
|
# Successfully create a wallet with a new name
|
||||||
loadwallet_name = self.nodes[0].createwallet('w9')
|
loadwallet_name = self.nodes[0].createwallet('w9')
|
||||||
|
in_wallet_dir.append('w9')
|
||||||
assert_equal(loadwallet_name['name'], 'w9')
|
assert_equal(loadwallet_name['name'], 'w9')
|
||||||
w9 = node.get_wallet_rpc('w9')
|
w9 = node.get_wallet_rpc('w9')
|
||||||
assert_equal(w9.getwalletinfo()['walletname'], 'w9')
|
assert_equal(w9.getwalletinfo()['walletname'], 'w9')
|
||||||
|
@ -343,7 +363,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[0].listwallets(), ['w1'])
|
assert_equal(self.nodes[0].listwallets(), ['w1'])
|
||||||
assert_equal(w1.getwalletinfo()['walletname'], 'w1')
|
assert_equal(w1.getwalletinfo()['walletname'], 'w1')
|
||||||
|
|
||||||
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy', 'w9'])
|
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), sorted(in_wallet_dir))
|
||||||
|
|
||||||
# Test backing up and restoring wallets
|
# Test backing up and restoring wallets
|
||||||
self.log.info("Test wallet backup")
|
self.log.info("Test wallet backup")
|
||||||
|
|
Loading…
Reference in a new issue