-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |