Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for CWalletTx::GetImmatureCredit() returning stale values. #9359

Merged
merged 1 commit into from Mar 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/wallet/test/wallet_tests.cpp
Expand Up @@ -428,4 +428,29 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
}
}

// Check that GetImmatureCredit() returns a newly calculated value instead of
// the cached value after a MarkDirty() call.
//
// This is a regression test written to verify a bugfix for the immature credit
// function. Similar tests probably should be written for the other credit and
// debit functions.
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
{
CWallet wallet;
CWalletTx wtx(&wallet, MakeTransactionRef(coinbaseTxns.back()));
LOCK2(cs_main, wallet.cs_wallet);
wtx.hashBlock = chainActive.Tip()->GetBlockHash();
wtx.nIndex = 0;

// Call GetImmatureCredit() once before adding the key to the wallet to
// cache the current immature credit amount, which is 0.
BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis:

Assertion failed: lock cs_main not held in ../../src/wallet/wallet.cpp:3761; locks held:
Running 221 test cases...
unknown location(0): fatal error: in "wallet_tests/coin_mark_dirty_immature_credit": signal: SIGABRT (application abort requested)
../../src/wallet/test/wallet_tests.cpp(371): last checkpoint
test_bitcoin: ../../src/key.cpp:300: void ECC_Start(): Assertion `secp256k1_context_sign == __null' failed.
unknown location(0): fatal error: in "wallet_tests/coin_selection_tests": signal: SIGABRT (application abort requested)
../../src/wallet/test/wallet_tests.cpp(70): last checkpoint: "coin_selection_tests" fixture entry.
test_bitcoin: ../../src/key.cpp:300: void ECC_Start(): Assertion `secp256k1_context_sign == __null' failed.
unknown location(0): fatal error: in "wallet_crypto/decrypt": signal: SIGABRT (application abort requested)
../../src/wallet/test/crypto_tests.cpp(217): last checkpoint: "decrypt" fixture entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the locking error has been fixed.


// Invalidate the cached value, add the key, and make sure a new immature
// credit amount is calculated.
wtx.MarkDirty();
wallet.AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey());
BOOST_CHECK_EQUAL(wtx.GetImmatureCredit(), 50*COIN);
}

BOOST_AUTO_TEST_SUITE_END()