55"""Test processing of feefilter messages."""
66
77from decimal import Decimal
8- import time
98
109from test_framework .messages import MSG_TX , MSG_WTX , msg_feefilter
1110from test_framework .mininode import mininode_lock , P2PInterface
@@ -17,16 +16,6 @@ def hashToHex(hash):
1716 return format (hash , '064x' )
1817
1918
20- # Wait up to 60 secs to see if the testnode has received all the expected invs
21- def allInvsMatch (invsExpected , testnode ):
22- for _ in range (60 ):
23- with mininode_lock :
24- if (sorted (invsExpected ) == sorted (testnode .txinvs )):
25- return True
26- time .sleep (1 )
27- return False
28-
29-
3019class FeefilterConn (P2PInterface ):
3120 feefilter_received = False
3221
@@ -48,6 +37,10 @@ def on_inv(self, message):
4837 if (i .type == MSG_TX ) or (i .type == MSG_WTX ):
4938 self .txinvs .append (hashToHex (i .hash ))
5039
40+ def wait_for_invs_to_match (self , invs_expected ):
41+ invs_expected .sort ()
42+ self .wait_until (lambda : invs_expected == sorted (self .txinvs ), timeout = 60 )
43+
5144 def clear_invs (self ):
5245 with mininode_lock :
5346 self .txinvs = []
@@ -91,7 +84,7 @@ def test_feefilter(self):
9184 self .log .info ("Test txs paying 0.2 sat/byte are received by test connection" )
9285 node1 .settxfee (Decimal ("0.00000200" ))
9386 txids = [node1 .sendtoaddress (node1 .getnewaddress (), 1 ) for _ in range (3 )]
94- assert allInvsMatch (txids , conn )
87+ conn . wait_for_invs_to_match (txids )
9588 conn .clear_invs ()
9689
9790 # Set a fee filter of 0.15 sat/byte on test connection
@@ -100,7 +93,7 @@ def test_feefilter(self):
10093 self .log .info ("Test txs paying 0.15 sat/byte are received by test connection" )
10194 node1 .settxfee (Decimal ("0.00000150" ))
10295 txids = [node1 .sendtoaddress (node1 .getnewaddress (), 1 ) for _ in range (3 )]
103- assert allInvsMatch (txids , conn )
96+ conn . wait_for_invs_to_match (txids )
10497 conn .clear_invs ()
10598
10699 self .log .info ("Test txs paying 0.1 sat/byte are no longer received by test connection" )
@@ -117,13 +110,13 @@ def test_feefilter(self):
117110 # as well.
118111 node0 .settxfee (Decimal ("0.00020000" ))
119112 txids = [node0 .sendtoaddress (node0 .getnewaddress (), 1 )]
120- assert allInvsMatch (txids , conn )
113+ conn . wait_for_invs_to_match (txids )
121114 conn .clear_invs ()
122115
123116 self .log .info ("Remove fee filter and check txs are received again" )
124117 conn .send_and_ping (msg_feefilter (0 ))
125118 txids = [node1 .sendtoaddress (node1 .getnewaddress (), 1 ) for _ in range (3 )]
126- assert allInvsMatch (txids , conn )
119+ conn . wait_for_invs_to_match (txids )
127120 conn .clear_invs ()
128121
129122
0 commit comments