5
5
"""Test processing of feefilter messages."""
6
6
7
7
from decimal import Decimal
8
- import time
9
8
10
9
from test_framework .messages import MSG_TX , MSG_WTX , msg_feefilter
11
10
from test_framework .mininode import mininode_lock , P2PInterface
@@ -17,16 +16,6 @@ def hashToHex(hash):
17
16
return format (hash , '064x' )
18
17
19
18
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
-
30
19
class FeefilterConn (P2PInterface ):
31
20
feefilter_received = False
32
21
@@ -48,6 +37,10 @@ def on_inv(self, message):
48
37
if (i .type == MSG_TX ) or (i .type == MSG_WTX ):
49
38
self .txinvs .append (hashToHex (i .hash ))
50
39
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
+
51
44
def clear_invs (self ):
52
45
with mininode_lock :
53
46
self .txinvs = []
@@ -91,7 +84,7 @@ def test_feefilter(self):
91
84
self .log .info ("Test txs paying 0.2 sat/byte are received by test connection" )
92
85
node1 .settxfee (Decimal ("0.00000200" ))
93
86
txids = [node1 .sendtoaddress (node1 .getnewaddress (), 1 ) for _ in range (3 )]
94
- assert allInvsMatch (txids , conn )
87
+ conn . wait_for_invs_to_match (txids )
95
88
conn .clear_invs ()
96
89
97
90
# Set a fee filter of 0.15 sat/byte on test connection
@@ -100,7 +93,7 @@ def test_feefilter(self):
100
93
self .log .info ("Test txs paying 0.15 sat/byte are received by test connection" )
101
94
node1 .settxfee (Decimal ("0.00000150" ))
102
95
txids = [node1 .sendtoaddress (node1 .getnewaddress (), 1 ) for _ in range (3 )]
103
- assert allInvsMatch (txids , conn )
96
+ conn . wait_for_invs_to_match (txids )
104
97
conn .clear_invs ()
105
98
106
99
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):
117
110
# as well.
118
111
node0 .settxfee (Decimal ("0.00020000" ))
119
112
txids = [node0 .sendtoaddress (node0 .getnewaddress (), 1 )]
120
- assert allInvsMatch (txids , conn )
113
+ conn . wait_for_invs_to_match (txids )
121
114
conn .clear_invs ()
122
115
123
116
self .log .info ("Remove fee filter and check txs are received again" )
124
117
conn .send_and_ping (msg_feefilter (0 ))
125
118
txids = [node1 .sendtoaddress (node1 .getnewaddress (), 1 ) for _ in range (3 )]
126
- assert allInvsMatch (txids , conn )
119
+ conn . wait_for_invs_to_match (txids )
127
120
conn .clear_invs ()
128
121
129
122
0 commit comments