qa: Test ZMQ notification after chain reorg
This commit is contained in:
parent
aa2622a726
commit
abdfc5e89b
1 changed files with 25 additions and 0 deletions
|
@ -46,6 +46,7 @@ class ZMQTest (BitcoinTestFramework):
|
|||
self.ctx = zmq.Context()
|
||||
try:
|
||||
self.test_basic()
|
||||
self.test_reorg()
|
||||
finally:
|
||||
# Destroy the ZMQ context.
|
||||
self.log.debug("Destroying ZMQ context")
|
||||
|
@ -122,5 +123,29 @@ class ZMQTest (BitcoinTestFramework):
|
|||
|
||||
assert_equal(self.nodes[1].getzmqnotifications(), [])
|
||||
|
||||
def test_reorg(self):
|
||||
import zmq
|
||||
address = 'tcp://127.0.0.1:28333'
|
||||
socket = self.ctx.socket(zmq.SUB)
|
||||
socket.set(zmq.RCVTIMEO, 60000)
|
||||
socket.connect(address)
|
||||
hashblock = ZMQSubscriber(socket, b'hashblock')
|
||||
|
||||
# Should only notify the tip if a reorg occurs
|
||||
self.restart_node(0, ['-zmqpub%s=%s' % (hashblock.topic.decode(), address)])
|
||||
|
||||
# Generate 1 block in nodes[0] and receive all notifications
|
||||
self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)
|
||||
assert_equal(self.nodes[0].getbestblockhash(), hashblock.receive().hex())
|
||||
|
||||
# Generate 2 blocks in nodes[1]
|
||||
self.nodes[1].generatetoaddress(2, ADDRESS_BCRT1_UNSPENDABLE)
|
||||
|
||||
# nodes[0] will reorg chain after connecting back nodes[1]
|
||||
connect_nodes(self.nodes[0], 1)
|
||||
|
||||
# Should receive nodes[1] tip
|
||||
assert_equal(self.nodes[1].getbestblockhash(), hashblock.receive().hex())
|
||||
|
||||
if __name__ == '__main__':
|
||||
ZMQTest().main()
|
||||
|
|
Loading…
Reference in a new issue