Changeset View
Changeset View
Standalone View
Standalone View
src/test/transaction_tests.cpp
Show All 33 Lines | |||||
#include <map> | #include <map> | ||||
#include <string> | #include <string> | ||||
typedef std::vector<uint8_t> valtype; | typedef std::vector<uint8_t> valtype; | ||||
BOOST_FIXTURE_TEST_SUITE(transaction_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(transaction_tests, BasicTestingSetup) | ||||
static COutPoint buildOutPoint(const UniValue &vinput) { | |||||
TxId txid; | |||||
txid.SetHex(vinput[0].get_str()); | |||||
return COutPoint(txid, vinput[1].get_int()); | |||||
} | |||||
BOOST_AUTO_TEST_CASE(tx_valid) { | BOOST_AUTO_TEST_CASE(tx_valid) { | ||||
// Read tests from test/data/tx_valid.json | // Read tests from test/data/tx_valid.json | ||||
// Format is an array of arrays | // Format is an array of arrays | ||||
// Inner arrays are either [ "comment" ] | // Inner arrays are either [ "comment" ] | ||||
// or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], | // or [[[prevout hash, prevout index, prevout scriptPubKey], [input 2], | ||||
// ...],"], serializedTransaction, verifyFlags | // ...],"], serializedTransaction, verifyFlags | ||||
// ... where all scripts are stringified scripts. | // ... where all scripts are stringified scripts. | ||||
// | // | ||||
Show All 23 Lines | for (size_t idx = 0; idx < tests.size(); idx++) { | ||||
fValid = false; | fValid = false; | ||||
break; | break; | ||||
} | } | ||||
UniValue vinput = input.get_array(); | UniValue vinput = input.get_array(); | ||||
if (vinput.size() < 3 || vinput.size() > 4) { | if (vinput.size() < 3 || vinput.size() > 4) { | ||||
fValid = false; | fValid = false; | ||||
break; | break; | ||||
} | } | ||||
COutPoint outpoint(uint256S(vinput[0].get_str()), | COutPoint outpoint = buildOutPoint(vinput); | ||||
vinput[1].get_int()); | |||||
mapprevOutScriptPubKeys[outpoint] = | mapprevOutScriptPubKeys[outpoint] = | ||||
ParseScript(vinput[2].get_str()); | ParseScript(vinput[2].get_str()); | ||||
if (vinput.size() >= 4) { | if (vinput.size() >= 4) { | ||||
mapprevOutValues[outpoint] = | mapprevOutValues[outpoint] = | ||||
vinput[3].get_int64() * SATOSHI; | vinput[3].get_int64() * SATOSHI; | ||||
} | } | ||||
} | } | ||||
if (!fValid) { | if (!fValid) { | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | for (size_t idx = 0; idx < tests.size(); idx++) { | ||||
fValid = false; | fValid = false; | ||||
break; | break; | ||||
} | } | ||||
UniValue vinput = input.get_array(); | UniValue vinput = input.get_array(); | ||||
if (vinput.size() < 3 || vinput.size() > 4) { | if (vinput.size() < 3 || vinput.size() > 4) { | ||||
fValid = false; | fValid = false; | ||||
break; | break; | ||||
} | } | ||||
COutPoint outpoint(uint256S(vinput[0].get_str()), | COutPoint outpoint = buildOutPoint(vinput); | ||||
vinput[1].get_int()); | |||||
mapprevOutScriptPubKeys[outpoint] = | mapprevOutScriptPubKeys[outpoint] = | ||||
ParseScript(vinput[2].get_str()); | ParseScript(vinput[2].get_str()); | ||||
if (vinput.size() >= 4) { | if (vinput.size() >= 4) { | ||||
mapprevOutValues[outpoint] = | mapprevOutValues[outpoint] = | ||||
vinput[3].get_int64() * SATOSHI; | vinput[3].get_int64() * SATOSHI; | ||||
} | } | ||||
} | } | ||||
if (!fValid) { | if (!fValid) { | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_big_transaction) { | ||||
mtx.nVersion = 1; | mtx.nVersion = 1; | ||||
// create a big transaction of 4500 inputs signed by the same key. | // create a big transaction of 4500 inputs signed by the same key. | ||||
const static size_t OUTPUT_COUNT = 4500; | const static size_t OUTPUT_COUNT = 4500; | ||||
mtx.vout.reserve(OUTPUT_COUNT); | mtx.vout.reserve(OUTPUT_COUNT); | ||||
for (size_t ij = 0; ij < OUTPUT_COUNT; ij++) { | for (size_t ij = 0; ij < OUTPUT_COUNT; ij++) { | ||||
size_t i = mtx.vin.size(); | size_t i = mtx.vin.size(); | ||||
uint256 prevId = uint256S( | TxId prevId(uint256S("0000000000000000000000000000000000000000000000000" | ||||
"0000000000000000000000000000000000000000000000000000000000000100"); | "000000000000100")); | ||||
COutPoint outpoint(prevId, i); | COutPoint outpoint(prevId, i); | ||||
mtx.vin.resize(mtx.vin.size() + 1); | mtx.vin.resize(mtx.vin.size() + 1); | ||||
mtx.vin[i].prevout = outpoint; | mtx.vin[i].prevout = outpoint; | ||||
mtx.vin[i].scriptSig = CScript(); | mtx.vin[i].scriptSig = CScript(); | ||||
mtx.vout.emplace_back(1000 * SATOSHI, CScript() << OP_1); | mtx.vout.emplace_back(1000 * SATOSHI, CScript() << OP_1); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 350 Lines • Show Last 20 Lines |