Skip to content

test: Get rid of default wallet hacks - #20034

Merged
maflcko merged 2 commits into
bitcoin:masterfrom
ryanofsky:pr/defw
Oct 2, 2020
Merged

maflcko merged 2 commits into
bitcoin:masterfrom
ryanofsky:pr/defw

Conversation

@ryanofsky

@ryanofsky ryanofsky commented Sep 29, 2020 •

Copy link
Copy Markdown
Contributor

Changes:

  • Get rid of setup_nodes (-wallet, -nowallet, -disablewallet) argument rewriting
  • Get rid of hardcoded wallet "" names and -wallet="" args

Motivation:

  • Simplify test framework behavior so it's easier to write new tests without having arguments mangled by the framework
  • Make tests more readable, replacing unexplained "" string literals with default_wallet_name references
  • Make it trivial to update default wallet name and wallet data filename for sqlite wallet: Add sqlite as an alternative wallet database and use it for new descriptor wallets #19077 testing
  • Stop relying on -wallet arguments to create wallets, so it is easy to change -wallet option in the future to only load existing wallets not create new ones (to avoid accidental wallet creation, and encourage use of wallet encryption and descriptor features)

- Get rid of hardcoded wallet "" names and -wallet="" args
- Get rid of setup_nodes (-wallet, -nowallet, -disablewallet) argument rewriting

Motivation:

- Simplify test framework behavior so it's easier to write new tests without
  having arguments mangled by the framework
- Make tests more readable, replacing unexplained "" string literals with
  default_wallet_name references
- Make it trivial to update default wallet name and wallet data filename for
  sqlite bitcoin#19077 testing
- Stop relying on -wallet arguments to create wallets, so it is easy to change
  -wallet option in the future to only load existing wallets not create new
  ones (to avoid accidental wallet creation, and encourage use of wallet
  encryption and descriptor features)
