2021-10-10 11:33:30 +02:00
|
|
|
# standard imports
|
2022-03-01 08:01:56 +01:00
|
|
|
import logging
|
2021-10-10 11:33:30 +02:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
from funga.error import DecryptError
|
2022-03-01 08:01:56 +01:00
|
|
|
from funga.eth.keystore.dict import DictKeystore
|
2021-10-10 11:33:30 +02:00
|
|
|
from hexathon import uniform as hex_uniform
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
# external imports
|
|
|
|
from cic.keystore import KeystoreDirectory
|
|
|
|
|
2021-10-10 15:37:26 +02:00
|
|
|
# test imports
|
|
|
|
from tests.base_cic import test_base_dir
|
2021-10-10 11:33:30 +02:00
|
|
|
|
2021-10-10 15:37:26 +02:00
|
|
|
logging = logging.getLogger()
|
2021-10-10 11:33:30 +02:00
|
|
|
|
2021-10-10 15:37:26 +02:00
|
|
|
script_dir = test_base_dir
|
2021-10-10 11:33:30 +02:00
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
|
2021-10-10 11:33:30 +02:00
|
|
|
def pass_getter():
|
2022-03-01 08:01:56 +01:00
|
|
|
return "test"
|
2021-10-10 11:33:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
class EthKeystoreDirectory(DictKeystore, KeystoreDirectory):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class TestKeyfile(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2022-03-01 08:01:56 +01:00
|
|
|
self.path = os.path.join(script_dir, "testdata", "keystore")
|
2021-10-10 11:33:30 +02:00
|
|
|
self.keystore = EthKeystoreDirectory()
|
|
|
|
|
|
|
|
def test_keystore_bogus(self):
|
2022-03-01 08:01:56 +01:00
|
|
|
bogus_path = os.path.join(self.path, "bogus")
|
2021-10-10 11:33:30 +02:00
|
|
|
self.keystore.process_dir(bogus_path)
|
|
|
|
|
|
|
|
def test_keystore_ok(self):
|
2022-03-01 08:01:56 +01:00
|
|
|
ok_path = os.path.join(self.path, "ok")
|
2021-10-10 11:33:30 +02:00
|
|
|
with self.assertRaises(DecryptError):
|
2022-03-01 08:01:56 +01:00
|
|
|
self.keystore.process_dir(ok_path) # wrong password
|
|
|
|
self.keystore.process_dir(ok_path, default_password="test")
|
2021-10-10 11:33:30 +02:00
|
|
|
self.keystore.process_dir(ok_path, password_retriever=pass_getter)
|
2022-03-01 08:01:56 +01:00
|
|
|
self.assertTrue(
|
|
|
|
hex_uniform("cc4f82F5DacDE395E1E0CFc4d62827C8B8B5688C")
|
|
|
|
in self.keystore.list()
|
|
|
|
)
|
2021-10-10 11:33:30 +02:00
|
|
|
|
|
|
|
|
2022-03-01 08:01:56 +01:00
|
|
|
if __name__ == "__main__":
|
2021-10-10 11:33:30 +02:00
|
|
|
unittest.main()
|