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;
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++)
102 for (
int in = 0; in < ins; in++) {
103 tx.
vin.emplace_back();
111 tx.
vout.emplace_back();
122 #if defined(PRINT_SIGHASH_JSON) 124 std::cout <<
"\t[\"raw_transaction, script, input_index, hashType, signature_hash (result)\"],\n";
125 int nRandomTests = 500;
127 int nRandomTests = 50000;
129 for (
int i=0; i<nRandomTests; i++) {
140 #if defined(PRINT_SIGHASH_JSON) 144 std::cout <<
"\t[\"" ;
145 std::cout <<
HexStr(ss) <<
"\", \"";
146 std::cout <<
HexStr(scriptCode) <<
"\", ";
147 std::cout << nIn <<
", ";
148 std::cout << nHashType <<
", \"";
149 std::cout << sho.GetHex() <<
"\"]";
150 if (i+1 != nRandomTests) {
157 #if defined(PRINT_SIGHASH_JSON) 167 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
169 std::string strTest = test.
write();
172 BOOST_ERROR(
"Bad test: " << strTest);
175 if (test.
size() == 1)
continue;
177 std::string raw_tx, raw_script, sigHashHex;
186 raw_script = test[1].
get_str();
187 nIn = test[2].
getInt<
int>();
188 nHashType = test[3].
getInt<
int>();
189 sigHashHex = test[4].
get_str();
198 std::vector<unsigned char> raw =
ParseHex(raw_script);
199 scriptCode.
insert(scriptCode.
end(), raw.begin(), raw.end());
201 BOOST_ERROR(
"Bad test, couldn't deserialize data: " << strTest);
206 BOOST_CHECK_MESSAGE(sh.
GetHex() == sigHashHex, strTest);
std::shared_ptr< const CTransaction > CTransactionRef
static const std::string sighash
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::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
iterator insert(iterator pos, const T &value)
static bool InsecureRandBool()
static void RandomTransaction(CMutableTransaction &tx, bool fSingle)
const std::string & get_str() const
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
const std::vector< CTxIn > vin
static uint64_t InsecureRandRange(uint64_t range)
UniValue read_json(const std::string &jsondata)
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
An input of a transaction.
BOOST_AUTO_TEST_SUITE_END()
opcodetype
Script opcodes.
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
static uint256 SignatureHashOld(CScript scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
An output of a transaction.
static uint256 InsecureRand256()
std::vector< CTxOut > vout
BOOST_AUTO_TEST_CASE(sighash_test)
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
Serialized script, used inside transaction inputs and outputs.
static const int PROTOCOL_VERSION
network protocol versioning
static uint32_t InsecureRand32()
std::string GetHex() const
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
static uint64_t InsecureRandBits(int bits)
A mutable version of CTransaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
int FindAndDelete(CScript &script, const CScript &b)
static void RandomScript(CScript &script)
bool CheckTransaction(const CTransaction &tx, TxValidationState &state)
#define BOOST_CHECK(expr)
static CAmount InsecureRandMoneyAmount()