copy key file to bootnode folder in python tests (#260)
Some checks are pending
abi-consistent-check / build-and-compare (push) Waiting to run
code-coverage / unittest-cov (push) Waiting to run
rust / check (push) Waiting to run
rust / test (push) Waiting to run
rust / lints (push) Waiting to run
functional-test / test (push) Waiting to run

This commit is contained in:
Bo QIU 2024-11-06 14:01:47 +08:00 committed by GitHub
parent bcbd8b3baa
commit baf0521c99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 13 deletions

View File

@ -1,3 +1,5 @@
import os
from web3 import Web3 from web3 import Web3
ZGS_CONFIG = { ZGS_CONFIG = {
@ -22,6 +24,8 @@ ZGS_CONFIG = {
} }
} }
CONFIG_DIR = os.path.dirname(__file__)
ZGS_KEY_FILE = os.path.join(CONFIG_DIR, "zgs", "network", "key")
ZGS_NODEID = "16Uiu2HAmLkGFUbNFYdhuSbTQ5hmnPjFXx2zUDtwQ2uihHpN9YNNe" ZGS_NODEID = "16Uiu2HAmLkGFUbNFYdhuSbTQ5hmnPjFXx2zUDtwQ2uihHpN9YNNe"
BSC_CONFIG = dict( BSC_CONFIG = dict(

View File

@ -1 +0,0 @@
enr:-Ly4QJZwz9htAorBIx_otqoaRFPohX7NQJ31iBB6mcEhBiuPWsOnigc1ABQsg6tLU1OirQdLR6aEvv8SlkkfIbV72T8CgmlkgnY0gmlwhH8AAAGQbmV0d29ya19pZGVudGl0eZ8oIwAAAAAAADPyz8cpvYcPpUtQMmYOBrTPKn-UAAIAiXNlY3AyNTZrMaEDeDdgnDgLPkxNxB39jKb9f1Na30t6R9vVolpTk5zu-hODdGNwgir4g3VkcIIq-A

View File

@ -3,7 +3,7 @@
import os import os
import time import time
from config.node_config import ZGS_NODEID from config.node_config import ZGS_KEY_FILE, ZGS_NODEID
from test_framework.test_framework import TestFramework from test_framework.test_framework import TestFramework
from utility.utils import p2p_port from utility.utils import p2p_port
@ -17,13 +17,9 @@ class NetworkDiscoveryTest(TestFramework):
self.num_nodes = 3 self.num_nodes = 3
# setup for node 0 as bootnode # setup for node 0 as bootnode
tests_dir = os.path.dirname(__file__) self.zgs_node_key_files = [ZGS_KEY_FILE]
network_dir = os.path.join(tests_dir, "config", "zgs", "network")
bootnode_port = p2p_port(0) bootnode_port = p2p_port(0)
self.zgs_node_configs[0] = { self.zgs_node_configs[0] = {
# load pre-defined keypair
"network_dir": network_dir,
# enable UDP discovery relevant configs # enable UDP discovery relevant configs
"network_enr_address": "127.0.0.1", "network_enr_address": "127.0.0.1",
"network_enr_tcp_port": bootnode_port, "network_enr_tcp_port": bootnode_port,

View File

@ -3,7 +3,7 @@
import os import os
import time import time
from config.node_config import ZGS_NODEID from config.node_config import ZGS_KEY_FILE, ZGS_NODEID
from test_framework.test_framework import TestFramework from test_framework.test_framework import TestFramework
from utility.utils import p2p_port from utility.utils import p2p_port
@ -17,13 +17,9 @@ class NetworkDiscoveryUpgradeTest(TestFramework):
self.num_nodes = 2 self.num_nodes = 2
# setup for node 0 as bootnode # setup for node 0 as bootnode
tests_dir = os.path.dirname(__file__) self.zgs_node_key_files = [ZGS_KEY_FILE]
network_dir = os.path.join(tests_dir, "config", "zgs", "network")
bootnode_port = p2p_port(0) bootnode_port = p2p_port(0)
self.zgs_node_configs[0] = { self.zgs_node_configs[0] = {
# load pre-defined keypair
"network_dir": network_dir,
# enable UDP discovery relevant configs # enable UDP discovery relevant configs
"network_enr_address": "127.0.0.1", "network_enr_address": "127.0.0.1",
"network_enr_tcp_port": bootnode_port, "network_enr_tcp_port": bootnode_port,

View File

@ -55,6 +55,7 @@ class TestFramework:
self.lifetime_seconds = 3600 self.lifetime_seconds = 3600
self.launch_wait_seconds = 1 self.launch_wait_seconds = 1
self.num_deployed_contracts = 0 self.num_deployed_contracts = 0
self.zgs_node_key_files = []
# Set default binary path # Set default binary path
binary_ext = ".exe" if is_windows_platform() else "" binary_ext = ".exe" if is_windows_platform() else ""
@ -190,6 +191,10 @@ class TestFramework:
else: else:
updated_config = {} updated_config = {}
zgs_node_key_file = None
if i < len(self.zgs_node_key_files):
zgs_node_key_file = self.zgs_node_key_files[i]
assert os.path.exists(self.zgs_binary), ( assert os.path.exists(self.zgs_binary), (
"%s should be exist" % self.zgs_binary "%s should be exist" % self.zgs_binary
) )
@ -202,6 +207,7 @@ class TestFramework:
self.mine_contract.address(), self.mine_contract.address(),
self.reward_contract.address(), self.reward_contract.address(),
self.log, self.log,
key_file=zgs_node_key_file,
) )
self.nodes.append(node) self.nodes.append(node)
node.setup_config() node.setup_config()

View File

@ -24,6 +24,7 @@ class ZgsNode(TestNode):
log, log,
rpc_timeout=10, rpc_timeout=10,
libp2p_nodes=None, libp2p_nodes=None,
key_file=None,
): ):
local_conf = ZGS_CONFIG.copy() local_conf = ZGS_CONFIG.copy()
if libp2p_nodes is None: if libp2p_nodes is None:
@ -54,6 +55,7 @@ class ZgsNode(TestNode):
# Overwrite with personalized configs. # Overwrite with personalized configs.
update_config(local_conf, updated_config) update_config(local_conf, updated_config)
data_dir = os.path.join(root_dir, "zgs_node" + str(index)) data_dir = os.path.join(root_dir, "zgs_node" + str(index))
self.key_file = key_file
rpc_url = "http://" + rpc_listen_address rpc_url = "http://" + rpc_listen_address
super().__init__( super().__init__(
NodeType.Zgs, NodeType.Zgs,
@ -68,10 +70,16 @@ class ZgsNode(TestNode):
def setup_config(self): def setup_config(self):
os.mkdir(self.data_dir) os.mkdir(self.data_dir)
log_config_path = os.path.join(self.data_dir, self.config["log_config_file"]) log_config_path = os.path.join(self.data_dir, self.config["log_config_file"])
with open(log_config_path, "w") as f: with open(log_config_path, "w") as f:
f.write("trace,hyper=info,h2=info") f.write("trace,hyper=info,h2=info")
if self.key_file is not None:
network_dir = os.path.join(self.data_dir, "network")
os.mkdir(network_dir)
shutil.copy(self.key_file, network_dir)
initialize_toml_config(self.config_file, self.config) initialize_toml_config(self.config_file, self.config)
def wait_for_rpc_connection(self): def wait_for_rpc_connection(self):