Skip to content

Commit 06b2d85

Browse files
laanwjknst
authored andcommitted
partial Merge bitcoin#20267: Disable and fix tests for when BDB is not compiled
Backport notice: changes in feature_notification.py are missing due to bitcoin#18878 is not done yet 49797c3 tests: Disable bdb dump test when no bdb (Andrew Chow) 1194cf9 Fix wallet_send.py wallet setup to work with descriptors (Andrew Chow) fbaea7b Require legacy wallet for wallet_upgradewallet.py (Andrew Chow) b1b679e Explicitly mark legacy wallet tests as such (Andrew Chow) 09514e1 Setup wallets for interface_zmq.py (Andrew Chow) 4d03ef9 Use MiniWallet in rpc_net.py (Andrew Chow) 4de2382 Setup wallets for interface_bitcoin_cli.py (Andrew Chow) 7c71c62 Setup wallets with descriptors for feature_notifications (Andrew Chow) 1f1bef8 Have feature_filelock.py test both bdb and sqlite, depending on compiled (Andrew Chow) c77975a Disable upgrades tests that require BDB if BDB is not compiled (Andrew Chow) 1f20cac Disable wallet_descriptor.py bdb format check if BDB is not compiled (Andrew Chow) 3641597 tests: Don't make any wallets unless wallet is required (Andrew Chow) b9b88f5 Skip legacy wallet reliant tests if BDB is not compiled (Andrew Chow) 6f36242 tests: Set descriptors default based on compilation (Andrew Chow) Pull request description: This PR fixes tests for when BDB is not compiled. Tests which rely on or test legacy wallet behavior are disabled and skipped when BDB is not compiled. For the components of some tests that are for legacy wallet things, those parts of the tests are skipped. For the majority of tests, changes are made so that they can be run with either legacy wallets or descriptor wallets without materially effecting the test. Most tests only need the wallet for balance and transactions, so the type of wallet is not an important part of those tests. Additionally, some tests are wallet agnostic and modified to instead use the test framework's MiniWallet. ACKs for top commit: laanwj: ACK 49797c3 ryanofsky: Code review ACK 49797c3. Only change since last review is dropping last commit. Previous review w/ suggestions for future followup is bitcoin#20267 (review) Tree-SHA512: 69659f8a81fb437ecbca962f4082c12835282dbf1fba7d9952f727a49e01981d749af9b09feda1c8ca737516c7d7a08ef17e782795df3fa69892d5021b41c1ed
1 parent 0a62b9f commit 06b2d85

File tree

8 files changed

+202
-123
lines changed

8 files changed

+202
-123
lines changed

test/functional/feature_backwards_compatibility.py

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -350,51 +350,53 @@ def run_test(self):
350350
#v17_hdkeypath = v17_info["hdkeypath"]
351351
v17_pubkey = v17_info["pubkey"]
352352

353-
# Copy the 0.17 wallet to the last Bitcoin Core version and open it:
354-
node_v17.unloadwallet("u1_v17")
355-
shutil.copytree(
356-
os.path.join(node_v17_wallets_dir, "u1_v17"),
357-
os.path.join(node_master_wallets_dir, "u1_v17")
358-
)
359-
node_master.loadwallet("u1_v17")
360-
wallet = node_master.get_wallet_rpc("u1_v17")
361-
info = wallet.getaddressinfo(address)
362-
# TODO enable back when HD wallets are created by default
363-
#descriptor = "pkh([" + info["hdmasterfingerprint"] + hdkeypath[1:] + "]" + v17_pubkey + ")"
364-
#assert_equal(info["desc"], descsum_create(descriptor))
365-
assert_equal(info["pubkey"], v17_pubkey)
366-
367-
# Now copy that same wallet back to 0.17 to make sure no automatic upgrade breaks it
368-
node_master.unloadwallet("u1_v17")
369-
shutil.rmtree(os.path.join(node_v17_wallets_dir, "u1_v17"))
370-
shutil.copytree(
371-
os.path.join(node_master_wallets_dir, "u1_v17"),
372-
os.path.join(node_v17_wallets_dir, "u1_v17")
373-
)
374-
node_v17.loadwallet("u1_v17")
375-
wallet = node_v17.get_wallet_rpc("u1_v17")
376-
info = wallet.getaddressinfo(address)
377-
assert_equal(info, v17_info)
378-
379-
# Copy the 0.19 wallet to the last Bitcoin Core version and open it:
380-
shutil.copytree(
381-
os.path.join(node_v19_wallets_dir, "w1_v19"),
382-
os.path.join(node_master_wallets_dir, "w1_v19")
383-
)
384-
node_master.loadwallet("w1_v19")
385-
wallet = node_master.get_wallet_rpc("w1_v19")
386-
assert wallet.getaddressinfo(address_18075)["solvable"]
353+
if self.is_bdb_compiled():
354+
# Old wallets are BDB and will only work if BDB is compiled
355+
# Copy the 0.16 wallet to the last Bitcoin Core version and open it:
356+
node_v17.unloadwallet("u1_v17")
357+
shutil.copytree(
358+
os.path.join(node_v17_wallets_dir, "u1_v17"),
359+
os.path.join(node_master_wallets_dir, "u1_v17")
360+
)
361+
node_master.loadwallet("u1_v17")
362+
wallet = node_master.get_wallet_rpc("u1_v17")
363+
info = wallet.getaddressinfo(address)
364+
# TODO enable back when HD wallets are created by default
365+
#descriptor = "pkh([" + info["hdmasterfingerprint"] + hdkeypath[1:] + "]" + v17_pubkey + ")"
366+
#assert_equal(info["desc"], descsum_create(descriptor))
367+
assert_equal(info["pubkey"], v17_pubkey)
387368

