Add missing parts from bitcoin PR #7762

This commit is contained in:
Alexander Block 2017-09-15 14:13:13 +02:00
parent 8678f2b391
commit c3e590968d

View File

@ -11,6 +11,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
import zmq import zmq
import binascii import binascii
import struct
try: try:
import http.client as httplib import http.client as httplib
@ -47,11 +48,17 @@ class ZMQTest (BitcoinTestFramework):
print "listen..." print "listen..."
msg = self.zmqSubSocket.recv_multipart() msg = self.zmqSubSocket.recv_multipart()
topic = msg[0] topic = msg[0]
assert_equal(topic, b"hashtx")
body = msg[1] body = msg[1]
nseq = msg[2]
msgSequence = struct.unpack('<I', msg[-1])[-1]
assert_equal(msgSequence, 0) #must be sequence 0 on hashtx
msg = self.zmqSubSocket.recv_multipart() msg = self.zmqSubSocket.recv_multipart()
topic = msg[0] topic = msg[0]
body = msg[1] body = msg[1]
msgSequence = struct.unpack('<I', msg[-1])[-1]
assert_equal(msgSequence, 0) #must be sequence 0 on hashblock
blkhash = bytes_to_hex_str(body) blkhash = bytes_to_hex_str(body)
assert_equal(genhashes[0], blkhash) #blockhash from generate must be equal to the hash received over zmq assert_equal(genhashes[0], blkhash) #blockhash from generate must be equal to the hash received over zmq
@ -61,12 +68,16 @@ class ZMQTest (BitcoinTestFramework):
self.sync_all() self.sync_all()
zmqHashes = [] zmqHashes = []
blockcount = 0
for x in range(0,n*2): for x in range(0,n*2):
msg = self.zmqSubSocket.recv_multipart() msg = self.zmqSubSocket.recv_multipart()
topic = msg[0] topic = msg[0]
body = msg[1] body = msg[1]
if topic == b"hashblock": if topic == b"hashblock":
zmqHashes.append(bytes_to_hex_str(body)) zmqHashes.append(bytes_to_hex_str(body))
msgSequence = struct.unpack('<I', msg[-1])[-1]
assert_equal(msgSequence, blockcount+1)
blockcount += 1
for x in range(0,n): for x in range(0,n):
assert_equal(genhashes[x], zmqHashes[x]) #blockhash from generate must be equal to the hash received over zmq assert_equal(genhashes[x], zmqHashes[x]) #blockhash from generate must be equal to the hash received over zmq
@ -82,6 +93,8 @@ class ZMQTest (BitcoinTestFramework):
hashZMQ = "" hashZMQ = ""
if topic == b"hashtx": if topic == b"hashtx":
hashZMQ = bytes_to_hex_str(body) hashZMQ = bytes_to_hex_str(body)
msgSequence = struct.unpack('<I', msg[-1])[-1]
assert_equal(msgSequence, blockcount+1)
assert_equal(hashRPC, hashZMQ) #blockhash from generate must be equal to the hash received over zmq assert_equal(hashRPC, hashZMQ) #blockhash from generate must be equal to the hash received over zmq