funga-eth

Ethereum implementation of the funga keystore and signer
Info | Log | Files | Refs | README | LICENSE

test_keystore_dict.py (1519B)


      1 #!/usr/bin/python
      2 
      3 # standard imports
      4 import unittest
      5 import logging
      6 import base64
      7 import os
      8 
      9 # external imports
     10 from hexathon import (
     11     strip_0x,
     12     add_0x,
     13     )
     14 
     15 # local imports
     16 from funga.error import UnknownAccountError
     17 from funga.eth.keystore.dict import DictKeystore
     18 from funga.eth.signer import EIP155Signer
     19 
     20 logging.basicConfig(level=logging.DEBUG)
     21 logg = logging.getLogger()
     22 
     23 script_dir = os.path.realpath(os.path.dirname(__file__))
     24 
     25 
     26 class TestDict(unittest.TestCase):
     27 
     28     address_hex = None
     29     db = None
     30 
     31     def setUp(self):
     32         self.db = DictKeystore()
     33 
     34         keystore_filepath = os.path.join(script_dir, 'testdata', 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72')
     35 
     36         address_hex = self.db.import_keystore_file(keystore_filepath, '')
     37         self.address_hex = add_0x(address_hex)
     38 
     39 
     40     def tearDown(self): 
     41         pass
     42 
     43 
     44     def test_get_key(self):
     45         logg.debug('getting {}'.format(strip_0x(self.address_hex)))
     46         pk = self.db.get(strip_0x(self.address_hex), '')
     47 
     48         self.assertEqual(self.address_hex.lower(), '0x00a329c0648769a73afac7f9381e08fb43dbea72')
     49 
     50         bogus_account = os.urandom(20).hex()
     51         with self.assertRaises(UnknownAccountError):
     52            self.db.get(bogus_account, '')
     53 
     54     
     55     def test_sign_message(self):
     56         s = EIP155Signer(self.db)
     57         z = s.sign_ethereum_message(strip_0x(self.address_hex), b'foo')
     58         logg.debug('zzz {}'.format(str(z)))
     59 
     60 
     61 
     62 if __name__ == '__main__':
     63     unittest.main()