diff --git a/doc/functional-tests.md b/doc/functional-tests.md --- a/doc/functional-tests.md +++ b/doc/functional-tests.md @@ -338,9 +338,12 @@ #### Using the P2P interface -- [messages.py](/test/functional/test_framework/messages.py) contains all the -definitions for objects that pass over the network (`CBlock`, `CTransaction`, -etc, along with the network-level wrappers for them, `msg_block`, `msg_tx`, etc). +- `P2P`s can be used to test specific P2P protocol behavior. +[p2p.py](/test/functional/test_framework/p2p.py) contains test framework +p2p objects and [messages.py](/test/functional/test_framework/messages.py) +contains all the definitions for objects passed over the network (`CBlock`, +`CTransaction`, etc, along with the network-level wrappers for them, +`msg_block`, `msg_tx`, etc). - P2P tests have two threads. One thread handles all network communication with the bitcoind(s) being tested in a callback-based event loop; the other @@ -351,8 +354,22 @@ the Bitcoin Core node application logic. For custom behaviour, subclass the P2PInterface object and override the callback methods. -- Can be used to write tests where specific P2P protocol behavior is tested. -Examples tests are [p2p_unrequested_blocks.py](/test/functional/p2p_unrequested_blocks.py), +`P2PConnection`s can be used as such: + +```python +p2p_conn = node.add_p2p_connection(P2PInterface()) +p2p_conn.send_and_ping(msg) +``` + +They can also be referenced by indexing into a `TestNode`'s `p2ps` list, which +contains the list of test framework `p2p` objects connected to itself +(it does not include any `TestNode`s): + +```python +node.p2ps[0].sync_with_ping() +``` + +More examples can be found in [p2p_unrequested_blocks.py](/test/functional/p2p_unrequested_blocks.py), [p2p_compactblocks.py](/test/functional/p2p_compactblocks.py). #### Prototyping tests