diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -6,6 +6,7 @@ from base64 import b64encode from binascii import hexlify, unhexlify from decimal import Decimal, ROUND_DOWN +import hashlib import json import logging import os @@ -196,6 +197,14 @@ return hexlify(byte_str).decode('ascii') +def hash256(byte_str): + sha256 = hashlib.sha256() + sha256.update(byte_str) + sha256d = hashlib.sha256() + sha256d.update(sha256.digest()) + return sha256d.digest()[::-1] + + def hex_str_to_bytes(hex_str): return unhexlify(hex_str.encode('ascii')) diff --git a/test/functional/zmq_test.py b/test/functional/zmq_test.py --- a/test/functional/zmq_test.py +++ b/test/functional/zmq_test.py @@ -1,19 +1,17 @@ #!/usr/bin/env python3 -# Copyright (c) 2015-2017 The Bitcoin Core developers -# Copyright (c) 2017 The Bitcoin developers +# Copyright (c) 2015-2016 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. - """Test the ZMQ API.""" import configparser import os import struct from test_framework.test_framework import BitcoinTestFramework, SkipTest -from test_framework.util import ( - assert_equal, - bytes_to_hex_str, -) +from test_framework.util import (assert_equal, + bytes_to_hex_str, + hash256, + ) class ZMQTest (BitcoinTestFramework): @@ -42,11 +40,12 @@ self.zmqSubSocket.set(zmq.RCVTIMEO, 60000) self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock") self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx") - + self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawblock") + self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"rawtx") ip_address = "tcp://127.0.0.1:28332" self.zmqSubSocket.connect(ip_address) - self.extra_args = [['-zmqpubhashtx=%s' % - ip_address, '-zmqpubhashblock=%s' % ip_address], []] + self.extra_args = [['-zmqpubhashblock=%s' % ip_address, '-zmqpubhashtx=%s' % ip_address, + '-zmqpubrawblock=%s' % ip_address, '-zmqpubrawtx=%s' % ip_address], []] self.add_nodes(self.num_nodes, self.extra_args) self.start_nodes() @@ -66,32 +65,52 @@ msg = self.zmqSubSocket.recv_multipart() topic = msg[0] assert_equal(topic, b"hashtx") + txhash = msg[1] + msgSequence = struct.unpack('