5#include <chainparams.h>
11#include <boost/test/unit_test.hpp>
13BOOST_AUTO_TEST_SUITE(txospenderindex_tests)
18 BOOST_REQUIRE(txospenderindex.
Init());
21 for (
int i = 0; i < 50; i++) {
22 std::vector<CMutableTransaction> no_txns;
23 CreateAndProcessBlock(no_txns, this->m_coinbase_txns[i]->vout[0].scriptPubKey);
25 std::vector<COutPoint> spent(10);
26 std::vector<CMutableTransaction> spender(spent.size());
28 for (
size_t i = 0; i < spent.size(); i++) {
29 spent[i] =
COutPoint(this->m_coinbase_txns[i]->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 = this->m_coinbase_txns[i]->GetValueOut();
36 spender[i].vout[0].scriptPubKey = this->m_coinbase_txns[i]->vout[0].scriptPubKey;
39 std::vector<unsigned char> vchSig;
41 coinbaseKey.Sign(hash, vchSig);
43 spender[i].vin[0].scriptSig << vchSig;
46 CBlock block = CreateAndProcessBlock(spender, this->m_coinbase_txns[0]->vout[0].scriptPubKey);
49 for (
const auto& outpoint : spent) {
54 BOOST_CHECK(!txospenderindex.BlockUntilSyncedToCurrentChain());
56 txospenderindex.
Sync();
57 for (
size_t i = 0; i < spent.size(); i++) {
58 const auto tx_spender{txospenderindex.
FindSpender(spent[i])};
59 BOOST_REQUIRE(tx_spender.has_value());
60 BOOST_REQUIRE(tx_spender->has_value());
74 txospenderindex.
Stop();
void Stop()
Stops the instance from staying in sync with blockchain updates.
bool Init()
Initializes the sync state and registers the instance to the validation interface so that it stays in...
void Sync()
Sync the index with the block index starting from the current best block.
An outpoint - a combination of a transaction hash and an index n into its vout.
TxoSpenderIndex is used to look up which transaction spent a given output.
util::Expected< std::optional< TxoSpender >, std::string > FindSpender(const COutPoint &txo) const
BOOST_AUTO_TEST_SUITE_END()
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)
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
BOOST_FIXTURE_TEST_CASE(txospenderindex_initial_sync, TestChain100Setup)