Skip to content

Commit 13e31dd

Browse files
author
MarcoFalke
committed
Merge #11791: [tests] Rename NodeConn and NodeConnCB
873beca [tests] Rename NodeConn and NodeConnCB (John Newbery) Pull request description: Final step in #11518 NodeConn -> P2PConnection NodeConnCB -> P2PInterface This is basically just a rename. Should be an easy review. Tree-SHA512: fe1204b2b3d8182c5e324ffa7cb4099a47ef8536380e0bb9d37a5fccf76a24f548d1f1a7988ab8f830986a3058b670696de3fc891af5e5f75dbeb4e3273005d7
2 parents fbce66a + 873beca commit 13e31dd

18 files changed

+50
-55
lines changed

test/functional/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ wrappers for them, `msg_block`, `msg_tx`, etc).
6363
with the bitcoind(s) being tested (using python's asyncore package); the other
6464
implements the test logic.
6565

66-
- `NodeConn` is the class used to connect to a bitcoind. If you implement
67-
a callback class that derives from `NodeConnCB` and pass that to the
68-
`NodeConn` object, your code will receive the appropriate callbacks when
69-
events of interest arrive.
66+
- `P2PConnection` is the class used to connect to a bitcoind. `P2PInterface`
67+
contains the higher level logic for processing P2P payloads and connecting to
68+
the Bitcoin Core node application logic. For custom behaviour, subclass the
69+
P2PInterface object and override the callback methods.
7070

71-
- Call `NetworkThread.start()` after all `NodeConn` objects are created to
71+
- Call `NetworkThread.start()` after all `P2PInterface` objects are created to
7272
start the networking thread. (Continue with the test logic in your existing
7373
thread.)
7474

test/functional/assumevalid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
CTxIn,
4040
CTxOut,
4141
NetworkThread,
42-
NodeConnCB,
42+
P2PInterface,
4343
msg_block,
4444
msg_headers)
4545
from test_framework.script import (CScript, OP_TRUE)
4646
from test_framework.test_framework import BitcoinTestFramework
4747
from test_framework.util import assert_equal
4848

49-
class BaseNode(NodeConnCB):
49+
class BaseNode(P2PInterface):
5050
def send_header_for_blocks(self, new_blocks):
5151
headers_message = msg_headers()
5252
headers_message.headers = [CBlockHeader(b) for b in new_blocks]

test/functional/bip65-cltv-p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def set_test_params(self):
6666
self.setup_clean_chain = True
6767

6868
def run_test(self):
69-
self.nodes[0].add_p2p_connection(NodeConnCB())
69+
self.nodes[0].add_p2p_connection(P2PInterface())
7070

7171
NetworkThread().start() # Start up network handling in another thread
7272

test/functional/bipdersig-p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def set_test_params(self):
5454
self.setup_clean_chain = True
5555

5656
def run_test(self):
57-
self.nodes[0].add_p2p_connection(NodeConnCB())
57+
self.nodes[0].add_p2p_connection(P2PInterface())
5858

5959
NetworkThread().start() # Start up network handling in another thread
6060

test/functional/example_test.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
from test_framework.mininode import (
1919
CInv,
2020
NetworkThread,
21-
NodeConnCB,
21+
P2PInterface,
2222
mininode_lock,
2323
msg_block,
2424
msg_getdata,
25+
NODE_NETWORK,
2526
)
2627
from test_framework.test_framework import BitcoinTestFramework
2728
from test_framework.util import (
@@ -30,15 +31,15 @@
3031
wait_until,
3132
)
3233

33-
# NodeConnCB is a class containing callbacks to be executed when a P2P
34-
# message is received from the node-under-test. Subclass NodeConnCB and
34+
# P2PInterface is a class containing callbacks to be executed when a P2P
35+
# message is received from the node-under-test. Subclass P2PInterface and
3536
# override the on_*() methods if you need custom behaviour.
36-
class BaseNode(NodeConnCB):
37+
class BaseNode(P2PInterface):
3738
def __init__(self):
38-
"""Initialize the NodeConnCB
39+
"""Initialize the P2PInterface
3940
4041
Used to inialize custom properties for the Node that aren't
41-
included by default in the base class. Be aware that the NodeConnCB
42+
included by default in the base class. Be aware that the P2PInterface
4243
base class already stores a counter for each P2P message type and the
4344
last received message of each type, which should be sufficient for the
4445
needs of most tests.
@@ -174,7 +175,7 @@ def run_test(self):
174175
block = create_block(self.tip, create_coinbase(height), self.block_time)
175176
block.solve()
176177
block_message = msg_block(block)
177-
# Send message is used to send a P2P message to the node over our NodeConn connection
178+
# Send message is used to send a P2P message to the node over our P2PInterface
178179
self.nodes[0].p2p.send_message(block_message)
179180
self.tip = block.sha256
180181
blocks.append(self.tip)
@@ -199,12 +200,12 @@ def run_test(self):
199200
self.nodes[2].p2p.send_message(getdata_request)
200201

