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 decimal import Decimal | |||||
from test_framework.key import ECKey | from test_framework.key import ECKey | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
MAX_BLOCK_BASE_SIZE, | MAX_BLOCK_BASE_SIZE, | ||||
MAX_MONEY, | MAX_MONEY, | ||||
XEC, | XEC, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxOut, | CTxOut, | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
raw_tx_0 = node.signrawtransactionwithwallet(node.createrawtransaction( | raw_tx_0 = node.signrawtransactionwithwallet(node.createrawtransaction( | ||||
inputs=[{"txid": txid_in_block, "vout": 0, | inputs=[{"txid": txid_in_block, "vout": 0, | ||||
"sequence": 0xfffffffd}], | "sequence": 0xfffffffd}], | ||||
outputs=[{node.getnewaddress(): 300000 - fee}], | outputs=[{node.getnewaddress(): 300000 - fee}], | ||||
))['hex'] | ))['hex'] | ||||
tx = FromHex(CTransaction(), raw_tx_0) | tx = FromHex(CTransaction(), raw_tx_0) | ||||
txid_0 = tx.rehash() | txid_0 = tx.rehash() | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': txid_0, 'allowed': True}], | result_expected=[{'txid': txid_0, 'allowed': True, | ||||
'size': tx.billable_size(), | |||||
'fees': {'base': Decimal(str(fee))}}], | |||||
rawtxs=[raw_tx_0], | rawtxs=[raw_tx_0], | ||||
) | ) | ||||
self.log.info('A final transaction not in the mempool') | self.log.info('A final transaction not in the mempool') | ||||
# Pick a random coin(base) to spend | # Pick a random coin(base) to spend | ||||
coin = coins.pop() | coin = coins.pop() | ||||
output_amount = 25_000 | |||||
raw_tx_final = node.signrawtransactionwithwallet(node.createrawtransaction( | raw_tx_final = node.signrawtransactionwithwallet(node.createrawtransaction( | ||||
inputs=[{'txid': coin['txid'], 'vout': coin['vout'], | inputs=[{'txid': coin['txid'], 'vout': coin['vout'], | ||||
"sequence": 0xffffffff}], # SEQUENCE_FINAL | "sequence": 0xffffffff}], # SEQUENCE_FINAL | ||||
outputs=[{node.getnewaddress(): 25000}], | outputs=[{node.getnewaddress(): output_amount}], | ||||
locktime=node.getblockcount() + 2000, # Can be anything | locktime=node.getblockcount() + 2000, # Can be anything | ||||
))['hex'] | ))['hex'] | ||||
tx = FromHex(CTransaction(), raw_tx_final) | tx = FromHex(CTransaction(), raw_tx_final) | ||||
fee_expected = int(coin['amount']) - output_amount | |||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': tx.rehash(), 'allowed': True}], | result_expected=[{'txid': tx.rehash(), 'allowed': True, | ||||
'size': tx.billable_size(), | |||||
'fees': {'base': Decimal(str(fee_expected))}}], | |||||
rawtxs=[tx.serialize().hex()], | rawtxs=[tx.serialize().hex()], | ||||
maxfeerate=0, | maxfeerate=0, | ||||
) | ) | ||||
node.sendrawtransaction(hexstring=raw_tx_final, maxfeerate=0) | node.sendrawtransaction(hexstring=raw_tx_final, maxfeerate=0) | ||||
self.mempool_size += 1 | self.mempool_size += 1 | ||||
self.log.info('A transaction in the mempool') | self.log.info('A transaction in the mempool') | ||||
node.sendrawtransaction(hexstring=raw_tx_0) | node.sendrawtransaction(hexstring=raw_tx_0) | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info('Create a signed "reference" tx for later use') | self.log.info('Create a signed "reference" tx for later use') | ||||
raw_tx_reference = node.signrawtransactionwithwallet(node.createrawtransaction( | raw_tx_reference = node.signrawtransactionwithwallet(node.createrawtransaction( | ||||
inputs=[{'txid': txid_spend_both, 'vout': 0}], | inputs=[{'txid': txid_spend_both, 'vout': 0}], | ||||
outputs=[{node.getnewaddress(): 50000}], | outputs=[{node.getnewaddress(): 50000}], | ||||
))['hex'] | ))['hex'] | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
# Reference tx should be valid on itself | # Reference tx should be valid on itself | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': tx.rehash(), 'allowed': True}], | result_expected=[{'txid': tx.rehash(), 'allowed': True, | ||||
'size': tx.billable_size(), | |||||
'fees': {'base': Decimal(100_000 - 50_000)}}], | |||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
maxfeerate=0, | maxfeerate=0, | ||||
) | ) | ||||
self.log.info('A transaction with no outputs') | self.log.info('A transaction with no outputs') | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
tx.vout = [] | tx.vout = [] | ||||
# Skip re-signing the transaction for context independent checks from now on | # Skip re-signing the transaction for context independent checks from now on | ||||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |