aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_tx_download.py
diff options
context:
space:
mode:
authorAntoine Riard <ariard@student.42.fr>2020-10-22 09:20:49 -0400
committerAntoine Riard <ariard@student.42.fr>2020-11-02 18:29:49 -0500
commitd3b5eac9a989878e2e09e5fde71c49149b123f18 (patch)
tree7c07442194f9a794fa506e857db993c2a5e4b544 /test/functional/p2p_tx_download.py
parent06efb3163cdf30e74df3f78afc4896b0f55ce937 (diff)
Add mutation for functional test test_preferred_inv
Add a booelan arg to test_preferred_inv to cover NONPREF_PEER_TX_DELAY as applied as a TxRequestTracker parameter in AddTxAnnouncement.
Diffstat (limited to 'test/functional/p2p_tx_download.py')
-rwxr-xr-xtest/functional/p2p_tx_download.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/test/functional/p2p_tx_download.py b/test/functional/p2p_tx_download.py
index b82ca95cbe..164ab4b126 100755
--- a/test/functional/p2p_tx_download.py
+++ b/test/functional/p2p_tx_download.py
@@ -47,6 +47,7 @@ TXID_RELAY_DELAY = 2 # seconds
OVERLOADED_PEER_DELAY = 2 # seconds
MAX_GETDATA_IN_FLIGHT = 100
MAX_PEER_TX_ANNOUNCEMENTS = 5000
+NONPREF_PEER_TX_DELAY = 2
# Python test constants
NUM_INBOUND = 10
@@ -207,14 +208,24 @@ class TxDownloadTest(BitcoinTestFramework):
with p2p_lock:
assert_equal(peer_fallback.tx_getdata_count, 1)
- def test_preferred_inv(self):
- self.log.info('Check that invs from preferred peers are downloaded immediately')
- self.restart_node(0, extra_args=['-whitelist=noban@127.0.0.1'])
+ def test_preferred_inv(self, preferred=False):
+ if preferred:
+ self.log.info('Check invs from preferred peers are downloaded immediately')
+ self.restart_node(0, extra_args=['-whitelist=noban@127.0.0.1'])
+ else:
+ self.log.info('Check invs from non-preferred peers are downloaded after {} s'.format(NONPREF_PEER_TX_DELAY))
+ mock_time = int(time.time() + 1)
+ self.nodes[0].setmocktime(mock_time)
peer = self.nodes[0].add_p2p_connection(TestP2PConn())
peer.send_message(msg_inv([CInv(t=MSG_WTX, h=0xff00ff00)]))
- peer.wait_until(lambda: peer.tx_getdata_count >= 1, timeout=1)
- with p2p_lock:
- assert_equal(peer.tx_getdata_count, 1)
+ peer.sync_with_ping()
+ if preferred:
+ peer.wait_until(lambda: peer.tx_getdata_count >= 1, timeout=1)
+ else:
+ with p2p_lock:
+ assert_equal(peer.tx_getdata_count, 0)
+ self.nodes[0].setmocktime(mock_time + NONPREF_PEER_TX_DELAY)
+ peer.wait_until(lambda: peer.tx_getdata_count >= 1, timeout=1)
def test_txid_inv_delay(self, glob_wtxid=False):
self.log.info('Check that inv from a txid-relay peers are delayed by {} s, with a wtxid peer {}'.format(TXID_RELAY_DELAY, glob_wtxid))
@@ -261,6 +272,7 @@ class TxDownloadTest(BitcoinTestFramework):
self.test_disconnect_fallback()
self.test_notfound_fallback()
self.test_preferred_inv()
+ self.test_preferred_inv(True)
self.test_txid_inv_delay()
self.test_txid_inv_delay(True)
self.test_large_inv_batch()