[RPC] Add RPC long poll notifications #7949

Open
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+437 −0
Split
@@ -141,6 +141,7 @@
'segwit.py',
'importprunedfunds.py',
'signmessages.py',
+ 'rpcsignals.py'
]
if ENABLE_ZMQ:
testScripts.append('zmq_test.py')
View
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+# Copyright (c) 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.
+
+# Exercise the rpc signals API
+
+from test_framework.test_framework import BitcoinTestFramework
+from test_framework.util import *
+import threading
+import uuid
+
+class pollThread (threading.Thread):
+ def __init__(self, threadID, node, clientUUID):
+ threading.Thread.__init__(self)
+ self.threadID = threadID
+ self.node = node
+ self.uuid = clientUUID
+ def run(self):
+ self.node.pollnotifications(self.uuid, 5)
+
+class RpcSignalsTest(BitcoinTestFramework):
+
+ def pollthread(self, node):
+ print("thread")
+
+ def setup_nodes(self):
+ return start_nodes(4, self.options.tmpdir)
+
+ def run_test(self):
+ clientUUID = str(uuid.uuid1())
+ try:
+ self.nodes[0].getregisterednotifications(clientUUID)
+ raise AssertionError("ClientUUID should not exists")
+ except JSONRPCException as e:
+ assert(e.error['code']==-8)
+
+ self.nodes[0].setregisterednotifications(clientUUID, ["hashblock", "hashtx"])
+ data = self.nodes[0].getregisterednotifications(clientUUID)
+ assert("hashblock" in data)
+ assert("hashtx" in data)
+
+ self.nodes[0].generate(1)
+ data = self.nodes[0].pollnotifications(clientUUID)
+ assert(len(data) == 2)
+
+ myThread = pollThread(1, self.nodes[0], clientUUID)
+ myThread.start()
+ time.sleep(3)
+ assert(myThread.isAlive() == True)
+ time.sleep(5)
+ assert(myThread.isAlive() == False)
+ myThread.join()
+
+ self.nodes[0].setregisterednotifications(clientUUID, [])
+ data = self.nodes[0].getregisterednotifications(clientUUID)
+ assert(len(data) == 0)
+ self.nodes[0].generate(1)
+ data = self.nodes[0].pollnotifications(clientUUID, 5)
+ assert(len(data) == 0)
+
+if __name__ == '__main__':
+ RpcSignalsTest().main()
+
View
@@ -184,6 +184,7 @@ libbitcoin_server_a_SOURCES = \
rpc/mining.cpp \
rpc/misc.cpp \
rpc/net.cpp \
+ rpc/notifications.cpp \
rpc/rawtransaction.cpp \
rpc/server.cpp \
script/sigcache.cpp \
View
@@ -104,6 +104,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "setban", 3 },
{ "getmempoolancestors", 1 },
{ "getmempooldescendants", 1 },
+ { "setregisterednotifications", 1 },
+ { "pollnotifications", 1 },
};
class CRPCConvertTable
Oops, something went wrong.