Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_leak_tx.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017-2018 The Bitcoin Core developers | # Copyright (c) 2017-2018 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 that we don't leak txs to inbound peers that we haven't yet announced to""" | """Test that we don't leak txs to inbound peers that we haven't yet announced to""" | ||||
from test_framework.messages import msg_getdata, CInv | from test_framework.messages import msg_getdata, CInv, MSG_TX | ||||
from test_framework.mininode import P2PDataStore | from test_framework.mininode import P2PDataStore | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
) | ) | ||||
class P2PNode(P2PDataStore): | class P2PNode(P2PDataStore): | ||||
Show All 18 Lines | def run_test(self): | ||||
MAX_REPEATS = 100 | MAX_REPEATS = 100 | ||||
self.log.info("Running test up to {} times.".format(MAX_REPEATS)) | self.log.info("Running test up to {} times.".format(MAX_REPEATS)) | ||||
for i in range(MAX_REPEATS): | for i in range(MAX_REPEATS): | ||||
self.log.info('Run repeat {}'.format(i + 1)) | self.log.info('Run repeat {}'.format(i + 1)) | ||||
txid = gen_node.sendtoaddress(gen_node.getnewaddress(), 0.01) | txid = gen_node.sendtoaddress(gen_node.getnewaddress(), 0.01) | ||||
want_tx = msg_getdata() | want_tx = msg_getdata() | ||||
want_tx.inv.append(CInv(t=1, h=int(txid, 16))) | want_tx.inv.append(CInv(t=MSG_TX, h=int(txid, 16))) | ||||
inbound_peer.last_message.pop('notfound', None) | inbound_peer.last_message.pop('notfound', None) | ||||
inbound_peer.send_and_ping(want_tx) | inbound_peer.send_and_ping(want_tx) | ||||
if inbound_peer.last_message.get('notfound'): | if inbound_peer.last_message.get('notfound'): | ||||
self.log.debug( | self.log.debug( | ||||
'tx {} was not yet announced to us.'.format(txid)) | 'tx {} was not yet announced to us.'.format(txid)) | ||||
self.log.debug( | self.log.debug( | ||||
"node has responded with a notfound message. End test.") | "node has responded with a notfound message. End test.") | ||||
Show All 13 Lines |