Changeset View
Changeset View
Standalone View
Standalone View
src/test/txindex_tests.cpp
Show All 14 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 : coinbaseTxns) { | for (const auto &txn : m_coinbase_txns) { | ||||
BOOST_CHECK(!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)); | BOOST_CHECK(!txindex.FindTx(txn.GetHash(), 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 : coinbaseTxns) { | for (const auto &txn : m_coinbase_txns) { | ||||
if (!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)) { | if (!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)) { | ||||
BOOST_ERROR("FindTx failed"); | BOOST_ERROR("FindTx failed"); | ||||
} else if (tx_disk->GetHash() != txn.GetHash()) { | } else if (tx_disk->GetHash() != txn.GetHash()) { | ||||
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. | ||||
Show All 26 Lines |