From bb85972f53cd8506f49f7da53dc0e889232ca5c7 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:24:11 +0000 Subject: [PATCH 1/2] qa: Test scanning errors individually This change ensures that each condition potentially triggering the "Error scanning" log message is tested independently, avoiding false positives. Additionally, the "Permission denied" error test is now performed conditionally, skipping scenarios where it is not applicable (e.g., when running as root or on Windows). --- test/functional/wallet_multiwallet.py | 35 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index e241edd3fa6..e511795f594 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -86,9 +86,6 @@ class MultiWalletTest(BitcoinTestFramework): os.symlink('..', wallet_dir('recursive_dir_symlink')) - os.mkdir(wallet_dir('self_walletdat_symlink')) - os.symlink('wallet.dat', wallet_dir('self_walletdat_symlink/wallet.dat')) - # rename wallet.dat to make sure plain wallet file paths (as opposed to # directory paths) can be loaded # create another dummy wallet for use in testing backups later @@ -129,14 +126,30 @@ class MultiWalletTest(BitcoinTestFramework): for wallet_name in to_load: self.nodes[0].loadwallet(wallet_name) - os.mkdir(wallet_dir('no_access')) - os.chmod(wallet_dir('no_access'), 0) - try: - with self.nodes[0].assert_debug_log(expected_msgs=['Error scanning']): - walletlist = self.nodes[0].listwalletdir()['wallets'] - finally: - # Need to ensure access is restored for cleanup - os.chmod(wallet_dir('no_access'), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) + # Tests for possible scanning errors: + # 0. Baseline, no errors. + with self.nodes[0].assert_debug_log(expected_msgs=[], unexpected_msgs=['Error scanning']): + walletlist = self.nodes[0].listwalletdir()['wallets'] + assert_equal(sorted(map(lambda w: w['name'], walletlist)), sorted(in_wallet_dir)) + # 1. "Permission denied" error. + if platform.system() != 'Windows': + if os.geteuid() == 0: + self.log.warning('Skipping "permission denied"-test requiring non-root user.') + else: + os.mkdir(wallet_dir('no_access')) + os.chmod(wallet_dir('no_access'), 0) + try: + with self.nodes[0].assert_debug_log(expected_msgs=['Error scanning']): + walletlist = self.nodes[0].listwalletdir()['wallets'] + finally: + # Need to ensure access is restored for cleanup + os.chmod(wallet_dir('no_access'), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) + assert_equal(sorted(map(lambda w: w['name'], walletlist)), sorted(in_wallet_dir)) + # 2. "Too many levels of symbolic links" error. + os.mkdir(wallet_dir('self_walletdat_symlink')) + os.symlink('wallet.dat', wallet_dir('self_walletdat_symlink/wallet.dat')) + with self.nodes[0].assert_debug_log(expected_msgs=['Error scanning']): + walletlist = self.nodes[0].listwalletdir()['wallets'] assert_equal(sorted(map(lambda w: w['name'], walletlist)), sorted(in_wallet_dir)) assert_equal(set(node.listwallets()), set(wallet_names)) From 9025657baaf99fcf630cc1a37baec11b072196fa Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:24:33 +0000 Subject: [PATCH 2/2] qa: Disable self-symlink test on Windows and document it --- test/functional/wallet_multiwallet.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index e511795f594..90bb226cbaa 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -146,11 +146,16 @@ class MultiWalletTest(BitcoinTestFramework): os.chmod(wallet_dir('no_access'), stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) assert_equal(sorted(map(lambda w: w['name'], walletlist)), sorted(in_wallet_dir)) # 2. "Too many levels of symbolic links" error. - os.mkdir(wallet_dir('self_walletdat_symlink')) - os.symlink('wallet.dat', wallet_dir('self_walletdat_symlink/wallet.dat')) - with self.nodes[0].assert_debug_log(expected_msgs=['Error scanning']): - walletlist = self.nodes[0].listwalletdir()['wallets'] - assert_equal(sorted(map(lambda w: w['name'], walletlist)), sorted(in_wallet_dir)) + # This test cannot be conducted robustly on Windows + # because it depends on the build toolchain: + # - A cross-compiled bitcoind.exe parses self_walletdat_symlink without errors. + # - A natively compiled bitcoind.exe logs the "Error scanning" message. + if platform.system() != 'Windows': + os.mkdir(wallet_dir('self_walletdat_symlink')) + os.symlink('wallet.dat', wallet_dir('self_walletdat_symlink/wallet.dat')) + with self.nodes[0].assert_debug_log(expected_msgs=['Error scanning']): + walletlist = self.nodes[0].listwalletdir()['wallets'] + assert_equal(sorted(map(lambda w: w['name'], walletlist)), sorted(in_wallet_dir)) assert_equal(set(node.listwallets()), set(wallet_names))