funga-eth/tests/test_pbkdf2.py
lash e5cd1cad58
Implement PBKDF2 support in keyfile
---

Squashed commit of the following:

commit 4a4f76b19c
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 20:12:34 2022 +0300

    remove unused import and renaming pbkdf2 default params

commit 23a94c3ba1
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 20:07:22 2022 +0300

    defaulting to scrypt in to_dict fun

commit 1c0047398a
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 15:12:38 2022 +0300

    making final review  changes

commit 0a4f3eaa98
Merge: b208533 903f659
Author: Mohamed Sohail <kamikazechaser@noreply.localhost>
Date:   Mon Jan 24 11:10:35 2022 +0000

    Merge branch 'master' into Ida/pbkdf2

commit b20853312d
Author: idaapayo <idaapayo@gmail.com>
Date:   Mon Jan 24 13:23:12 2022 +0300

    review changes with tests

commit b9c6db414b
Author: idaapayo <idaapayo@gmail.com>
Date:   Fri Jan 21 11:13:35 2022 +0300

    making review changes

commit 1f5d057a9a
Author: idaapayo <idaapayo@gmail.com>
Date:   Wed Jan 19 14:37:22 2022 +0300

    second pbkdf2 implementation

commit 01598a8c59
Author: idaapayo <idaapayo@gmail.com>
Date:   Wed Jan 19 13:49:29 2022 +0300

    pkdf2 implementation
2022-01-24 17:54:59 +00:00

60 lines
1.5 KiB
Python

#!/usr/bin/python
# standard imports
import unittest
import logging
import base64
import os
# external imports
from hexathon import (
strip_0x,
add_0x,
)
# local imports
from funga.error import UnknownAccountError
from funga.eth.keystore.dict import DictKeystore
from funga.eth.signer import EIP155Signer
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
script_dir = os.path.realpath(os.path.dirname(__file__))
class TestDict(unittest.TestCase):
address_hex = None
db = None
def setUp(self):
self.db = DictKeystore()
keystore_filepath = os.path.join(script_dir, 'testdata',
'UTC--2022-01-24T10-34-04Z--cc47ad90-71a0-7fbe-0224-63326e27263a')
address_hex = self.db.import_keystore_file(keystore_filepath, 'test')
self.address_hex = add_0x(address_hex)
def tearDown(self):
pass
def test_get_key(self):
logg.debug('getting {}'.format(strip_0x(self.address_hex)))
pk = self.db.get(strip_0x(self.address_hex), '')
self.assertEqual(self.address_hex.lower(), '0xb8df77e1b4fa142e83bf9706f66fd76ad2a564f8')
bogus_account = os.urandom(20).hex()
with self.assertRaises(UnknownAccountError):
self.db.get(bogus_account, '')
def test_sign_message(self):
s = EIP155Signer(self.db)
z = s.sign_ethereum_message(strip_0x(self.address_hex), b'foo')
logg.debug('zzz {}'.format(str(z)))
if __name__ == '__main__':
unittest.main()