def list_encrypted_file_paths():
    file_paths = []
    for f in sorted(os.listdir(get_key_file_path())):
        f_path = os.path.join(get_key_file_path(), f)
        if os.path.isfile(f_path) and f.startswith(
                ENCYPTED_CONF_PREFIX) and f.endswith(ENCYPTED_CONF_POSTFIX):
            file_paths.append(f_path)
    return file_paths
Example #2
0
    def test_get_key_file_path(self):
        """
        test get_key_file_path
        """
        global_config_map["key_file_path"].value = "/my_wallets"
        self.assertEqual(get_key_file_path(),
                         global_config_map["key_file_path"].value)

        global_config_map["key_file_path"].value = None
        self.assertEqual(get_key_file_path(), DEFAULT_KEY_FILE_PATH)
Example #3
0
    def test_import_and_save_wallet(self):
        """
        test import_and_save_wallet
        this is almost the same as test_save_wallet, but good to have in case the functions diverge and we want to be
        notified if the behavior changes unexpectedly
        """

        temp_dir = tempfile.gettempdir()
        global_config_map["key_file_path"].value = temp_dir + "/"
        password = "******"

        ill_formed_private_key1 = "not_hex"
        self.assertRaisesRegex(ValueError,
                               "^when sending a str, it must be a hex string",
                               import_and_save_wallet, password,
                               ill_formed_private_key1)

        ill_formed_private_key2 = "0x123123123"  # not the expected length
        self.assertRaisesRegex(
            ValueError, "^The private key must be exactly 32 bytes long",
            import_and_save_wallet, password, ill_formed_private_key2)

        # this private key must be in the correct format or it will fail
        private_key = "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f"  # noqa: mock
        password = "******"
        acct = import_and_save_wallet(password, private_key)
        file_path = "%s%s%s%s" % (get_key_file_path(), KEYFILE_PREFIX,
                                  acct.address, KEYFILE_POSTFIX)
        self.assertEqual(os.path.exists(file_path), True)
Example #4
0
    def test_save_wallet(self):
        """
        test save_wallet
        """
        # set the temp_dir as the file that will get returned from get_key_file_path
        temp_dir = tempfile.gettempdir()
        global_config_map["key_file_path"].value = temp_dir + "/"

        # this private key must be in the correct format or it will fail
        # account isn't our code but it gets tested indirectly in test_import_and_save_wallet
        private_key = "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f"  # noqa: mock
        acct = Account.privateKeyToAccount(private_key)

        # there is no check on the format of the password in save_wallet
        save_wallet(acct, "topsecret")
        file_path = "%s%s%s%s" % (get_key_file_path(), KEYFILE_PREFIX,
                                  acct.address, KEYFILE_POSTFIX)
        self.assertEqual(os.path.exists(file_path), True)
def get_encrypted_config_path(config_var):
    return "%s%s%s%s" % (get_key_file_path(), ENCYPTED_CONF_PREFIX,
                         config_var.key, ENCYPTED_CONF_POSTFIX)
Example #6
0
def encrypted_file_path(config_key: str):
    return "%s%s%s%s" % (get_key_file_path(), ENCYPTED_CONF_PREFIX, config_key,
                         ENCYPTED_CONF_POSTFIX)
Example #7
0
def encrypted_file_path(config_key: str):
    return os.path.join(
        get_key_file_path(),
        f"{ENCYPTED_CONF_PREFIX}{config_key}{ENCYPTED_CONF_POSTFIX}")