Skip to content

Commit 7ed143c

Browse files
committed
Add test for CWalletTx::GetImmatureCredit() returning stale values.
Add test for cached immature credit flag not being cleared in CWalletTx::MarkDirty() bug, which was fixed in bitcoin/bitcoin#8717, commit a560378.
1 parent 3fabae7 commit 7ed143c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,29 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
428428
}
429429
}
430430

431+
// Check that GetImmatureCredit() returns a newly calculated value instead of
432+
// the cached value after a MarkDirty() call.
433+
//
434+
// This is a regression test written to verify a bugfix for the immature credit
435+
// function. Similar tests probably should be written for the other credit and
436+
// debit functions.
437+
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
438+
{
439+
CWallet wallet;
440+
CWalletTx wtx(&wallet, MakeTransactionRef(coinbaseTxns.back()));
441+
LOCK2(cs_main, wallet.cs_wallet);
442+
wtx.hashBlock = chainActive.Tip()->GetBlockHash();
443+
wtx.nIndex = 0;
444+
445+
// Call GetImmatureCredit() once before adding the key to the wallet to
446+
// cache the current immature credit amount, which is 0.
447+
BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), 0);
448+
449+
// Invalidate the cached value, add the key, and make sure a new immature
450+
// credit amount is calculated.
451+
wtx.MarkDirty();
452+
wallet.AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey());
453+
BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), 50*COIN);
454+
}
455+
431456
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)