test: modify key value for nomos_node_0

This commit is contained in:
Roman 2025-06-02 14:05:01 +08:00
parent 7e7177fb8f
commit 51b8527655
No known key found for this signature in database
GPG Key ID: 583BDF43C238B83E
2 changed files with 33 additions and 1 deletions

View File

@ -37,7 +37,7 @@ setuptools==70.0.0
tenacity==8.2.3
typeguard==4.1.5
typing-inspect==0.9.0
typing_extensions==4.9.0
typing_extensions>=4.10
urllib3==2.2.2
virtualenv==20.25.0
Jinja2~=3.1.5

View File

@ -3,6 +3,7 @@ import json
import tarfile
import pytest
from ruamel.yaml import YAML
from src.client.nomos_cli import NomosCli
from src.env_vars import CONSENSUS_SLOT_TIME, NOMOS_CUSTOM
@ -15,6 +16,32 @@ from src.test_data import DATA_TO_DISPERSE
logger = get_custom_logger(__name__)
def modify_key_value(file_path, yaml_key_path):
yaml = YAML()
yaml.preserve_quotes = True
with open(file_path, "r") as f:
data = yaml.load(f)
keys = yaml_key_path.split(".")
ref = data
for key in keys[:-1]:
if key not in ref:
raise KeyError(f"Key '{key}' not found in path '{'.'.join(keys)}'")
ref = ref[key]
final_key = keys[-1]
if final_key not in ref:
raise KeyError(f"Key '{final_key}' not found in path '{'.'.join(keys)}'")
old_value = ref[final_key]
# Swap last two characters
ref[final_key] = old_value[:-2] + old_value[-1] + old_value[-2]
with open(file_path, "w") as f:
yaml.dump(data, f)
class TestDataConfidentiality(StepsDataAvailability):
main_nodes = []
@ -45,6 +72,11 @@ class TestDataConfidentiality(StepsDataAvailability):
self.node2.stop()
# Change the private key of the nomos_node_0 -> change its PeerId
modify_key_value("./cluster_config/config.yaml", "network.backend.node_key")
modify_key_value("./cluster_config/config.yaml", "blend.backend.node_key")
modify_key_value("./cluster_config/config.yaml", "da_network.backend.node_key")
# Start new node with the same hostname and configuration as first node
self.nodeX = NomosNode(NOMOS_CUSTOM, "nomos_node_0")
self.nodeX.start()