From fa96574b0d2d2c0880447f163cd0280fb3551910 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 21 Aug 2020 15:37:38 +0200 Subject: [PATCH 1/3] test: Move doxygen comment to header Also, unrelated formatting fixups. Can be reviewed with --word-diff-regex=. --- src/test/util/setup_common.cpp | 20 ++++++++------------ src/test/util/setup_common.h | 13 +++++++------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index b2ae1cb845d..c882ae38f26 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -204,27 +204,24 @@ TestChain100Setup::TestChain100Setup() // Generate a 100-block chain: coinbaseKey.MakeNewKey(true); - CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; - for (int i = 0; i < COINBASE_MATURITY; i++) - { + CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; + for (int i = 0; i < COINBASE_MATURITY; i++) { std::vector noTxns; CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey); m_coinbase_txns.push_back(b.vtx[0]); } } -// Create a new block with just given transactions, coinbase paying to -// scriptPubKey, and try to add it to the current chain. CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector& txns, const CScript& scriptPubKey) { const CChainParams& chainparams = Params(); - std::unique_ptr pblocktemplate = BlockAssembler(*m_node.mempool, chainparams).CreateNewBlock(scriptPubKey); - CBlock& block = pblocktemplate->block; + CBlock block = BlockAssembler(*m_node.mempool, chainparams).CreateNewBlock(scriptPubKey)->block; // Replace mempool-selected txns with just coinbase plus passed-in txns: block.vtx.resize(1); - for (const CMutableTransaction& tx : txns) + for (const CMutableTransaction& tx : txns) { block.vtx.push_back(MakeTransactionRef(tx)); + } // IncrementExtraNonce creates a valid coinbase and merkleRoot { LOCK(cs_main); @@ -237,8 +234,7 @@ CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector shared_pblock = std::make_shared(block); Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr); - CBlock result = block; - return result; + return block; } TestChain100Setup::~TestChain100Setup() @@ -246,8 +242,8 @@ TestChain100Setup::~TestChain100Setup() gArgs.ForceSetArg("-segwitheight", "0"); } - -CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx) { +CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) +{ return FromTx(MakeTransactionRef(tx)); } diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 78b279e42a5..22f5d6d9362 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -102,15 +102,16 @@ class CBlock; struct CMutableTransaction; class CScript; -// -// Testing fixture that pre-creates a -// 100-block REGTEST-mode block chain -// +/** + * Testing fixture that pre-creates a 100-block REGTEST-mode block chain + */ struct TestChain100Setup : public RegTestingSetup { TestChain100Setup(); - // Create a new block with just given transactions, coinbase paying to - // scriptPubKey, and try to add it to the current chain. + /** + * Create a new block with just given transactions, coinbase paying to + * scriptPubKey, and try to add it to the current chain. + */ CBlock CreateAndProcessBlock(const std::vector& txns, const CScript& scriptPubKey); From fa11ff29803ca4f5fd0035bede697448cff7d960 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 21 Aug 2020 15:20:10 +0200 Subject: [PATCH 2/3] test: Pass empty tx pool to block assembler --- src/test/util/setup_common.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index c882ae38f26..e3d396e96d0 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -215,10 +215,10 @@ TestChain100Setup::TestChain100Setup() CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector& txns, const CScript& scriptPubKey) { const CChainParams& chainparams = Params(); - CBlock block = BlockAssembler(*m_node.mempool, chainparams).CreateNewBlock(scriptPubKey)->block; + CTxMemPool empty_pool; + CBlock block = BlockAssembler(empty_pool, chainparams).CreateNewBlock(scriptPubKey)->block; - // Replace mempool-selected txns with just coinbase plus passed-in txns: - block.vtx.resize(1); + Assert(block.vtx.size() == 1); for (const CMutableTransaction& tx : txns) { block.vtx.push_back(MakeTransactionRef(tx)); } From fad84b7e14ff92465bc17bfdaf1362bcffe092f6 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 21 Aug 2020 15:12:45 +0200 Subject: [PATCH 3/3] test: Activate segwit in TestChain100Setup --- src/test/util/setup_common.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index e3d396e96d0..bd416380ffd 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -196,12 +196,6 @@ TestingSetup::~TestingSetup() TestChain100Setup::TestChain100Setup() { - // CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests. - // TODO: fix the code to support SegWit blocks. - gArgs.ForceSetArg("-segwitheight", "432"); - // Need to recreate chainparams - SelectParams(CBaseChainParams::REGTEST); - // Generate a 100-block chain: coinbaseKey.MakeNewKey(true); CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; @@ -222,12 +216,7 @@ CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector