PIVX Core  5.6.99
P2P Digital Currency
transaction_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin Core developers
2 // Copyright (c) 2017-2021 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "test/test_pivx.h"
7 
10 
11 #include "consensus/tx_verify.h"
12 #include "clientversion.h"
13 #include "checkqueue.h"
14 #include "core_io.h"
15 #include "key.h"
16 #include "keystore.h"
17 #include "policy/policy.h"
18 #include "script/script.h"
19 #include "script/script_error.h"
20 #include "script/sign.h"
21 #include "validation.h"
22 
23 #include <boost/algorithm/string/classification.hpp>
24 #include <boost/algorithm/string/split.hpp>
25 #include <boost/test/unit_test.hpp>
26 
27 #include <univalue.h>
28 
29 // In script_tests.cpp
30 extern UniValue read_json(const std::string& jsondata);
31 
32 // Helper
33 bool IsStandardTx(const CTransaction& tx, int nBlockHeight, std::string& reason)
34 {
35  return IsStandardTx(MakeTransactionRef(tx), nBlockHeight, reason);
36 }
37 
38 static std::map<std::string, unsigned int> mapFlagNames = {
39  {std::string("NONE"), (unsigned int)SCRIPT_VERIFY_NONE},
40  {std::string("P2SH"), (unsigned int)SCRIPT_VERIFY_P2SH},
41  {std::string("STRICTENC"), (unsigned int)SCRIPT_VERIFY_STRICTENC},
42  {std::string("DERSIG"), (unsigned int)SCRIPT_VERIFY_DERSIG},
43  {std::string("LOW_S"), (unsigned int)SCRIPT_VERIFY_LOW_S},
44  {std::string("SIGPUSHONLY"), (unsigned int)SCRIPT_VERIFY_SIGPUSHONLY},
45  {std::string("MINIMALDATA"), (unsigned int)SCRIPT_VERIFY_MINIMALDATA},
46  {std::string("NULLDUMMY"), (unsigned int)SCRIPT_VERIFY_NULLDUMMY},
47  {std::string("DISCOURAGE_UPGRADABLE_NOPS"), (unsigned int)SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS},
48  {std::string("CLEANSTACK"), (unsigned int)SCRIPT_VERIFY_CLEANSTACK},
49  {std::string("CHECKLOCKTIMEVERIFY"), (unsigned int)SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY},
50  {std::string("EXCHANGEADDRVERIFY"), (unsigned int)SCRIPT_VERIFY_EXCHANGEADDR},
51 };
52 
53 unsigned int ParseScriptFlags(std::string strFlags)
54 {
55  if (strFlags.empty()) {
56  return 0;
57  }
58  unsigned int flags = 0;
59  std::vector<std::string> words;
60  boost::algorithm::split(words, strFlags, boost::algorithm::is_any_of(","));
61 
62  for (std::string word : words)
63  {
64  if (!mapFlagNames.count(word))
65  BOOST_ERROR("Bad test: unknown verification flag '" << word << "'");
66  flags |= mapFlagNames[word];
67  }
68 
69  return flags;
70 }
71 
72 std::string FormatScriptFlags(unsigned int flags)
73 {
74  if (flags == 0) {
75  return "";
76  }
77  std::string ret;
78  std::map<std::string, unsigned int>::const_iterator it = mapFlagNames.begin();
79  while (it != mapFlagNames.end()) {
80  if (flags & it->second) {
81  ret += it->first + ",";
82  }
83  it++;
84  }
85  return ret.substr(0, ret.size() - 1);
86 }
87 
88 BOOST_FIXTURE_TEST_SUITE(transaction_tests, TestingSetup)
89 
91 {
92  // Read tests from test/data/tx_valid.json
93  // Format is an array of arrays
94  // Inner arrays are either [ "comment" ]
95  // or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...],"], serializedTransaction, verifyFlags
96  // ... where all scripts are stringified scripts.
97  //
98  // verifyFlags is a comma separated list of script verification flags to apply, or "NONE"
99  UniValue tests = read_json(std::string(json_tests::tx_valid, json_tests::tx_valid + sizeof(json_tests::tx_valid)));
100 
101  ScriptError err;
102  for (unsigned int idx = 0; idx < tests.size(); idx++) {
103  UniValue test = tests[idx];
104  std::string strTest = test.write();
105  if (test[0].isArray())
106  {
107  if (test.size() != 3 || !test[1].isStr() || !test[2].isStr())
108  {
109  BOOST_ERROR("Bad test: " << strTest);
110  continue;
111  }
112 
113  std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
114  UniValue inputs = test[0].get_array();
115  bool fValid = true;
116  for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
117  const UniValue& input = inputs[inpIdx];
118  if (!input.isArray())
119  {
120  fValid = false;
121  break;
122  }
123  UniValue vinput = input.get_array();
124  if (vinput.size() != 3)
125  {
126  fValid = false;
127  break;
128  }
129 
130  mapprevOutScriptPubKeys[COutPoint(uint256S(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
131  }
132  if (!fValid)
133  {
134  BOOST_ERROR("Bad test: " << strTest);
135  continue;
136  }
137 
138  std::string transaction = test[1].get_str();
139  CDataStream stream(ParseHex(transaction), SER_NETWORK, PROTOCOL_VERSION);
140  CTransaction tx(deserialize, stream);
141 
142  CValidationState state;
143  BOOST_CHECK_MESSAGE(CheckTransaction(tx, state, false), strTest);
144  BOOST_CHECK(state.IsValid());
145 
146  PrecomputedTransactionData precomTxData(tx);
147  for (unsigned int i = 0; i < tx.vin.size(); i++)
148  {
149  if (!mapprevOutScriptPubKeys.count(tx.vin[i].prevout))
150  {
151  BOOST_ERROR("Bad test: " << strTest);
152  break;
153  }
154 
155  CAmount amount = 0;
156  unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
157  BOOST_CHECK_MESSAGE(VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
158  verify_flags, TransactionSignatureChecker(&tx, i, amount, precomTxData), tx.GetRequiredSigVersion(), &err),
159  strTest);
160  BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
161  }
162  }
163  }
164 }
165 
167 {
168  // Read tests from test/data/tx_invalid.json
169  // Format is an array of arrays
170  // Inner arrays are either [ "comment" ]
171  // or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], ...],"], serializedTransaction, verifyFlags
172  // ... where all scripts are stringified scripts.
173  //
174  // verifyFlags is a comma separated list of script verification flags to apply, or "NONE"
175  UniValue tests = read_json(std::string(json_tests::tx_invalid, json_tests::tx_invalid + sizeof(json_tests::tx_invalid)));
176 
177  ScriptError err;
178  for (unsigned int idx = 0; idx < tests.size(); idx++) {
179  UniValue test = tests[idx];
180  std::string strTest = test.write();
181  if (test[0].isArray())
182  {
183  if (test.size() != 3 || !test[1].isStr() || !test[2].isStr())
184  {
185  BOOST_ERROR("Bad test: " << strTest);
186  continue;
187  }
188 
189  std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
190  UniValue inputs = test[0].get_array();
191  bool fValid = true;
192  for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
193  const UniValue& input = inputs[inpIdx];
194  if (!input.isArray())
195  {
196  fValid = false;
197  break;
198  }
199  UniValue vinput = input.get_array();
200  if (vinput.size() != 3)
201  {
202  fValid = false;
203  break;
204  }
205 
206  mapprevOutScriptPubKeys[COutPoint(uint256S(vinput[0].get_str()), vinput[1].get_int())] = ParseScript(vinput[2].get_str());
207  }
208  if (!fValid)
209  {
210  BOOST_ERROR("Bad test: " << strTest);
211  continue;
212  }
213 
214  std::string transaction = test[1].get_str();
215  CDataStream stream(ParseHex(transaction), SER_NETWORK, PROTOCOL_VERSION);
216  CTransaction tx(deserialize, stream);
217 
218  CValidationState state;
219  fValid = CheckTransaction(tx, state, false) && state.IsValid();
220 
221  PrecomputedTransactionData precomTxData(tx);
222  for (unsigned int i = 0; i < tx.vin.size() && fValid; i++)
223  {
224  if (!mapprevOutScriptPubKeys.count(tx.vin[i].prevout))
225  {
226  BOOST_ERROR("Bad test: " << strTest);
227  break;
228  }
229 
230  CAmount amount = 0;
231  unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
232  fValid = VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
233  verify_flags, TransactionSignatureChecker(&tx, i, amount, precomTxData), tx.GetRequiredSigVersion(), &err);
234  }
235  BOOST_CHECK_MESSAGE(!fValid, strTest);
236  BOOST_CHECK_MESSAGE(err != SCRIPT_ERR_OK, ScriptErrorString(err));
237  }
238  }
239 }
240 
241 BOOST_AUTO_TEST_CASE(basic_transaction_tests)
242 {
243  // Random real transaction (e2769b09e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436)
244  unsigned char ch[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x6b, 0xff, 0x7f, 0xcd, 0x4f, 0x85, 0x65, 0xef, 0x40, 0x6d, 0xd5, 0xd6, 0x3d, 0x4f, 0xf9, 0x4f, 0x31, 0x8f, 0xe8, 0x20, 0x27, 0xfd, 0x4d, 0xc4, 0x51, 0xb0, 0x44, 0x74, 0x01, 0x9f, 0x74, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x49, 0x30, 0x46, 0x02, 0x21, 0x00, 0xda, 0x0d, 0xc6, 0xae, 0xce, 0xfe, 0x1e, 0x06, 0xef, 0xdf, 0x05, 0x77, 0x37, 0x57, 0xde, 0xb1, 0x68, 0x82, 0x09, 0x30, 0xe3, 0xb0, 0xd0, 0x3f, 0x46, 0xf5, 0xfc, 0xf1, 0x50, 0xbf, 0x99, 0x0c, 0x02, 0x21, 0x00, 0xd2, 0x5b, 0x5c, 0x87, 0x04, 0x00, 0x76, 0xe4, 0xf2, 0x53, 0xf8, 0x26, 0x2e, 0x76, 0x3e, 0x2d, 0xd5, 0x1e, 0x7f, 0xf0, 0xbe, 0x15, 0x77, 0x27, 0xc4, 0xbc, 0x42, 0x80, 0x7f, 0x17, 0xbd, 0x39, 0x01, 0x41, 0x04, 0xe6, 0xc2, 0x6e, 0xf6, 0x7d, 0xc6, 0x10, 0xd2, 0xcd, 0x19, 0x24, 0x84, 0x78, 0x9a, 0x6c, 0xf9, 0xae, 0xa9, 0x93, 0x0b, 0x94, 0x4b, 0x7e, 0x2d, 0xb5, 0x34, 0x2b, 0x9d, 0x9e, 0x5b, 0x9f, 0xf7, 0x9a, 0xff, 0x9a, 0x2e, 0xe1, 0x97, 0x8d, 0xd7, 0xfd, 0x01, 0xdf, 0xc5, 0x22, 0xee, 0x02, 0x28, 0x3d, 0x3b, 0x06, 0xa9, 0xd0, 0x3a, 0xcf, 0x80, 0x96, 0x96, 0x8d, 0x7d, 0xbb, 0x0f, 0x91, 0x78, 0xff, 0xff, 0xff, 0xff, 0x02, 0x8b, 0xa7, 0x94, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xba, 0xde, 0xec, 0xfd, 0xef, 0x05, 0x07, 0x24, 0x7f, 0xc8, 0xf7, 0x42, 0x41, 0xd7, 0x3b, 0xc0, 0x39, 0x97, 0x2d, 0x7b, 0x88, 0xac, 0x40, 0x94, 0xa8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93, 0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43, 0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00};
245  std::vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
246  CDataStream stream(vch, SER_DISK, CLIENT_VERSION);
248  stream >> tx;
249  CValidationState state;
250  BOOST_CHECK_MESSAGE(CheckTransaction(tx, state, false) && state.IsValid(), "Simple deserialized transaction should be valid.");
251 
252  // Check that duplicate txins fail
253  tx.vin.push_back(tx.vin[0]);
254  BOOST_CHECK_MESSAGE(!CheckTransaction(tx, state, false) || !state.IsValid(), "Transaction with duplicate txins should be invalid.");
255 }
256 
257 //
258 // Helper: create two dummy transactions, each with
259 // two outputs. The first has 11 and 50 CENT outputs
260 // paid to a TX_PUBKEY, the second 21 and 22 CENT outputs
261 // paid to a TX_PUBKEYHASH.
262 //
263 static std::vector<CMutableTransaction>
264 SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
265 {
266  std::vector<CMutableTransaction> dummyTransactions;
267  dummyTransactions.resize(2);
268 
269  // Add some keys to the keystore:
270  CKey key[4];
271  for (int i = 0; i < 4; i++)
272  {
273  key[i].MakeNewKey(i % 2);
274  keystoreRet.AddKey(key[i]);
275  }
276 
277  // Create some dummy input transactions
278  dummyTransactions[0].vout.resize(2);
279  dummyTransactions[0].vout[0].nValue = 11*CENT;
280  dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
281  dummyTransactions[0].vout[1].nValue = 50*CENT;
282  dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
283  AddCoins(coinsRet, dummyTransactions[0], 0);
284 
285  dummyTransactions[1].vout.resize(2);
286  dummyTransactions[1].vout[0].nValue = 21*CENT;
287  dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(key[2].GetPubKey().GetID());
288  dummyTransactions[1].vout[1].nValue = 22*CENT;
289  dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(key[3].GetPubKey().GetID());
290  AddCoins(coinsRet, dummyTransactions[1], 0);
291 
292  return dummyTransactions;
293 }
294 
296 {
297  CBasicKeyStore keystore;
298  CCoinsView coinsDummy;
299  CCoinsViewCache coins(&coinsDummy);
300  std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);
301 
303  t1.vin.resize(3);
304  t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
305  t1.vin[0].prevout.n = 1;
306  t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
307  t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();
308  t1.vin[1].prevout.n = 0;
309  t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
310  t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();
311  t1.vin[2].prevout.n = 1;
312  t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
313  t1.vout.resize(2);
314  t1.vout[0].nValue = 90*CENT;
315  t1.vout[0].scriptPubKey << OP_1;
316 
317  BOOST_CHECK(AreInputsStandard(t1, coins));
318  BOOST_CHECK_EQUAL(coins.GetValueIn(t1), (50+21+22)*CENT);
319 }
320 
321 BOOST_AUTO_TEST_CASE(test_big_witness_transaction) {
324 
325  CKey key;
326  key.MakeNewKey(false);
327  CBasicKeyStore keystore;
328  keystore.AddKeyPubKey(key, key.GetPubKey());
329  CKeyID hash = key.GetPubKey().GetID();
330  CScript scriptPubKey = GetScriptForDestination(hash);
331 
332  std::vector<int> sigHashes;
333  sigHashes.push_back(SIGHASH_NONE | SIGHASH_ANYONECANPAY);
334  sigHashes.push_back(SIGHASH_SINGLE | SIGHASH_ANYONECANPAY);
335  sigHashes.push_back(SIGHASH_ALL | SIGHASH_ANYONECANPAY);
336  sigHashes.push_back(SIGHASH_NONE);
337  sigHashes.push_back(SIGHASH_SINGLE);
338  sigHashes.push_back(SIGHASH_ALL);
339 
340  // create a big transaction of 4500 inputs signed by the same key
341  for(uint32_t ij = 0; ij < 4500; ij++) {
342  uint32_t i = mtx.vin.size();
343  uint256 prevId;
344  prevId.SetHex("0000000000000000000000000000000000000000000000000000000000000100");
345  COutPoint outpoint(prevId, i);
346 
347  mtx.vin.resize(mtx.vin.size() + 1);
348  mtx.vin[i].prevout = outpoint;
349  mtx.vin[i].scriptSig = CScript();
350 
351  mtx.vout.resize(mtx.vout.size() + 1);
352  mtx.vout[i].nValue = 1000;
353  mtx.vout[i].scriptPubKey = CScript() << OP_1;
354  }
355 
356  // sign all inputs
357  for(uint32_t i = 0; i < mtx.vin.size(); i++) {
358  bool hashSigned = SignSignature(keystore, scriptPubKey, mtx, i, 1000, sigHashes.at(i % sigHashes.size()));
359  assert(hashSigned);
360  }
361 
362  CDataStream ssout(SER_NETWORK, PROTOCOL_VERSION);
363  ssout << mtx;
364  CTransaction tx(deserialize, ssout);
365 
366  // check all inputs concurrently, with the cache
367  PrecomputedTransactionData precomTxData(tx);
368  boost::thread_group threadGroup;
369  CCheckQueue<CScriptCheck> scriptcheckqueue(128);
370  CCheckQueueControl<CScriptCheck> control(&scriptcheckqueue);
371 
372  for (int i=0; i<20; i++)
373  threadGroup.create_thread(std::bind(&CCheckQueue<CScriptCheck>::Thread, std::ref(scriptcheckqueue)));
374 
375  std::vector<Coin> coins;
376  for(uint32_t i = 0; i < mtx.vin.size(); i++) {
377  Coin coin;
378  coin.nHeight = 1;
379  coin.out.nValue = 1000;
380  coin.out.scriptPubKey = scriptPubKey;
381  coins.emplace_back(std::move(coin));
382  }
383 
384  for(uint32_t i = 0; i < mtx.vin.size(); i++) {
385  std::vector<CScriptCheck> vChecks;
386  CScriptCheck check(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH, false, &precomTxData);
387  vChecks.emplace_back();
388  check.swap(vChecks.back());
389  control.Add(vChecks);
390  }
391 
392  bool controlCheck = control.Wait();
393  assert(controlCheck);
394 
395  threadGroup.interrupt_all();
396  threadGroup.join_all();
397 }
398 
399 BOOST_AUTO_TEST_CASE(test_IsStandard)
400 {
401  LOCK(cs_main);
402  CBasicKeyStore keystore;
403  CCoinsView coinsDummy;
404  CCoinsViewCache coins(&coinsDummy);
405  std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);
406 
408  t.vin.resize(1);
409  t.vin[0].prevout.hash = dummyTransactions[0].GetHash();
410  t.vin[0].prevout.n = 1;
411  t.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
412  t.vout.resize(1);
413  t.vout[0].nValue = 90*CENT;
414  CKey key;
415  key.MakeNewKey(true);
416  t.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());
417 
418  std::string reason;
419  BOOST_CHECK(IsStandardTx(t, 0, reason));
420 
421  // Check dust with default relay fee:
422  CAmount nDustThreshold = GetDustThreshold(dustRelayFee);
423  BOOST_CHECK_EQUAL(nDustThreshold, 5460);
424  // dust:
425  t.vout[0].nValue = nDustThreshold - 1;
426  BOOST_CHECK(!IsStandardTx(t, 0, reason));
427  // not dust:
428  t.vout[0].nValue = nDustThreshold;
429  BOOST_CHECK(IsStandardTx(t, 0, reason));
430 
431  // Check dust with odd relay fee to verify rounding:
432  // nDustThreshold = 182 * 3702 / 1000
433  dustRelayFee = CFeeRate(3702);
434  // dust:
435  t.vout[0].nValue = 673 - 1;
436  BOOST_CHECK(!IsStandardTx(t, 0, reason));
437  // not dust:
438  t.vout[0].nValue = 673;
439  BOOST_CHECK(IsStandardTx(t, 0, reason));
440  dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
441 
442  t.vout[0].scriptPubKey = CScript() << OP_1;
443  BOOST_CHECK(!IsStandardTx(t, 0, reason));
444 
445  // MAX_OP_RETURN_RELAY-byte TX_NULL_DATA (standard)
446  t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
447  BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY, t.vout[0].scriptPubKey.size());
448  BOOST_CHECK(IsStandardTx(t, 0, reason));
449 
450  // MAX_OP_RETURN_RELAY+1-byte TX_NULL_DATA (non-standard)
451  t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800");
452  BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY + 1, t.vout[0].scriptPubKey.size());
453  BOOST_CHECK(!IsStandardTx(t, 0, reason));
454 
455  // Data payload can be encoded in any way...
456  t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("");
457  BOOST_CHECK(IsStandardTx(t, 0, reason));
458  t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("00") << ParseHex("01");
459  BOOST_CHECK(IsStandardTx(t, 0, reason));
460  // OP_RESERVED *is* considered to be a PUSHDATA type opcode by IsPushOnly()!
461  t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RESERVED << -1 << 0 << ParseHex("01") << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16;
462  BOOST_CHECK(IsStandardTx(t, 0, reason));
463  t.vout[0].scriptPubKey = CScript() << OP_RETURN << 0 << ParseHex("01") << 2 << ParseHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
464  BOOST_CHECK(IsStandardTx(t, 0, reason));
465 
466  // ...so long as it only contains PUSHDATA's
467  t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RETURN;
468  BOOST_CHECK(!IsStandardTx(t, 0, reason));
469 
470  // TX_NULL_DATA w/o PUSHDATA
471  t.vout.resize(1);
472  t.vout[0].scriptPubKey = CScript() << OP_RETURN;
473  BOOST_CHECK(IsStandardTx(t, 0, reason));
474 
475  // Only one TX_NULL_DATA permitted in all cases
476  t.vout.resize(2);
477  t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
478  t.vout[1].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
479  BOOST_CHECK(!IsStandardTx(t, 0, reason));
480 
481  t.vout[0].scriptPubKey = CScript() << OP_RETURN << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38");
482  t.vout[1].scriptPubKey = CScript() << OP_RETURN;
483  BOOST_CHECK(!IsStandardTx(t, 0, reason));
484 
485  t.vout[0].scriptPubKey = CScript() << OP_RETURN;
486  t.vout[1].scriptPubKey = CScript() << OP_RETURN;
487  BOOST_CHECK(!IsStandardTx(t, 0, reason));
488 }
489 
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
Basic key store, that keeps keys in an address->secret map.
Definition: keystore.h:99
bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
Add a key to the store.
Definition: keystore.cpp:34
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
Definition: checkqueue.h:172
void Add(std::vector< T > &vChecks)
Definition: checkqueue.h:196
Queue for verifications that have to be performed.
Definition: checkqueue.h:29
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:283
CAmount GetValueIn(const CTransaction &tx) const
Amount of pivx coming in to a transaction Note that lightweight clients may not know anything besides...
Definition: coins.cpp:337
Abstract view on the open txout dataset.
Definition: coins.h:201
Fee rate in PIV per kilobyte: CAmount / kB.
Definition: feerate.h:20
An encapsulated private key.
Definition: key.h:30
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:158
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:186
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:21
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:14
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:72
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:167
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:273
void swap(CScriptCheck &check)
Definition: validation.h:296
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:244
std::vector< CTxIn > vin
Definition: transaction.h:270
SigVersion GetRequiredSigVersion() const
Definition: transaction.h:347
CScript scriptPubKey
Definition: transaction.h:140
CAmount nValue
Definition: transaction.h:139
Capture information about block/transaction validation.
Definition: validation.h:24
bool IsValid() const
Definition: validation.h:69
A UTXO entry.
Definition: coins.h:32
CTxOut out
unspent transaction output
Definition: coins.h:41
uint32_t nHeight
at which height the containing transaction was included in the active block chain
Definition: coins.h:44
const std::string & get_str() const
bool isArray() const
Definition: univalue.h:83
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
size_t size() const
Definition: univalue.h:68
bool isStr() const
Definition: univalue.h:81
const UniValue & get_array() const
void SetHex(const char *psz)
Definition: uint256.cpp:31
void emplace_back(Args &&... args)
Definition: prevector.h:426
256-bit opaque blob.
Definition: uint256.h:138
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.
Definition: coins.cpp:116
CScript ParseScript(std::string s)
Definition: core_read.cpp:23
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_NULLDUMMY
Definition: interpreter.h:51
@ SCRIPT_VERIFY_P2SH
Definition: interpreter.h:36
@ SCRIPT_VERIFY_SIGPUSHONLY
Definition: interpreter.h:54
@ SCRIPT_VERIFY_LOW_S
Definition: interpreter.h:48
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
Definition: interpreter.h:83
@ SCRIPT_VERIFY_STRICTENC
Definition: interpreter.h:41
@ SCRIPT_VERIFY_DERSIG
Definition: interpreter.h:44
@ SCRIPT_VERIFY_CLEANSTACK
Definition: interpreter.h:78
@ SCRIPT_VERIFY_NONE
Definition: interpreter.h:33
@ SCRIPT_VERIFY_MINIMALDATA
Definition: interpreter.h:61
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
Definition: interpreter.h:71
@ SCRIPT_VERIFY_EXCHANGEADDR
Definition: interpreter.h:87
@ SIGHASH_ANYONECANPAY
Definition: interpreter.h:27
@ SIGHASH_ALL
Definition: interpreter.h:24
@ SIGHASH_NONE
Definition: interpreter.h:25
@ SIGHASH_SINGLE
Definition: interpreter.h:26
@ LOCK
Definition: lockunlock.h:16
@ SAPLING
Definition: logging.h:63
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
int flags
Definition: pivx-tx.cpp:400
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check for standard transaction types.
Definition: policy.cpp:191
CAmount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
Definition: policy.cpp:21
CFeeRate dustRelayFee
Definition: policy.cpp:19
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:43
@ OP_CHECKSIG
Definition: script.h:166
@ OP_1
Definition: script.h:59
@ OP_RETURN
Definition: script.h:87
@ OP_RESERVED
Definition: script.h:58
const char * ScriptErrorString(const ScriptError serror)
Definition: script_error.cpp:9
enum ScriptError_t ScriptError
@ SCRIPT_ERR_OK
Definition: script_error.h:12
@ SER_DISK
Definition: serialize.h:175
@ SER_NETWORK
Definition: serialize.h:174
constexpr deserialize_type deserialize
Definition: serialize.h:57
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.
Definition: sign.cpp:192
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
Definition: standard.cpp:278
A mutable version of CTransaction.
Definition: transaction.h:409
std::vector< CTxOut > vout
Definition: transaction.h:411
std::vector< CTxIn > vin
Definition: transaction.h:410
bool IsStandardTx(const CTransaction &tx, int nBlockHeight, std::string &reason)
UniValue read_json(const std::string &jsondata)
BOOST_AUTO_TEST_CASE(tx_valid)
unsigned int ParseScriptFlags(std::string strFlags)
std::string FormatScriptFlags(unsigned int flags)
bool CheckTransaction(const CTransaction &tx, CValidationState &state, bool fColdStakingActive)
Transaction validation functions.
Definition: tx_verify.cpp:54
uint256 uint256S(const char *str)
Definition: uint256.h:157
std::vector< unsigned char > ParseHex(const char *psz)
boost::thread_group threadGroup