Skip to content

Commit

Permalink
Create test_transaction.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 12, 2024
1 parent 6b7f4a2 commit 73b629b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 73b629b

Please sign in to comment.