aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_v2_misbehaving.py
AgeCommit message (Collapse)Author
2024-07-23test: Fix intermittent issue in p2p_v2_misbehaving.pyMarcoFalke
Without the fix, the test could fail intermittently. For example: node0 2024-07-22T16:31:54.104994Z [httpworker.0] [rpc/request.cpp:232] [parse] [rpc] ThreadRPCServer method=setmocktime user=__cookie__ test 2024-07-22T16:31:54.291000Z TestFramework (INFO): Sending first 4 bytes of ellswift which match network magic test 2024-07-22T16:31:54.292000Z TestFramework (INFO): If a response is received, assertion failure would happen in our custom data_received() function test 2024-07-22T16:31:54.292000Z TestFramework.p2p (DEBUG): Connecting to Bitcoin Node: 127.0.0.1:12644 test 2024-07-22T16:31:54.293000Z TestFramework.p2p (DEBUG): Connected & Listening: 127.0.0.1:12644 test 2024-07-22T16:31:54.588000Z TestFramework.p2p (DEBUG): sending 4050 bytes of garbage data test 2024-07-22T16:31:54.588000Z TestFramework (INFO): Sending remaining ellswift and garbage which are different from V1_PREFIX. Since a response is test 2024-07-22T16:31:54.588000Z TestFramework (INFO): expected now, our custom data_received() function wouldn't result in assertion failure node0 2024-07-22T16:31:55.523868Z (mocktime: 2024-07-22T16:31:54Z) [net] [net.cpp:3764] [CNode] [net] Added connection peer=0 node0 2024-07-22T16:31:55.625145Z (mocktime: 2024-07-22T16:31:54Z) [net] [net.cpp:1814] [CreateNodeFromAcceptedSocket] [net] connection from 127.0.0.1:45154 accepted node0 2024-07-22T16:31:55.625769Z (mocktime: 2024-07-22T16:31:54Z) [http] [httpserver.cpp:305] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:33320 node0 2024-07-22T16:31:55.626543Z (mocktime: 2024-07-22T16:31:54Z) [httpworker.1] [rpc/request.cpp:232] [parse] [rpc] ThreadRPCServer method=getpeerinfo user=__cookie__ test 2024-07-22T16:31:55.818000Z TestFramework (ERROR): Unexpected exception caught during testing Traceback (most recent call last): File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 132, in main self.run_test() File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/p2p_v2_misbehaving.py", line 133, in run_test self.test_earlykeyresponse() File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/p2p_v2_misbehaving.py", line 151, in test_earlykeyresponse self.wait_until(lambda: node0.getpeerinfo()[-1]["bytesrecv"] > 4) File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 791, in wait_until return wait_until_helper_internal(test_function, timeout=timeout, timeout_factor=self.options.timeout_factor) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/test_framework/util.py", line 289, in wait_until_helper_internal if predicate(): ^^^^^^^^^^^ File "/ci_container_base/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/test/functional/p2p_v2_misbehaving.py", line 151, in <lambda> self.wait_until(lambda: node0.getpeerinfo()[-1]["bytesrecv"] > 4) ~~~~~~~~~~~~~~~~~~~^^^^ IndexError: list index out of range
2024-07-22Merge bitcoin/bitcoin#30463: qa: Functional test improvementsglozow
a8e3af1a82dd584a1cc3ffbe587e66889f72e3c7 qa: Do not assume running `feature_asmap.py` from source directory (Hennadii Stepanov) 9bf7ca6cad888d460f57d249264dc0062025bb3f qa: Consider `cache` and `config.ini` relative to invocation directory (Hennadii Stepanov) a0473442d1c22043f5a288bd9255c006fd85d947 scripted-diff: Add `__file__` argument to `BitcoinTestFramework.init()` (Hennadii Stepanov) Pull request description: This PR includes changes split from https://github.com/bitcoin/bitcoin/pull/30454. They improve the functional test framework, allowing users to [run individual functional tests](https://github.com/hebasto/bitcoin/issues/146) from the build directory in the new CMake-based build system. This functionality is not available for out-of-source builds using the current Autotools-based build system, which always requires write permissions for the source directory. Nevertheless, this PR can be tested as suggested in https://github.com/bitcoin/bitcoin/pull/30463#issuecomment-2232618421: 1. Make an out-of-source build: ``` $ ./autogen.sh $ mkdir ../build && cd ../build $ ../bitcoin/configure $ make ``` 2. Create a symlink in the build directory to a functional test: ``` $ ln --symbolic ../../../bitcoin/test/functional/wallet_disable.py ./test/functional/ ``` 3. Run this symlink: ``` $ ./test/functional/wallet_disable.py ``` The last command fails on the master branch: ``` Traceback (most recent call last): File "/home/hebasto/git/build/./test/functional/wallet_disable.py", line 31, in <module> DisableWalletTest().main() ^^^^^^^^^^^^^^^^^^^ File "/home/hebasto/git/bitcoin/test/functional/test_framework/test_framework.py", line 106, in __init__ self.parse_args() File "/home/hebasto/git/bitcoin/test/functional/test_framework/test_framework.py", line 210, in parse_args config.read_file(open(self.options.configfile)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/home/hebasto/git/bitcoin/test/config.ini' ``` and succeeds with this PR. ACKs for top commit: maflcko: tested ACK a8e3af1a82dd584a1cc3ffbe587e66889f72e3c 🎨 glozow: ACK a8e3af1a82dd584a1cc3ffbe587e66889f72e3c7, tested with the steps in op stickies-v: ACK a8e3af1a82dd584a1cc3ffbe587e66889f72e3c7 Tree-SHA512: 899e4efc09edec13ea3f5b47825d03173fb21d3569c360deda7fa6a56b99b4d24e09ad4f0883bad1ee926b1c706e47ba07c6a6160c63c07c82b3cf4ae5816e91
2024-07-17test: bump mocktime after node has received and sent bytesstratospher
a different error message "socket no message in first %i seconds" will be displayed if m_last_send=0 or if m_last_recv is 0. make the test robust by ensuring that they will not be 0 before bumping mocktime.
2024-07-16scripted-diff: Add `__file__` argument to `BitcoinTestFramework.init()`Hennadii Stepanov
-BEGIN VERIFY SCRIPT- sed -i -e 's/\s*().main\s*()/(__file__).main()/' $(git ls-files test/functional/*.py) sed -i -e 's/def __init__(self)/def __init__(self, test_file)/' test/functional/test_framework/test_framework.py -END VERIFY SCRIPT-
2024-07-15test: Fix intermittent failure in p2p_v2_misbehaving.pystratospher
The ellswift bytes are computed in the NetworkThread and sent in the MainThread. Add a `wait_until()` to make sure that ellswift computation is completed in NetworkThread before sending it in the MainThread. Also wait until bytes sent are actually received and use mocktime for more robust disconnection checking.
2024-06-21test: Check that non empty version packet is ignored and no disconnection ↵stratospher
happens This test type is represented using SEND_NON_EMPTY_VERSION_PACKET.
2024-06-21test: Check that disconnection happens when AAD isn't filledstratospher
This test type is represented using SEND_NO_AAD. If AAD of the first encrypted packet sent after the garbage terminator (optional decoy packet/version packet) hasn't been filled, disconnection happens.
2024-06-21test: Check that disconnection happens when garbage sent/received are differentstratospher
This test type is represented using WRONG_GARBAGE. Here, garbage bytes sent to TestNode are assumed to be tampered with and do not correspond to the garbage bytes which P2PInterface calculated and uses.
2024-06-21test: Check that disconnection happens when wrong garbage terminator is sentstratospher
This test type is represented using WRONG_GARBAGE_TERMINATOR. since the wrong garbage terminator is sent to TestNode, TestNode will interpret all of the gabage bytes, wrong garbage terminator, decoy messages and version packet it receives as garbage bytes. If the length of all these is more than 4095 + 16, it will result in a missing garbage terminator error. otherwise, it will result in a V2 handshake timeout error. Send only MAX_GARBAGE_LEN//2 bytes of garbage data to TestNode so that the total length received by the TestNode is at max = (MAX_GARBAGE_LEN//2) + 16 + 10*120 + 20 = 3283 bytes (which is less than 4095 + 16 bytes) and we get a consistent V2 handshake timeout error message. If we do not limit the garbage length sent, we will intermittently get both missing garbage terminator error and V2 handshake timeout error based on the garbage length and decoy packets length which are chosen at random.
2024-06-21test: Check that disconnection happens when >4095 garbage bytes is sentstratospher
This test type is represented using EXCESS_GARBAGE.
2024-06-17test: Introduce test types and modify v2 handshake function accordinglystratospher
Prior to this commit, TestEncryptedP2PState would always send initial_v2_handshake bytes in 2 parts (as required by early key response test). For generalising this test and having different v2 handshake behaviour based on the test type, special behaviours like sending initial_v2_handshake bytes in 2 parts are executed only if test_type is set to EARLY_KEY_RESPONSE.
2024-03-11test: Rename early key response test and move random_bitflip to utilstratospher
Early key response test is a special kind of test which requires modified v2 handshake functions. More such tests can be added where v2 handshake functions send incorrect garbage terminator, excess garbage bytes etc.. Hence, rename p2p_v2_earlykey.py to a general test file name - p2p_v2_misbehaving.py. random_bitflip function (used in signature tests prior to this commit) can be used in p2p_v2_misbehaving test to generate wrong garbage terminator, wrong garbage bytes etc.. So, move the function to util.