388-
# Now copy that same wallet back to 0.19 to make sure no automatic upgrade breaks it
389-
node_master.unloadwallet("w1_v19")
390-
shutil.rmtree(os.path.join(node_v19_wallets_dir, "w1_v19"))
391-
shutil.copytree(
392-
os.path.join(node_master_wallets_dir, "w1_v19"),
393-
os.path.join(node_v19_wallets_dir, "w1_v19")
394-
)
395-
node_v19.loadwallet("w1_v19")
396-
wallet = node_v19.get_wallet_rpc("w1_v19")
397-
assert wallet.getaddressinfo(address_18075)["solvable"]
369+
# Now copy that same wallet back to 0.17 to make sure no automatic upgrade breaks it
370+
node_master.unloadwallet("u1_v17")
371+
shutil.rmtree(os.path.join(node_v17_wallets_dir, "u1_v17"))
372+
shutil.copytree(
373+
os.path.join(node_master_wallets_dir, "u1_v17"),
374+
os.path.join(node_v17_wallets_dir, "u1_v17")
375+
)
376+
node_v17.loadwallet("u1_v17")
377+
wallet = node_v17.get_wallet_rpc("u1_v17")
378+
info = wallet.getaddressinfo(address)
379+
assert_equal(info, v17_info)
380+
381+
# Copy the 0.19 wallet to the last Bitcoin Core version and open it:
382+
shutil.copytree(
383+
os.path.join(node_v19_wallets_dir, "w1_v19"),
384+
os.path.join(node_master_wallets_dir, "w1_v19")
385+
)
386+
node_master.loadwallet("w1_v19")
387+
wallet = node_master.get_wallet_rpc("w1_v19")
388+
assert wallet.getaddressinfo(address_18075)["solvable"]
389+
390+
# Now copy that same wallet back to 0.19 to make sure no automatic upgrade breaks it
391+
node_master.unloadwallet("w1_v19")
392+
shutil.rmtree(os.path.join(node_v19_wallets_dir, "w1_v19"))
393+
shutil.copytree(
394+
os.path.join(node_master_wallets_dir, "w1_v19"),
395+
os.path.join(node_v19_wallets_dir, "w1_v19")
396+
)
397+
node_v19.loadwallet("w1_v19")
398+
wallet = node_v19.get_wallet_rpc("w1_v19")
399+
assert wallet.getaddressinfo(address_18075)["solvable"]
398400

399401
if __name__ == '__main__':
400402
BackwardsCompatibilityTest().main()

test/functional/feature_filelock.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,21 @@ def run_test(self):
3333
self.nodes[1].assert_start_raises_init_error(extra_args=['-datadir={}'.format(self.nodes[0].datadir), '-noserver'], expected_msg=expected_msg)
3434