@fanquake fanquake added the Tests label Sep 29, 2020
# should not initialize if wallet path can't be created
exp_stderr = "boost::filesystem::create_directory:"
self.nodes[0].assert_start_raises_init_error(['-wallet=wallet.dat/bad'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
self.nodes[0].assert_start_raises_init_error(['-wallet=w8/bad'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)

@ryanofsky ryanofsky Sep 29, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This change isn't strictly necessary, but using w8 instead of wallet.dat here makes the test more robust so default_wallet_filename can be changed in the future. The top level wallet directory will always contain a w8 file, but may or may not contain a wallet.dat file, depending on the default_wallet_filename value.

@fanquake
fanquake requested a review from achow101 September 29, 2020 12:28
@DrahtBot

DrahtBot commented Sep 29, 2020 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko

maflcko commented Sep 29, 2020

Copy link
Copy Markdown
Member

Do all of the changes need to happen in one commit? Also, the build without wallet doesn't pass the tests

@ryanofsky

Copy link
Copy Markdown
Contributor Author

Thanks, I'll check the no wallet build. I don't think this is PR hard to review. It was very difficult to write, because every one change I made broke other things and required more changes. But in the end, the main change was just dropping -wallet="" arguments and tweaking things to work around the dropped arguments.

I would also expect if you're looking at one test and want to see how this PR affects the test, you'd rather look at one diff instead of multiple diffs. But I guess you have that option regardless by diffing across commits, so I'll see if there are sensible ways to have multiple commits.

@ryanofsky

Copy link
Copy Markdown
Contributor Author

Updated 9fbba7c -> c072c85 (pr/defw.1 -> pr/defw.2, compare) with suggestions from Marco (thanks!) splitting up commits and adding missing is_wallet_compiled check

@achow101

Copy link
Copy Markdown
Member

I don't really like removing the createwallet override as it makes it more difficult to enable additional tests for descriptor wallets and lets us enable a test for descriptor wallets without having to modify every createwallet call in a test.

@ryanofsky

Copy link
Copy Markdown
Contributor Author

re: @achow101 #20034 (comment)

I don't really like removing the createwallet override as it makes it more difficult to enable additional tests for descriptor wallets and lets us enable a test for descriptor wallets without having to modify every createwallet call in a test.

Thanks! Dropped commit be968c4 as I didn't realize it was separable. The change does seem like a win to me for simplicity and making things explicit, so maybe I will try to revive it in some form. But there's no reason to include it here.


Updated c072c85 -> 5338dfa (pr/defw.2 -> pr/defw.3, compare) just dropping commit be968c4

self.assert_tool_output('', '-wallet=salvage', 'salvage')

def run_test(self):
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the -wallet=wallet.dat throughout this test use self.wallet_data_filename too then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #20034 (comment)

Should the -wallet=wallet.dat throughout this test use self.wallet_data_filename too then?

It effectively is. I think you are maybe only looking at the first commit, not the overall diff? The wallet.dat references are removed in the second commit, since more robust way to refer to wallets is by directory name not data file name. (The data file name used inside wallets is an implementation detail and referring to it is only supported in limited cases for backwards compatibility. Dropping references to the data file name lets the test work with all default_wallet_name values.)

wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', '']
extra_args = ['-wallet={}'.format(n) for n in wallet_names]
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', self.default_wallet_name]
extra_args = ['-nowallet'] + ['-wallet={}'.format(n) for n in wallet_names]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #20034 (comment)

Why?

Specifying -nowallet keeps test behavior unchanged now that the load on startup option is used. Probably if you were writing this test from scratch, you would drop -nowallet and instead change the checks below. But this is the most minimal update for the existing test, it is also nice because it keeps the test more narrow and robust to outside changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the first commit:

The test passes without this change, so I am still wondering why this is needed.

Also, the commit doesn't seem to be exhaustive. The wallet.dat/bad should be replaced as well. Also, the usages in tool_wallet.py. See the diff I used for testing:

diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index bd1d114730..89d7325e1c 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -20,6 +20,6 @@ void SplitWalletPath(const fs::path& wallet_path, fs::path& env_directory, std::
         // Normal case: Interpret wallet path as a directory path containing
         // data and log files.
         env_directory = wallet_path;
-        database_filename = "wallet.dat";
+        database_filename = "wallet_dat";
     }
 }
diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp
index 8f0083cd2e..3489d48879 100644
--- a/src/wallet/test/db_tests.cpp
+++ b/src/wallet/test/db_tests.cpp
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(getwalletenv_file)
 
 BOOST_AUTO_TEST_CASE(getwalletenv_directory)
 {
-    std::string expected_name = "wallet.dat";
+    std::string expected_name = "wallet_dat";
     const fs::path datadir = GetDataDir();
 
     std::string filename;
diff --git a/src/wallet/walletutil.cpp b/src/wallet/walletutil.cpp
index e4c72aed98..3a16cb3e75 100644
--- a/src/wallet/walletutil.cpp
+++ b/src/wallet/walletutil.cpp
@@ -71,11 +71,11 @@ std::vector<fs::path> ListWalletDir()
         // This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
         const fs::path path = it->path().string().substr(offset);
 
-        if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet.dat")) {
+        if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet_dat")) {
             // Found a directory which contains wallet.dat btree file, add it as a wallet.
             paths.emplace_back(path);
         } else if (it.level() == 0 && it->symlink_status().type() == fs::regular_file && IsBerkeleyBtree(it->path())) {
-            if (it->path().filename() == "wallet.dat") {
+            if (it->path().filename() == "wallet_dat") {
                 // Found top-level wallet.dat btree file, add top level directory ""
                 // as a wallet.
                 paths.emplace_back();
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 100be26c59..fa72420178 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -103,7 +103,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
         self.supports_cli = True
         self.bind_to_localhost_only = True
         self.default_wallet_name = ""
-        self.wallet_data_filename = "wallet.dat"
+        self.wallet_data_filename = "wallet_dat"
         self.set_test_params()
         self.parse_args()
         if self.options.timeout_factor == 0 :
diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py
index ef68e224b6..8d3e7f8f62 100755
--- a/test/functional/tool_wallet.py
+++ b/test/functional/tool_wallet.py
@@ -73,7 +73,7 @@ class ToolWalletTest(BitcoinTestFramework):
         locked_dir = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets")
         self.assert_raises_tool_error(
             'Error initializing wallet database environment "{}"!'.format(locked_dir),
-            '-wallet=wallet.dat',
+            '-wallet=wallet_dat',
             'info',
         )
         path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "nonexistent.dat")
@@ -104,7 +104,7 @@ class ToolWalletTest(BitcoinTestFramework):
             Transactions: 0
             Address Book: 3
         ''')
-        self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
+        self.assert_tool_output(out, '-wallet=wallet_dat', 'info')
         timestamp_after = self.wallet_timestamp()
         self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
         self.log_wallet_timestamp_comparison(timestamp_before, timestamp_after)
@@ -143,7 +143,7 @@ class ToolWalletTest(BitcoinTestFramework):
             Transactions: 1
             Address Book: 3
         ''')
-        self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
+        self.assert_tool_output(out, '-wallet=wallet_dat', 'info')
         shasum_after = self.wallet_shasum()
         timestamp_after = self.wallet_timestamp()
         self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py
index 09581d864b..5fdabf89c8 100755
--- a/test/functional/wallet_dump.py
+++ b/test/functional/wallet_dump.py
@@ -203,7 +203,7 @@ class WalletDumpTest(BitcoinTestFramework):
         assert result['ismine']
 
         self.log.info('Check that wallet is flushed')
-        with self.nodes[0].assert_debug_log(['Flushing wallet.dat'], timeout=20):
+        with self.nodes[0].assert_debug_log(['Flushing wallet_dat'], timeout=20):
             self.nodes[0].getnewaddress()
 
 
diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py
index 7b975af065..71aa86abdb 100755
--- a/test/functional/wallet_multiwallet.py
+++ b/test/functional/wallet_multiwallet.py
@@ -95,7 +95,7 @@ class MultiWalletTest(BitcoinTestFramework):
         #   w8         - to verify existing wallet file is loaded 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]
-        extra_args = ['-nowallet'] + ['-wallet={}'.format(n) for n in wallet_names]
+        extra_args = ['-wallet={}'.format(n) for n in wallet_names]
         self.start_node(0, extra_args)
         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'])
 
@@ -108,7 +108,7 @@ class MultiWalletTest(BitcoinTestFramework):
 
         # should not initialize if wallet path can't be created
         exp_stderr = "boost::filesystem::create_directory:"
-        self.nodes[0].assert_start_raises_init_error(['-wallet=wallet.dat/bad'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
+        self.nodes[0].assert_start_raises_init_error(['-wallet={}/bad'.format(self.wallet_data_filename)], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
 
         self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" does not exist')
         self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" is a relative path', cwd=data_dir())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #20034 (comment)

in the first commit:

The test passes without this change, so I am still wondering why this is needed.

Oh, good catch. That was supposed to be in the second commit not the first. -nowallet makes the list of wallets which are loaded explicit, and the tradeoffs around using it here are described in #20034 (comment). The change is necessary to be able to make default_wallet_name nonempty as described in PR description (to add multiwallet test coverage for #19077, to fix accidental wallet creation problems in #15454).

Also, the commit doesn't seem to be exhaustive. The wallet.dat/bad should be replaced as well. Also, the usages in tool_wallet.py. See the diff I used for testing:

That's a useful test, but I think it makes more sense to apply to the overall PR, not the first commit. Applying it to the first commit and making the first commit exhaustive with temporary changes that are subsequently replaced seems like it just adds more code to review and more opportunities to make mistakes in the PR. I would prefer not to make extra changes in the first commit if we can both agree it does not affect the final outcome.

@achow101

Copy link
Copy Markdown
Member

ACK 5338dfa

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK 5338dfa. Skimmed the two commits and left some coments.

wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', '']
extra_args = ['-wallet={}'.format(n) for n in wallet_names]
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', self.default_wallet_name]
extra_args = ['-nowallet'] + ['-wallet={}'.format(n) for n in wallet_names]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the first commit:

The test passes without this change, so I am still wondering why this is needed.

Also, the commit doesn't seem to be exhaustive. The wallet.dat/bad should be replaced as well. Also, the usages in tool_wallet.py. See the diff I used for testing:

diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index bd1d114730..89d7325e1c 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -20,6 +20,6 @@ void SplitWalletPath(const fs::path& wallet_path, fs::path& env_directory, std::
         // Normal case: Interpret wallet path as a directory path containing
         // data and log files.
         env_directory = wallet_path;
-        database_filename = "wallet.dat";
+        database_filename = "wallet_dat";
     }
 }
diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp
index 8f0083cd2e..3489d48879 100644
--- a/src/wallet/test/db_tests.cpp
+++ b/src/wallet/test/db_tests.cpp
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(getwalletenv_file)
 
 BOOST_AUTO_TEST_CASE(getwalletenv_directory)
 {
-    std::string expected_name = "wallet.dat";
+    std::string expected_name = "wallet_dat";
     const fs::path datadir = GetDataDir();
 
     std::string filename;
diff --git a/src/wallet/walletutil.cpp b/src/wallet/walletutil.cpp
index e4c72aed98..3a16cb3e75 100644
--- a/src/wallet/walletutil.cpp
+++ b/src/wallet/walletutil.cpp
@@ -71,11 +71,11 @@ std::vector<fs::path> ListWalletDir()
         // This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
         const fs::path path = it->path().string().substr(offset);
 
-        if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet.dat")) {
+        if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet_dat")) {
             // Found a directory which contains wallet.dat btree file, add it as a wallet.
             paths.emplace_back(path);
         } else if (it.level() == 0 && it->symlink_status().type() == fs::regular_file && IsBerkeleyBtree(it->path())) {
-            if (it->path().filename() == "wallet.dat") {
+            if (it->path().filename() == "wallet_dat") {
                 // Found top-level wallet.dat btree file, add top level directory ""
                 // as a wallet.
                 paths.emplace_back();
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 100be26c59..fa72420178 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -103,7 +103,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
         self.supports_cli = True
         self.bind_to_localhost_only = True
         self.default_wallet_name = ""
-        self.wallet_data_filename = "wallet.dat"
+        self.wallet_data_filename = "wallet_dat"
         self.set_test_params()
         self.parse_args()
         if self.options.timeout_factor == 0 :
diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py
index ef68e224b6..8d3e7f8f62 100755
--- a/test/functional/tool_wallet.py
+++ b/test/functional/tool_wallet.py
@@ -73,7 +73,7 @@ class ToolWalletTest(BitcoinTestFramework):
         locked_dir = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets")
         self.assert_raises_tool_error(
             'Error initializing wallet database environment "{}"!'.format(locked_dir),
-            '-wallet=wallet.dat',
+            '-wallet=wallet_dat',
             'info',
         )
         path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "nonexistent.dat")
@@ -104,7 +104,7 @@ class ToolWalletTest(BitcoinTestFramework):
             Transactions: 0
             Address Book: 3
         ''')
-        self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
+        self.assert_tool_output(out, '-wallet=wallet_dat', 'info')
         timestamp_after = self.wallet_timestamp()
         self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
         self.log_wallet_timestamp_comparison(timestamp_before, timestamp_after)
@@ -143,7 +143,7 @@ class ToolWalletTest(BitcoinTestFramework):
             Transactions: 1
             Address Book: 3
         ''')
-        self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
+        self.assert_tool_output(out, '-wallet=wallet_dat', 'info')
         shasum_after = self.wallet_shasum()
         timestamp_after = self.wallet_timestamp()
         self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py
index 09581d864b..5fdabf89c8 100755
--- a/test/functional/wallet_dump.py
+++ b/test/functional/wallet_dump.py
@@ -203,7 +203,7 @@ class WalletDumpTest(BitcoinTestFramework):
         assert result['ismine']
 
         self.log.info('Check that wallet is flushed')
-        with self.nodes[0].assert_debug_log(['Flushing wallet.dat'], timeout=20):
+        with self.nodes[0].assert_debug_log(['Flushing wallet_dat'], timeout=20):
             self.nodes[0].getnewaddress()
 
 
diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py
index 7b975af065..71aa86abdb 100755
--- a/test/functional/wallet_multiwallet.py
+++ b/test/functional/wallet_multiwallet.py
@@ -95,7 +95,7 @@ class MultiWalletTest(BitcoinTestFramework):
         #   w8         - to verify existing wallet file is loaded 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]
-        extra_args = ['-nowallet'] + ['-wallet={}'.format(n) for n in wallet_names]
+        extra_args = ['-wallet={}'.format(n) for n in wallet_names]
         self.start_node(0, extra_args)
         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'])
 
@@ -108,7 +108,7 @@ class MultiWalletTest(BitcoinTestFramework):
 
         # should not initialize if wallet path can't be created
         exp_stderr = "boost::filesystem::create_directory:"
-        self.nodes[0].assert_start_raises_init_error(['-wallet=wallet.dat/bad'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
+        self.nodes[0].assert_start_raises_init_error(['-wallet={}/bad'.format(self.wallet_data_filename)], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
 
         self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" does not exist')
         self.nodes[0].assert_start_raises_init_error(['-walletdir=wallets'], 'Error: Specified -walletdir "wallets" is a relative path', cwd=data_dir())

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

Updated 5338dfa -> c1585bc (pr/defw.3 -> pr/defw.4, compare) with suggested changes

wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', '']
extra_args = ['-wallet={}'.format(n) for n in wallet_names]
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', self.default_wallet_name]
extra_args = ['-nowallet'] + ['-wallet={}'.format(n) for n in wallet_names]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: #20034 (comment)

in the first commit:

The test passes without this change, so I am still wondering why this is needed.

Oh, good catch. That was supposed to be in the second commit not the first. -nowallet makes the list of wallets which are loaded explicit, and the tradeoffs around using it here are described in #20034 (comment). The change is necessary to be able to make default_wallet_name nonempty as described in PR description (to add multiwallet test coverage for #19077, to fix accidental wallet creation problems in #15454).

Also, the commit doesn't seem to be exhaustive. The wallet.dat/bad should be replaced as well. Also, the usages in tool_wallet.py. See the diff I used for testing:

That's a useful test, but I think it makes more sense to apply to the overall PR, not the first commit. Applying it to the first commit and making the first commit exhaustive with temporary changes that are subsequently replaced seems like it just adds more code to review and more opportunities to make mistakes in the PR. I would prefer not to make extra changes in the first commit if we can both agree it does not affect the final outcome.

@maflcko

maflcko commented Oct 2, 2020

Copy link
Copy Markdown
Member

ACK c1585bc, only effective change is adding documentation 🎵

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK c1585bca8dae01dee6a1dd8eadae2f8b100503df, only effective change is adding documentation 🎵
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhp/gv9HLJ3Y2W8Ok3zvRURR+0h8Qo5u1mOhbHmlS/HNUyM92HAL9OI7D+J+uZa
4ZlfbjiNaGgqEWcrbI1ptkPUy1VsBRCZKSmAMpJdQ9ahbY8UAQo/x1AyBYSnFdPD
MxSxfQ81YzwE8aCvezZdkBGx3t4f1EcBK2+2Q1e8EPjHhNOdZLfEAXoo0CIoBpB9
DzKEMh9hzRE5M3/ELloNLMhVy4XJ7HcH/GjoSPuxQggEKIDBluBiJDaCi2MnTV0C
vqj61OVr4ekci/YhpIvY049iW2XP3jp4qfYPHiInn8IK+swTlrSQ7dFjTfS10etr
wEmfNHWWlmvGQe1pUBIdabQ+FpwBC8CLg8NPavETm+mRx98EL2GwdPPCiPsU3oS+
VWttIL28ICzQZEpcDXcXij2XodcOANVlGifhmyxxxlyj2hVNU8cWp2Ep5fw1kcnH
eAn7wZztEJntWSKc7BhJW9EJ+rA+CX+OSMT7dBmqVVXUDP6XwaVlUoZ/sqWWPjcy
jTy++c1j
=XL4w
-----END PGP SIGNATURE-----

Timestamp of file with hash 21bb7e58a106d518ab420a88873a29f5a4a1169244282ef31f53cec8fd2f3417 -

@maflcko
maflcko merged commit 171cd05 into bitcoin:master Oct 2, 2020
@maflcko

maflcko commented Oct 2, 2020

Copy link
Copy Markdown
Member

Tested with

diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index bd1d114730..89d7325e1c 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -20,6 +20,6 @@ void SplitWalletPath(const fs::path& wallet_path, fs::path& env_directory, std::
         // Normal case: Interpret wallet path as a directory path containing
         // data and log files.
         env_directory = wallet_path;
-        database_filename = "wallet.dat";
+        database_filename = "wallet_dat";
     }
 }
diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp
index 8f0083cd2e..3489d48879 100644
--- a/src/wallet/test/db_tests.cpp
+++ b/src/wallet/test/db_tests.cpp
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(getwalletenv_file)
 
 BOOST_AUTO_TEST_CASE(getwalletenv_directory)
 {
-    std::string expected_name = "wallet.dat";
+    std::string expected_name = "wallet_dat";
     const fs::path datadir = GetDataDir();
 
     std::string filename;
diff --git a/src/wallet/walletutil.cpp b/src/wallet/walletutil.cpp
index e4c72aed98..3a16cb3e75 100644
--- a/src/wallet/walletutil.cpp
+++ b/src/wallet/walletutil.cpp
@@ -71,11 +71,11 @@ std::vector<fs::path> ListWalletDir()
         // This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
         const fs::path path = it->path().string().substr(offset);
 
-        if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet.dat")) {
+        if (it->status().type() == fs::directory_file && IsBerkeleyBtree(it->path() / "wallet_dat")) {
             // Found a directory which contains wallet.dat btree file, add it as a wallet.
             paths.emplace_back(path);
         } else if (it.level() == 0 && it->symlink_status().type() == fs::regular_file && IsBerkeleyBtree(it->path())) {
-            if (it->path().filename() == "wallet.dat") {
+            if (it->path().filename() == "wallet_dat") {
                 // Found top-level wallet.dat btree file, add top level directory ""
                 // as a wallet.
                 paths.emplace_back();
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 2824d80434..6ab813ff1c 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -104,7 +104,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
         self.bind_to_localhost_only = True
         self.parse_args()
         self.default_wallet_name = ""
-        self.wallet_data_filename = "wallet.dat"
+        self.wallet_data_filename = "wallet_dat"
         # Optional list of wallet names that can be set in set_test_params to
         # create and import keys to. If unset, default is len(nodes) *
         # [default_wallet_name]. If wallet names are None, wallet creation is
diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py
index 09581d864b..5fdabf89c8 100755
--- a/test/functional/wallet_dump.py
+++ b/test/functional/wallet_dump.py
@@ -203,7 +203,7 @@ class WalletDumpTest(BitcoinTestFramework):
         assert result['ismine']
 
         self.log.info('Check that wallet is flushed')
-        with self.nodes[0].assert_debug_log(['Flushing wallet.dat'], timeout=20):
+        with self.nodes[0].assert_debug_log(['Flushing wallet_dat'], timeout=20):
             self.nodes[0].getnewaddress()
 
 

Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 3, 2021
…ables

Summary:
No changes in behavior

This is a backport of [[bitcoin/bitcoin#20034 | core#20034]] [1/2]
bitcoin/bitcoin@ed3acda

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10421
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 3, 2021
Summary:
- Get rid of hardcoded wallet "" names and -wallet="" args
- Get rid of setup_nodes (-wallet, -nowallet, -disablewallet) argument rewriting

Motivation:

- Simplify test framework behavior so it's easier to write new tests without
  having arguments mangled by the framework
- Make tests more readable, replacing unexplained "" string literals with
  default_wallet_name references
- Make it trivial to update default wallet name and wallet data filename for
  sqlite #19077 testing
- Stop relying on -wallet arguments to create wallets, so it is easy to change
  -wallet option in the future to only load existing wallets not create new
  ones (to avoid accidental wallet creation, and encourage use of wallet
  encryption and descriptor features)

This is a backport of [[bitcoin/bitcoin#20034 | core#20034]] [2/2]
bitcoin/bitcoin@c1585bc

Depends on D10421

Test Plan: `ninja check-functional-extended`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10422
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants