2021-01-09 20:25:47 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import unittest
|
|
|
|
import logging
|
|
|
|
import base64
|
|
|
|
import os
|
|
|
|
|
2021-03-31 12:13:04 +02:00
|
|
|
# external imports
|
|
|
|
from hexathon import (
|
|
|
|
strip_0x,
|
|
|
|
add_0x,
|
|
|
|
)
|
|
|
|
|
2021-01-09 20:25:47 +01:00
|
|
|
# local imports
|
2021-10-10 09:41:56 +02:00
|
|
|
from funga.error import UnknownAccountError
|
|
|
|
from funga.eth.keystore.dict import DictKeystore
|
|
|
|
from funga.eth.signer import EIP155Signer
|
2021-01-09 20:25:47 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
script_dir = os.path.realpath(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
2021-01-09 22:05:24 +01:00
|
|
|
class TestDict(unittest.TestCase):
|
2021-01-09 20:25:47 +01:00
|
|
|
|
|
|
|
address_hex = None
|
|
|
|
db = None
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.db = DictKeystore()
|
|
|
|
|
|
|
|
keystore_filepath = os.path.join(script_dir, 'testdata', 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72')
|
|
|
|
|
2021-03-31 12:13:04 +02:00
|
|
|
address_hex = self.db.import_keystore_file(keystore_filepath, '')
|
|
|
|
self.address_hex = add_0x(address_hex)
|
2021-01-09 20:25:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_key(self):
|
2021-03-31 12:13:04 +02:00
|
|
|
logg.debug('getting {}'.format(strip_0x(self.address_hex)))
|
|
|
|
pk = self.db.get(strip_0x(self.address_hex), '')
|
2021-01-09 20:25:47 +01:00
|
|
|
|
2021-01-09 20:37:16 +01:00
|
|
|
self.assertEqual(self.address_hex.lower(), '0x00a329c0648769a73afac7f9381e08fb43dbea72')
|
2021-01-09 20:25:47 +01:00
|
|
|
|
|
|
|
bogus_account = os.urandom(20).hex()
|
|
|
|
with self.assertRaises(UnknownAccountError):
|
|
|
|
self.db.get(bogus_account, '')
|
|
|
|
|
2021-01-09 20:37:16 +01:00
|
|
|
|
|
|
|
def test_sign_message(self):
|
2021-10-10 09:41:56 +02:00
|
|
|
s = EIP155Signer(self.db)
|
2021-03-31 12:13:04 +02:00
|
|
|
z = s.sign_ethereum_message(strip_0x(self.address_hex), b'foo')
|
2021-01-09 20:37:16 +01:00
|
|
|
logg.debug('zzz {}'.format(str(z)))
|
|
|
|
|
|
|
|
|
2021-01-09 20:25:47 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|