201202
# wait_until() will loop until a predicate condition is met. Use it to test properties of the
202-
# NodeConnCB objects.
203+
# P2PInterface objects.
203204
wait_until(lambda: sorted(blocks) == sorted(list(self.nodes[2].p2p.block_receive_map.keys())), timeout=5, lock=mininode_lock)
204205

205206
self.log.info("Check that each block was received only once")
206-
# The network thread uses a global lock on data access to the NodeConn objects when sending and receiving
207-
# messages. The test thread should acquire the global lock before accessing any NodeConn data to avoid locking
207+
# The network thread uses a global lock on data access to the P2PConnection objects when sending and receiving
208+
# messages. The test thread should acquire the global lock before accessing any P2PConnection data to avoid locking
208209
# and synchronization issues. Note wait_until() acquires this global lock when testing the predicate.
209210
with mininode_lock:
210211
for block in self.nodes[2].p2p.block_receive_map.values():

test/functional/maxuploadtarget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from test_framework.test_framework import BitcoinTestFramework
1818
from test_framework.util import *
1919

20-
class TestNode(NodeConnCB):
20+
class TestNode(P2PInterface):
2121
def __init__(self):
2222
super().__init__()
2323
self.block_receive_map = defaultdict(int)

test/functional/p2p-acceptblock.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Setup: two nodes, node0+node1, not connected to each other. Node1 will have
88
nMinimumChainWork set to 0x10, so it won't process low-work unrequested blocks.
99
10-
We have one NodeConn connection to node0 called test_node, and one to node1
10+
We have one P2PInterface connection to node0 called test_node, and one to node1
1111
called min_work_node.
1212
1313
The test:
@@ -79,9 +79,9 @@ def setup_network(self):
7979
def run_test(self):
8080
# Setup the p2p connections and start up the network thread.
8181
# test_node connects to node0 (not whitelisted)
82-
test_node = self.nodes[0].add_p2p_connection(NodeConnCB())
83-
# min_work_node connects to node1
84-
min_work_node = self.nodes[1].add_p2p_connection(NodeConnCB())
82+
test_node = self.nodes[0].add_p2p_connection(P2PInterface())
83+
# min_work_node connects to node1 (whitelisted)
84+
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface())
8585

8686
NetworkThread().start() # Start up network handling in another thread
8787

@@ -207,7 +207,7 @@ def run_test(self):
207207
# disconnect/reconnect first
208208

209209
self.nodes[0].disconnect_p2ps()
210-
test_node = self.nodes[0].add_p2p_connection(NodeConnCB())
210+
test_node = self.nodes[0].add_p2p_connection(P2PInterface())
211211

212212
test_node.wait_for_verack()
213213
test_node.send_message(msg_block(block_h1f))
@@ -292,7 +292,7 @@ def run_test(self):
292292
test_node.wait_for_disconnect()
293293

294294
self.nodes[0].disconnect_p2ps()
295-
test_node = self.nodes[0].add_p2p_connection(NodeConnCB())
295+
test_node = self.nodes[0].add_p2p_connection(P2PInterface())
296296

297297
NetworkThread().start() # Start up network handling in another thread
298298
test_node.wait_for_verack()

test/functional/p2p-compactblocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from test_framework.script import CScript, OP_TRUE
1616

1717
# TestNode: A peer we use to send messages to bitcoind, and store responses.
18-
class TestNode(NodeConnCB):
18+
class TestNode(P2PInterface):
1919
def __init__(self):
2020
super().__init__()
2121
self.last_sendcmpct = []

test/functional/p2p-feefilter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def allInvsMatch(invsExpected, testnode):
2222
time.sleep(1)
2323
return False
2424

25-
class TestNode(NodeConnCB):
25+
class TestNode(P2PInterface):
2626
def __init__(self):
2727
super().__init__()
2828
self.txinvs = []

test/functional/p2p-fingerprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from test_framework.mininode import (
1515
CInv,
1616
NetworkThread,
17-
NodeConnCB,
17+
P2PInterface,
1818
msg_headers,
1919
msg_block,
2020
msg_getdata,
@@ -75,7 +75,7 @@ def last_header_equals(self, expected_hash, node):
7575
# This does not currently test that stale blocks timestamped within the
7676
# last month but that have over a month's worth of work are also withheld.
7777
def run_test(self):
78-
node0 = self.nodes[0].add_p2p_connection(NodeConnCB())
78+
node0 = self.nodes[0].add_p2p_connection(P2PInterface())
7979

8080
NetworkThread().start()
8181
node0.wait_for_verack()

0 commit comments

Comments
 (0)