3535
if self.is_wallet_compiled():
36-
wallet_name = ''.join([random.choice(string.ascii_lowercase) for _ in range(6)])
37-
self.nodes[0].createwallet(wallet_name=wallet_name)
38-
wallet_dir = os.path.join(datadir, 'wallets')
39-
self.log.info("Check that we can't start a second dashd instance using the same wallet")
40-
expected_msg = "Error: SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another dashd?"
36+
def check_wallet_filelock(descriptors):
37+
wallet_name = ''.join([random.choice(string.ascii_lowercase) for _ in range(6)])
38+
self.nodes[0].createwallet(wallet_name=wallet_name, descriptors=descriptors)
39+
wallet_dir = os.path.join(datadir, 'wallets')
40+
self.log.info("Check that we can't start a second dashd instance using the same wallet")
41+
if descriptors:
42+
expected_msg = "Error: SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another dashd?"
43+
else:
44+
expected_msg = "Error: Error initializing wallet database environment"
45+
self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-wallet=' + wallet_name, '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
46+
4147
if self.is_bdb_compiled():
42-
expected_msg = "Error: Error initializing wallet database environment"
43-
self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-wallet=' + wallet_name, '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
48+
check_wallet_filelock(False)
49+
if self.is_sqlite_compiled():
50+
check_wallet_filelock(True)
4451

4552
if __name__ == '__main__':
4653
FilelockTest().main()

test/functional/interface_zmq.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def receive(self):
4242
class ZMQTest (BitcoinTestFramework):
4343
def set_test_params(self):
4444
self.num_nodes = 2
45+
if self.is_wallet_compiled():
46+
self.requires_wallet = True
4547

4648
def skip_test_if_missing_module(self):
4749
self.skip_if_no_py3_zmq()

test/functional/rpc_net.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
assert_raises_rpc_error,
2424
p2p_port,
2525
)
26+
from test_framework.wallet import MiniWallet
2627

2728

2829
def assert_net_servicesnames(servicesflag, servicenames):
@@ -44,6 +45,9 @@ def set_test_params(self):
4445
self.supports_cli = False
4546

4647
def run_test(self):
48+
# We need miniwallet to make a transaction
49+
self.wallet = MiniWallet(self.nodes[0])
50+
self.wallet.generate(1)
4751
# Get out of IBD for the getpeerinfo tests.
4852
self.nodes[0].generate(101)
4953
# Wait for one ping/pong to finish so that we can be sure that there is no chatter between nodes for some time
@@ -163,8 +167,7 @@ def test_getaddednodeinfo(self):
163167
def test_getpeerinfo(self):
164168
self.log.info("Test getpeerinfo")
165169
# Create a few getpeerinfo last_block/last_transaction values.
166-
if self.is_wallet_compiled():
167-
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
170+
self.wallet.send_self_transfer(from_node=self.nodes[0]) # Make a transaction so we can see it in the getpeerinfo results
168171
self.nodes[1].generate(1)
169172
self.sync_all()
170173
time_now = self.mocktime

test/functional/test_framework/test_framework.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ def parse_args(self):
222222
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')
223223

224224
group = parser.add_mutually_exclusive_group()
225-
group.add_argument("--descriptors", default=False, action="store_true",
225+
group.add_argument("--descriptors", action='store_const', const=True,
226226
help="Run test using a descriptor wallet", dest='descriptors')
227-
group.add_argument("--legacy-wallet", default=False, action="store_false",
227+
group.add_argument("--legacy-wallet", action='store_const', const=False,
228228
help="Run test using legacy wallets", dest='descriptors')
229229

230230
self.add_options(parser)
@@ -240,6 +240,17 @@ def parse_args(self):
240240
# source: https://stackoverflow.com/questions/48796169/how-to-fix-ipykernel-launcher-py-error-unrecognized-arguments-in-jupyter/56349168#56349168
241241
parser.add_argument("-f", "--fff", help="a dummy argument to fool ipython", default="1")
242242

243+
if self.options.descriptors is None:
244+
# Prefer BDB unless it isn't available
245+
if self.is_bdb_compiled():
246+
self.options.descriptors = False
247+
elif self.is_sqlite_compiled():
248+
self.options.descriptors = True
249+
else:
250+
# If neither are compiled, tests requiring a wallet will be skipped and the value of self.options.descriptors won't matter
251+
# It still needs to exist and be None in order for tests to work however.
252+
self.options.descriptors = None
253+
243254
PortSeed.n = self.options.port_seed
244255

245256
def setup(self):

0 commit comments

Comments
 (0)