20#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;
59 if (nOut >= txTmp.
vout.size())
63 txTmp.
vout.resize(nOut+1);
64 for (
unsigned int i = 0; i < nOut; i++)
65 txTmp.
vout[i].SetNull();
68 for (
unsigned int i = 0; i < txTmp.
vin.size(); i++)
70 txTmp.
vin[i].nSequence = 0;
76 txTmp.
vin[0] = txTmp.
vin[nIn];
82 ss << txTmp << nHashType;
90 for (
int i=0; i<ops; i++)
101 for (
int in = 0; in < ins; in++) {
109 for (
int out = 0; out < outs; out++) {
121 #if defined(PRINT_SIGHASH_JSON)
123 std::cout <<
"\t[\"raw_transaction, script, input_index, hashType, signature_hash (result)\"],\n";
124 int nRandomTests = 500;
126 int nRandomTests = 50000;
128 for (
int i=0; i<nRandomTests; i++) {
139 #if defined(PRINT_SIGHASH_JSON)
143 std::cout <<
"\t[\"" ;
144 std::cout <<
HexStr(ss) <<
"\", \"";
145 std::cout <<
HexStr(scriptCode) <<
"\", ";
146 std::cout << nIn <<
", ";
147 std::cout << nHashType <<
", \"";
148 std::cout << sho.
GetHex() <<
"\"]";
149 if (i+1 != nRandomTests) {
156 #if defined(PRINT_SIGHASH_JSON)
166 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
168 std::string strTest = test.
write();
171 BOOST_ERROR(
"Bad test: " << strTest);
174 if (test.
size() == 1)
continue;
176 std::string raw_tx, raw_script, sigHashHex;
185 raw_script = test[1].
get_str();
188 sigHashHex = test[4].
get_str();
197 std::vector<unsigned char> raw =
ParseHex(raw_script);
198 scriptCode.
insert(scriptCode.
end(), raw.begin(), raw.end());
200 BOOST_ERROR(
"Bad test, couldn't deserialize data: " << strTest);
205 BOOST_CHECK_MESSAGE(sh.
GetHex() == sigHashHex, strTest);
Double ended buffer combining vector and stream-like interfaces.
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetHash()
Compute the double-SHA256 hash of all data written to this object.
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.
const std::string & get_str() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
std::string GetHex() const
iterator insert(iterator pos, const T &value)
BOOST_AUTO_TEST_SUITE_END()
int FindAndDelete(CScript &script, const CScript &b)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
static unsigned const char sighash[]
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK(expr)
static const int SERIALIZE_TRANSACTION_NO_WITNESS
A flag that is ORed into the protocol version to designate that a transaction should be (un)serialize...
std::shared_ptr< const CTransaction > CTransactionRef
opcodetype
Script opcodes.
static uint64_t InsecureRandRange(uint64_t range)
static uint256 InsecureRand256()
static uint64_t InsecureRandBits(int bits)
static uint32_t InsecureRand32()
static bool InsecureRandBool()
static uint256 SignatureHashOld(CScript scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
UniValue read_json(const std::string &jsondata)
static void RandomTransaction(CMutableTransaction &tx, bool fSingle)
BOOST_AUTO_TEST_CASE(sighash_test)
static void RandomScript(CScript &script)
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::vector< unsigned char > ParseHex(const char *psz)
A mutable version of CTransaction.
std::vector< CTxOut > vout
bool CheckTransaction(const CTransaction &tx, TxValidationState &state)
static const int PROTOCOL_VERSION
network protocol versioning