Repository: Naruno/Naruno (language: python)

Issue:
tests: Adding unit test for validate_main function



Discussion / hints:

Fix patch:
diff --git a/decentra_network/consensus/rounds/round_2/process/validate/validate_main.py b/decentra_network/consensus/rounds/round_2/process/validate/validate_main.py
index 2565f5c8..1f1d880a 100644
--- a/decentra_network/consensus/rounds/round_2/process/validate/validate_main.py
+++ b/decentra_network/consensus/rounds/round_2/process/validate/validate_main.py
@@ -18,8 +18,9 @@
 logger = get_logger("CONSENSUS_SECOND_ROUND")
 
 
-def validate_main(block: Block):
+def validate_main(block: Block) -> Block:
     logger.info("Block approved")
     block.validated = True
     block.validated_time = int(time.time())
     block.round_2 = True
+    return block


Test patch:
diff --git a/tests/unit_tests/test_consensus.py b/tests/unit_tests/test_consensus.py
index bb6e3c87..89f20852 100644
--- a/tests/unit_tests/test_consensus.py
+++ b/tests/unit_tests/test_consensus.py
@@ -50,6 +50,8 @@
     time_difference_check as time_difference_check_round_2
 from decentra_network.consensus.rounds.round_2.process.candidate_blocks_hashes.candidate_blocks_hashes_main import \
     process_candidate_blocks_hashes
+from decentra_network.consensus.rounds.round_2.process.validate.validate_main import \
+    validate_main
 from decentra_network.consensus.time.true_time.true_time_main import true_time
 from decentra_network.lib.clean_up import CleanUp_tests
 from decentra_network.node.server.server import server
@@ -1258,5 +1260,13 @@ def test_process_candidate_blocks_hashes(self):
             expected_result,
         )
 
+    def test_validate_main(self):
+        block = Block("Onur")
+        old_block = copy.copy(block)
+        result = validate_main(block)
+        self.assertEqual(result.validated, True)
+        self.assertEqual(result.round_2, True)
+        self.assertNotEqual(old_block.validated_time, result.validated_time)
+
 
 unittest.main(exit=False)