]> Git Repo - VerusCoin.git/blobdiff - src/test/sighash_tests.cpp
Remove FindAndDelete. refs #1386
[VerusCoin.git] / src / test / sighash_tests.cpp
index afb7a41bbd4b3af49520ec038bd40f9daeb459c2..8eb614c9bf8d46b2160738d56d1a633be6970b76 100644 (file)
@@ -2,15 +2,17 @@
 // Distributed under the MIT software license, see the accompanying
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
+#include "consensus/validation.h"
 #include "data/sighash.json.h"
 #include "main.h"
 #include "random.h"
-#include "serialize.h"
-#include "script/script.h"
 #include "script/interpreter.h"
+#include "script/script.h"
+#include "serialize.h"
+#include "test/test_bitcoin.h"
 #include "util.h"
 #include "version.h"
-#include "test/test_bitcoin.h"
+#include "sodium.h"
 
 #include <iostream>
 
@@ -33,10 +35,6 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
     }
     CMutableTransaction txTmp(txTo);
 
-    // In case concatenating two scripts ends up with two codeseparators,
-    // or an extra one at the end, this prevents all those possible incompatibilities.
-    scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR));
-
     // Blank out other inputs' signatures
     for (unsigned int i = 0; i < txTmp.vin.size(); i++)
         txTmp.vin[i].scriptSig = CScript();
@@ -79,6 +77,9 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
         txTmp.vin.resize(1);
     }
 
+    // Blank out the joinsplit signature.
+    memset(&txTmp.joinSplitSig[0], 0, txTmp.joinSplitSig.size());
+
     // Serialize and hash
     CHashWriter ss(SER_GETHASH, 0);
     ss << txTmp << nHashType;
@@ -100,6 +101,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
     tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0;
     int ins = (insecure_rand() % 4) + 1;
     int outs = fSingle ? ins : (insecure_rand() % 4) + 1;
+    int joinsplits = (insecure_rand() % 4);
     for (int in = 0; in < ins; in++) {
         tx.vin.push_back(CTxIn());
         CTxIn &txin = tx.vin.back();
@@ -114,6 +116,42 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
         txout.nValue = insecure_rand() % 100000000;
         RandomScript(txout.scriptPubKey);
     }
+    if (tx.nVersion >= 2) {
+        for (int js = 0; js < joinsplits; js++) {
+            JSDescription jsdesc;
+            if (insecure_rand() % 2 == 0) {
+                jsdesc.vpub_old = insecure_rand() % 100000000;
+            } else {
+                jsdesc.vpub_new = insecure_rand() % 100000000;
+            }
+
+            jsdesc.anchor = GetRandHash();
+            jsdesc.nullifiers[0] = GetRandHash();
+            jsdesc.nullifiers[1] = GetRandHash();
+            jsdesc.ephemeralKey = GetRandHash();
+            jsdesc.randomSeed = GetRandHash();
+            randombytes_buf(jsdesc.ciphertexts[0].begin(), jsdesc.ciphertexts[0].size());
+            randombytes_buf(jsdesc.ciphertexts[1].begin(), jsdesc.ciphertexts[1].size());
+            jsdesc.proof = libzcash::ZCProof::random_invalid();
+            jsdesc.macs[0] = GetRandHash();
+            jsdesc.macs[1] = GetRandHash();
+
+            tx.vjoinsplit.push_back(jsdesc);
+        }
+
+        unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES];
+        crypto_sign_keypair(tx.joinSplitPubKey.begin(), joinSplitPrivKey);
+
+        // Empty output script.
+        CScript scriptCode;
+        CTransaction signTx(tx);
+        uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL);
+
+        assert(crypto_sign_detached(&tx.joinSplitSig[0], NULL,
+                                    dataToBeSigned.begin(), 32,
+                                    joinSplitPrivKey
+                                    ) == 0);
+    }
 }
 
 BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
@@ -199,7 +237,7 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
           stream >> tx;
 
           CValidationState state;
-          BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
+          BOOST_CHECK_MESSAGE(CheckTransactionWithoutProofVerification(tx, state), strTest);
           BOOST_CHECK(state.IsValid());
 
           std::vector<unsigned char> raw = ParseHex(raw_script);
This page took 0.026809 seconds and 4 git commands to generate.