]> Git Repo - VerusCoin.git/commitdiff
Make transaction test failures print the comments preceding the test JSON.
authorDaira Hopwood <[email protected]>
Wed, 7 Jun 2017 12:09:56 +0000 (13:09 +0100)
committerDaira Hopwood <[email protected]>
Mon, 19 Jun 2017 15:33:18 +0000 (16:33 +0100)
Signed-off-by: Daira Hopwood <[email protected]>
src/test/transaction_tests.cpp

index c2543b183f5958f5b09da5b6858a2588443e7742..3fa691a94f01a013b2c0a04662f6a2bce368d358 100644 (file)
@@ -97,6 +97,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
     //
     // verifyFlags is a comma separated list of script verification flags to apply, or "NONE"
     UniValue tests = read_json(std::string(json_tests::tx_valid, json_tests::tx_valid + sizeof(json_tests::tx_valid)));
+    std::string comment("");
 
     auto verifier = libzcash::ProofVerifier::Strict();
     ScriptError err;
@@ -107,7 +108,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
         {
             if (test.size() != 3 || !test[1].isStr() || !test[2].isStr())
             {
-                BOOST_ERROR("Bad test: " << strTest);
+                BOOST_ERROR("Bad test: " << strTest << comment);
                 continue;
             }
 
@@ -132,7 +133,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
             }
             if (!fValid)
             {
-                BOOST_ERROR("Bad test: " << strTest);
+                BOOST_ERROR("Bad test: " << strTest << comment);
                 continue;
             }
 
@@ -142,23 +143,30 @@ BOOST_AUTO_TEST_CASE(tx_valid)
             stream >> tx;
 
             CValidationState state;
-            BOOST_CHECK_MESSAGE(CheckTransaction(tx, state, verifier), strTest);
-            BOOST_CHECK(state.IsValid());
+            BOOST_CHECK_MESSAGE(CheckTransaction(tx, state, verifier), strTest + comment);
+            BOOST_CHECK_MESSAGE(state.IsValid(), comment);
 
             for (unsigned int i = 0; i < tx.vin.size(); i++)
             {
                 if (!mapprevOutScriptPubKeys.count(tx.vin[i].prevout))
                 {
-                    BOOST_ERROR("Bad test: " << strTest);
+                    BOOST_ERROR("Bad test: " << strTest << comment);
                     break;
                 }
 
                 unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
                 BOOST_CHECK_MESSAGE(VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
                                                  verify_flags, TransactionSignatureChecker(&tx, i), &err),
-                                    strTest);
-                BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
+                                    strTest + comment);
+                BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err) + comment);
             }
+
+            comment = "";
+        }
+        else if (test.size() == 1)
+        {
+            comment += "\n# ";
+            comment += test[0].write();
         }
     }
 }
@@ -173,6 +181,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
     //
     // verifyFlags is a comma separated list of script verification flags to apply, or "NONE"
     UniValue tests = read_json(std::string(json_tests::tx_invalid, json_tests::tx_invalid + sizeof(json_tests::tx_invalid)));
+    std::string comment("");
 
     auto verifier = libzcash::ProofVerifier::Strict();
     ScriptError err;
@@ -183,7 +192,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
         {
             if (test.size() != 3 || !test[1].isStr() || !test[2].isStr())
             {
-                BOOST_ERROR("Bad test: " << strTest);
+                BOOST_ERROR("Bad test: " << strTest << comment);
                 continue;
             }
 
@@ -208,7 +217,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
             }
             if (!fValid)
             {
-                BOOST_ERROR("Bad test: " << strTest);
+                BOOST_ERROR("Bad test: " << strTest << comment);
                 continue;
             }
 
@@ -224,7 +233,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
             {
                 if (!mapprevOutScriptPubKeys.count(tx.vin[i].prevout))
                 {
-                    BOOST_ERROR("Bad test: " << strTest);
+                    BOOST_ERROR("Bad test: " << strTest << comment);
                     break;
                 }
 
@@ -232,8 +241,15 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
                 fValid = VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
                                       verify_flags, TransactionSignatureChecker(&tx, i), &err);
             }
-            BOOST_CHECK_MESSAGE(!fValid, strTest);
-            BOOST_CHECK_MESSAGE(err != SCRIPT_ERR_OK, ScriptErrorString(err));
+            BOOST_CHECK_MESSAGE(!fValid, strTest + comment);
+            BOOST_CHECK_MESSAGE(err != SCRIPT_ERR_OK, ScriptErrorString(err) + comment);
+
+            comment = "";
+        }
+        else if (test.size() == 1)
+        {
+            comment += "\n# ";
+            comment += test[0].write();
         }
     }
 }
This page took 0.031009 seconds and 4 git commands to generate.