Skip to content

Commit f7ec7cf

Browse files
author
MarcoFalke
committed
Merge #9359: Add test for CWalletTx::GetImmatureCredit() returning stale values.
7ed143c Add test for CWalletTx::GetImmatureCredit() returning stale values. (Russell Yanofsky) Tree-SHA512: c95088ed6dfc5a0774ddaa2fe14ac0a9ebd830922a4d77100ec3d51fdeb6df40ad97de4f2ea970ed0f4122dcc0022ee1d43ab3c7188becd7f90c1c6af0ed39b7
2 parents 65d90f5 + 7ed143c commit f7ec7cf

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)