Merge #21211: test: Move P2WSH_OP_TRUE to shared test library

22220ef6d5f331c9e1f3e9487eaf07ab13693921 test: Move P2WSH_OP_TRUE to shared test library (MarcoFalke)

Pull request description:

  Otherwise it can't be used in other tests (unit, fuzz, bench, ...)

ACKs for top commit:
  darosior:
    ACK 22220ef6d5f331c9e1f3e9487eaf07ab13693921

Tree-SHA512: 1b636e751281291f7c21ac51c3d014f6a565144c9482974391c516228e756442b077655eda970eb8bdb12974b97855a909b2b60d518026a8d5f41aa15ec7cbc8
This commit is contained in:
MarcoFalke 2021-02-19 13:14:15 +01:00 committed by Konstantin Akimov
parent 91e0359df4
commit 259a767a38
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
2 changed files with 14 additions and 12 deletions

View File

@ -5,6 +5,17 @@
#ifndef BITCOIN_TEST_UTIL_SCRIPT_H #ifndef BITCOIN_TEST_UTIL_SCRIPT_H
#define BITCOIN_TEST_UTIL_SCRIPT_H #define BITCOIN_TEST_UTIL_SCRIPT_H
#include <crypto/sha256.h>
#include <script/script.h>
#include <script/standard.h>
static const std::vector<uint8_t> STACK_ELEM_OP_TRUE{uint8_t{OP_TRUE}};
static const CScript P2SH_OP_TRUE{
CScript{}
<< OP_HASH160
<< ToByteVector(CScriptID{CScript{} << OP_TRUE})
<< OP_EQUAL};
/** Flags that are not forbidden by an assert in script validation */ /** Flags that are not forbidden by an assert in script validation */
bool IsValidFlagCombination(unsigned flags); bool IsValidFlagCombination(unsigned flags);

View File

@ -19,6 +19,7 @@
#include <random.h> #include <random.h>
#include <script/standard.h> #include <script/standard.h>
#include <spork.h> #include <spork.h>
#include <test/util/script.h>
#include <test/util/setup_common.h> #include <test/util/setup_common.h>
#include <util/time.h> #include <util/time.h>
#include <validation.h> #include <validation.h>
@ -36,8 +37,6 @@ struct MinerTestingSetup : public RegTestingSetup {
}; };
} // namespace validation_block_tests } // namespace validation_block_tests
static const std::vector<unsigned char> V_OP_TRUE{OP_TRUE};
BOOST_FIXTURE_TEST_SUITE(validation_block_tests, MinerTestingSetup) BOOST_FIXTURE_TEST_SUITE(validation_block_tests, MinerTestingSetup)
struct TestSubscriber final : public CValidationInterface { struct TestSubscriber final : public CValidationInterface {
@ -72,19 +71,11 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
static int i = 0; static int i = 0;
static uint64_t time = Params().GenesisBlock().nTime; static uint64_t time = Params().GenesisBlock().nTime;
CScript pubKey; auto ptemplate = BlockAssembler(::ChainstateActive(), m_node, *m_node.mempool, Params()).CreateNewBlock(CScript{} << i++ << OP_TRUE);
pubKey << i++ << OP_TRUE;
auto ptemplate = BlockAssembler(::ChainstateActive(), m_node, *m_node.mempool, Params()).CreateNewBlock(pubKey);
auto pblock = std::make_shared<CBlock>(ptemplate->block); auto pblock = std::make_shared<CBlock>(ptemplate->block);
pblock->hashPrevBlock = prev_hash; pblock->hashPrevBlock = prev_hash;
pblock->nTime = ++time; pblock->nTime = ++time;
pubKey.clear();
{
pubKey << OP_HASH160 << ToByteVector(CScriptID(CScript() << OP_TRUE))
<< OP_EQUAL;
}
// Make the coinbase transaction with two outputs: // Make the coinbase transaction with two outputs:
// One zero-value one that has a unique pubkey to make sure that blocks at // One zero-value one that has a unique pubkey to make sure that blocks at
// the same height can have a different hash. Another one that has the // the same height can have a different hash. Another one that has the
@ -92,7 +83,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
// spend // spend
CMutableTransaction txCoinbase(*pblock->vtx[0]); CMutableTransaction txCoinbase(*pblock->vtx[0]);
txCoinbase.vout.resize(2); txCoinbase.vout.resize(2);
txCoinbase.vout[1].scriptPubKey = pubKey; txCoinbase.vout[1].scriptPubKey = P2SH_OP_TRUE;
txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue; txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue;
txCoinbase.vout[0].nValue = 0; txCoinbase.vout[0].nValue = 0;
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));