Skip to content

Commit

Permalink
[test] make submit optional in CreateValidMempoolTransaction
Browse files Browse the repository at this point in the history
This allows us to easily create transaction chains for package
validation. We don't test_accept if submit=false because we want to be
able to make transactions that wouldn't pass ATMP (i.e. a child
transaction in a package would fail due to missing inputs).
  • Loading branch information
glozow committed May 24, 2021
1 parent 2ef1879 commit cd9a11a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactio
int input_height,
CKey input_signing_key,
CScript output_destination,
CAmount output_amount)
CAmount output_amount,
bool submit)
{
// Transaction we will submit to the mempool
CMutableTransaction mempool_txn;
Expand Down Expand Up @@ -296,8 +297,8 @@ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactio
std::map<int, std::string> input_errors;
assert(SignTransaction(mempool_txn, &keystore, input_coins, nHashType, input_errors));

// Add transaction to the mempool
{
// If submit=true, add transaction to the mempool.
if (submit) {
LOCK(cs_main);
const MempoolAcceptResult result = AcceptToMemoryPool(::ChainstateActive(), *m_node.mempool.get(), MakeTransactionRef(mempool_txn), /* bypass_limits */ false);
assert(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
Expand Down
4 changes: 3 additions & 1 deletion src/test/util/setup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ struct TestChain100Setup : public RegTestingSetup {
* @param input_signing_key The key to spend the input_transaction
* @param output_destination Where to send the output
* @param output_amount How much to send
* @param submit Whether or not to submit to mempool
*/
CMutableTransaction CreateValidMempoolTransaction(CTransactionRef input_transaction,
int input_vout,
int input_height,
CKey input_signing_key,
CScript output_destination,
CAmount output_amount = CAmount(1 * COIN));
CAmount output_amount = CAmount(1 * COIN),
bool submit = true);

~TestChain100Setup();

Expand Down

0 comments on commit cd9a11a

Please sign in to comment.