Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_accept.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017-2019 The Bitcoin Core developers | # Copyright (c) 2017-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test mempool acceptance of raw transactions.""" | """Test mempool acceptance of raw transactions.""" | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.key import ECKey | from test_framework.key import ECKey | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
COIN, | COIN, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxOut, | CTxOut, | ||||
FromHex, | FromHex, | ||||
MAX_BLOCK_BASE_SIZE, | MAX_BLOCK_BASE_SIZE, | ||||
ToHex, | ToHex, | ||||
MAX_MONEY, | |||||
) | ) | ||||
from test_framework.script import ( | from test_framework.script import ( | ||||
hash160, | hash160, | ||||
CScript, | CScript, | ||||
OP_0, | OP_0, | ||||
OP_2, | OP_2, | ||||
OP_3, | OP_3, | ||||
OP_CHECKMULTISIG, | OP_CHECKMULTISIG, | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
), 'allowed': False, 'reject-reason': 'bad-txns-vout-negative'}], | ), 'allowed': False, 'reject-reason': 'bad-txns-vout-negative'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
# The following two validations prevent overflow of the output amounts | # The following two validations prevent overflow of the output amounts | ||||
# (see CVE-2010-5139). | # (see CVE-2010-5139). | ||||
self.log.info('A transaction with too large output value') | self.log.info('A transaction with too large output value') | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
tx.vout[0].nValue = 21000000 * COIN + 1 | tx.vout[0].nValue = MAX_MONEY + 1 | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': tx.rehash( | result_expected=[{'txid': tx.rehash( | ||||
), 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}], | ), 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
self.log.info('A transaction with too large sum of output values') | self.log.info('A transaction with too large sum of output values') | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
tx.vout = [tx.vout[0]] * 2 | tx.vout = [tx.vout[0]] * 2 | ||||
tx.vout[0].nValue = 21000000 * COIN | tx.vout[0].nValue = MAX_MONEY | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': tx.rehash( | result_expected=[{'txid': tx.rehash( | ||||
), 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}], | ), 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
self.log.info('A transaction with duplicate inputs') | self.log.info('A transaction with duplicate inputs') | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines |