mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-15 06:12:37 -03:00
2068f089c8
-BEGIN VERIFY SCRIPT- mkdir -p src/util git mv src/util.h src/util/system.h git mv src/util.cpp src/util/system.cpp git mv src/utilmemory.h src/util/memory.h git mv src/utilmoneystr.h src/util/moneystr.h git mv src/utilmoneystr.cpp src/util/moneystr.cpp git mv src/utilstrencodings.h src/util/strencodings.h git mv src/utilstrencodings.cpp src/util/strencodings.cpp git mv src/utiltime.h src/util/time.h git mv src/utiltime.cpp src/util/time.cpp sed -i 's/<util\.h>/<util\/system\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utilmemory\.h>/<util\/memory\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utilmoneystr\.h>/<util\/moneystr\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utiltime\.h>/<util\/time\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h sed -i 's/BITCOIN_UTILMEMORY_H/BITCOIN_UTIL_MEMORY_H/g' src/util/memory.h sed -i 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h sed -i 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h sed -i 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h sed -i 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am sed -i 's/utilmemory\.\(h\|cpp\)/util\/memory\.\1/g' src/Makefile.am sed -i 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am sed -i 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am sed -i 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am sed -i 's/-> util ->/-> util\/system ->/' test/lint/lint-circular-dependencies.sh sed -i 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-format-strings.py test/lint/lint-locale-dependence.sh sed -i 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh sed -i 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh sed -i 's/src\\utilstrencodings\.cpp/src\\util\\strencodings\.cpp/' build_msvc/libbitcoinconsensus/libbitcoinconsensus.vcxproj -END VERIFY SCRIPT-
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
// Copyright (c) 2017-2018 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <index/txindex.h>
|
|
#include <script/standard.h>
|
|
#include <test/test_bitcoin.h>
|
|
#include <util/system.h>
|
|
#include <util/time.h>
|
|
#include <validation.h>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
BOOST_AUTO_TEST_SUITE(txindex_tests)
|
|
|
|
BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
|
|
{
|
|
TxIndex txindex(1 << 20, true);
|
|
|
|
CTransactionRef tx_disk;
|
|
uint256 block_hash;
|
|
|
|
// Transaction should not be found in the index before it is started.
|
|
for (const auto& txn : m_coinbase_txns) {
|
|
BOOST_CHECK(!txindex.FindTx(txn->GetHash(), block_hash, tx_disk));
|
|
}
|
|
|
|
// BlockUntilSyncedToCurrentChain should return false before txindex is started.
|
|
BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain());
|
|
|
|
txindex.Start();
|
|
|
|
// Allow tx index to catch up with the block index.
|
|
constexpr int64_t timeout_ms = 10 * 1000;
|
|
int64_t time_start = GetTimeMillis();
|
|
while (!txindex.BlockUntilSyncedToCurrentChain()) {
|
|
BOOST_REQUIRE(time_start + timeout_ms > GetTimeMillis());
|
|
MilliSleep(100);
|
|
}
|
|
|
|
// Check that txindex has all txs that were in the chain before it started.
|
|
for (const auto& txn : m_coinbase_txns) {
|
|
if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) {
|
|
BOOST_ERROR("FindTx failed");
|
|
} else if (tx_disk->GetHash() != txn->GetHash()) {
|
|
BOOST_ERROR("Read incorrect tx");
|
|
}
|
|
}
|
|
|
|
// Check that new transactions in new blocks make it into the index.
|
|
for (int i = 0; i < 10; i++) {
|
|
CScript coinbase_script_pub_key = GetScriptForDestination(coinbaseKey.GetPubKey().GetID());
|
|
std::vector<CMutableTransaction> no_txns;
|
|
const CBlock& block = CreateAndProcessBlock(no_txns, coinbase_script_pub_key);
|
|
const CTransaction& txn = *block.vtx[0];
|
|
|
|
BOOST_CHECK(txindex.BlockUntilSyncedToCurrentChain());
|
|
if (!txindex.FindTx(txn.GetHash(), block_hash, tx_disk)) {
|
|
BOOST_ERROR("FindTx failed");
|
|
} else if (tx_disk->GetHash() != txn.GetHash()) {
|
|
BOOST_ERROR("Read incorrect tx");
|
|
}
|
|
}
|
|
|
|
txindex.Stop(); // Stop thread before calling destructor
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|