mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 21:42:47 +01:00
b07a7b810c
* Merge #11796: [tests] Functional test naming convention5fecd84
[tests] Remove redundant import in blocktools.py test (Anthony Towns)9b20bb4
[tests] Check tests conform to naming convention (Anthony Towns)7250b4e
[tests] README.md nit fixes (Anthony Towns)82b2712
[tests] move witness util functions to blocktools.py (John Newbery)1e10854
[tests] [docs] update README for new test naming scheme (John Newbery) Pull request description: Splitting #11774 into two parts -- this part updates the README with the proposed naming convention, and adds some checks to test_runner.py that the number of tests violating the naming convention doesn't increase too much. Idea is this part of the change should not introduce merge conflicts or require much rebasing, so reviews of the complicated bits won't become invalidated too often; while the second part will just be file renames, which will require regular rebasing and will introduce merge conflicts with pending PRs, but can be merged later, and should also be much easier to review, since it will only include relatively trivial changes. Tree-SHA512: b96557d41714addbbfe2aed62fb5a48639eaeb1eb3aba30ac1b3a86bb3cb8d796c6247f9c414c4695c4bf54c0ec9968ac88e2f88fb62483bc1a2f89368f7fc80 * update violation count Signed-off-by: pasta <pasta@dashboost.org> * Merge #11774: [tests] Rename functional tests6f881cc880
[tests] Remove EXPECTED_VIOLATION_COUNT (Anthony Towns)3150b3fea7
[tests] Rename misc functional tests. (Anthony Towns)81b79f2c39
[tests] Rename rpc_* functional tests. (Anthony Towns)61b8f7f273
[tests] Rename p2p_* functional tests. (Anthony Towns)90600bc7db
[tests] Rename wallet_* functional tests. (Anthony Towns)ca6523d0c8
[tests] Rename feature_* functional tests. (Anthony Towns) Pull request description: This PR changes the functional tests to have a consistent naming scheme: tests for individual RPC methods are named rpc_... tests for interfaces (REST, ZMQ, RPC features) are named interface_... tests that explicitly test the p2p interface are named p2p_... tests for wallet features are named wallet_... tests for mining features are named mining_... tests for mempool behaviour are named mempool_... tests for full features that aren't wallet/mining/mempool are named feature_... Rationale: it's sometimes difficult for new contributors to know what's already covered by existing tests and where new tests should be added. Naming in a consistent fashion makes it easier to see what's already covered at a glance. Tree-SHA512: 4246790552d42bbd95f6d5bdf67702b81b3b2c583ce7eaf1fe6d8e254721279b47315973c6e9ae82dad6e4c747f12188160764bf2624c0f8f3b4d39330ec8b16 * rename tests and edit associated strings to align test-suite with test name standards Signed-off-by: pasta <pasta@dashboost.org> * fix grammar in test/functional/test_runner.py Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> * ci: Fix excluded test names * rename feature_privatesend.py to rpc_privatesend.py Signed-off-by: pasta <pasta@dashboost.org> Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com> Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> Co-authored-by: xdustinface <xdustinfacex@gmail.com>
123 lines
5.0 KiB
Python
Executable File
123 lines
5.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2017 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Tests NODE_NETWORK_LIMITED.
|
|
|
|
Tests that a node configured with -prune=550 signals NODE_NETWORK_LIMITED correctly
|
|
and that it responds to getdata requests for blocks correctly:
|
|
- send a block within 288 + 2 of the tip
|
|
- disconnect peers who request blocks older than that."""
|
|
from test_framework.messages import CInv, msg_getdata, NODE_BLOOM, NODE_NETWORK_LIMITED, msg_verack
|
|
from test_framework.mininode import P2PInterface, wait_until, mininode_lock, network_thread_start, network_thread_join
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal, disconnect_nodes, connect_nodes_bi, sync_blocks
|
|
|
|
import sys
|
|
|
|
class P2PIgnoreInv(P2PInterface):
|
|
firstAddrnServices = 0
|
|
def on_inv(self, message):
|
|
# The node will send us invs for other blocks. Ignore them.
|
|
pass
|
|
def on_addr(self, message):
|
|
self.firstAddrnServices = message.addrs[0].nServices
|
|
def wait_for_addr(self, timeout=5):
|
|
test_function = lambda: self.last_message.get("addr")
|
|
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
|
def send_getdata_for_block(self, blockhash):
|
|
getdata_request = msg_getdata()
|
|
getdata_request.inv.append(CInv(2, int(blockhash, 16)))
|
|
self.send_message(getdata_request)
|
|
|
|
class NodeNetworkLimitedTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 3
|
|
self.stderr = sys.stdout
|
|
self.extra_args = [['-prune=550', '-txindex=0', '-addrmantest'], [], []]
|
|
|
|
def disconnect_all(self):
|
|
disconnect_nodes(self.nodes[0], 1)
|
|
disconnect_nodes(self.nodes[1], 0)
|
|
disconnect_nodes(self.nodes[2], 1)
|
|
disconnect_nodes(self.nodes[2], 0)
|
|
disconnect_nodes(self.nodes[0], 2)
|
|
disconnect_nodes(self.nodes[1], 2)
|
|
|
|
def setup_network(self):
|
|
super(NodeNetworkLimitedTest, self).setup_network()
|
|
self.disconnect_all()
|
|
|
|
def run_test(self):
|
|
node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
|
|
network_thread_start()
|
|
node.wait_for_verack()
|
|
|
|
expected_services = NODE_BLOOM | NODE_NETWORK_LIMITED
|
|
|
|
self.log.info("Check that node has signalled expected services.")
|
|
assert_equal(node.nServices, expected_services)
|
|
|
|
self.log.info("Check that the localservices is as expected.")
|
|
assert_equal(int(self.nodes[0].getnetworkinfo()['localservices'], 16), expected_services)
|
|
|
|
self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
|
|
connect_nodes_bi(self.nodes, 0, 1)
|
|
blocks = self.nodes[1].generate(292)
|
|
sync_blocks([self.nodes[0], self.nodes[1]])
|
|
|
|
self.log.info("Make sure we can max retrieve block at tip-288.")
|
|
node.send_getdata_for_block(blocks[1]) # last block in valid range
|
|
node.wait_for_block(int(blocks[1], 16), timeout=3)
|
|
|
|
self.log.info("Requesting block at height 2 (tip-289) must fail (ignored).")
|
|
node.send_getdata_for_block(blocks[0]) # first block outside of the 288+2 limit
|
|
node.wait_for_disconnect(5)
|
|
|
|
self.log.info("Check local address relay, do a fresh connection.")
|
|
self.nodes[0].disconnect_p2ps()
|
|
network_thread_join()
|
|
node1 = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
|
|
network_thread_start()
|
|
node1.wait_for_verack()
|
|
node1.send_message(msg_verack())
|
|
|
|
node1.wait_for_addr()
|
|
#must relay address with NODE_NETWORK_LIMITED
|
|
assert_equal(node1.firstAddrnServices, 1028) # Not 1036 like bitcoin, because NODE_WITNESS = 1 << 3 = 8
|
|
|
|
self.nodes[0].disconnect_p2ps()
|
|
node1.wait_for_disconnect()
|
|
|
|
# connect unsynced node 2 with pruned NODE_NETWORK_LIMITED peer
|
|
# because node 2 is in IBD and node 0 is a NODE_NETWORK_LIMITED peer, sync must not be possible
|
|
connect_nodes_bi(self.nodes, 0, 2)
|
|
try:
|
|
sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
|
|
except:
|
|
pass
|
|
# node2 must remain at heigh 0
|
|
assert_equal(self.nodes[2].getblockheader(self.nodes[2].getbestblockhash())['height'], 0)
|
|
|
|
# now connect also to node 1 (non pruned)
|
|
connect_nodes_bi(self.nodes, 1, 2)
|
|
|
|
# sync must be possible
|
|
sync_blocks(self.nodes)
|
|
|
|
# disconnect all peers
|
|
self.disconnect_all()
|
|
|
|
# mine 10 blocks on node 0 (pruned node)
|
|
self.nodes[0].generate(10)
|
|
|
|
# connect node1 (non pruned) with node0 (pruned) and check if the can sync
|
|
connect_nodes_bi(self.nodes, 0, 1)
|
|
|
|
# sync must be possible, node 1 is no longer in IBD and should therefore connect to node 0 (NODE_NETWORK_LIMITED)
|
|
sync_blocks([self.nodes[0], self.nodes[1]])
|
|
|
|
if __name__ == '__main__':
|
|
NodeNetworkLimitedTest().main()
|