mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-02 16:59:44 +01:00
[tests] Make NodeConnCB a subclass of NodeConn
This makes NodeConnCB a subclass of NodeConn, and removes the need for the client code to know anything about the implementation details of NodeConnCB. NodeConn can now be swapped out for any other implementation of a low-level connection without changing client code.
This commit is contained in:
@@ -14,7 +14,6 @@ import subprocess
|
||||
import time
|
||||
|
||||
from .authproxy import JSONRPCException
|
||||
from .mininode import NodeConn
|
||||
from .util import (
|
||||
assert_equal,
|
||||
get_rpc_proxy,
|
||||
@@ -158,7 +157,7 @@ class TestNode():
|
||||
self.encryptwallet(passphrase)
|
||||
self.wait_until_stopped()
|
||||
|
||||
def add_p2p_connection(self, p2p_conn, **kwargs):
|
||||
def add_p2p_connection(self, p2p_conn, *args, **kwargs):
|
||||
"""Add a p2p connection to the node.
|
||||
|
||||
This method adds the p2p connection to the self.p2ps list and also
|
||||
@@ -167,9 +166,9 @@ class TestNode():
|
||||
kwargs['dstport'] = p2p_port(self.index)
|
||||
if 'dstaddr' not in kwargs:
|
||||
kwargs['dstaddr'] = '127.0.0.1'
|
||||
|
||||
p2p_conn.peer_connect(*args, **kwargs)
|
||||
self.p2ps.append(p2p_conn)
|
||||
kwargs.update({'callback': p2p_conn})
|
||||
p2p_conn.add_connection(NodeConn(**kwargs))
|
||||
|
||||
return p2p_conn
|
||||
|
||||
@@ -185,10 +184,8 @@ class TestNode():
|
||||
def disconnect_p2ps(self):
|
||||
"""Close all p2p connections to the node."""
|
||||
for p in self.p2ps:
|
||||
# Connection could have already been closed by other end.
|
||||
if p.connection is not None:
|
||||
p.connection.disconnect_node()
|
||||
self.p2ps = []
|
||||
p.peer_disconnect()
|
||||
del self.p2ps[:]
|
||||
|
||||
|
||||
class TestNodeCLI():
|
||||
|
||||
Reference in New Issue
Block a user