-
Notifications
You must be signed in to change notification settings - Fork 134
/
txvalidation_tests.cpp
91 lines (68 loc) · 1.68 KB
/
txvalidation_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <validation.h>
#include <txmempool.h>
#include <amount.h>
#include <consensus/validation.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <test/test_raptoreum.h>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(txvalidation_tests)
/**
* Ensure that the mempool won't accept coinbase transactions.
*/
BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup
)
{
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
CMutableTransaction coinbaseTx;
coinbaseTx.
nVersion = 1;
coinbaseTx.vin.resize(1);
coinbaseTx.vout.resize(1);
coinbaseTx.vin[0].
scriptSig = CScript() << OP_11 << OP_EQUAL;
coinbaseTx.vout[0].
nValue = 1 * CENT;
coinbaseTx.vout[0].
scriptPubKey = scriptPubKey;
assert(CTransaction(coinbaseTx)
.
IsCoinBase()
);
CValidationState state;
LOCK(cs_main);
unsigned int initialPoolSize = m_node.mempool->size();
BOOST_CHECK_EQUAL(
false,
AcceptToMemoryPool(*m_node
.mempool, state,
MakeTransactionRef(coinbaseTx),
nullptr /* pfMissingInputs */,
true /* bypass_limits */,
0 /* nAbsurdFee */));
// Check that the transaction hasn't been added to mempool.
BOOST_CHECK_EQUAL(m_node
.mempool->
size(), initialPoolSize
);
// Check that the validation state reflects the unsuccessful attempt.
BOOST_CHECK(state
.
IsInvalid()
);
BOOST_CHECK_EQUAL(state
.
GetRejectReason(),
"coinbase");
int nDoS;
BOOST_CHECK_EQUAL(state
.
IsInvalid(nDoS),
true);
BOOST_CHECK_EQUAL(nDoS,
100);
}
BOOST_AUTO_TEST_SUITE_END()