13#include <test/data/sighash.json.h>
22#include <boost/test/unit_test.hpp>
29 if (nIn >= txTo.
vin.size())
40 for (
unsigned int i = 0; i <
txTmp.vin.size(); i++)
42 txTmp.vin[nIn].scriptSig = scriptCode;
51 for (
unsigned int i = 0; i <
txTmp.vin.size(); i++)
53 txTmp.vin[i].nSequence = 0;
58 unsigned int nOut = nIn;
64 for (
unsigned int i = 0; i <
nOut; i++)
68 for (
unsigned int i = 0; i <
txTmp.vin.size(); i++)
70 txTmp.vin[i].nSequence = 0;
91 for (
int i=0; i<ops; i++)
103 for (
int in = 0; in <
ins; in++) {
104 tx.
vin.emplace_back();
111 for (
int out = 0; out <
outs; out++) {
112 tx.
vout.emplace_back();
124 #if defined(PRINT_SIGHASH_JSON)
126 std::cout <<
"\t[\"raw_transaction, script, input_index, hashType, signature_hash (result)\"],\n";
132 int nHashType{
int(m_rng.rand32())};
136 RandomScript(scriptCode);
137 int nIn = m_rng.randrange(txTo.
vin.size());
142 #if defined(PRINT_SIGHASH_JSON)
146 std::cout <<
"\t[\"" ;
147 std::cout <<
HexStr(
ss) <<
"\", \"";
148 std::cout <<
HexStr(scriptCode) <<
"\", ";
149 std::cout << nIn <<
", ";
150 std::cout << nHashType <<
", \"";
151 std::cout <<
sho.GetHex() <<
"\"]";
159 #if defined(PRINT_SIGHASH_JSON)
169 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
177 if (test.
size() == 1)
continue;
189 nIn = test[2].
getInt<
int>();
190 nHashType = test[3].
getInt<
int>();
219 RandomTransaction(tx,
false);
221 const auto amount{m_rng.rand<
CAmount>()};
229 for (
int i{0}; i < 10; ++i) {
int64_t CAmount
Amount in satoshis (Can be negative)
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
Double ended buffer combining vector and stream-like interfaces.
A writer stream (for serialization) that computes a 256-bit hash.
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
uint256 rand256() noexcept
generate a random uint256.
bool randbool() noexcept
Generate a random boolean.
uint32_t rand32() noexcept
Generate a random 32-bit integer.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Data structure to cache SHA256 midstates for the ECDSA sighash calculations (bare,...
void Store(int32_t hash_type, const CScript &script_code, const HashWriter &writer) noexcept
Store into this cache object the provided SHA256 midstate.
bool Load(int32_t hash_type, const CScript &script_code, HashWriter &writer) const noexcept
Load into writer the SHA256 midstate if found in this cache.
Minimal stream for reading from an existing byte array by std::span.
const std::string & get_str() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
iterator insert(iterator pos, const T &value)
static transaction_identifier FromUint256(const uint256 &id)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
int FindAndDelete(CScript &script, const CScript &b)
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.
@ WITNESS_V0
Witness v0 (P2WPKH and P2WSH); see BIP 141.
UniValue read_json(std::string_view jsondata)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static constexpr TransactionSerParams TX_NO_WITNESS
static constexpr TransactionSerParams TX_WITH_WITNESS
std::shared_ptr< const CTransaction > CTransactionRef
opcodetype
Script opcodes.
static uint256 SignatureHashOld(CScript scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
BOOST_AUTO_TEST_CASE(sighash_test)
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
A mutable version of CTransaction.
std::vector< CTxOut > vout
void RandomScript(CScript &script)
void RandomTransaction(CMutableTransaction &tx, bool fSingle)
CAmount RandMoney(Rng &&rng)
bool CheckTransaction(const CTransaction &tx, TxValidationState &state)
BOOST_CHECK_NE(OneL.ToString(), ArrayToString(ZeroArray, 32))
constexpr std::array tests
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.