diff --git a/src/test/wallet_tests.cpp b/src/test/wallet_tests.cpp index cb0bd63..4b41231 100644 --- a/src/test/wallet_tests.cpp +++ b/src/test/wallet_tests.cpp @@ -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()