Changeset View
Changeset View
Standalone View
Standalone View
src/test/txindex_tests.cpp
Show All 15 Lines | |||||
BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup) { | ||||
TxIndex txindex(1 << 20, true); | TxIndex txindex(1 << 20, true); | ||||
CTransactionRef tx_disk; | CTransactionRef tx_disk; | ||||
uint256 block_hash; | uint256 block_hash; | ||||
// Transaction should not be found in the index before it is started. | // Transaction should not be found in the index before it is started. | ||||
for (const auto &txn : m_coinbase_txns) { | for (const auto &txn : m_coinbase_txns) { | ||||
BOOST_CHECK(!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)); | BOOST_CHECK(!txindex.FindTx(txn->GetId(), block_hash, tx_disk)); | ||||
} | } | ||||
// BlockUntilSyncedToCurrentChain should return false before txindex is | // BlockUntilSyncedToCurrentChain should return false before txindex is | ||||
// started. | // started. | ||||
BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain()); | BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain()); | ||||
txindex.Start(); | txindex.Start(); | ||||
// Allow tx index to catch up with the block index. | // Allow tx index to catch up with the block index. | ||||
constexpr int64_t timeout_ms = 10 * 1000; | constexpr int64_t timeout_ms = 10 * 1000; | ||||
int64_t time_start = GetTimeMillis(); | int64_t time_start = GetTimeMillis(); | ||||
while (!txindex.BlockUntilSyncedToCurrentChain()) { | while (!txindex.BlockUntilSyncedToCurrentChain()) { | ||||
BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis()); | BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis()); | ||||
MilliSleep(100); | MilliSleep(100); | ||||
} | } | ||||
// Check that txindex has all txs that were in the chain before it started. | // Check that txindex has all txs that were in the chain before it started. | ||||
for (const auto &txn : m_coinbase_txns) { | for (const auto &txn : m_coinbase_txns) { | ||||
if (!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)) { | if (!txindex.FindTx(txn->GetId(), block_hash, tx_disk)) { | ||||
BOOST_ERROR("FindTx failed"); | BOOST_ERROR("FindTx failed"); | ||||
} else if (tx_disk->GetHash() != txn.GetHash()) { | } else if (tx_disk->GetId() != txn->GetId()) { | ||||
BOOST_ERROR("Read incorrect tx"); | BOOST_ERROR("Read incorrect tx"); | ||||
} | } | ||||
} | } | ||||
// Check that new transactions in new blocks make it into the index. | // Check that new transactions in new blocks make it into the index. | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
CScript coinbase_script_pub_key = | CScript coinbase_script_pub_key = | ||||
GetScriptForDestination(coinbaseKey.GetPubKey().GetID()); | GetScriptForDestination(coinbaseKey.GetPubKey().GetID()); | ||||
std::vector<CMutableTransaction> no_txns; | std::vector<CMutableTransaction> no_txns; | ||||
const CBlock &block = | const CBlock &block = | ||||
CreateAndProcessBlock(no_txns, coinbase_script_pub_key); | CreateAndProcessBlock(no_txns, coinbase_script_pub_key); | ||||
const CTransaction &txn = *block.vtx[0]; | const CTransactionRef &txn = block.vtx[0]; | ||||
BOOST_CHECK(txindex.BlockUntilSyncedToCurrentChain()); | BOOST_CHECK(txindex.BlockUntilSyncedToCurrentChain()); | ||||
if (!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)) { | if (!txindex.FindTx(txn->GetId(), block_hash, tx_disk)) { | ||||
BOOST_ERROR("FindTx failed"); | BOOST_ERROR("FindTx failed"); | ||||
} else if (tx_disk->GetHash() != txn.GetHash()) { | } else if (tx_disk->GetId() != txn->GetId()) { | ||||
BOOST_ERROR("Read incorrect tx"); | BOOST_ERROR("Read incorrect tx"); | ||||
} | } | ||||
} | } | ||||
// shutdown sequence (c.f. Shutdown() in init.cpp) | // shutdown sequence (c.f. Shutdown() in init.cpp) | ||||
txindex.Stop(); | txindex.Stop(); | ||||
threadGroup.interrupt_all(); | threadGroup.interrupt_all(); | ||||
threadGroup.join_all(); | threadGroup.join_all(); | ||||
// Rest of shutdown sequence and destructors happen in ~TestingSetup() | // Rest of shutdown sequence and destructors happen in ~TestingSetup() | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |