Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_accept.py
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'missing-inputs'}], | {'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'missing-inputs'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
self.log.info( | self.log.info( | ||||
'A transaction with missing inputs, that existed once in the past') | 'A transaction with missing inputs, that existed once in the past') | ||||
tx = FromHex(CTransaction(), raw_tx_0) | tx = FromHex(CTransaction(), raw_tx_0) | ||||
# Set vout to 1, to spend the other outpoint (49 coins) of the in-chain-tx we want to double spend | # Set vout to 1, to spend the other outpoint (49 coins) of the | ||||
# in-chain-tx we want to double spend | |||||
tx.vin[0].prevout.n = 1 | tx.vin[0].prevout.n = 1 | ||||
raw_tx_1 = node.signrawtransactionwithwallet( | raw_tx_1 = node.signrawtransactionwithwallet( | ||||
ToHex(tx))['hex'] | ToHex(tx))['hex'] | ||||
txid_1 = node.sendrawtransaction( | txid_1 = node.sendrawtransaction( | ||||
hexstring=raw_tx_1, allowhighfees=True) | hexstring=raw_tx_1, allowhighfees=True) | ||||
# Now spend both to "clearly hide" the outputs, ie. remove the coins from the utxo set by spending them | # Now spend both to "clearly hide" the outputs, ie. remove the coins | ||||
# from the utxo set by spending them | |||||
raw_tx_spend_both = node.signrawtransactionwithwallet(node.createrawtransaction( | raw_tx_spend_both = node.signrawtransactionwithwallet(node.createrawtransaction( | ||||
inputs=[ | inputs=[ | ||||
{'txid': txid_0, 'vout': 0}, | {'txid': txid_0, 'vout': 0}, | ||||
{'txid': txid_1, 'vout': 0}, | {'txid': txid_1, 'vout': 0}, | ||||
], | ], | ||||
outputs=[{node.getnewaddress(): 0.1}] | outputs=[{node.getnewaddress(): 0.1}] | ||||
))['hex'] | ))['hex'] | ||||
txid_spend_both = node.sendrawtransaction( | txid_spend_both = node.sendrawtransaction( | ||||
hexstring=raw_tx_spend_both, allowhighfees=True) | hexstring=raw_tx_spend_both, allowhighfees=True) | ||||
node.generate(1) | node.generate(1) | ||||
self.mempool_size = 0 | self.mempool_size = 0 | ||||
# Now see if we can add the coins back to the utxo set by sending the exact txs again | # Now see if we can add the coins back to the utxo set by sending the | ||||
# exact txs again | |||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': txid_0, 'allowed': False, 'reject-reason': 'missing-inputs'}], | {'txid': txid_0, 'allowed': False, 'reject-reason': 'missing-inputs'}], | ||||
rawtxs=[raw_tx_0], | rawtxs=[raw_tx_0], | ||||
) | ) | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': txid_1, 'allowed': False, 'reject-reason': 'missing-inputs'}], | {'txid': txid_1, 'allowed': False, 'reject-reason': 'missing-inputs'}], | ||||
Show All 20 Lines | def run_test(self): | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': tx.rehash( | result_expected=[{'txid': tx.rehash( | ||||
), 'allowed': False, 'reject-reason': '16: bad-txns-vout-empty'}], | ), 'allowed': False, 'reject-reason': '16: bad-txns-vout-empty'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
self.log.info('A really large transaction') | self.log.info('A really large transaction') | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
tx.vin = [tx.vin[0]] * (1 + MAX_BLOCK_BASE_SIZE // | tx.vin = [tx.vin[0]] * (1 + MAX_BLOCK_BASE_SIZE | ||||
len(tx.vin[0].serialize())) | // len(tx.vin[0].serialize())) | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-oversize'}], | {'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-oversize'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
self.log.info('A transaction with negative output value') | self.log.info('A transaction with negative output value') | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
Show All 28 Lines | def run_test(self): | ||||
tx.vin = [tx.vin[0]] * 2 | tx.vin = [tx.vin[0]] * 2 | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[{'txid': tx.rehash( | result_expected=[{'txid': tx.rehash( | ||||
), 'allowed': False, 'reject-reason': '16: bad-txns-inputs-duplicate'}], | ), 'allowed': False, 'reject-reason': '16: bad-txns-inputs-duplicate'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
self.log.info('A coinbase transaction') | self.log.info('A coinbase transaction') | ||||
# Pick the input of the first tx we signed, so it has to be a coinbase tx | # Pick the input of the first tx we signed, so it has to be a coinbase | ||||
# tx | |||||
raw_tx_coinbase_spent = node.getrawtransaction( | raw_tx_coinbase_spent = node.getrawtransaction( | ||||
txid=node.decoderawtransaction(hexstring=raw_tx_in_block)['vin'][0]['txid']) | txid=node.decoderawtransaction(hexstring=raw_tx_in_block)['vin'][0]['txid']) | ||||
tx = FromHex(CTransaction(), raw_tx_coinbase_spent) | tx = FromHex(CTransaction(), raw_tx_coinbase_spent) | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-tx-coinbase'}], | {'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-tx-coinbase'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: bad-txns-nonfinal'}], | {'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: bad-txns-nonfinal'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
) | ) | ||||
self.log.info('A transaction that is locked by BIP68 sequence logic') | self.log.info('A transaction that is locked by BIP68 sequence logic') | ||||
tx = FromHex(CTransaction(), raw_tx_reference) | tx = FromHex(CTransaction(), raw_tx_reference) | ||||
# We could include it in the second block mined from now, but not the very next one | # We could include it in the second block mined from now, but not the | ||||
# very next one | |||||
tx.vin[0].nSequence = 2 | tx.vin[0].nSequence = 2 | ||||
# Can skip re-signing the tx because of early rejection | # Can skip re-signing the tx because of early rejection | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
result_expected=[ | result_expected=[ | ||||
{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: non-BIP68-final'}], | {'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: non-BIP68-final'}], | ||||
rawtxs=[ToHex(tx)], | rawtxs=[ToHex(tx)], | ||||
allowhighfees=True, | allowhighfees=True, | ||||
) | ) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
MempoolAcceptanceTest().main() | MempoolAcceptanceTest().main() |