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.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, | ||||
) | ) | ||||
from test_framework.script import ( | from test_framework.script import ( | ||||
hash160, | hash160, | ||||
CScript, | CScript, | ||||
OP_0, | OP_0, | ||||
OP_2, | |||||
OP_3, | |||||
OP_CHECKMULTISIG, | |||||
OP_EQUAL, | OP_EQUAL, | ||||
OP_HASH160, | OP_HASH160, | ||||
OP_RETURN, | OP_RETURN, | ||||
) | ) | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
) | ) | ||||
class MempoolAcceptanceTest(BitcoinTestFramework): | class MempoolAcceptanceTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [[ | self.extra_args = [[ | ||||
'-txindex', | '-txindex', | ||||
'-acceptnonstdtxn=0', # Try to mimic main-net | '-acceptnonstdtxn=0', # Try to mimic main-net | ||||
'-permitbaremultisig=0', | |||||
]] * self.num_nodes | ]] * self.num_nodes | ||||
self.supports_cli = False | self.supports_cli = False | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def check_mempool_result(self, result_expected, *args, **kwargs): | def check_mempool_result(self, result_expected, *args, **kwargs): | ||||
"""Wrapper to check result of testmempoolaccept on node_0's mempool""" | """Wrapper to check result of testmempoolaccept on node_0's mempool""" | ||||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
tx.vout[0].scriptPubKey = CScript([OP_0]) # Some non-standard script | tx.vout[0].scriptPubKey = CScript([OP_0]) # Some non-standard script | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptpubkey'}], | {'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptpubkey'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
key = ECKey() | |||||
key.generate() | |||||
pubkey = key.get_pubkey().get_bytes() | |||||
# Some bare multisig script (2-of-3) | |||||
tx.vout[0].scriptPubKey = CScript( | |||||
[OP_2, pubkey, pubkey, pubkey, OP_3, OP_CHECKMULTISIG]) | |||||
self.check_mempool_result( | |||||
result_expected=[{'txid': tx.rehash(), 'allowed': False, | |||||
'reject-reason': 'bare-multisig'}], | |||||
rawtxs=[tx.serialize().hex()], | |||||
) | |||||
tx = FromHex(CTransaction(), raw_tx_reference) | |||||
# Some not-pushonly scriptSig | # Some not-pushonly scriptSig | ||||
tx.vin[0].scriptSig = CScript([OP_HASH160]) | tx.vin[0].scriptSig = CScript([OP_HASH160]) | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': tx.rehash( | result_expected=[{'txid': tx.rehash( | ||||
), 'allowed': False, 'reject-reason': 'scriptsig-not-pushonly'}], | ), 'allowed': False, 'reject-reason': 'scriptsig-not-pushonly'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |