mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Merge pull request #7171
2f601d2
test: remove necessity to call create_callback_map (Wladimir J. van der Laan)
This commit is contained in:
commit
82bcf405f6
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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])
|
||||
|
Loading…
Reference in New Issue
Block a user