in 7bae5221ba69962531b1f9fc2e12a273a4df2c2d wallet/test: add test for corrupt tx hash on wallet load
This test is wrong it is not testing the DBErrors::CORRUPT path intended to test. This can be easily tested by just running this test on master.
There are three path for LoadTxRecords that make the load fail as DBErrors::CORRUPT:
try {
CWalletTx wtx{deserialize, value, ReadWtxVariants(batch, hash)};
if (wtx.GetHash() != hash) {
return DBErrors::CORRUPT;
}
if (wtx.nOrderPos == -1) {
any_unordered = true;
}
if (!pwallet->LoadToWallet(std::move(wtx))) {
err = "Error: Corrupt transaction found";
return DBErrors::CORRUPT;
}
} catch (const std::exception& e) {
err = strprintf("Error: Corrupt tx record found: %s" ,e.what());
return DBErrors::CORRUPT;
}
return result;
});
The one intended to test is the Corrupt transaction found catch is the first one which where a tx has an invalid hash.
However this test is passing because the third one (the one inside the catch) is hit.
This happens because the transaction has no inputs and when trying to deserialize it runs out of bytes and throws with end of data.
$ ./build/bin/test_bitcoin --run_test=walletload_tests/wallet_load_corrupt_tx_hash -- -printtoconsole=1 -logthreadnames=1 -debug=walletdb 2>&1 | grep "WalletLogPrintf"
2026-08-21T09:11:45.625958Z [test] [wallet/wallet.h:949] [WalletLogPrintf] [default wallet] Legacy Wallet Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total.
2026-08-21T09:11:45.625989Z [test] [wallet/wallet.h:949] [WalletLogPrintf] [default wallet] Descriptors: 0, Descriptor Keys: 0 plaintext, 0 encrypted, 0 total.
2026-08-21T09:11:45.626255Z [test] [wallet/wallet.h:949] [WalletLogPrintf] [default wallet] Error: Corrupt tx record found: DataStream::read(): end of data: iostream error
The fix is simple just add a dummy input to the transaction:
$ git diff
diff --git a/src/wallet/test/walletload_tests.cpp b/src/wallet/test/walletload_tests.cpp
index 6946503542..c5e07b64ee 100644
--- a/src/wallet/test/walletload_tests.cpp
+++ b/src/wallet/test/walletload_tests.cpp
@@ -102,6 +102,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_corrupt_tx_hash, TestingSetup)
auto database = CreateMockableWalletDatabase();
{
CMutableTransaction mtx;
+ mtx.vin.emplace_back();
mtx.vout.emplace_back(COIN, CScript() << OP_TRUE);
CWalletTx wtx{MakeTransactionRef(std::move(mtx)), TxStateInactive{}};
auto batch = database->MakeBatch();
$ ./build/bin/test_bitcoin --run_test=walletload_tests/wallet_load_corrupt_tx_hash -- -printtoconsole=1 -logthreadnames=1 -debug=walletdb 2>&1 | grep "WalletLogPrintf"
2026-08-21T09:14:29.109542Z [test] [wallet/wallet.h:949] [WalletLogPrintf] [default wallet] Legacy Wallet Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total.
2026-08-21T09:14:29.109585Z [test] [wallet/wallet.h:949] [WalletLogPrintf] [default wallet] Descriptors: 0, Descriptor Keys: 0 plaintext, 0 encrypted, 0 total.
2026-08-21T09:14:29.109849Z [test] [wallet/wallet.h:949] [WalletLogPrintf] [default wallet]
As said in https://github.com/bitcoin/bitcoin/pull/35760/changes/a79db308cb9bafc6c910e64f4cf6aceee7db55c3#r3828796073 the empty WalletLogPrintf is ugly, could be improved by adding an err.