Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_accept.py
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | class MempoolAcceptanceTest(BitcoinTestFramework): | ||||
def run_test(self): | def run_test(self): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
self.log.info('Start with empty mempool, and 200 blocks') | self.log.info('Start with empty mempool, and 200 blocks') | ||||
self.mempool_size = 0 | self.mempool_size = 0 | ||||
wait_until(lambda: node.getblockcount() == 200) | wait_until(lambda: node.getblockcount() == 200) | ||||
assert_equal(node.getmempoolinfo()['size'], self.mempool_size) | assert_equal(node.getmempoolinfo()['size'], self.mempool_size) | ||||
coins = node.listunspent() | |||||
self.log.info('Should not accept garbage to testmempoolaccept') | self.log.info('Should not accept garbage to testmempoolaccept') | ||||
assert_raises_rpc_error(-3, 'Expected type array, got string', | assert_raises_rpc_error(-3, 'Expected type array, got string', | ||||
lambda: node.testmempoolaccept(rawtxs='ff00baar')) | lambda: node.testmempoolaccept(rawtxs='ff00baar')) | ||||
assert_raises_rpc_error(-8, 'Array must contain exactly one raw transaction for now', | assert_raises_rpc_error(-8, 'Array must contain exactly one raw transaction for now', | ||||
lambda: node.testmempoolaccept(rawtxs=['ff00baar', 'ff22'])) | lambda: node.testmempoolaccept(rawtxs=['ff00baar', 'ff22'])) | ||||
assert_raises_rpc_error(-22, 'TX decode failed', | assert_raises_rpc_error(-22, 'TX decode failed', | ||||
lambda: node.testmempoolaccept(rawtxs=['ff00baar'])) | lambda: node.testmempoolaccept(rawtxs=['ff00baar'])) | ||||
self.log.info('A transaction already in the blockchain') | self.log.info('A transaction already in the blockchain') | ||||
coin = node.listunspent()[0] # Pick a random coin(base) to spend | # Pick a random coin(base) to spend | ||||
coin = coins.pop() | |||||
raw_tx_in_block = node.signrawtransactionwithwallet(node.createrawtransaction( | raw_tx_in_block = node.signrawtransactionwithwallet(node.createrawtransaction( | ||||
inputs=[{'txid': coin['txid'], 'vout': coin['vout']}], | inputs=[{'txid': coin['txid'], 'vout': coin['vout']}], | ||||
outputs=[{node.getnewaddress(): 0.3}, {node.getnewaddress(): 49}], | outputs=[{node.getnewaddress(): 0.3}, {node.getnewaddress(): 49}], | ||||
))['hex'] | ))['hex'] | ||||
txid_in_block = node.sendrawtransaction( | txid_in_block = node.sendrawtransaction( | ||||
hexstring=raw_tx_in_block, allowhighfees=True) | hexstring=raw_tx_in_block, allowhighfees=True) | ||||
node.generate(1) | node.generate(1) | ||||
self.mempool_size = 0 | self.mempool_size = 0 | ||||
Show All 14 Lines | def run_test(self): | ||||
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_0))) | tx.deserialize(BytesIO(hex_str_to_bytes(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}], | ||||
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') | ||||
coin = node.listunspent()[0] # Pick a random coin(base) to spend | # Pick a random coin(base) to spend | ||||
coin = coins.pop() | |||||
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(): 0.025}], | outputs=[{node.getnewaddress(): 0.025}], | ||||
locktime=node.getblockcount() + 2000, # Can be anything | locktime=node.getblockcount() + 2000, # Can be anything | ||||
))['hex'] | ))['hex'] | ||||
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_final))) | tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_final))) | ||||
self.check_mempool_result( | self.check_mempool_result( | ||||
▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines |