Skip to content

Commit abdfc5e

Browse files
committed
qa: Test ZMQ notification after chain reorg
1 parent aa2622a commit abdfc5e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/functional/interface_zmq.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def run_test(self):
4646
self.ctx = zmq.Context()
4747
try:
4848
self.test_basic()
49+
self.test_reorg()
4950
finally:
5051
# Destroy the ZMQ context.
5152
self.log.debug("Destroying ZMQ context")
@@ -122,5 +123,29 @@ def test_basic(self):
122123

123124
assert_equal(self.nodes[1].getzmqnotifications(), [])
124125

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+
125150
if __name__ == '__main__':
126151
ZMQTest().main()

0 commit comments

Comments
 (0)