From 73b629b32f0735578f39ba96d8afaafcd86c0b17 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 12 May 2024 22:42:07 +0700 Subject: [PATCH] Create test_transaction.py --- tests/test_transaction.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/test_transaction.py diff --git a/tests/test_transaction.py b/tests/test_transaction.py new file mode 100644 index 000000000..36a78442a --- /dev/null +++ b/tests/test_transaction.py @@ -0,0 +1,39 @@ +import unittest +from transaction import Transaction + +class TestTransaction(unittest.TestCase): + def test_create_transaction(self): + transaction = Transaction("sender", "receiver", 100) + self.assertEqual(transaction.sender, "sender") + self.assertEqual(transaction.receiver, "receiver") + self.assertEqual(transaction.amount, 100) + self.assertEqual(transaction.timestamp, 1234567890) + self.assertEqual(transaction.hash, "hash_value") # Replace with actual hash value + + def test_calculate_hash(self): + transaction = Transaction("sender", "receiver", 100) + self.assertEqual(transaction.calculate_hash(), "hash_value") # Replace with actual hash value + + def test_is_valid(self): + transaction = Transaction("sender", "receiver", 100) + self.assertTrue(transaction.is_valid()) + + # Test invalid transaction with modified data + transaction.data = "modified_data" + self.assertFalse(transaction.is_valid()) + + # Test invalid transaction with modified sender + transaction.sender = "modified_sender" + self.assertFalse(transaction.is_valid()) + + # Test invalid transaction with modified receiver + transaction.receiver = "modified_receiver" + self.assertFalse(transaction.is_valid()) + + # Test invalid transaction with modified amount + transaction.amount = 200 + self.assertFalse(transaction.is_valid()) + + # Test invalid transaction with modified timestamp + transaction.timestamp = 1234567891 + self.assertFalse(transaction.is_valid())