Use fully static linkage #364

Closed
bvbfan wants to merge 78 commits from static_link into master
22 changed files with 87 additions and 72 deletions
Showing only changes of commit 8a35d5a15e - Show all commits

View file

@ -25,6 +25,7 @@
#include <timedata.h> #include <timedata.h>
#include <util.h> #include <util.h>
#include <utilmoneystr.h> #include <utilmoneystr.h>
#include <validation.h>
#include <validationinterface.h> #include <validationinterface.h>
#include <algorithm> #include <algorithm>

View file

@ -8,7 +8,6 @@
#include <primitives/block.h> #include <primitives/block.h>
#include <txmempool.h> #include <txmempool.h>
#include <validation.h>
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>

View file

@ -4,6 +4,7 @@
#include <rpc/blockchain.h> #include <rpc/blockchain.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>
#include <txdb.h>
/* Equality between doubles is imprecise. Comparison should be done /* Equality between doubles is imprecise. Comparison should be done
* with a small threshold of tolerance, rather than exact equality. * with a small threshold of tolerance, rather than exact equality.

View file

@ -8,6 +8,7 @@
#include <pow.h> #include <pow.h>
#include <random.h> #include <random.h>
#include <streams.h> #include <streams.h>
#include <txmempool.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>
@ -19,6 +20,8 @@ struct RegtestingSetup : public TestingSetup {
RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {} RegtestingSetup() : TestingSetup(CBaseChainParams::REGTEST) {}
}; };
extern CTxMemPoolEntry FromTx(CTransactionRef tx, const TestMemPoolEntryHelper& entry);
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegtestingSetup) BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegtestingSetup)
static CBlock BuildBlockTestCase() { static CBlock BuildBlockTestCase() {
@ -64,7 +67,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
CBlock block(BuildBlockTestCase()); CBlock block(BuildBlockTestCase());
LOCK(pool.cs); LOCK(pool.cs);
pool.addUnchecked(block.vtx[2]->GetHash(), entry.FromTx(block.vtx[2])); pool.addUnchecked(block.vtx[2]->GetHash(), FromTx(block.vtx[2], entry));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);
// Do a simple ShortTxIDs RT // Do a simple ShortTxIDs RT
@ -164,7 +167,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
CBlock block(BuildBlockTestCase()); CBlock block(BuildBlockTestCase());
LOCK(pool.cs); LOCK(pool.cs);
pool.addUnchecked(block.vtx[2]->GetHash(), entry.FromTx(block.vtx[2])); pool.addUnchecked(block.vtx[2]->GetHash(), FromTx(block.vtx[2], entry));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);
uint256 txhash; uint256 txhash;
@ -234,7 +237,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
CBlock block(BuildBlockTestCase()); CBlock block(BuildBlockTestCase());
LOCK(pool.cs); LOCK(pool.cs);
pool.addUnchecked(block.vtx[1]->GetHash(), entry.FromTx(block.vtx[1])); pool.addUnchecked(block.vtx[1]->GetHash(), FromTx(block.vtx[1], entry));
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0);
uint256 txhash; uint256 txhash;

View file

@ -3,6 +3,7 @@
// file COPYING or http://opensource.org/licenses/mit-license.php // file COPYING or http://opensource.org/licenses/mit-license.php
#include <test/claimtriefixture.h> #include <test/claimtriefixture.h>
#include <validation.h>
using namespace std; using namespace std;

View file

@ -1,5 +1,4 @@
#include <claimtrie/forks.h>
#include <nameclaim.h> #include <nameclaim.h>
#include <uint256.h> #include <uint256.h>
#include <validation.h> #include <validation.h>

View file

@ -3,6 +3,7 @@
// file COPYING or http://opensource.org/licenses/mit-license.php // file COPYING or http://opensource.org/licenses/mit-license.php
#include <test/claimtriefixture.h> #include <test/claimtriefixture.h>
#include <validation.h>
using namespace std; using namespace std;

View file

@ -3,7 +3,10 @@
// file COPYING or http://opensource.org/licenses/mit-license.php // file COPYING or http://opensource.org/licenses/mit-license.php
#include <functional> #include <functional>
#include <miner.h>
#include <primitives/transaction.h>
#include <test/claimtriefixture.h> #include <test/claimtriefixture.h>
#include <validation.h>
using namespace std; using namespace std;
@ -267,7 +270,7 @@ CMutableTransaction ClaimTrieChainFixture::MakeUpdate(const CTransaction &prev,
return tx; return tx;
} }
CTransaction ClaimTrieChainFixture::GetCoinbase() CTransaction& ClaimTrieChainFixture::GetCoinbase()
{ {
return coinbase_txs.at(coinbase_txs_used++); return coinbase_txs.at(coinbase_txs_used++);
} }

View file

@ -10,33 +10,30 @@
#include <coins.h> #include <coins.h>
#include <consensus/merkle.h> #include <consensus/merkle.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <miner.h>
#include <nameclaim.h> #include <nameclaim.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <pow.h> #include <pow.h>
#include <primitives/transaction.h>
#include <random.h> #include <random.h>
#include <rpc/claimrpchelp.h> #include <rpc/claimrpchelp.h>
#include <rpc/server.h> #include <rpc/server.h>
#include <streams.h> #include <streams.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>
#include <txmempool.h>
#include <util.h> #include <util.h>
#include <validation.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <iostream> #include <iostream>
extern ::CChainState g_chainstate;
extern ::ArgsManager gArgs; extern ::ArgsManager gArgs;
extern std::vector<std::string> random_strings(std::size_t count); extern std::vector<std::string> random_strings(std::size_t count);
class CTransaction;
CMutableTransaction BuildTransaction(const uint256& prevhash); CMutableTransaction BuildTransaction(const uint256& prevhash);
CMutableTransaction BuildTransaction(const CTransaction& prev, uint32_t prevout=0, unsigned int numOutputs=1, int locktime=0); CMutableTransaction BuildTransaction(const CTransaction& prev, uint32_t prevout=0, unsigned int numOutputs=1, int locktime=0);
class BlockAssembler;
BlockAssembler AssemblerForTest(); BlockAssembler AssemblerForTest();
class CBlockTemplate;
// Test Fixtures // Test Fixtures
struct ClaimTrieChainFixture: public CClaimTrieCache struct ClaimTrieChainFixture: public CClaimTrieCache
{ {
@ -85,7 +82,7 @@ struct ClaimTrieChainFixture: public CClaimTrieCache
// make update at the current block // make update at the current block
CMutableTransaction MakeUpdate(const CTransaction &prev, const std::string& name, const std::string& value, const uint160& claimId, CAmount quantity); CMutableTransaction MakeUpdate(const CTransaction &prev, const std::string& name, const std::string& value, const uint160& claimId, CAmount quantity);
CTransaction GetCoinbase(); CTransaction& GetCoinbase();
// create i blocks // create i blocks
void IncrementBlocks(int num_blocks, bool mark = false); void IncrementBlocks(int num_blocks, bool mark = false);

View file

@ -2,7 +2,9 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://opensource.org/licenses/mit-license.php // file COPYING or http://opensource.org/licenses/mit-license.php
#include <miner.h>
#include <test/claimtriefixture.h> #include <test/claimtriefixture.h>
#include <validation.h>
using namespace std; using namespace std;

View file

@ -3,6 +3,9 @@
// file COPYING or http://opensource.org/licenses/mit-license.php // file COPYING or http://opensource.org/licenses/mit-license.php
#include <test/claimtriefixture.h> #include <test/claimtriefixture.h>
#include <validation.h>
extern ::CChainState g_chainstate;
using namespace std; using namespace std;

View file

@ -4,6 +4,7 @@
#include <test/claimtriefixture.h> #include <test/claimtriefixture.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
#include <validation.h>
using namespace std; using namespace std;

View file

@ -4,6 +4,7 @@
#include <clientversion.h> #include <clientversion.h>
#include <hash.h> #include <hash.h>
#include <primitives/transaction.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>

View file

@ -573,20 +573,20 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
SetMockTime(0); SetMockTime(0);
} }
inline CTransactionRef make_tx(std::vector<CAmount>&& output_values, std::vector<CTransactionRef>&& inputs=std::vector<CTransactionRef>(), std::vector<uint32_t>&& input_indices=std::vector<uint32_t>()) inline CMutableTransaction make_tx(std::vector<CAmount>&& output_values, std::vector<CMutableTransaction>&& inputs=std::vector<CMutableTransaction>(), std::vector<uint32_t>&& input_indices=std::vector<uint32_t>())
{ {
CMutableTransaction tx = CMutableTransaction(); CMutableTransaction tx = CMutableTransaction();
tx.vin.resize(inputs.size()); tx.vin.resize(inputs.size());
tx.vout.resize(output_values.size()); tx.vout.resize(output_values.size());
for (size_t i = 0; i < inputs.size(); ++i) { for (size_t i = 0; i < inputs.size(); ++i) {
tx.vin[i].prevout.hash = inputs[i]->GetHash(); tx.vin[i].prevout.hash = inputs[i].GetHash();
tx.vin[i].prevout.n = input_indices.size() > i ? input_indices[i] : 0; tx.vin[i].prevout.n = input_indices.size() > i ? input_indices[i] : 0;
} }
for (size_t i = 0; i < output_values.size(); ++i) { for (size_t i = 0; i < output_values.size(); ++i) {
tx.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL; tx.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
tx.vout[i].nValue = output_values[i]; tx.vout[i].nValue = output_values[i];
} }
return MakeTransactionRef(tx); return tx;
} }
@ -602,11 +602,11 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// //
// [tx1] // [tx1]
// //
CTransactionRef tx1 = make_tx(/* output_values */ {10 * COIN}); auto tx1 = make_tx(/* output_values */ {10 * COIN});
pool.addUnchecked(tx1->GetHash(), entry.Fee(10000LL).FromTx(tx1)); pool.addUnchecked(tx1.GetHash(), entry.Fee(10000LL).FromTx(tx1));
// Ancestors / descendants should be 1 / 1 (itself / itself) // Ancestors / descendants should be 1 / 1 (itself / itself)
pool.GetTransactionAncestry(tx1->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx1.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 1ULL); BOOST_CHECK_EQUAL(ancestors, 1ULL);
BOOST_CHECK_EQUAL(descendants, 1ULL); BOOST_CHECK_EQUAL(descendants, 1ULL);
@ -614,18 +614,18 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// //
// [tx1].0 <- [tx2] // [tx1].0 <- [tx2]
// //
CTransactionRef tx2 = make_tx(/* output_values */ {495 * CENT, 5 * COIN}, /* inputs */ {tx1}); auto tx2 = make_tx(/* output_values */ {495 * CENT, 5 * COIN}, /* inputs */ {tx1});
pool.addUnchecked(tx2->GetHash(), entry.Fee(10000LL).FromTx(tx2)); pool.addUnchecked(tx2.GetHash(), entry.Fee(10000LL).FromTx(tx2));
// Ancestors / descendants should be: // Ancestors / descendants should be:
// transaction ancestors descendants // transaction ancestors descendants
// ============ =========== =========== // ============ =========== ===========
// tx1 1 (tx1) 2 (tx1,2) // tx1 1 (tx1) 2 (tx1,2)
// tx2 2 (tx1,2) 2 (tx1,2) // tx2 2 (tx1,2) 2 (tx1,2)
pool.GetTransactionAncestry(tx1->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx1.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 1ULL); BOOST_CHECK_EQUAL(ancestors, 1ULL);
BOOST_CHECK_EQUAL(descendants, 2ULL); BOOST_CHECK_EQUAL(descendants, 2ULL);
pool.GetTransactionAncestry(tx2->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx2.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 2ULL); BOOST_CHECK_EQUAL(ancestors, 2ULL);
BOOST_CHECK_EQUAL(descendants, 2ULL); BOOST_CHECK_EQUAL(descendants, 2ULL);
@ -633,8 +633,8 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// //
// [tx1].0 <- [tx2].0 <- [tx3] // [tx1].0 <- [tx2].0 <- [tx3]
// //
CTransactionRef tx3 = make_tx(/* output_values */ {290 * CENT, 200 * CENT}, /* inputs */ {tx2}); auto tx3 = make_tx(/* output_values */ {290 * CENT, 200 * CENT}, /* inputs */ {tx2});
pool.addUnchecked(tx3->GetHash(), entry.Fee(10000LL).FromTx(tx3)); pool.addUnchecked(tx3.GetHash(), entry.Fee(10000LL).FromTx(tx3));
// Ancestors / descendants should be: // Ancestors / descendants should be:
// transaction ancestors descendants // transaction ancestors descendants
@ -642,13 +642,13 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// tx1 1 (tx1) 3 (tx1,2,3) // tx1 1 (tx1) 3 (tx1,2,3)
// tx2 2 (tx1,2) 3 (tx1,2,3) // tx2 2 (tx1,2) 3 (tx1,2,3)
// tx3 3 (tx1,2,3) 3 (tx1,2,3) // tx3 3 (tx1,2,3) 3 (tx1,2,3)
pool.GetTransactionAncestry(tx1->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx1.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 1ULL); BOOST_CHECK_EQUAL(ancestors, 1ULL);
BOOST_CHECK_EQUAL(descendants, 3ULL); BOOST_CHECK_EQUAL(descendants, 3ULL);
pool.GetTransactionAncestry(tx2->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx2.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 2ULL); BOOST_CHECK_EQUAL(ancestors, 2ULL);
BOOST_CHECK_EQUAL(descendants, 3ULL); BOOST_CHECK_EQUAL(descendants, 3ULL);
pool.GetTransactionAncestry(tx3->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx3.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 3ULL); BOOST_CHECK_EQUAL(ancestors, 3ULL);
BOOST_CHECK_EQUAL(descendants, 3ULL); BOOST_CHECK_EQUAL(descendants, 3ULL);
@ -658,8 +658,8 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// | // |
// \---1 <- [tx4] // \---1 <- [tx4]
// //
CTransactionRef tx4 = make_tx(/* output_values */ {290 * CENT, 250 * CENT}, /* inputs */ {tx2}, /* input_indices */ {1}); auto tx4 = make_tx(/* output_values */ {290 * CENT, 250 * CENT}, /* inputs */ {tx2}, /* input_indices */ {1});
pool.addUnchecked(tx4->GetHash(), entry.Fee(10000LL).FromTx(tx4)); pool.addUnchecked(tx4.GetHash(), entry.Fee(10000LL).FromTx(tx4));
// Ancestors / descendants should be: // Ancestors / descendants should be:
// transaction ancestors descendants // transaction ancestors descendants
@ -668,16 +668,16 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// tx2 2 (tx1,2) 4 (tx1,2,3,4) // tx2 2 (tx1,2) 4 (tx1,2,3,4)
// tx3 3 (tx1,2,3) 4 (tx1,2,3,4) // tx3 3 (tx1,2,3) 4 (tx1,2,3,4)
// tx4 3 (tx1,2,4) 4 (tx1,2,3,4) // tx4 3 (tx1,2,4) 4 (tx1,2,3,4)
pool.GetTransactionAncestry(tx1->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx1.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 1ULL); BOOST_CHECK_EQUAL(ancestors, 1ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL); BOOST_CHECK_EQUAL(descendants, 4ULL);
pool.GetTransactionAncestry(tx2->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx2.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 2ULL); BOOST_CHECK_EQUAL(ancestors, 2ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL); BOOST_CHECK_EQUAL(descendants, 4ULL);
pool.GetTransactionAncestry(tx3->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx3.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 3ULL); BOOST_CHECK_EQUAL(ancestors, 3ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL); BOOST_CHECK_EQUAL(descendants, 4ULL);
pool.GetTransactionAncestry(tx4->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx4.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 3ULL); BOOST_CHECK_EQUAL(ancestors, 3ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL); BOOST_CHECK_EQUAL(descendants, 4ULL);
@ -689,20 +689,20 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// | // |
// \---1 <- [tx4] // \---1 <- [tx4]
// //
CTransactionRef ty1, ty2, ty3, ty4, ty5; CMutableTransaction ty1, ty2, ty3, ty4, ty5;
CTransactionRef* ty[5] = {&ty1, &ty2, &ty3, &ty4, &ty5}; CMutableTransaction* ty[5] = {&ty1, &ty2, &ty3, &ty4, &ty5};
CAmount v = 5 * COIN; CAmount v = 5 * COIN;
for (uint64_t i = 0; i < 5; i++) { for (uint64_t i = 0; i < 5; i++) {
CTransactionRef& tyi = *ty[i]; auto& tyi = *ty[i];
tyi = make_tx(/* output_values */ {v}, /* inputs */ i > 0 ? std::vector<CTransactionRef>{*ty[i - 1]} : std::vector<CTransactionRef>{}); tyi = make_tx(/* output_values */ {v}, /* inputs */ i > 0 ? std::vector<CMutableTransaction>{*ty[i - 1]} : std::vector<CMutableTransaction>{});
v -= 50 * CENT; v -= 50 * CENT;
pool.addUnchecked(tyi->GetHash(), entry.Fee(10000LL).FromTx(tyi)); pool.addUnchecked(tyi.GetHash(), entry.Fee(10000LL).FromTx(tyi));
pool.GetTransactionAncestry(tyi->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tyi.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, i+1); BOOST_CHECK_EQUAL(ancestors, i+1);
BOOST_CHECK_EQUAL(descendants, i+1); BOOST_CHECK_EQUAL(descendants, i+1);
} }
CTransactionRef ty6 = make_tx(/* output_values */ {5 * COIN}, /* inputs */ {tx3, ty5}); auto ty6 = make_tx(/* output_values */ {5 * COIN}, /* inputs */ {tx3, ty5});
pool.addUnchecked(ty6->GetHash(), entry.Fee(10000LL).FromTx(ty6)); pool.addUnchecked(ty6.GetHash(), entry.Fee(10000LL).FromTx(ty6));
// Ancestors / descendants should be: // Ancestors / descendants should be:
// transaction ancestors descendants // transaction ancestors descendants
@ -717,34 +717,34 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
// ty4 4 (y1234) 6 (ty1,2,3,4,5,6) // ty4 4 (y1234) 6 (ty1,2,3,4,5,6)
// ty5 5 (y12345) 6 (ty1,2,3,4,5,6) // ty5 5 (y12345) 6 (ty1,2,3,4,5,6)
// ty6 9 (tx123, ty123456) 6 (ty1,2,3,4,5,6) // ty6 9 (tx123, ty123456) 6 (ty1,2,3,4,5,6)
pool.GetTransactionAncestry(tx1->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx1.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 1ULL); BOOST_CHECK_EQUAL(ancestors, 1ULL);
BOOST_CHECK_EQUAL(descendants, 5ULL); BOOST_CHECK_EQUAL(descendants, 5ULL);
pool.GetTransactionAncestry(tx2->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx2.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 2ULL); BOOST_CHECK_EQUAL(ancestors, 2ULL);
BOOST_CHECK_EQUAL(descendants, 5ULL); BOOST_CHECK_EQUAL(descendants, 5ULL);
pool.GetTransactionAncestry(tx3->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx3.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 3ULL); BOOST_CHECK_EQUAL(ancestors, 3ULL);
BOOST_CHECK_EQUAL(descendants, 5ULL); BOOST_CHECK_EQUAL(descendants, 5ULL);
pool.GetTransactionAncestry(tx4->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(tx4.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 3ULL); BOOST_CHECK_EQUAL(ancestors, 3ULL);
BOOST_CHECK_EQUAL(descendants, 5ULL); BOOST_CHECK_EQUAL(descendants, 5ULL);
pool.GetTransactionAncestry(ty1->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(ty1.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 1ULL); BOOST_CHECK_EQUAL(ancestors, 1ULL);
BOOST_CHECK_EQUAL(descendants, 6ULL); BOOST_CHECK_EQUAL(descendants, 6ULL);
pool.GetTransactionAncestry(ty2->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(ty2.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 2ULL); BOOST_CHECK_EQUAL(ancestors, 2ULL);
BOOST_CHECK_EQUAL(descendants, 6ULL); BOOST_CHECK_EQUAL(descendants, 6ULL);
pool.GetTransactionAncestry(ty3->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(ty3.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 3ULL); BOOST_CHECK_EQUAL(ancestors, 3ULL);
BOOST_CHECK_EQUAL(descendants, 6ULL); BOOST_CHECK_EQUAL(descendants, 6ULL);
pool.GetTransactionAncestry(ty4->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(ty4.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 4ULL); BOOST_CHECK_EQUAL(ancestors, 4ULL);
BOOST_CHECK_EQUAL(descendants, 6ULL); BOOST_CHECK_EQUAL(descendants, 6ULL);
pool.GetTransactionAncestry(ty5->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(ty5.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 5ULL); BOOST_CHECK_EQUAL(ancestors, 5ULL);
BOOST_CHECK_EQUAL(descendants, 6ULL); BOOST_CHECK_EQUAL(descendants, 6ULL);
pool.GetTransactionAncestry(ty6->GetHash(), ancestors, descendants); pool.GetTransactionAncestry(ty6.GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 9ULL); BOOST_CHECK_EQUAL(ancestors, 9ULL);
BOOST_CHECK_EQUAL(descendants, 6ULL); BOOST_CHECK_EQUAL(descendants, 6ULL);
} }

View file

@ -12,7 +12,7 @@
#include <script/ismine.h> #include <script/ismine.h>
#include <uint256.h> #include <uint256.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>
#include <tinyformat.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>

View file

@ -6,6 +6,7 @@
#include <streams.h> #include <streams.h>
#include <hash.h> #include <hash.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
#include <primitives/transaction.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>

View file

@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <coins.h>
#include <consensus/tx_verify.h> #include <consensus/tx_verify.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <pubkey.h> #include <pubkey.h>

View file

@ -19,6 +19,7 @@
#include <rpc/server.h> #include <rpc/server.h>
#include <rpc/register.h> #include <rpc/register.h>
#include <script/sigcache.h> #include <script/sigcache.h>
#include <txdb.h>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_parameters.hpp> #include <boost/test/unit_test_parameters.hpp>
@ -205,7 +206,7 @@ TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
{ {
std::vector<CMutableTransaction> noTxns; std::vector<CMutableTransaction> noTxns;
CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey); CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey);
m_coinbase_txns.push_back(b.vtx[0]); m_coinbase_txns.emplace_back(*b.vtx[0]);
} }
} }
@ -258,14 +259,15 @@ RegTestingSetup::~RegTestingSetup()
minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
} }
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx) { CTxMemPoolEntry FromTx(CTransactionRef tx, const TestMemPoolEntryHelper& entry)
return FromTx(MakeTransactionRef(tx)); {
return CTxMemPoolEntry(tx, entry.nFee, entry.nTime, entry.nHeight,
entry.spendsCoinbase, entry.sigOpCost, LockPoints{});
} }
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef& tx) CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx)
{ {
return CTxMemPoolEntry(tx, nFee, nTime, nHeight, return ::FromTx(MakeTransactionRef(tx), *this);
spendsCoinbase, sigOpCost, lp);
} }
/** /**

View file

@ -5,14 +5,13 @@
#ifndef BITCOIN_TEST_TEST_BITCOIN_H #ifndef BITCOIN_TEST_TEST_BITCOIN_H
#define BITCOIN_TEST_TEST_BITCOIN_H #define BITCOIN_TEST_TEST_BITCOIN_H
#include <amount.h>
#include <chainparamsbase.h> #include <chainparamsbase.h>
#include <fs.h> #include <fs.h>
#include <key.h> #include <key.h>
#include <pubkey.h> #include <pubkey.h>
#include <random.h> #include <random.h>
#include <scheduler.h> #include <scheduler.h>
#include <txdb.h>
#include <txmempool.h>
#include <memory> #include <memory>
@ -91,7 +90,7 @@ struct TestChain100Setup : public TestingSetup {
~TestChain100Setup() override; ~TestChain100Setup() override;
std::vector<CTransactionRef> m_coinbase_txns; // For convenience, coinbase transactions std::vector<CMutableTransaction> m_coinbase_txns; // For convenience, coinbase transactions
CKey coinbaseKey; // private/public key needed to spend coinbase transactions CKey coinbaseKey; // private/public key needed to spend coinbase transactions
}; };
@ -110,14 +109,12 @@ struct TestMemPoolEntryHelper
unsigned int nHeight; unsigned int nHeight;
bool spendsCoinbase; bool spendsCoinbase;
unsigned int sigOpCost; unsigned int sigOpCost;
LockPoints lp;
TestMemPoolEntryHelper() : TestMemPoolEntryHelper() :
nFee(0), nTime(0), nHeight(1), nFee(0), nTime(0), nHeight(1),
spendsCoinbase(false), sigOpCost(4) { } spendsCoinbase(false), sigOpCost(4) { }
CTxMemPoolEntry FromTx(const CMutableTransaction& tx); CTxMemPoolEntry FromTx(const CMutableTransaction& tx);
CTxMemPoolEntry FromTx(const CTransactionRef& tx);
// Change the default value // Change the default value
TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; } TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; }
@ -130,8 +127,11 @@ struct TestMemPoolEntryHelper
CBlock getTestBlock(); CBlock getTestBlock();
// define an implicit conversion here so that uint256 may be used directly in BOOST_CHECK_* // define an implicit conversion here so that uint256 may be used directly in BOOST_CHECK_*
std::ostream& operator<<(std::ostream& os, const uint256& num); std::ostream& operator<<(std::ostream& os, const uint256& num);
std::ostream& operator<<(std::ostream& os, const uint160& num); std::ostream& operator<<(std::ostream& os, const uint160& num);
class COutPoint;
std::ostream& operator<<(std::ostream& os, const COutPoint& point); std::ostream& operator<<(std::ostream& os, const COutPoint& point);
std::ostream& operator<<(std::ostream& os, const CUint256& num); std::ostream& operator<<(std::ostream& os, const CUint256& num);

View file

@ -48,7 +48,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
{ {
spends[i].nVersion = 1; spends[i].nVersion = 1;
spends[i].vin.resize(1); spends[i].vin.resize(1);
spends[i].vin[0].prevout.hash = m_coinbase_txns[0]->GetHash(); spends[i].vin[0].prevout.hash = m_coinbase_txns[0].GetHash();
spends[i].vin[0].prevout.n = 0; spends[i].vin[0].prevout.n = 0;
spends[i].vout.resize(1); spends[i].vout.resize(1);
spends[i].vout[0].nValue = 11*CENT; spends[i].vout[0].nValue = 11*CENT;
@ -167,7 +167,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
spend_tx.nVersion = 1; spend_tx.nVersion = 1;
spend_tx.vin.resize(1); spend_tx.vin.resize(1);
spend_tx.vin[0].prevout.hash = m_coinbase_txns[0]->GetHash(); spend_tx.vin[0].prevout.hash = m_coinbase_txns[0].GetHash();
spend_tx.vin[0].prevout.n = 0; spend_tx.vin[0].prevout.n = 0;
spend_tx.vout.resize(4); spend_tx.vout.resize(4);
spend_tx.vout[0].nValue = 11*CENT; spend_tx.vout[0].nValue = 11*CENT;

View file

@ -7,7 +7,6 @@
#define BITCOIN_UNDO_H #define BITCOIN_UNDO_H
#include <compressor.h> #include <compressor.h>
#include <claimtrie/forks.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <serialize.h> #include <serialize.h>

View file

@ -120,14 +120,14 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
// will pick up both blocks, not just the first. // will pick up both blocks, not just the first.
const int64_t BLOCK_TIME = chainActive.Tip()->GetBlockTimeMax() + 5; const int64_t BLOCK_TIME = chainActive.Tip()->GetBlockTimeMax() + 5;
SetMockTime(BLOCK_TIME); SetMockTime(BLOCK_TIME);
m_coinbase_txns.emplace_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]); m_coinbase_txns.emplace_back(*CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
m_coinbase_txns.emplace_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]); m_coinbase_txns.emplace_back(*CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
// Set key birthday to block time increased by the timestamp window, so // Set key birthday to block time increased by the timestamp window, so
// rescan will start at the block time. // rescan will start at the block time.
const int64_t KEY_TIME = BLOCK_TIME + TIMESTAMP_WINDOW; const int64_t KEY_TIME = BLOCK_TIME + TIMESTAMP_WINDOW;
SetMockTime(KEY_TIME); SetMockTime(KEY_TIME);
m_coinbase_txns.emplace_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]); m_coinbase_txns.emplace_back(*CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
LOCK(cs_main); LOCK(cs_main);
@ -164,7 +164,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U); BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U);
BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U); BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U);
for (size_t i = 0; i < m_coinbase_txns.size(); ++i) { for (size_t i = 0; i < m_coinbase_txns.size(); ++i) {
bool found = wallet->GetWalletTx(m_coinbase_txns[i]->GetHash()); bool found = wallet->GetWalletTx(m_coinbase_txns[i].GetHash());
bool expected = i >= 100; bool expected = i >= 100;
BOOST_CHECK_EQUAL(found, expected); BOOST_CHECK_EQUAL(found, expected);
} }
@ -182,7 +182,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
{ {
CWallet wallet(WalletLocation(), WalletDatabase::CreateDummy()); CWallet wallet(WalletLocation(), WalletDatabase::CreateDummy());
CWalletTx wtx(&wallet, m_coinbase_txns.back()); CWalletTx wtx(&wallet, MakeTransactionRef(m_coinbase_txns.back()));
LOCK2(cs_main, wallet.cs_wallet); LOCK2(cs_main, wallet.cs_wallet);
wtx.hashBlock = chainActive.Tip()->GetBlockHash(); wtx.hashBlock = chainActive.Tip()->GetBlockHash();
wtx.nIndex = 0; wtx.nIndex = 0;