8 #include <validation.h> 10 #include <boost/test/unit_test.hpp> 12 BOOST_AUTO_TEST_SUITE(txospenderindex_tests)
18 const CScript& coinbase_script = m_coinbase_txns[0]->vout[0].scriptPubKey;
19 for (
int i = 0; i < 10; i++) CreateAndProcessBlock({}, coinbase_script);
22 std::vector<COutPoint> spent(10);
23 std::vector<CMutableTransaction> spender(spent.size());
24 for (
size_t i = 0; i < spent.size(); i++) {
26 auto coinbase_tx = m_coinbase_txns[i];
27 spent[i] =
COutPoint(coinbase_tx->GetHash(), 0);
30 spender[i].version = 1;
31 spender[i].vin.resize(1);
32 spender[i].vin[0].prevout.
hash = spent[i].hash;
33 spender[i].vin[0].prevout.n = spent[i].n;
34 spender[i].vout.resize(1);
35 spender[i].vout[0].nValue = coinbase_tx->GetValueOut();
36 spender[i].vout[0].scriptPubKey = coinbase_script;
39 std::vector<unsigned char> vchSig;
41 BOOST_REQUIRE(coinbaseKey.Sign(hash, vchSig));
43 spender[i].vin[0].scriptSig << vchSig;
47 const uint256 tip_hash = CreateAndProcessBlock(spender, coinbase_script).GetHash();
53 BOOST_REQUIRE(txospenderindex.
Init());
54 BOOST_CHECK(!txospenderindex.BlockUntilSyncedToCurrentChain());
58 for (
const auto& outpoint : spent) {
62 txospenderindex.
Sync();
65 for (
size_t i = 0; i < spent.size(); i++) {
66 const auto tx_spender{txospenderindex.
FindSpender(spent[i])};
67 BOOST_REQUIRE(tx_spender.has_value());
68 BOOST_REQUIRE(tx_spender->has_value());
74 txospenderindex.
Stop();
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache, SigHashCache *sighash_cache)
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
TxoSpenderIndex is used to look up which transaction spent a given output.
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
void Stop()
Stops the instance from staying in sync with blockchain updates.
BOOST_AUTO_TEST_SUITE_END()
void Sync()
Sync the index with the block index starting from the current best block.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
An outpoint - a combination of a transaction hash and an index n into its vout.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
BOOST_FIXTURE_TEST_CASE(txospenderindex_initial_sync, TestChain100Setup)
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
util::Expected< std::optional< TxoSpender >, std::string > FindSpender(const COutPoint &txo) const
Search the index for a transaction that spends the given outpoint.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
std::unique_ptr< ChainstateManager > chainman
#define BOOST_CHECK(expr)
IndexSummary GetSummary() const
Get a summary of the index and its state.