16 #include "validation.h"
20 #include <boost/test/unit_test.hpp>
24 static std::vector<unsigned char>
27 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;
63 for (
int i = 0; i < 4; i++)
77 for (
int i = 0; i < 4; i++)
85 txFrom.
vout.resize(8);
86 for (
int i = 0; i < 4; i++)
88 txFrom.
vout[i].scriptPubKey = evalScripts[i];
89 txFrom.
vout[i].nValue = COIN;
90 txFrom.
vout[i+4].scriptPubKey = standardScripts[i];
91 txFrom.
vout[i+4].nValue = COIN;
96 for (
int i = 0; i < 8; i++)
98 txTo[i].
vin.resize(1);
99 txTo[i].
vout.resize(1);
100 txTo[i].
vin[0].prevout.n = i;
101 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
102 txTo[i].
vout[0].nValue = 1;
103 BOOST_CHECK_MESSAGE(
IsMine(keystore, txFrom.
vout[i].scriptPubKey),
strprintf(
"IsMine %d", i));
105 for (
int i = 0; i < 8; i++)
111 for (
int i = 0; i < 8; i++) {
113 for (
int j = 0; j < 8; j++) {
115 txTo[i].
vin[0].scriptSig = txTo[j].
vin[0].scriptSig;
117 false, &precomTxData)();
119 BOOST_CHECK_MESSAGE(sigOK,
strprintf(
"VerifySignature %d %d", i, j));
121 BOOST_CHECK_MESSAGE(!sigOK,
strprintf(
"VerifySignature %d %d", i, j));
122 txTo[i].
vin[0].scriptSig = sigSave;
160 std::vector<CPubKey> keys;
161 for (
int i = 0; i < 4; i++)
165 keys.push_back(key[i].GetPubKey());
175 for (
int i = 0; i < 4; i++)
183 txFrom.
vout.resize(4);
184 for (
int i = 0; i < 4; i++)
186 txFrom.
vout[i].scriptPubKey = outer[i];
187 txFrom.
vout[i].nValue = CENT;
192 for (
int i = 0; i < 4; i++)
194 txTo[i].
vin.resize(1);
195 txTo[i].
vout.resize(1);
196 txTo[i].
vin[0].prevout.n = i;
197 txTo[i].
vin[0].prevout.hash = txFrom.
GetHash();
198 txTo[i].
vout[0].nValue = 1*CENT;
199 txTo[i].
vout[0].scriptPubKey = inner[i];
200 BOOST_CHECK_MESSAGE(
IsMine(keystore, txFrom.
vout[i].scriptPubKey),
strprintf(
"IsMine %d", i));
202 for (
int i = 0; i < 4; i++)
205 BOOST_CHECK_MESSAGE(
IsStandardTx(MakeTransactionRef(txTo[i]), 0, reason),
strprintf(
"txTo[%d].IsStandard", i));
218 static const unsigned char direct[] = {
OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
OP_EQUAL };
220 static const unsigned char pushdata1[] = {
OP_HASH160,
OP_PUSHDATA1, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
OP_EQUAL };
222 static const unsigned char pushdata2[] = {
OP_HASH160,
OP_PUSHDATA2, 20,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
OP_EQUAL };
224 static const unsigned char pushdata4[] = {
OP_HASH160,
OP_PUSHDATA4, 20,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
OP_EQUAL };
267 std::vector<CPubKey> keys;
268 for (
int i = 0; i < 6; i++)
273 for (
int i = 0; i < 3; i++)
277 txFrom.
vout.resize(7);
285 txFrom.
vout[0].nValue = 1000;
286 txFrom.
vout[1].scriptPubKey = pay1;
287 txFrom.
vout[1].nValue = 2000;
288 txFrom.
vout[2].scriptPubKey = pay1of3;
289 txFrom.
vout[2].nValue = 3000;
300 txFrom.
vout[3].nValue = 4000;
304 for (
unsigned i = 0; i < MAX_P2SH_SIGOPS; i++)
309 txFrom.
vout[4].nValue = 5000;
315 txFrom.
vout[5].nValue = 5000;
319 txFrom.
vout[6].nValue = 6000;
328 for (
int i = 0; i < 5; i++)
330 txTo.
vin[i].prevout.n = i;
339 txTo.
vin[3].scriptSig << OP_11 << OP_11 << std::vector<unsigned char>(oneAndTwo.
begin(), oneAndTwo.
end());
340 txTo.
vin[4].scriptSig << std::vector<unsigned char>(fifteenSigops.
begin(), fifteenSigops.
end());
347 txToNonStd1.
vout.resize(1);
349 txToNonStd1.
vout[0].nValue = 1000;
350 txToNonStd1.
vin.resize(1);
351 txToNonStd1.
vin[0].prevout.n = 5;
352 txToNonStd1.
vin[0].prevout.hash = txFrom.
GetHash();
353 txToNonStd1.
vin[0].scriptSig << std::vector<unsigned char>(sixteenSigops.
begin(), sixteenSigops.
end());
359 txToNonStd2.
vout.resize(1);
361 txToNonStd2.
vout[0].nValue = 1000;
362 txToNonStd2.
vin.resize(1);
363 txToNonStd2.
vin[0].prevout.n = 6;
364 txToNonStd2.
vin[0].prevout.hash = txFrom.
GetHash();
365 txToNonStd2.
vin[0].scriptSig << std::vector<unsigned char>(twentySigops.
begin(), twentySigops.
end());
Basic key store, that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Abstract view on the open txout dataset.
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.
virtual bool AddKey(const CKey &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
A reference to a CScript: the Hash160 of its serialization (see script.h)
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check, bool fSkipInvalid)
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, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror)
@ SCRIPT_VERIFY_STRICTENC
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
RecursiveMutex cs_main
Global state.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check for standard transaction types.
bool IsStandardTx(const CTransactionRef &tx, int nBlockHeight, std::string &reason)
Check for standard transaction types.
std::vector< unsigned char > ToByteVector(const T &in)
BOOST_AUTO_TEST_CASE(sign)
const char * ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
void Serialize(Stream &s, char a)
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType, bool fColdStake)
Produce a script signature for a transaction.
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
SigVersion GetRequiredSigVersion() const
std::vector< CTxOut > vout
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.