funga-eth

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

test_pbkdf2.py (1537B)


      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     address_hex = None
     28     db = None
     29 
     30     def setUp(self):
     31         self.db = DictKeystore()
     32 
     33         keystore_filepath = os.path.join(script_dir, 'testdata',
     34                                          'UTC--2022-01-24T10-34-04Z--cc47ad90-71a0-7fbe-0224-63326e27263a')
     35 
     36         address_hex = self.db.import_keystore_file(keystore_filepath, 'test')
     37         self.address_hex = add_0x(address_hex)
     38 
     39     def tearDown(self):
     40         pass
     41 
     42     def test_get_key(self):
     43         logg.debug('getting {}'.format(strip_0x(self.address_hex)))
     44         pk = self.db.get(strip_0x(self.address_hex), '')
     45 
     46         self.assertEqual(self.address_hex.lower(), '0xb8df77e1b4fa142e83bf9706f66fd76ad2a564f8')
     47 
     48         bogus_account = os.urandom(20).hex()
     49         with self.assertRaises(UnknownAccountError):
     50             self.db.get(bogus_account, '')
     51 
     52     def test_sign_message(self):
     53         s = EIP155Signer(self.db)
     54         z = s.sign_ethereum_message(strip_0x(self.address_hex), b'foo')
     55         logg.debug('zzz {}'.format(str(z)))
     56 
     57 
     58 if __name__ == '__main__':
     59     unittest.main()