Skip to content

test/mutation: check wallet listings and wrapped P2WSH addresses in wallet_migration.py - #36968

Open
l0rinc wants to merge 3 commits into
bitcoin:masterfrom
l0rinc:l0rinc/test-wallet-migration-listing-checks
Open

l0rinc wants to merge 3 commits into
bitcoin:masterfrom
l0rinc:l0rinc/test-wallet-migration-listing-checks

Conversation

@l0rinc

@l0rinc l0rinc commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem: The migration test checks the legacy-wallet warning only if it finds the wallet in listwalletdir, so a missing wallet goes unnoticed.
It skips the warning check for path/to/trailing/ even when the wallet is listed because the returned name has no trailing separator.
After migration, the test looks for a dictionary containing only the backup name, but every entry also has a warnings field, so the check passes even if the backup is listed.

The P2WSH test imports a wrapped output but checks only the native address after migration.

Fix: Require listwalletdir to return the legacy wallet with its migration warning, then check that the backup filename is absent from the listed names after migration.
For both the native and wrapped addresses, check that getaddressinfo reports ismine as true and includes the embedded field.

Mutation tests: To test each change, apply the mutation in its commit message and run wallet_migration.py.

@DrahtBot

DrahtBot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36257 (qa: assert_equal -> assert_true/assert_false by hodlinator)

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 Nov 24, 2026

Copy link
Copy Markdown
Member

I think it is better to share mutations via a git diff, and not via some bash script

@l0rinc l0rinc changed the title test/mutation: catch missing legacy wallets and listed backups in wallet_migration.py test/mutation: check wallet listings and wrapped P2WSH addresses in wallet_migration.py Nov 24, 2026
@l0rinc
l0rinc force-pushed the l0rinc/test-wallet-migration-listing-checks branch from 6883114 to cc9a9a8 Compare November 24, 2026 20:40
@l0rinc

l0rinc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

share mutations via a git diff

I wanted to avoid adding 9 more lines to a commit message, but if this is simpler for reviewers, I don't mind: pushed, thanks.

If `listwalletdir` omits the wallet, the loop never checks its warning and the test passes.
The loop also skips `path/to/trailing/` because the listed name has no trailing separator.

Match the wallet by its listed name and require the migration warning.
With the following mutation, the original test passes and the new check fails because `basic0` is missing.

```diff
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index 3af0f1c..40a9917873 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -34,5 +34,4 @@ std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wall
                 if (IsBDBFile(BDBDataFile(it->path()))) {
                     // Found a directory which contains wallet.dat btree file, add it as a wallet with BERKELEY format.
-                    paths.emplace_back(path, "bdb");
                 } else if (IsSQLiteFile(SQLiteDataFile(it->path()))) {
                     // Found a directory which contains wallet.dat sqlite file, add it as a wallet with SQLITE format.
```
Every wallet returned by `listwalletdir` has a `warnings` field, so checking that `{"name": backup_filename}` is absent passes even when the backup is listed.
Compare the backup filename with the listed names instead.

Removing the `.bak` filter makes `listwalletdir` return the backup, which the previous test accepts and the new check catches.

```diff
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index 3af0f1c..a2d41065ec 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -39,5 +39,5 @@ std::vector<std::pair<fs::path, std::string>> ListDatabases(const fs::path& wall
                     paths.emplace_back(path, "sqlite");
                 }
-            } else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular && it->path().extension() != ".bak") {
+            } else if (it.depth() == 0 && it->symlink_status().type() == fs::file_type::regular) {
                 if (it->path().filename() == "wallet.dat") {
                     // Found top-level wallet.dat file, add top level directory ""
```
The test imports a `sh(wsh(pkh()))` output but only calls `getaddressinfo` on the native P2WSH address after migration.
Check that the migrated wallet owns both forms and reports the embedded script for each.

With this mutation, `getaddressinfo` omits `embedded` for the wrapped address while still returning it for the native address.

```diff
diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp
index 3470bce..f85951a34f 100644
--- a/src/wallet/rpc/addresses.cpp
+++ b/src/wallet/rpc/addresses.cpp
@@ -319,5 +319,5 @@ public:
         UniValue obj(UniValue::VOBJ);
         CScript subscript;
-        if (provider && provider->GetCScript(ToScriptID(scripthash), subscript)) {
+        if (provider && provider->GetCScript(ToScriptID(scripthash), subscript) && !subscript.IsPayToWitnessScriptHash()) {
             ProcessSubScript(subscript, obj);
         }
```
@l0rinc
l0rinc force-pushed the l0rinc/test-wallet-migration-listing-checks branch from cc9a9a8 to 6e765ad Compare November 26, 2026 12:20
@l0rinc

l0rinc commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on #34193, kept its cleanup check, and limited the pre-migration listwalletdir check to wallets it can list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants