Skip to content

Commit 8abe570

Browse files
committed
test: Add IPv6 test to zmq
1 parent ded449b commit 8abe570

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/functional/interface_zmq.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
assert_equal,
1414
assert_raises_rpc_error,
1515
)
16+
from test_framework.netutil import test_ipv6_local
1617
from io import BytesIO
1718
from time import sleep
1819

@@ -108,17 +109,20 @@ def run_test(self):
108109
self.test_mempool_sync()
109110
self.test_reorg()
110111
self.test_multiple_interfaces()
112+
self.test_ipv6()
111113
finally:
112114
# Destroy the ZMQ context.
113115
self.log.debug("Destroying ZMQ context")
114116
self.ctx.destroy(linger=None)
115117

116118
# Restart node with the specified zmq notifications enabled, subscribe to
117119
# 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):
119121
subscribers = []
120122
for topic, address in services:
121123
socket = self.ctx.socket(zmq.SUB)
124+
if ipv6:
125+
socket.setsockopt(zmq.IPV6, 1)
122126
subscribers.append(ZMQSubscriber(socket, topic.encode()))
123127

124128
self.restart_node(0, ["-zmqpub%s=%s" % (topic, address) for topic, address in services] +
@@ -557,5 +561,22 @@ def test_multiple_interfaces(self):
557561
assert_equal(self.nodes[0].getbestblockhash(), subscribers[0].receive().hex())
558562
assert_equal(self.nodes[0].getbestblockhash(), subscribers[1].receive().hex())
559563

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

0 commit comments

Comments
 (0)