aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-01-10 20:18:00 -0500
committerGavin Andresen <gavinandresen@gmail.com>2012-01-13 10:22:24 -0500
commit8d7849b6db5f54dc32fe4f8c6c7283068473cd21 (patch)
tree44c3f275be983eaa8ca69c422e77d693fb02b8e8 /src/test
parent922e8e2929a2e78270868385aa46f96002fbcff3 (diff)
Refactored ConnectInputs, so valid-transaction-checks are done before ECDSA-verifying signatures.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/transaction_tests.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index 3268343bbe..33765ca966 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -22,4 +22,89 @@ BOOST_AUTO_TEST_CASE(basic_transaction_tests)
BOOST_CHECK_MESSAGE(!tx.CheckTransaction(), "Transaction with duplicate txins should be invalid.");
}
+//
+// Helper: create two dummy transactions, each with
+// two outputs. The first has 11 and 50 CENT outputs,
+// the second 21 and 22 CENT outputs.
+//
+static std::vector<CTransaction>
+SetupDummyInputs(CBasicKeyStore& keystoreRet, MapPrevTx& inputsRet)
+{
+ std::vector<CTransaction> dummyTransactions;
+ dummyTransactions.resize(2);
+
+ // Add some keys to the keystore:
+ CKey key[4];
+ for (int i = 0; i < 4; i++)
+ {
+ key[i].MakeNewKey();
+ keystoreRet.AddKey(key[i]);
+ }
+
+ // Create some dummy input transactions
+ dummyTransactions[0].vout.resize(2);
+ dummyTransactions[0].vout[0].nValue = 11*CENT;
+ dummyTransactions[0].vout[0].scriptPubKey.SetBitcoinAddress(key[0].GetPubKey());
+ dummyTransactions[0].vout[1].nValue = 50*CENT;
+ dummyTransactions[0].vout[1].scriptPubKey.SetBitcoinAddress(key[1].GetPubKey());
+ inputsRet[dummyTransactions[0].GetHash()] = make_pair(CTxIndex(), dummyTransactions[0]);
+
+ dummyTransactions[1].vout.resize(2);
+ dummyTransactions[1].vout[0].nValue = 21*CENT;
+ dummyTransactions[1].vout[0].scriptPubKey.SetBitcoinAddress(key[2].GetPubKey());
+ dummyTransactions[1].vout[1].nValue = 22*CENT;
+ dummyTransactions[1].vout[1].scriptPubKey.SetBitcoinAddress(key[3].GetPubKey());
+ inputsRet[dummyTransactions[1].GetHash()] = make_pair(CTxIndex(), dummyTransactions[1]);
+
+ return dummyTransactions;
+}
+
+BOOST_AUTO_TEST_CASE(test_Get)
+{
+ CBasicKeyStore keystore;
+ MapPrevTx dummyInputs;
+ std::vector<CTransaction> dummyTransactions = SetupDummyInputs(keystore, dummyInputs);
+
+ CTransaction t1;
+ t1.vin.resize(3);
+ t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
+ t1.vin[0].prevout.n = 1;
+ t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();;
+ t1.vin[1].prevout.n = 0;
+ t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();;
+ t1.vin[2].prevout.n = 1;
+ t1.vout.resize(2);
+ t1.vout[0].nValue = 90*CENT;
+ t1.vout[0].scriptPubKey << OP_1;
+
+ BOOST_CHECK(t1.AreInputsStandard(dummyInputs));
+ BOOST_CHECK_EQUAL(t1.GetSigOpCount(dummyInputs), 3);
+ BOOST_CHECK_EQUAL(t1.GetValueIn(dummyInputs), (50+21+22)*CENT);
+}
+
+BOOST_AUTO_TEST_CASE(test_GetThrow)
+{
+ CBasicKeyStore keystore;
+ MapPrevTx dummyInputs;
+ std::vector<CTransaction> dummyTransactions = SetupDummyInputs(keystore, dummyInputs);
+
+ MapPrevTx missingInputs;
+
+ CTransaction t1;
+ t1.vin.resize(3);
+ t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
+ t1.vin[0].prevout.n = 0;
+ t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();;
+ t1.vin[1].prevout.n = 0;
+ t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();;
+ t1.vin[2].prevout.n = 1;
+ t1.vout.resize(2);
+ t1.vout[0].nValue = 90*CENT;
+ t1.vout[0].scriptPubKey << OP_1;
+
+ BOOST_CHECK_THROW(t1.AreInputsStandard(missingInputs), runtime_error);
+ BOOST_CHECK_THROW(t1.GetSigOpCount(missingInputs), runtime_error);
+ BOOST_CHECK_THROW(t1.GetValueIn(missingInputs), runtime_error);
+}
+
BOOST_AUTO_TEST_SUITE_END()