@@ -46,6 +46,7 @@ def run_test(self):
46
46
self .ctx = zmq .Context ()
47
47
try :
48
48
self .test_basic ()
49
+ self .test_reorg ()
49
50
finally :
50
51
# Destroy the ZMQ context.
51
52
self .log .debug ("Destroying ZMQ context" )
@@ -122,5 +123,29 @@ def test_basic(self):
122
123
123
124
assert_equal (self .nodes [1 ].getzmqnotifications (), [])
124
125
126
+ def test_reorg (self ):
127
+ import zmq
128
+ address = 'tcp://127.0.0.1:28333'
129
+ socket = self .ctx .socket (zmq .SUB )
130
+ socket .set (zmq .RCVTIMEO , 60000 )
131
+ socket .connect (address )
132
+ hashblock = ZMQSubscriber (socket , b'hashblock' )
133
+
134
+ # Should only notify the tip if a reorg occurs
135
+ self .restart_node (0 , ['-zmqpub%s=%s' % (hashblock .topic .decode (), address )])
136
+
137
+ # Generate 1 block in nodes[0] and receive all notifications
138
+ self .nodes [0 ].generatetoaddress (1 , ADDRESS_BCRT1_UNSPENDABLE )
139
+ assert_equal (self .nodes [0 ].getbestblockhash (), hashblock .receive ().hex ())
140
+
141
+ # Generate 2 blocks in nodes[1]
142
+ self .nodes [1 ].generatetoaddress (2 , ADDRESS_BCRT1_UNSPENDABLE )
143
+
144
+ # nodes[0] will reorg chain after connecting back nodes[1]
145
+ connect_nodes (self .nodes [0 ], 1 )
146
+
147
+ # Should receive nodes[1] tip
148
+ assert_equal (self .nodes [1 ].getbestblockhash (), hashblock .receive ().hex ())
149
+
125
150
if __name__ == '__main__' :
126
151
ZMQTest ().main ()
0 commit comments