Changeset View
Changeset View
Standalone View
Standalone View
src/test/transaction_tests.cpp
Show All 23 Lines | |||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <test/data/tx_invalid.json.h> | #include <test/data/tx_invalid.json.h> | ||||
#include <test/data/tx_valid.json.h> | #include <test/data/tx_valid.json.h> | ||||
#include <test/jsonutil.h> | #include <test/jsonutil.h> | ||||
#include <test/scriptflags.h> | #include <test/scriptflags.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <test/util/transaction_utils.h> | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <map> | #include <map> | ||||
#include <string> | #include <string> | ||||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(basic_transaction_tests) { | ||||
// Check that duplicate txins fail | // Check that duplicate txins fail | ||||
tx.vin.push_back(tx.vin[0]); | tx.vin.push_back(tx.vin[0]); | ||||
BOOST_CHECK_MESSAGE(!CheckRegularTransaction(CTransaction(tx), state) || | BOOST_CHECK_MESSAGE(!CheckRegularTransaction(CTransaction(tx), state) || | ||||
!state.IsValid(), | !state.IsValid(), | ||||
"Transaction with duplicate txins should be invalid."); | "Transaction with duplicate txins should be invalid."); | ||||
} | } | ||||
// | |||||
// Helper: create two dummy transactions, each with | |||||
// two outputs. The first has 11 and 50 CENT outputs | |||||
// paid to a TX_PUBKEY, the second 21 and 22 CENT outputs | |||||
// paid to a TX_PUBKEYHASH. | |||||
// | |||||
static std::vector<CMutableTransaction> | |||||
SetupDummyInputs(FillableSigningProvider &keystoreRet, | |||||
CCoinsViewCache &coinsRet) { | |||||
std::vector<CMutableTransaction> dummyTransactions; | |||||
dummyTransactions.resize(2); | |||||
// Add some keys to the keystore: | |||||
CKey key[4]; | |||||
for (int i = 0; i < 4; i++) { | |||||
key[i].MakeNewKey(i % 2); | |||||
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 | |||||
<< ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG; | |||||
dummyTransactions[0].vout[1].nValue = 50 * CENT; | |||||
dummyTransactions[0].vout[1].scriptPubKey | |||||
<< ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG; | |||||
AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0); | |||||
dummyTransactions[1].vout.resize(2); | |||||
dummyTransactions[1].vout[0].nValue = 21 * CENT; | |||||
dummyTransactions[1].vout[0].scriptPubKey = | |||||
GetScriptForDestination(PKHash(key[2].GetPubKey())); | |||||
dummyTransactions[1].vout[1].nValue = 22 * CENT; | |||||
dummyTransactions[1].vout[1].scriptPubKey = | |||||
GetScriptForDestination(PKHash(key[3].GetPubKey())); | |||||
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0); | |||||
return dummyTransactions; | |||||
} | |||||
BOOST_AUTO_TEST_CASE(test_Get) { | BOOST_AUTO_TEST_CASE(test_Get) { | ||||
FillableSigningProvider keystore; | FillableSigningProvider keystore; | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
std::vector<CMutableTransaction> dummyTransactions = | std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs( | ||||
SetupDummyInputs(keystore, coins); | keystore, coins, {{11 * CENT, 50 * CENT, 21 * CENT, 22 * CENT}}); | ||||
CMutableTransaction t1; | CMutableTransaction t1; | ||||
t1.vin.resize(3); | t1.vin.resize(3); | ||||
t1.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | t1.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | ||||
t1.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | t1.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | ||||
t1.vin[1].prevout = COutPoint(dummyTransactions[1].GetId(), 0); | t1.vin[1].prevout = COutPoint(dummyTransactions[1].GetId(), 0); | ||||
t1.vin[1].scriptSig << std::vector<uint8_t>(65, 0) | t1.vin[1].scriptSig << std::vector<uint8_t>(65, 0) | ||||
<< std::vector<uint8_t>(33, 4); | << std::vector<uint8_t>(33, 4); | ||||
▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_witness) { | ||||
CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true); | CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_IsStandard) { | BOOST_AUTO_TEST_CASE(test_IsStandard) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
FillableSigningProvider keystore; | FillableSigningProvider keystore; | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
std::vector<CMutableTransaction> dummyTransactions = | std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs( | ||||
SetupDummyInputs(keystore, coins); | keystore, coins, {{11 * CENT, 50 * CENT, 21 * CENT, 22 * CENT}}); | ||||
CMutableTransaction t; | CMutableTransaction t; | ||||
t.vin.resize(1); | t.vin.resize(1); | ||||
t.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | t.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | ||||
t.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | t.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | ||||
t.vout.resize(1); | t.vout.resize(1); | ||||
t.vout[0].nValue = 90 * CENT; | t.vout[0].nValue = 90 * CENT; | ||||
CKey key; | CKey key; | ||||
▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines |