Merge pull request #7171

2f601d2 test: remove necessity to call create_callback_map (Wladimir J. van der Laan)
This commit is contained in:
Wladimir J. van der Laan 2015-12-07 12:43:31 +01:00
commit 82bcf405f6
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
7 changed files with 2 additions and 32 deletions

View File

@ -47,10 +47,7 @@ implements the test logic.
* ```NodeConn``` is the class used to connect to a bitcoind. If you implement
a callback class that derives from ```NodeConnCB``` and pass that to the
```NodeConn``` object, your code will receive the appropriate callbacks when
events of interest arrive. NOTE: be sure to call
```self.create_callback_map()``` in your derived classes' ```__init__```
function, so that the correct mappings are set up between p2p messages and your
callback functions.
events of interest arrive.
* You can pass the same handler to multiple ```NodeConn```'s if you like, or pass
different ones to each -- whatever makes the most sense for your test.

View File

@ -34,7 +34,6 @@ class TestManager(NodeConnCB):
def __init__(self):
NodeConnCB.__init__(self)
self.log = logging.getLogger("BlockRelayTest")
self.create_callback_map()
def add_new_connection(self, connection):
self.connection = connection

View File

@ -25,7 +25,6 @@ if uploadtarget has been reached.
class TestNode(NodeConnCB):
def __init__(self):
NodeConnCB.__init__(self)
self.create_callback_map()
self.connection = None
self.ping_counter = 1
self.last_pong = msg_pong()

View File

@ -62,7 +62,6 @@ The test:
class TestNode(NodeConnCB):
def __init__(self):
NodeConnCB.__init__(self)
self.create_callback_map()
self.connection = None
self.ping_counter = 1
self.last_pong = msg_pong()

View File

@ -70,7 +70,6 @@ f. Announce 1 more header that builds on that fork.
class BaseNode(NodeConnCB):
def __init__(self):
NodeConnCB.__init__(self)
self.create_callback_map()
self.connection = None
self.last_inv = None
self.last_headers = None

View File

@ -45,7 +45,6 @@ class TestNode(NodeConnCB):
def __init__(self, block_store, tx_store):
NodeConnCB.__init__(self)
self.create_callback_map()
self.conn = None
self.bestblockhash = None
self.block_store = block_store

View File

@ -1015,32 +1015,10 @@ class NodeConnCB(object):
return
time.sleep(0.05)
# Derived classes should call this function once to set the message map
# which associates the derived classes' functions to incoming messages
def create_callback_map(self):
self.cbmap = {
"version": self.on_version,
"verack": self.on_verack,
"addr": self.on_addr,
"alert": self.on_alert,
"inv": self.on_inv,
"getdata": self.on_getdata,
"getblocks": self.on_getblocks,
"tx": self.on_tx,
"block": self.on_block,
"getaddr": self.on_getaddr,
"ping": self.on_ping,
"pong": self.on_pong,
"headers": self.on_headers,
"getheaders": self.on_getheaders,
"reject": self.on_reject,
"mempool": self.on_mempool
}
def deliver(self, conn, message):
with mininode_lock:
try:
self.cbmap[message.command](conn, message)
getattr(self, 'on_' + message.command)(conn, message)
except:
print "ERROR delivering %s (%s)" % (repr(message),
sys.exc_info()[0])