14 #include <validation.h> 18 #include <boost/test/unit_test.hpp> 28 std::vector<unsigned char> sSerialized(s.
begin(), s.
end());
36 txFrom.
vout.resize(1);
37 txFrom.
vout[0].scriptPubKey = scriptPubKey;
42 txTo.
vin[0].prevout.n = 0;
44 txTo.
vin[0].scriptSig = scriptSig;
45 txTo.
vout[0].nValue = 1;
62 for (
int i = 0; i < 4; i++)
76 for (
int i = 0; i < 4; i++)
84 txFrom.
vout.resize(8);
85 for (
int i = 0; i < 4; i++)
87 txFrom.
vout[i].scriptPubKey = evalScripts[i];
89 txFrom.
vout[i+4].scriptPubKey = standardScripts[i];
95 for (
int i = 0; i < 8; i++)
97 txTo[i].
vin.resize(1);
98 txTo[i].
vout.resize(1);
99 txTo[i].
vin[0].prevout.n = i;
100 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
101 txTo[i].
vout[0].nValue = 1;
103 for (
int i = 0; i < 8; i++)
110 for (
int i = 0; i < 8; i++) {
112 for (
int j = 0; j < 8; j++)
115 txTo[i].
vin[0].scriptSig = txTo[j].
vin[0].scriptSig;
118 BOOST_CHECK_MESSAGE(sigOK,
strprintf(
"VerifySignature %d %d", i, j));
120 BOOST_CHECK_MESSAGE(!sigOK,
strprintf(
"VerifySignature %d %d", i, j));
121 txTo[i].
vin[0].scriptSig = sigSave;
158 std::vector<CPubKey> keys;
160 for (
int i = 0; i < 4; i++)
174 for (
int i = 0; i < 4; i++)
182 txFrom.
vout.resize(4);
183 for (
int i = 0; i < 4; i++)
185 txFrom.
vout[i].scriptPubKey = outer[i];
191 for (
int i = 0; i < 4; i++)
193 txTo[i].
vin.resize(1);
194 txTo[i].
vout.resize(1);
195 txTo[i].
vin[0].prevout.n = i;
196 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
198 txTo[i].
vout[0].scriptPubKey = inner[i];
200 for (
int i = 0; i < 4; i++)
216 std::vector<unsigned char> direct = {
OP_HASH160, 20};
217 direct.insert(direct.end(), 20, 0);
223 pushdata1.insert(pushdata1.end(), 20, 0);
227 pushdata2.insert(pushdata2.end(), 20, 0);
231 pushdata4.insert(pushdata4.end(), 20, 0);
274 for (
int i = 0; i < 6; i++)
279 std::vector<CPubKey> keys;
281 for (
int i = 0; i < 3; i++)
285 txFrom.
vout.resize(7);
293 txFrom.
vout[0].nValue = 1000;
294 txFrom.
vout[1].scriptPubKey = pay1;
295 txFrom.
vout[1].nValue = 2000;
296 txFrom.
vout[2].scriptPubKey = pay1of3;
297 txFrom.
vout[2].nValue = 3000;
308 txFrom.
vout[3].nValue = 4000;
317 txFrom.
vout[4].nValue = 5000;
323 txFrom.
vout[5].nValue = 5000;
327 txFrom.
vout[6].nValue = 6000;
336 for (
int i = 0; i < 5; i++)
338 txTo.
vin[i].prevout.n = i;
350 txTo.
vin[3].scriptSig << OP_11 << OP_11 << std::vector<unsigned char>(oneAndTwo.
begin(), oneAndTwo.
end());
351 txTo.
vin[4].scriptSig << std::vector<unsigned char>(fifteenSigops.
begin(), fifteenSigops.
end());
358 txToNonStd1.
vout.resize(1);
360 txToNonStd1.
vout[0].nValue = 1000;
361 txToNonStd1.
vin.resize(1);
362 txToNonStd1.
vin[0].prevout.n = 5;
363 txToNonStd1.
vin[0].prevout.hash = txFrom.
GetHash();
364 txToNonStd1.
vin[0].scriptSig << std::vector<unsigned char>(sixteenSigops.
begin(), sixteenSigops.
end());
370 txToNonStd2.
vout.resize(1);
372 txToNonStd2.
vout[0].nValue = 1000;
373 txToNonStd2.
vin.resize(1);
374 txToNonStd2.
vin[0].prevout.n = 6;
375 txToNonStd2.
vin[0].prevout.hash = txFrom.
GetHash();
376 txToNonStd2.
vin[0].scriptSig << std::vector<unsigned char>(twentySigops.
begin(), twentySigops.
end());
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
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).
enum ScriptError_t ScriptError
bool IsPayToScriptHash() const
CPubKey GetPubKey() const
Compute the public key from a private key.
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
virtual bool AddCScript(const CScript &redeemScript)
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG
Default for -permitbaremultisig.
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs to mitigate two potential denial-of-service attacks:
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.
Abort execution through assertion failure (for consensus code)
Abstract view on the open txout dataset.
static std::vector< unsigned char > Serialize(const CScript &s)
BOOST_AUTO_TEST_SUITE_END()
static bool IsStandardTx(const CTransaction &tx, std::string &reason)
Fillable signing provider that keeps keys in an address->secret map.
std::string ScriptErrorString(const ScriptError serror)
BOOST_AUTO_TEST_CASE(sign)
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
static constexpr unsigned int MAX_P2SH_SIGOPS
Maximum number of signature check operations in an IsStandard() P2SH script.
GenericTransactionSignatureChecker< CMutableTransaction > MutableTransactionSignatureChecker
std::vector< CTxOut > vout
Closure representing one script verification Note that this stores references to the spending transac...
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
static constexpr unsigned int DUST_RELAY_TX_FEE
Min feerate for defining dust.
std::vector< unsigned char > ToByteVector(const T &in)
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
static bool Verify(const CScript &scriptSig, const CScript &scriptPubKey, bool fStrict, ScriptError &err)
A mutable version of CTransaction.
static constexpr CAmount CENT
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView that adds a memory cache for transactions to another CCoinsView.
virtual bool AddKey(const CKey &key)
#define BOOST_CHECK(expr)
static constexpr CAmount COIN
The amount of satoshis in one BTC.