14 #include <validation.h>
18 #include <boost/test/unit_test.hpp>
34 std::vector<unsigned char> sSerialized(s.
begin(), s.
end());
42 txFrom.
vout.resize(1);
43 txFrom.
vout[0].scriptPubKey = scriptPubKey;
48 txTo.
vin[0].prevout.n = 0;
50 txTo.
vin[0].scriptSig = scriptSig;
51 txTo.
vout[0].nValue = 1;
68 for (
int i = 0; i < 4; i++)
82 for (
int i = 0; i < 4; i++)
90 txFrom.
vout.resize(8);
91 for (
int i = 0; i < 4; i++)
93 txFrom.
vout[i].scriptPubKey = evalScripts[i];
95 txFrom.
vout[i+4].scriptPubKey = standardScripts[i];
101 for (
int i = 0; i < 8; i++)
103 txTo[i].
vin.resize(1);
104 txTo[i].
vout.resize(1);
105 txTo[i].
vin[0].prevout.n = i;
106 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
107 txTo[i].
vout[0].nValue = 1;
109 for (
int i = 0; i < 8; i++)
116 for (
int i = 0; i < 8; i++) {
118 for (
int j = 0; j < 8; j++)
121 txTo[i].
vin[0].scriptSig = txTo[j].
vin[0].scriptSig;
124 BOOST_CHECK_MESSAGE(sigOK,
strprintf(
"VerifySignature %d %d", i, j));
126 BOOST_CHECK_MESSAGE(!sigOK,
strprintf(
"VerifySignature %d %d", i, j));
127 txTo[i].
vin[0].scriptSig = sigSave;
164 std::vector<CPubKey> keys;
166 for (
int i = 0; i < 4; i++)
180 for (
int i = 0; i < 4; i++)
188 txFrom.
vout.resize(4);
189 for (
int i = 0; i < 4; i++)
191 txFrom.
vout[i].scriptPubKey = outer[i];
197 for (
int i = 0; i < 4; i++)
199 txTo[i].
vin.resize(1);
200 txTo[i].
vout.resize(1);
201 txTo[i].
vin[0].prevout.n = i;
202 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
204 txTo[i].
vout[0].scriptPubKey = inner[i];
206 for (
int i = 0; i < 4; i++)
212 BOOST_CHECK_MESSAGE((i == 0 ? no_pbms_is_std : !no_pbms_is_std),
strprintf(
"txTo[%d].IsStandard(permbaremulti=false)", i));
224 std::vector<unsigned char> direct = {
OP_HASH160, 20};
225 direct.insert(direct.end(), 20, 0);
231 pushdata1.insert(pushdata1.end(), 20, 0);
235 pushdata2.insert(pushdata2.end(), 20, 0);
239 pushdata4.insert(pushdata4.end(), 20, 0);
282 for (
int i = 0; i < 6; i++)
287 std::vector<CPubKey> keys;
289 for (
int i = 0; i < 3; i++)
293 txFrom.
vout.resize(7);
301 txFrom.
vout[0].nValue = 1000;
302 txFrom.
vout[1].scriptPubKey = pay1;
303 txFrom.
vout[1].nValue = 2000;
304 txFrom.
vout[2].scriptPubKey = pay1of3;
305 txFrom.
vout[2].nValue = 3000;
316 txFrom.
vout[3].nValue = 4000;
325 txFrom.
vout[4].nValue = 5000;
331 txFrom.
vout[5].nValue = 5000;
335 txFrom.
vout[6].nValue = 6000;
344 for (
int i = 0; i < 5; i++)
346 txTo.
vin[i].prevout.n = i;
358 txTo.
vin[3].scriptSig << OP_11 << OP_11 << std::vector<unsigned char>(oneAndTwo.
begin(), oneAndTwo.
end());
359 txTo.
vin[4].scriptSig << std::vector<unsigned char>(fifteenSigops.
begin(), fifteenSigops.
end());
366 txToNonStd1.
vout.resize(1);
368 txToNonStd1.
vout[0].nValue = 1000;
369 txToNonStd1.
vin.resize(1);
370 txToNonStd1.
vin[0].prevout.n = 5;
371 txToNonStd1.
vin[0].prevout.hash = txFrom.
GetHash();
372 txToNonStd1.
vin[0].scriptSig << std::vector<unsigned char>(sixteenSigops.
begin(), sixteenSigops.
end());
378 txToNonStd2.
vout.resize(1);
380 txToNonStd2.
vout[0].nValue = 1000;
381 txToNonStd2.
vin.resize(1);
382 txToNonStd2.
vin[0].prevout.n = 6;
383 txToNonStd2.
vin[0].prevout.hash = txFrom.
GetHash();
384 txToNonStd2.
vin[0].scriptSig << std::vector<unsigned char>(twentySigops.
begin(), twentySigops.
end());
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
static constexpr CAmount COIN
The amount of satoshis in one BTC.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Abstract view on the open txout dataset.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
Closure representing one script verification Note that this stores references to the spending transac...
Serialized script, used inside transaction inputs and outputs.
bool IsPayToScriptHash() const
The basic transaction that is broadcasted on the network and contained in blocks.
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
virtual bool AddKey(const CKey &key)
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
BOOST_AUTO_TEST_SUITE_END()
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
@ SCRIPT_VERIFY_STRICTENC
GenericTransactionSignatureChecker< CMutableTransaction > MutableTransactionSignatureChecker
@ ASSERT_FAIL
Abort execution through assertion failure (for consensus code)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs to mitigate two potential denial-of-service attacks:
static constexpr unsigned int DUST_RELAY_TX_FEE
Min feerate for defining dust.
static constexpr unsigned int MAX_P2SH_SIGOPS
Maximum number of signature check operations in an IsStandard() P2SH script.
std::vector< unsigned char > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
static bool Verify(const CScript &scriptSig, const CScript &scriptPubKey, bool fStrict, ScriptError &err)
static std::vector< unsigned char > Serialize(const CScript &s)
BOOST_AUTO_TEST_CASE(sign)
static bool IsStandardTx(const CTransaction &tx, bool permit_bare_multisig, std::string &reason)
static constexpr CAmount CENT
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType, SignatureData &sig_data)
Produce a satisfying script (scriptSig or witness).
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.