Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_blocksonly.py
Show All 13 Lines | class P2PBlocksOnly(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = False | self.setup_clean_chain = False | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [["-blocksonly"]] | self.extra_args = [["-blocksonly"]] | ||||
def run_test(self): | def run_test(self): | ||||
self.nodes[0].add_p2p_connection(P2PInterface()) | self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
self.log.info('Check that txs from p2p are rejected') | self.log.info( | ||||
'Check that txs from p2p are rejected and result in disconnect') | |||||
prevtx = self.nodes[0].getblock( | prevtx = self.nodes[0].getblock( | ||||
self.nodes[0].getblockhash(1), 2)['tx'][0] | self.nodes[0].getblockhash(1), 2)['tx'][0] | ||||
rawtx = self.nodes[0].createrawtransaction( | rawtx = self.nodes[0].createrawtransaction( | ||||
inputs=[{ | inputs=[{ | ||||
'txid': prevtx['txid'], | 'txid': prevtx['txid'], | ||||
'vout': 0 | 'vout': 0 | ||||
}], | }], | ||||
outputs=[{ | outputs=[{ | ||||
Show All 11 Lines | def run_test(self): | ||||
'amount': prevtx['vout'][0]['value'], | 'amount': prevtx['vout'][0]['value'], | ||||
'scriptPubKey': prevtx['vout'][0]['scriptPubKey']['hex'], | 'scriptPubKey': prevtx['vout'][0]['scriptPubKey']['hex'], | ||||
}], | }], | ||||
)['hex'] | )['hex'] | ||||
assert_equal(self.nodes[0].getnetworkinfo()['localrelay'], False) | assert_equal(self.nodes[0].getnetworkinfo()['localrelay'], False) | ||||
with self.nodes[0].assert_debug_log(['transaction sent in violation of protocol peer=0']): | with self.nodes[0].assert_debug_log(['transaction sent in violation of protocol peer=0']): | ||||
self.nodes[0].p2p.send_message( | self.nodes[0].p2p.send_message( | ||||
msg_tx(FromHex(CTransaction(), sigtx))) | msg_tx(FromHex(CTransaction(), sigtx))) | ||||
self.nodes[0].p2p.sync_with_ping() | self.nodes[0].p2p.wait_for_disconnect() | ||||
assert_equal(self.nodes[0].getmempoolinfo()['size'], 0) | assert_equal(self.nodes[0].getmempoolinfo()['size'], 0) | ||||
# Remove the disconnected peer and add a new one. | |||||
del self.nodes[0].p2ps[0] | |||||
self.nodes[0].add_p2p_connection(P2PInterface()) | |||||
self.log.info( | self.log.info( | ||||
'Check that txs from rpc are not rejected and relayed to other peers') | 'Check that txs from rpc are not rejected and relayed to other peers') | ||||
assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], True) | assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], True) | ||||
txid = self.nodes[0].testmempoolaccept([sigtx])[0]['txid'] | txid = self.nodes[0].testmempoolaccept([sigtx])[0]['txid'] | ||||
with self.nodes[0].assert_debug_log(['received getdata for: tx {} peer=0'.format(txid)]): | with self.nodes[0].assert_debug_log(['received getdata for: tx {} peer=1'.format(txid)]): | ||||
self.nodes[0].sendrawtransaction(sigtx) | self.nodes[0].sendrawtransaction(sigtx) | ||||
self.nodes[0].p2p.wait_for_tx(txid) | self.nodes[0].p2p.wait_for_tx(txid) | ||||
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1) | assert_equal(self.nodes[0].getmempoolinfo()['size'], 1) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
P2PBlocksOnly().main() | P2PBlocksOnly().main() |