From a544802f05dff7b4f171ffa27cc22d7847b7b214 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 12 May 2024 22:39:44 +0700 Subject: [PATCH] Create test_block.py --- tests/test_block.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_block.py diff --git a/tests/test_block.py b/tests/test_block.py new file mode 100644 index 000000000..926a8abab --- /dev/null +++ b/tests/test_block.py @@ -0,0 +1,31 @@ +import unittest +from block import Block + +class TestBlock(unittest.TestCase): + def test_create_block(self): + block = Block(1, "previous_hash", "data", 1234567890) + self.assertEqual(block.index, 1) + self.assertEqual(block.previous_hash, "previous_hash") + self.assertEqual(block.data, "data") + self.assertEqual(block.timestamp, 1234567890) + self.assertEqual(block.hash, "hash_value") # Replace with actual hash value + + def test_calculate_hash(self): + block = Block(1, "previous_hash", "data", 1234567890) + self.assertEqual(block.calculate_hash(), "hash_value") # Replace with actual hash value + + def test_is_valid(self): + block = Block(1, "previous_hash", "data", 1234567890) + self.assertTrue(block.is_valid()) + + # Test invalid block with modified data + block.data = "modified_data" + self.assertFalse(block.is_valid()) + + # Test invalid block with modified previous hash + block.previous_hash = "modified_previous_hash" + self.assertFalse(block.is_valid()) + + # Test invalid block with modified index + block.index = 2 + self.assertFalse(block.is_valid())