test: add boost unit tests for AbandonTransaction

Cover the validation paths:
  - abandon_unknown_txid_returns_false: hash not in wallet
  - abandon_not_from_me_returns_false: tx in wallet but fDebit=0

The success path (EraseFromWallet + DB write) requires a file-backed
wallet with a real on-disk DB, which boost's non-file-backed test
wallet (fFileBacked = false) doesn't provide. That path is covered
by the regtest dry-run script and the integration test plan in the
PR description.
This commit is contained in:
Krystie
2026-06-24 19:18:20 -07:00
parent c5f55fe802
commit 518de7cb2e
+40
View File
@@ -293,3 +293,43 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
}
BOOST_AUTO_TEST_SUITE_END()
// ----------------------------------------------------------------------------
// AbandonTransaction tests
//
// The CWallet::AbandonTransaction API was added to Triangles to recover
// from stuck or conflicted transactions without needing the heavy
// `-zapwallettxes=1` hammer that wipes ALL unconfirmed wallet txs.
//
// These tests cover the validation paths (tx not in wallet, tx not
// from this wallet, etc.). The success path requires a file-backed
// wallet with a real on-disk DB, which is covered by the integration
// regtest dry-run in scripts/ — boost unit tests use a non-file-backed
// wallet (fFileBacked = false), so we only assert the rejection paths
// here.
// ----------------------------------------------------------------------------
BOOST_AUTO_TEST_SUITE(abandon_transaction_tests)
BOOST_AUTO_TEST_CASE(abandon_unknown_txid_returns_false)
{
// Pick a hash that we know is not in the test wallet
uint256 hash;
hash.SetHex("0000000000000000000000000000000000000000000000000000000000000001");
BOOST_CHECK(!wallet.AbandonTransaction(hash));
}
BOOST_AUTO_TEST_CASE(abandon_not_from_me_returns_false)
{
// The test wallet has at least one tx (added by earlier tests in
// wallet_tests). Grab the first mapWallet entry — it has fDebit=0
// because add_coin() only sets fIsFromMe if we asked, so by default
// the tx is not from us.
BOOST_CHECK(!wallet.mapWallet.empty());
if (!wallet.mapWallet.empty()) {
uint256 hash = wallet.mapWallet.begin()->first;
BOOST_CHECK(!wallet.AbandonTransaction(hash));
}
}
BOOST_AUTO_TEST_SUITE_END()