Skip to content

Commit

Permalink
Create test_smart_contract.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 10, 2024
1 parent 8013700 commit 9c46897
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/tests/unit_tests/test_smart_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
from smart_contract import SmartContract

class TestSmartContract(unittest.TestCase):
def test_create_smart_contract(self):
contract = SmartContract('contract_owner', 'contract_code')
self.assertEqual(contract.owner, 'contract_owner')
self.assertEqual(contract.code, 'contract_code')
self.assertEqual(contract.hash, None)

def test_hash(self):
contract = SmartContract('contract_owner', 'contract_code')
contract.hash = None
contract.mine_hash()
self.assertNotEqual(contract.hash, None)

def test_mine_hash(self):
contract = SmartContract('contract_owner', 'contract_code')
contract.mine_hash(difficulty=2)
self.assertEqual(contract.hash[0:2], '00')

def test_execute_contract(self):
contract = SmartContract('contract_owner', 'contract_code')
result = contract.execute_contract('input_data')
self.assertIsInstance(result, str)

if __name__ == '__main__':
unittest.main()

0 comments on commit 9c46897

Please sign in to comment.