diff --git a/wls-module/src/utils/tests/__init__.py b/wls-module/src/utils/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wls-module/src/utils/tests/test_files.py b/wls-module/src/utils/tests/test_files.py new file mode 100644 index 0000000..ad65815 --- /dev/null +++ b/wls-module/src/utils/tests/test_files.py @@ -0,0 +1,33 @@ +import json +import unittest +import os + +from .. import files + + +class TestFiles(unittest.TestCase): + + def test_load_config_file(self): + config = files.load_config_file("test_files/test_config.json") + self.assertEqual(config["general"]["prng_seed"], 1234) + self.assertEqual(config["kurtosis"]["enclave_name"], "test") + + def test_config_file_error(self): + with self.assertRaises(FileNotFoundError): + files.load_config_file("test_files/test_config_error.json") + + def test_load_topology(self): + test_topology = files.load_topology("test_files/test_topology.json") + self.assertEqual(test_topology["containers"]["containers_0"][0], "node_0") + self.assertEqual(test_topology["nodes"]["node_0"]["image"], "nim-waku") + + def test_load_topology_error(self): + with self.assertRaises(FileNotFoundError): + files.load_topology("test_files/test_topology_error.json") + + def test_save_messages_to_json(self): + msgs_dict = {"test": "test"} + files.save_messages_to_json(msgs_dict) + with open("messages.json", "r") as f: + self.assertEqual(json.load(f), msgs_dict) + os.remove("messages.json") diff --git a/wls-module/src/utils/tests/test_files/test_config.json b/wls-module/src/utils/tests/test_files/test_config.json new file mode 100644 index 0000000..e13fe42 --- /dev/null +++ b/wls-module/src/utils/tests/test_files/test_config.json @@ -0,0 +1,8 @@ +{ + "general":{ + "prng_seed" : 1234 + }, + "kurtosis": { + "enclave_name": "test" + } +} diff --git a/wls-module/src/utils/tests/test_files/test_topology.json b/wls-module/src/utils/tests/test_files/test_topology.json new file mode 100644 index 0000000..54176ab --- /dev/null +++ b/wls-module/src/utils/tests/test_files/test_topology.json @@ -0,0 +1,18 @@ +{ + "containers": { + "containers_0": [ + "node_0" + ] + }, + "nodes": { + "node_0": { + "static_nodes": [], + "subnetwork": "subnetwork_0", + "image": "nim-waku", + "node_config": "node_0.toml", + "node_log": "node_0.log", + "port_shift": 0, + "container_id": "containers_0" + } + } +} \ No newline at end of file