@@ -87,7 +87,9 @@ P2P messages. These can be found in the following source files:
87
87
88
88
#### Using the P2P interface
89
89
90
- - [ messages.py] ( test_framework/messages.py ) contains all the definitions for objects that pass
90
+ - ` P2P ` s can be used to test specific P2P protocol behavior.
91
+ [ p2p.py] ( test_framework/p2p.py ) contains test framework p2p objects and
92
+ [ messages.py] ( test_framework/messages.py ) contains all the definitions for objects passed
91
93
over the network (` CBlock ` , ` CTransaction ` , etc, along with the network-level
92
94
wrappers for them, ` msg_block ` , ` msg_tx ` , etc).
93
95
@@ -100,8 +102,22 @@ contains the higher level logic for processing P2P payloads and connecting to
100
102
the Bitcoin Core node application logic. For custom behaviour, subclass the
101
103
P2PInterface object and override the callback methods.
102
104
103
- - Can be used to write tests where specific P2P protocol behavior is tested.
104
- Examples tests are [ p2p_unrequested_blocks.py] ( p2p_unrequested_blocks.py ) ,
105
+ ` P2PConnection ` s can be used as such:
106
+
107
+ ``` python
108
+ p2p_conn = node.add_p2p_connection(P2PInterface())
109
+ p2p_conn.send_and_ping(msg)
110
+ ```
111
+
112
+ They can also be referenced by indexing into a ` TestNode ` 's ` p2ps ` list, which
113
+ contains the list of test framework ` p2p ` objects connected to itself
114
+ (it does not include any ` TestNode ` s):
115
+
116
+ ``` python
117
+ node.p2ps[0 ].sync_with_ping()
118
+ ```
119
+
120
+ More examples can be found in [ p2p_unrequested_blocks.py] ( p2p_unrequested_blocks.py ) ,
105
121
[ p2p_compactblocks.py] ( p2p_compactblocks.py ) .
106
122
107
123
#### Prototyping tests
@@ -157,7 +173,7 @@ way is the use the `profile_with_perf` context manager, e.g.
157
173
with node.profile_with_perf(" send-big-msgs" ):
158
174
# Perform activity on the node you're interested in profiling, e.g.:
159
175
for _ in range (10000 ):
160
- node.p2p .send_message(some_large_message)
176
+ node.p2ps[ 0 ] .send_message(some_large_message)
161
177
```
162
178
163
179
To see useful textual output, run
0 commit comments