mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
[BROKEN] Adapt existing unit tests to CA
This commit is contained in:
parent
f4553d4b6d
commit
cd56626647
9 changed files with 77 additions and 58 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include <test/data/blockfilters.json.h>
|
||||
#include <test/test_bitcoin.h>
|
||||
|
||||
#include <asset.h>
|
||||
#include <blockfilter.h>
|
||||
#include <core_io.h>
|
||||
#include <serialize.h>
|
||||
|
|
@ -61,13 +62,13 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
|
|||
excluded_scripts[1] << std::vector<unsigned char>(5, 33) << OP_CHECKSIG;
|
||||
|
||||
CMutableTransaction tx_1;
|
||||
tx_1.vout.emplace_back(100, included_scripts[0]);
|
||||
tx_1.vout.emplace_back(200, included_scripts[1]);
|
||||
tx_1.vout.emplace_back(CTxOut(CAsset(), 100, included_scripts[0]));
|
||||
tx_1.vout.emplace_back(CTxOut(CAsset(), 200, included_scripts[1]));
|
||||
|
||||
CMutableTransaction tx_2;
|
||||
tx_2.vout.emplace_back(300, included_scripts[2]);
|
||||
tx_2.vout.emplace_back(0, excluded_scripts[0]);
|
||||
tx_2.vout.emplace_back(400, excluded_scripts[2]); // Script is empty
|
||||
tx_2.vout.emplace_back(CTxOut(CAsset(), 300, included_scripts[2]));
|
||||
tx_2.vout.emplace_back(CTxOut(CAsset(), 0, excluded_scripts[0]));
|
||||
tx_2.vout.emplace_back(CTxOut(CAsset(), 400, excluded_scripts[2])); // Script is empty
|
||||
|
||||
CBlock block;
|
||||
block.vtx.push_back(MakeTransactionRef(tx_1));
|
||||
|
|
@ -75,9 +76,9 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
|
|||
|
||||
CBlockUndo block_undo;
|
||||
block_undo.vtxundo.emplace_back();
|
||||
block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(500, included_scripts[3]), 1000, true);
|
||||
block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(600, included_scripts[4]), 10000, false);
|
||||
block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(700, excluded_scripts[2]), 100000, false);
|
||||
block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(CAsset(), 500, included_scripts[3]), 1000, true);
|
||||
block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(CAsset(), 600, included_scripts[4]), 10000, false);
|
||||
block_undo.vtxundo.back().vprevout.emplace_back(CTxOut(CAsset(), 700, excluded_scripts[2]), 100000, false);
|
||||
|
||||
BlockFilter block_filter(BlockFilterType::BASIC, block, block_undo);
|
||||
const GCSFilter& filter = block_filter.GetFilter();
|
||||
|
|
@ -125,7 +126,7 @@ BOOST_AUTO_TEST_CASE(blockfilters_json_test)
|
|||
const UniValue& prev_scripts = test[pos++].get_array();
|
||||
for (unsigned int ii = 0; ii < prev_scripts.size(); ii++) {
|
||||
std::vector<unsigned char> raw_script = ParseHex(prev_scripts[ii].get_str());
|
||||
CTxOut txout(0, CScript(raw_script.begin(), raw_script.end()));
|
||||
CTxOut txout(CAsset(), 0, CScript(raw_script.begin(), raw_script.end()));
|
||||
tx_undo.vprevout.emplace_back(txout, 0, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ static void Correct_Queue_range(std::vector<size_t> range)
|
|||
tg.create_thread([&]{small_queue->Thread();});
|
||||
}
|
||||
// Make vChecks here to save on malloc (this test can be slow...)
|
||||
std::vector<FakeCheckCheckCompletion> vChecks;
|
||||
std::vector<FakeCheckCheckCompletion*> vChecks;
|
||||
for (const size_t i : range) {
|
||||
size_t total = i;
|
||||
FakeCheckCheckCompletion::n_calls = 0;
|
||||
|
|
@ -226,10 +226,10 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
|
|||
while (remaining) {
|
||||
size_t r = InsecureRandRange(10);
|
||||
|
||||
std::vector<FailingCheck> vChecks;
|
||||
vChecks.reserve(r);
|
||||
for (size_t k = 0; k < r && remaining; k++, remaining--)
|
||||
vChecks.emplace_back(remaining == 1);
|
||||
std::vector<FailingCheck*> vChecks;
|
||||
for (size_t k = 0; k < r && remaining; k++, remaining--) {
|
||||
vChecks.push_back(new FailingCheck(remaining == 1));
|
||||
}
|
||||
control.Add(vChecks);
|
||||
}
|
||||
bool success = control.Wait();
|
||||
|
|
@ -256,9 +256,11 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
|
|||
for (const bool end_fails : {true, false}) {
|
||||
CCheckQueueControl<FailingCheck> control(fail_queue.get());
|
||||
{
|
||||
std::vector<FailingCheck> vChecks;
|
||||
vChecks.resize(100, false);
|
||||
vChecks[99] = end_fails;
|
||||
std::vector<FailingCheck*> vChecks;
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
vChecks.push_back(new FailingCheck(false));
|
||||
}
|
||||
vChecks[99] = new FailingCheck(end_fails);
|
||||
control.Add(vChecks);
|
||||
}
|
||||
bool r =control.Wait();
|
||||
|
|
@ -287,9 +289,10 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
|
|||
CCheckQueueControl<UniqueCheck> control(queue.get());
|
||||
while (total) {
|
||||
size_t r = InsecureRandRange(10);
|
||||
std::vector<UniqueCheck> vChecks;
|
||||
for (size_t k = 0; k < r && total; k++)
|
||||
vChecks.emplace_back(--total);
|
||||
std::vector<UniqueCheck*> vChecks;
|
||||
for (size_t k = 0; k < r && total; k++) {
|
||||
vChecks.emplace_back(new UniqueCheck(--total));
|
||||
}
|
||||
control.Add(vChecks);
|
||||
}
|
||||
}
|
||||
|
|
@ -321,12 +324,12 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
|
|||
CCheckQueueControl<MemoryCheck> control(queue.get());
|
||||
while (total) {
|
||||
size_t r = InsecureRandRange(10);
|
||||
std::vector<MemoryCheck> vChecks;
|
||||
std::vector<MemoryCheck*> vChecks;
|
||||
for (size_t k = 0; k < r && total; k++) {
|
||||
total--;
|
||||
// Each iteration leaves data at the front, back, and middle
|
||||
// to catch any sort of deallocation failure
|
||||
vChecks.emplace_back(total == 0 || total == i || total == i/2);
|
||||
vChecks.emplace_back(new MemoryCheck(total == 0 || total == i || total == i/2));
|
||||
}
|
||||
control.Add(vChecks);
|
||||
}
|
||||
|
|
@ -349,11 +352,12 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
|
|||
}
|
||||
std::thread t0([&]() {
|
||||
CCheckQueueControl<FrozenCleanupCheck> control(queue.get());
|
||||
std::vector<FrozenCleanupCheck> vChecks(1);
|
||||
std::vector<FrozenCleanupCheck*> vChecks;
|
||||
// Freezing can't be the default initialized behavior given how the queue
|
||||
// swaps in default initialized Checks (otherwise freezing destructor
|
||||
// would get called twice).
|
||||
vChecks[0].should_freeze = true;
|
||||
vChecks.push_back(new FrozenCleanupCheck());
|
||||
vChecks[0]->should_freeze = true;
|
||||
control.Add(vChecks);
|
||||
control.Wait(); // Hangs here
|
||||
});
|
||||
|
|
|
|||
|
|
@ -499,7 +499,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
|
|||
ss3 >> cc3;
|
||||
BOOST_CHECK_EQUAL(cc3.fCoinBase, false);
|
||||
BOOST_CHECK_EQUAL(cc3.nHeight, 0U);
|
||||
BOOST_CHECK_EQUAL(cc3.out.nValue, 0);
|
||||
BOOST_CHECK_EQUAL(cc3.out.nValue.GetAmount(), 0);
|
||||
BOOST_CHECK_EQUAL(cc3.out.scriptPubKey.size(), 0U);
|
||||
|
||||
// scriptPubKey that ends beyond the end of the stream
|
||||
|
|
@ -577,7 +577,7 @@ void GetCoinsMapEntry(const CCoinsMap& map, CAmount& value, char& flags)
|
|||
if (it->second.coin.IsSpent()) {
|
||||
value = PRUNED;
|
||||
} else {
|
||||
value = it->second.coin.out.nValue;
|
||||
value = it->second.coin.out.nValue.GetAmount();
|
||||
}
|
||||
flags = it->second.flags;
|
||||
assert(flags != NO_ENTRY);
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ static void TestPackageSelection(const CChainParams& chainparams, const CScript&
|
|||
// of the transactions is below the min relay fee
|
||||
// Remove the low fee transaction and replace with a higher fee transaction
|
||||
mempool.removeRecursive(tx);
|
||||
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
|
||||
tx.vout[0].nValue = tx.vout[0].nValue.GetAmount() - 2; // Now we should be just over the min relay fee
|
||||
hashLowFeeTx = tx.GetHash();
|
||||
mempool.addUnchecked(entry.Fee(feeToUse+2).FromTx(tx));
|
||||
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
|
||||
|
|
@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|||
tx.vout[0].nValue = BLOCKSUBSIDY;
|
||||
for (unsigned int i = 0; i < 1001; ++i)
|
||||
{
|
||||
tx.vout[0].nValue -= LOWFEE;
|
||||
tx.vout[0].nValue = tx.vout[0].nValue.GetAmount() - LOWFEE;
|
||||
hash = tx.GetHash();
|
||||
bool spendsCoinbase = i == 0; // only first tx spends coinbase
|
||||
// If we don't set the # of sig ops in the CTxMemPoolEntry, template creation fails
|
||||
|
|
@ -288,7 +288,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|||
tx.vout[0].nValue = BLOCKSUBSIDY;
|
||||
for (unsigned int i = 0; i < 1001; ++i)
|
||||
{
|
||||
tx.vout[0].nValue -= LOWFEE;
|
||||
tx.vout[0].nValue = tx.vout[0].nValue.GetAmount() - LOWFEE;
|
||||
hash = tx.GetHash();
|
||||
bool spendsCoinbase = i == 0; // only first tx spends coinbase
|
||||
// If we do set the # of sig ops in the CTxMemPoolEntry, template creation passes
|
||||
|
|
@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|||
tx.vout[0].nValue = BLOCKSUBSIDY;
|
||||
for (unsigned int i = 0; i < 128; ++i)
|
||||
{
|
||||
tx.vout[0].nValue -= LOWFEE;
|
||||
tx.vout[0].nValue = tx.vout[0].nValue.GetAmount() - LOWFEE;
|
||||
hash = tx.GetHash();
|
||||
bool spendsCoinbase = i == 0; // only first tx spends coinbase
|
||||
mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
|
||||
|
|
@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|||
tx.vin[1].scriptSig = CScript() << OP_1;
|
||||
tx.vin[1].prevout.hash = txFirst[0]->GetHash();
|
||||
tx.vin[1].prevout.n = 0;
|
||||
tx.vout[0].nValue = tx.vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE; //First txn output + fresh coinbase - new txn fee
|
||||
tx.vout[0].nValue = tx.vout[0].nValue.GetAmount() + BLOCKSUBSIDY - HIGHERFEE; //First txn output + fresh coinbase - new txn fee
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
||||
|
|
@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|||
mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
||||
tx.vin[0].prevout.hash = hash;
|
||||
tx.vin[0].scriptSig = CScript() << std::vector<unsigned char>(script.begin(), script.end());
|
||||
tx.vout[0].nValue -= LOWFEE;
|
||||
tx.vout[0].nValue = tx.vout[0].nValue.GetAmount() - LOWFEE;
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
|
||||
// Should throw block-validation-failed
|
||||
|
|
|
|||
|
|
@ -25,16 +25,14 @@
|
|||
|
||||
std::vector<std::vector<unsigned char> > witness_stack = {
|
||||
ParseHex("00ca9a3b00000000"),
|
||||
ParseHex("e48a1a02a8f799892fda58347c2d794144311d4307dbfd10f77ffe28088c60be"),
|
||||
ParseHex("ef4699c160d014d5ff79636d8a4cb990b9df4ebab649f144d19f5c495c585e47"),
|
||||
ParseHex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f"),
|
||||
ParseHex("00141eef6361cd1507a303834285d1521d6baf1b19ae"),
|
||||
ParseHex("0200000001b399292c8100b8a1b66eb23896f799c1712390d560af0f70e81acd2d17a3b06e0000000049483045022100c3c749623486ea57ea93dfaf78d85590d78c7590a25768fe80f0ea4d6047419002202a0a00a90392b86c53c0fdda908c4591ba28040c16c25734c23b7df3c8b70acd01feffffff0228196bee000000001976a914470dd41542ee1a1bd75f1a838878648c8d65622488ac00ca9a3b0000000017a914cb60b1d7f76ba12b45a116c482c165a74c5d7e388765000000"),
|
||||
ParseHex("000000205e3913a320cd2e3a2efa141e47419f54cb9e82320cf8dbc812fc19b9a1b2413a57f5e9fb4fa22de191454a241387f5d10cc794ee0fbf72ae2841baf3129a4eab8133025affff7f20000000000200000002f9d0be670007d38fceece999cb6144658a99c307ccc37f6d8f69129ed0f4545ff321df9790633bc33c67239c4174df8142ee616ee6a2e2788fe4820fe70e9bce0105")
|
||||
};
|
||||
|
||||
//std::vector<unsigned char> pegin_transaction = ParseHex("020000000101f321df9790633bc33c67239c4174df8142ee616ee6a2e2788fe4820fe70e9bce0100004000ffffffff0201e48a1a02a8f799892fda58347c2d794144311d4307dbfd10f77ffe28088c60be01000000003b9ab2e0001976a914809326f7628dc976fbe63806479a1b8dfcc8c4b988ac01e48a1a02a8f799892fda58347c2d794144311d4307dbfd10f77ffe28088c60be010000000000001720000000000000000002483045022100ae17064745d80650a6a5cbcbe15c8c45ba498d1c6f45a7c0f5f32d871b463fc60220799f2836471702c21f7cfe124651727b530ad41f7af4dc213c65f5030a2f6fc4012103a9d3c6c7c161a565a76113632fe13330cf2c0207ba79a76d1154cdc3cb94d940060800ca9a3b0000000020e48a1a02a8f799892fda58347c2d794144311d4307dbfd10f77ffe28088c60be2006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f1600141eef6361cd1507a303834285d1521d6baf1b19aebe0200000001b399292c8100b8a1b66eb23896f799c1712390d560af0f70e81acd2d17a3b06e0000000049483045022100c3c749623486ea57ea93dfaf78d85590d78c7590a25768fe80f0ea4d6047419002202a0a00a90392b86c53c0fdda908c4591ba28040c16c25734c23b7df3c8b70acd01feffffff0228196bee000000001976a914470dd41542ee1a1bd75f1a838878648c8d65622488ac00ca9a3b0000000017a914cb60b1d7f76ba12b45a116c482c165a74c5d7e38876500000097000000205e3913a320cd2e3a2efa141e47419f54cb9e82320cf8dbc812fc19b9a1b2413a57f5e9fb4fa22de191454a241387f5d10cc794ee0fbf72ae2841baf3129a4eab8133025affff7f20000000000200000002f9d0be670007d38fceece999cb6144658a99c307ccc37f6d8f69129ed0f4545ff321df9790633bc33c67239c4174df8142ee616ee6a2e2788fe4820fe70e9bce010500000000");
|
||||
std::vector<unsigned char> pegin_transaction = ParseHex("020000000101f321df9790633bc33c67239c4174df8142ee616ee6a2e2788fe4820fe70e9bce0100004000ffffffff02e0b29a3b000000001976a914809326f7628dc976fbe63806479a1b8dfcc8c4b988ac2017000000000000000000000002483045022100ae17064745d80650a6a5cbcbe15c8c45ba498d1c6f45a7c0f5f32d871b463fc60220799f2836471702c21f7cfe124651727b530ad41f7af4dc213c65f5030a2f6fc4012103a9d3c6c7c161a565a76113632fe13330cf2c0207ba79a76d1154cdc3cb94d940060800ca9a3b0000000020e48a1a02a8f799892fda58347c2d794144311d4307dbfd10f77ffe28088c60be2006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f1600141eef6361cd1507a303834285d1521d6baf1b19aebe0200000001b399292c8100b8a1b66eb23896f799c1712390d560af0f70e81acd2d17a3b06e0000000049483045022100c3c749623486ea57ea93dfaf78d85590d78c7590a25768fe80f0ea4d6047419002202a0a00a90392b86c53c0fdda908c4591ba28040c16c25734c23b7df3c8b70acd01feffffff0228196bee000000001976a914470dd41542ee1a1bd75f1a838878648c8d65622488ac00ca9a3b0000000017a914cb60b1d7f76ba12b45a116c482c165a74c5d7e38876500000097000000205e3913a320cd2e3a2efa141e47419f54cb9e82320cf8dbc812fc19b9a1b2413a57f5e9fb4fa22de191454a241387f5d10cc794ee0fbf72ae2841baf3129a4eab8133025affff7f20000000000200000002f9d0be670007d38fceece999cb6144658a99c307ccc37f6d8f69129ed0f4545ff321df9790633bc33c67239c4174df8142ee616ee6a2e2788fe4820fe70e9bce0105");
|
||||
|
||||
std::vector<unsigned char> pegin_transaction = ParseHex("020000000101f321df9790633bc33c67239c4174df8142ee616ee6a2e2788fe4820fe70e9bce0100004000ffffffff0201ef4699c160d014d5ff79636d8a4cb990b9df4ebab649f144d19f5c495c585e4701000000003b9ab2e0001976a914809326f7628dc976fbe63806479a1b8dfcc8c4b988ac01ef4699c160d014d5ff79636d8a4cb990b9df4ebab649f144d19f5c495c585e47010000000000001720000000000000000002483045022100ae17064745d80650a6a5cbcbe15c8c45ba498d1c6f45a7c0f5f32d871b463fc60220799f2836471702c21f7cfe124651727b530ad41f7af4dc213c65f5030a2f6fc4012103a9d3c6c7c161a565a76113632fe13330cf2c0207ba79a76d1154cdc3cb94d940060800ca9a3b0000000020ef4699c160d014d5ff79636d8a4cb990b9df4ebab649f144d19f5c495c585e472006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f1600141eef6361cd1507a303834285d1521d6baf1b19aebe0200000001b399292c8100b8a1b66eb23896f799c1712390d560af0f70e81acd2d17a3b06e0000000049483045022100c3c749623486ea57ea93dfaf78d85590d78c7590a25768fe80f0ea4d6047419002202a0a00a90392b86c53c0fdda908c4591ba28040c16c25734c23b7df3c8b70acd01feffffff0228196bee000000001976a914470dd41542ee1a1bd75f1a838878648c8d65622488ac00ca9a3b0000000017a914cb60b1d7f76ba12b45a116c482c165a74c5d7e38876500000097000000205e3913a320cd2e3a2efa141e47419f54cb9e82320cf8dbc812fc19b9a1b2413a57f5e9fb4fa22de191454a241387f5d10cc794ee0fbf72ae2841baf3129a4eab8133025affff7f20000000000200000002f9d0be670007d38fceece999cb6144658a99c307ccc37f6d8f69129ed0f4545ff321df9790633bc33c67239c4174df8142ee616ee6a2e2788fe4820fe70e9bce010500000000");
|
||||
|
||||
COutPoint prevout(uint256S("ce9b0ee70f82e48f78e2a2e66e61ee4281df74419c23673cc33b639097df21f3"), 1);
|
||||
|
||||
|
|
@ -59,10 +57,6 @@ BOOST_AUTO_TEST_CASE(witness_valid)
|
|||
// Missing byte on each field to make claim ill-formatted
|
||||
// This will break deserialization and other data-matching checks
|
||||
for (unsigned int i = 0; i < witness.stack.size(); i++) {
|
||||
//TODO(rebase) CA remove this exception
|
||||
if (i == 1) {
|
||||
continue;
|
||||
}
|
||||
witness.stack[i].pop_back();
|
||||
BOOST_CHECK(!IsValidPeginWitness(witness, prevout, err, false));
|
||||
witness.stack = witness_stack;
|
||||
|
|
@ -95,7 +89,12 @@ BOOST_AUTO_TEST_CASE(witness_valid)
|
|||
// Check validation of peg-in transaction's inputs and balance
|
||||
CDataStream ssTx(pegin_transaction, SER_NETWORK, PROTOCOL_VERSION);
|
||||
CTransactionRef txRef;
|
||||
ssTx >> txRef;
|
||||
try {
|
||||
ssTx >> txRef;
|
||||
} catch (...) {
|
||||
BOOST_CHECK(false);
|
||||
return;
|
||||
}
|
||||
CTransaction tx(*txRef);
|
||||
|
||||
// Only one(valid) input witness should exist, and should match
|
||||
|
|
@ -103,16 +102,16 @@ BOOST_AUTO_TEST_CASE(witness_valid)
|
|||
BOOST_CHECK(tx.witness.vtxinwit[0].m_pegin_witness.stack == witness_stack);
|
||||
BOOST_CHECK(tx.vin[0].m_is_pegin);
|
||||
// Check that serialization doesn't cause issuance to become non-null
|
||||
//TODO(rebase) CA
|
||||
//BOOST_CHECK(tx.vin[0].assetIssuance.IsNull());
|
||||
BOOST_CHECK(tx.vin[0].assetIssuance.IsNull());
|
||||
BOOST_CHECK(IsValidPeginWitness(tx.witness.vtxinwit[0].m_pegin_witness, prevout, err, false));
|
||||
|
||||
CAmountMap fee_map;
|
||||
|
||||
std::set<std::pair<uint256, COutPoint> > setPeginsSpent;
|
||||
CValidationState state;
|
||||
CCoinsView coinsDummy;
|
||||
CCoinsViewCache coins(&coinsDummy);
|
||||
CAmount txfee;
|
||||
BOOST_CHECK(Consensus::CheckTxInputs(tx, state, coins, 0, txfee, setPeginsSpent));
|
||||
BOOST_CHECK(Consensus::CheckTxInputs(tx, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true));
|
||||
BOOST_CHECK(setPeginsSpent.size() == 1);
|
||||
setPeginsSpent.clear();
|
||||
|
||||
|
|
@ -120,7 +119,7 @@ BOOST_AUTO_TEST_CASE(witness_valid)
|
|||
CMutableTransaction mtxn(tx);
|
||||
mtxn.witness.vtxinwit[0].m_pegin_witness.SetNull();
|
||||
CTransaction tx2(mtxn);
|
||||
BOOST_CHECK(!Consensus::CheckTxInputs(tx2, state, coins, 0, txfee, setPeginsSpent));
|
||||
BOOST_CHECK(!Consensus::CheckTxInputs(tx2, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true));
|
||||
BOOST_CHECK(setPeginsSpent.empty());
|
||||
|
||||
// Invalidate peg-in (and spending) authorization by pegin marker.
|
||||
|
|
@ -129,7 +128,7 @@ BOOST_AUTO_TEST_CASE(witness_valid)
|
|||
CMutableTransaction mtxn2(tx);
|
||||
mtxn2.vin[0].m_is_pegin = false;
|
||||
CTransaction tx3(mtxn2);
|
||||
BOOST_CHECK(!Consensus::CheckTxInputs(tx3, state, coins, 0, txfee, setPeginsSpent));
|
||||
BOOST_CHECK(!Consensus::CheckTxInputs(tx3, state, coins, 0, fee_map, setPeginsSpent, NULL, false, true));
|
||||
BOOST_CHECK(setPeginsSpent.empty());
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -183,12 +183,16 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScript
|
|||
#if defined(HAVE_CONSENSUS_LIB)
|
||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
|
||||
stream << tx2;
|
||||
CDataStream streamVal(SER_NETWORK, PROTOCOL_VERSION);
|
||||
streamVal << txCredit.vout[0].nValue;
|
||||
CDataStream streamVal0(SER_NETWORK, PROTOCOL_VERSION);
|
||||
streamVal0 << CConfidentialValue(0);
|
||||
int libconsensus_flags = flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL;
|
||||
if (libconsensus_flags == flags) {
|
||||
if (flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS) {
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), txCredit.vout[0].nValue, (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&streamVal[0], streamVal.size(), (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect, message);
|
||||
} else {
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), 0, (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&streamVal0[0], streamVal0.size(), (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expect,message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <test/test_bitcoin.h>
|
||||
|
||||
#include <asset.h>
|
||||
#include <chainparams.h>
|
||||
#include <consensus/consensus.h>
|
||||
#include <consensus/params.h>
|
||||
|
|
@ -12,6 +13,10 @@
|
|||
#include <miner.h>
|
||||
#include <net_processing.h>
|
||||
#include <pow.h>
|
||||
#include <ui_interface.h>
|
||||
#include <policy/policy.h>
|
||||
#include <streams.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/register.h>
|
||||
#include <rpc/server.h>
|
||||
#include <script/sigcache.h>
|
||||
|
|
@ -58,6 +63,8 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::st
|
|||
SetupNetworking();
|
||||
InitSignatureCache();
|
||||
InitScriptExecutionCache();
|
||||
InitRangeproofCache();
|
||||
InitSurjectionproofCache();
|
||||
fCheckBlockIndex = true;
|
||||
// Hack to allow testing of fedpeg args
|
||||
if (!fedpegscript.empty()) {
|
||||
|
|
@ -68,6 +75,11 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::st
|
|||
// TODO: fix the code to support SegWit blocks.
|
||||
gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT));
|
||||
SelectParams(chainName);
|
||||
|
||||
// ELEMENTS:
|
||||
// Set policy asset for correct fee output generation
|
||||
policyAsset = CAsset();
|
||||
|
||||
noui_connect();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -493,10 +493,8 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction) {
|
|||
}
|
||||
|
||||
for(uint32_t i = 0; i < mtx.vin.size(); i++) {
|
||||
std::vector<CScriptCheck> vChecks;
|
||||
CScriptCheck check(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
|
||||
vChecks.push_back(CScriptCheck());
|
||||
check.swap(vChecks.back());
|
||||
std::vector<CScriptCheck*> vChecks;
|
||||
vChecks.push_back(new CScriptCheck(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata));
|
||||
control.Add(vChecks);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <key.h>
|
||||
#include <validation.h>
|
||||
|
|
@ -19,7 +20,7 @@
|
|||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks);
|
||||
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CCheck*> *pvChecks);
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
|
||||
|
||||
|
|
@ -128,13 +129,13 @@ static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t fail
|
|||
// Test the caching
|
||||
if (ret && add_to_cache) {
|
||||
// Check that we get a cache hit if the tx was valid
|
||||
std::vector<CScriptCheck> scriptchecks;
|
||||
std::vector<CCheck*> scriptchecks;
|
||||
BOOST_CHECK(CheckInputs(tx, state, pcoinsTip.get(), true, test_flags, true, add_to_cache, txdata, &scriptchecks));
|
||||
BOOST_CHECK(scriptchecks.empty());
|
||||
} else {
|
||||
// Check that we get script executions to check, if the transaction
|
||||
// was invalid, or we didn't add to cache.
|
||||
std::vector<CScriptCheck> scriptchecks;
|
||||
std::vector<CCheck*> scriptchecks;
|
||||
BOOST_CHECK(CheckInputs(tx, state, pcoinsTip.get(), true, test_flags, true, add_to_cache, txdata, &scriptchecks));
|
||||
BOOST_CHECK_EQUAL(scriptchecks.size(), tx.vin.size());
|
||||
}
|
||||
|
|
@ -203,7 +204,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
|||
// If we call again asking for scriptchecks (as happens in
|
||||
// ConnectBlock), we should add a script check object for this -- we're
|
||||
// not caching invalidity (if that changes, delete this test case).
|
||||
std::vector<CScriptCheck> scriptchecks;
|
||||
std::vector<CCheck*> scriptchecks;
|
||||
BOOST_CHECK(CheckInputs(spend_tx, state, pcoinsTip.get(), true, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG, true, true, ptd_spend_tx, &scriptchecks));
|
||||
BOOST_CHECK_EQUAL(scriptchecks.size(), 1U);
|
||||
|
||||
|
|
@ -361,7 +362,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
|||
// This transaction is now invalid under segwit, because of the second input.
|
||||
BOOST_CHECK(!CheckInputs(tx, state, pcoinsTip.get(), true, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, nullptr));
|
||||
|
||||
std::vector<CScriptCheck> scriptchecks;
|
||||
std::vector<CCheck*> scriptchecks;
|
||||
// Make sure this transaction was not cached (ie because the first
|
||||
// input was valid)
|
||||
BOOST_CHECK(CheckInputs(tx, state, pcoinsTip.get(), true, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, &scriptchecks));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue