Skip to content

Commit

Permalink
fix zmq rpc test and zmq exmaple tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Jun 6, 2015
1 parent a1ed371 commit fe2e286
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions contrib/zmq/zmq_sub.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import binascii

port = 28332
topic1 = "BLK"
topic2 = "TXN"
topic1 = "block"
topic2 = "tx"
topic_len = len(topic1)

zmqContext = zmq.Context()
Expand All @@ -31,9 +31,9 @@ def handleTX(tx):
msg_topic = str(msg[0])
msg_data = msg[1]

if msg_topic == "TXN":
if msg_topic == "tx":
handleTX(msg_data)
elif msg_topic == "BLK":
elif msg_topic == "block":
handleBLK(msg_data)

except KeyboardInterrupt:
Expand Down
1 change: 1 addition & 0 deletions qa/pull-tester/rpc-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ testScripts=(
'merkle_blocks.py'
'signrawtransactions.py'
'walletbackup.py'
'zmq_test.py'
);
testScriptsExt=(
'bipdersig-p2p.py'
Expand Down
17 changes: 11 additions & 6 deletions qa/rpc-tests/zmq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
# Test ZMQ interface
#

from test_framework import BitcoinTestFramework
from util import *
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
import json
import zmq
import binascii
from mininode import hash256
from test_framework.mininode import hash256

try:
import http.client as httplib
Expand All @@ -37,14 +37,14 @@ def handleTX(self, tx):
def setup_nodes(self):
self.zmqContext = zmq.Context()
self.zmqSubSocket = self.zmqContext.socket(zmq.SUB)
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "BLK")
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "TXN")
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "block")
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "tx")
self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % self.port)

# Note: proxies are not used to connect to local nodes
# this is because the proxy to use is based on CService.GetNetwork(), which return NET_UNROUTABLE for localhost
return start_nodes(4, self.options.tmpdir, extra_args=[
['-zmqpub=tcp://127.0.0.1:'+str(self.port)],
['-zmqpubhashblock=tcp://127.0.0.1:'+str(self.port), '-zmqpubhashtransaction=tcp://127.0.0.1:'+str(self.port)],
[],
[],
[]
Expand All @@ -54,7 +54,9 @@ def run_test(self):

genhashes = self.nodes[0].generate(1);

print "goon"
msg = self.zmqSubSocket.recv()
print "goon2"
blkhash = self.handleBLK(msg[3:])
assert_equal(genhashes[0], blkhash) #blockhash from generate must be equal to the hash received over zmq

Expand All @@ -77,8 +79,11 @@ def run_test(self):
self.sync_all()

#now we should receive a zmq msg because the tx was broadcastet
print "goon"
msg = self.zmqSubSocket.recv()
print "ok"
hashZMQ = self.handleTX(msg[3:])
print hashZMQ
assert_equal(hashRPC, hashZMQ) #blockhash from generate must be equal to the hash received over zmq


Expand Down

0 comments on commit fe2e286

Please sign in to comment.