@@ -54,28 +54,31 @@ def run_test(self):
54
54
self .ctx .destroy (linger = None )
55
55
56
56
def test_basic (self ):
57
- # All messages are received in the same socket which means
58
- # that this test fails if the publishing order changes.
59
- # Note that the publishing order is not defined in the documentation and
60
- # is subject to change.
61
57
import zmq
62
58
63
59
# Invalid zmq arguments don't take down the node, see #17185.
64
60
self .restart_node (0 , ["-zmqpubrawtx=foo" , "-zmqpubhashtx=bar" ])
65
61
66
62
address = 'tcp://127.0.0.1:28332'
67
- socket = self .ctx .socket (zmq .SUB )
68
- socket .set (zmq .RCVTIMEO , 60000 )
63
+ sockets = []
64
+ subs = []
65
+ services = [b"hashblock" , b"hashtx" , b"rawblock" , b"rawtx" ]
66
+ for service in services :
67
+ sockets .append (self .ctx .socket (zmq .SUB ))
68
+ sockets [- 1 ].set (zmq .RCVTIMEO , 60000 )
69
+ subs .append (ZMQSubscriber (sockets [- 1 ], service ))
69
70
70
71
# Subscribe to all available topics.
71
- hashblock = ZMQSubscriber ( socket , b"hashblock" )
72
- hashtx = ZMQSubscriber ( socket , b"hashtx" )
73
- rawblock = ZMQSubscriber ( socket , b"rawblock" )
74
- rawtx = ZMQSubscriber ( socket , b"rawtx" )
72
+ hashblock = subs [ 0 ]
73
+ hashtx = subs [ 1 ]
74
+ rawblock = subs [ 2 ]
75
+ rawtx = subs [ 3 ]
75
76
76
77
self .restart_node (0 , ["-zmqpub%s=%s" % (sub .topic .decode (), address ) for sub in [hashblock , hashtx , rawblock , rawtx ]])
77
78
connect_nodes (self .nodes [0 ], 1 )
78
- socket .connect (address )
79
+ for socket in sockets :
80
+ socket .connect (address )
81
+
79
82
# Relax so that the subscriber is ready before publishing zmq messages
80
83
sleep (0.2 )
81
84
@@ -96,15 +99,16 @@ def test_basic(self):
96
99
tx .calc_sha256 ()
97
100
assert_equal (tx .hash , txid .hex ())
98
101
102
+ # Should receive the generated raw block.
103
+ block = rawblock .receive ()
104
+ assert_equal (genhashes [x ], hash256_reversed (block [:80 ]).hex ())
105
+
99
106
# Should receive the generated block hash.
100
107
hash = hashblock .receive ().hex ()
101
108
assert_equal (genhashes [x ], hash )
102
109
# The block should only have the coinbase txid.
103
110
assert_equal ([txid .hex ()], self .nodes [1 ].getblock (hash )["tx" ])
104
111
105
- # Should receive the generated raw block.
106
- block = rawblock .receive ()
107
- assert_equal (genhashes [x ], hash256_reversed (block [:80 ]).hex ())
108
112
109
113
if self .is_wallet_compiled ():
110
114
self .log .info ("Wait for tx from second node" )
0 commit comments