mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
Merge bitcoin/bitcoin#22118: test: check anchors.dat when node starts for the first time
ef99d03c2bbb6b5fa5ff3d3d3cb9c5da7d471133 test: check anchors.dat when node starts for the first time (bruno) Pull request description: See https://github.com/bitcoin/bitcoin/pull/21338#discussion_r598406712, https://github.com/bitcoin/bitcoin/pull/21338#discussion_r598406187, https://github.com/bitcoin/bitcoin/pull/21338#discussion_r598405613. ACKs for top commit: laanwj: Code review ACK ef99d03c2bbb6b5fa5ff3d3d3cb9c5da7d471133 Tree-SHA512: 505f1f34fbc0c72a92968883be0f1c5f169a4ba3aa8a56e1ce8bc5e514f49e3a17ce51fd40be0073dc4bc06eaeda36dfe90ace843c181170e34643226afd78ef
This commit is contained in:
parent
262c8b6f44
commit
9a1500ab47
@ -2,7 +2,7 @@
|
|||||||
# Copyright (c) 2020 The Bitcoin Core developers
|
# Copyright (c) 2020 The Bitcoin Core developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test Anchors functionality"""
|
"""Test block-relay-only anchors functionality"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -10,6 +10,9 @@ from test_framework.p2p import P2PInterface
|
|||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal
|
from test_framework.util import assert_equal
|
||||||
|
|
||||||
|
INBOUND_CONNECTIONS = 5
|
||||||
|
BLOCK_RELAY_CONNECTIONS = 2
|
||||||
|
|
||||||
|
|
||||||
def check_node_connections(*, node, num_in, num_out):
|
def check_node_connections(*, node, num_in, num_out):
|
||||||
info = node.getnetworkinfo()
|
info = node.getnetworkinfo()
|
||||||
@ -25,19 +28,26 @@ class AnchorsTest(BitcoinTestFramework):
|
|||||||
self.setup_nodes()
|
self.setup_nodes()
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.log.info("Add 2 block-relay-only connections to node 0")
|
node_anchors_path = os.path.join(
|
||||||
for i in range(2):
|
self.nodes[0].datadir, "regtest", "anchors.dat"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.log.info("When node starts, check if anchors.dat doesn't exist")
|
||||||
|
assert not os.path.exists(node_anchors_path)
|
||||||
|
|
||||||
|
self.log.info(f"Add {BLOCK_RELAY_CONNECTIONS} block-relay-only connections to node")
|
||||||
|
for i in range(BLOCK_RELAY_CONNECTIONS):
|
||||||
self.log.debug(f"block-relay-only: {i}")
|
self.log.debug(f"block-relay-only: {i}")
|
||||||
self.nodes[0].add_outbound_p2p_connection(
|
self.nodes[0].add_outbound_p2p_connection(
|
||||||
P2PInterface(), p2p_idx=i, connection_type="block-relay-only"
|
P2PInterface(), p2p_idx=i, connection_type="block-relay-only"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.log.info("Add 5 inbound connections to node 0")
|
self.log.info(f"Add {INBOUND_CONNECTIONS} inbound connections to node")
|
||||||
for i in range(5):
|
for i in range(INBOUND_CONNECTIONS):
|
||||||
self.log.debug(f"inbound: {i}")
|
self.log.debug(f"inbound: {i}")
|
||||||
self.nodes[0].add_p2p_connection(P2PInterface())
|
self.nodes[0].add_p2p_connection(P2PInterface())
|
||||||
|
|
||||||
self.log.info("Check node 0 connections")
|
self.log.info("Check node connections")
|
||||||
check_node_connections(node=self.nodes[0], num_in=5, num_out=2)
|
check_node_connections(node=self.nodes[0], num_in=5, num_out=2)
|
||||||
|
|
||||||
# 127.0.0.1
|
# 127.0.0.1
|
||||||
@ -57,14 +67,10 @@ class AnchorsTest(BitcoinTestFramework):
|
|||||||
self.log.info("Stop node 0")
|
self.log.info("Stop node 0")
|
||||||
self.stop_node(0)
|
self.stop_node(0)
|
||||||
|
|
||||||
node0_anchors_path = os.path.join(
|
|
||||||
self.nodes[0].datadir, "regtest", "anchors.dat"
|
|
||||||
)
|
|
||||||
|
|
||||||
# It should contain only the block-relay-only addresses
|
# It should contain only the block-relay-only addresses
|
||||||
self.log.info("Check the addresses in anchors.dat")
|
self.log.info("Check the addresses in anchors.dat")
|
||||||
|
|
||||||
with open(node0_anchors_path, "rb") as file_handler:
|
with open(node_anchors_path, "rb") as file_handler:
|
||||||
anchors = file_handler.read().hex()
|
anchors = file_handler.read().hex()
|
||||||
|
|
||||||
for port in block_relay_nodes_port:
|
for port in block_relay_nodes_port:
|
||||||
@ -74,11 +80,11 @@ class AnchorsTest(BitcoinTestFramework):
|
|||||||
ip_port = ip + port
|
ip_port = ip + port
|
||||||
assert ip_port not in anchors
|
assert ip_port not in anchors
|
||||||
|
|
||||||
self.log.info("Start node 0")
|
self.log.info("Start node")
|
||||||
self.start_node(0)
|
self.start_node(0)
|
||||||
|
|
||||||
self.log.info("When node starts, check if anchors.dat doesn't exist anymore")
|
self.log.info("When node starts, check if anchors.dat doesn't exist anymore")
|
||||||
assert not os.path.exists(node0_anchors_path)
|
assert not os.path.exists(node_anchors_path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user