|
13 | 13 | assert_equal,
|
14 | 14 | assert_raises_rpc_error,
|
15 | 15 | )
|
| 16 | +from test_framework.netutil import test_ipv6_local |
16 | 17 | from io import BytesIO
|
17 | 18 | from time import sleep
|
18 | 19 |
|
@@ -108,17 +109,20 @@ def run_test(self):
|
108 | 109 | self.test_mempool_sync()
|
109 | 110 | self.test_reorg()
|
110 | 111 | self.test_multiple_interfaces()
|
| 112 | + self.test_ipv6() |
111 | 113 | finally:
|
112 | 114 | # Destroy the ZMQ context.
|
113 | 115 | self.log.debug("Destroying ZMQ context")
|
114 | 116 | self.ctx.destroy(linger=None)
|
115 | 117 |
|
116 | 118 | # Restart node with the specified zmq notifications enabled, subscribe to
|
117 | 119 | # all of them and return the corresponding ZMQSubscriber objects.
|
118 |
| - def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True): |
| 120 | + def setup_zmq_test(self, services, *, recv_timeout=60, sync_blocks=True, ipv6=False): |
119 | 121 | subscribers = []
|
120 | 122 | for topic, address in services:
|
121 | 123 | socket = self.ctx.socket(zmq.SUB)
|
| 124 | + if ipv6: |
| 125 | + socket.setsockopt(zmq.IPV6, 1) |
122 | 126 | subscribers.append(ZMQSubscriber(socket, topic.encode()))
|
123 | 127 |
|
124 | 128 | self.restart_node(0, ["-zmqpub%s=%s" % (topic, address) for topic, address in services] +
|
@@ -557,5 +561,22 @@ def test_multiple_interfaces(self):
|
557 | 561 | assert_equal(self.nodes[0].getbestblockhash(), subscribers[0].receive().hex())
|
558 | 562 | assert_equal(self.nodes[0].getbestblockhash(), subscribers[1].receive().hex())
|
559 | 563 |
|
| 564 | + def test_ipv6(self): |
| 565 | + if not test_ipv6_local(): |
| 566 | + self.log.info("Skipping IPv6 test, because IPv6 is not supported.") |
| 567 | + return |
| 568 | + self.log.info("Testing IPv6") |
| 569 | + # Set up subscriber using IPv6 loopback address |
| 570 | + subscribers = self.setup_zmq_test([ |
| 571 | + ("hashblock", "tcp://[::1]:28332") |
| 572 | + ], ipv6=True) |
| 573 | + |
| 574 | + # Generate 1 block in nodes[0] |
| 575 | + self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE) |
| 576 | + |
| 577 | + # Should receive the same block hash |
| 578 | + assert_equal(self.nodes[0].getbestblockhash(), subscribers[0].receive().hex()) |
| 579 | + |
| 580 | + |
560 | 581 | if __name__ == '__main__':
|
561 | 582 | ZMQTest().main()
|
0 commit comments