From 49a8bded42cef310fc8dd3ac22581a15421a461e Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 26 May 2020 21:00:53 +0800 Subject: [PATCH 1/2] Add uuid test --- tests/test_cli.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4bfc6c1..c58effd 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -8,6 +8,7 @@ from click.testing import CliRunner from eth2deposit import deposit from eth2deposit.deposit import main from eth2deposit.utils.constants import DEFAULT_VALIDATOR_KEYS_FOLDER_NAME +from eth2deposit.key_handling.keystore import Keystore def clean_key_folder(my_folder_path): @@ -36,7 +37,7 @@ def test_deposit(monkeypatch): os.mkdir(my_folder_path) runner = CliRunner() - inputs = ['1', 'english', 'MyPassword', 'MyPassword', 'fakephrase'] + inputs = ['5', 'english', 'MyPassword', 'MyPassword', 'fakephrase'] data = '\n'.join(inputs) result = runner.invoke(main, ['--folder', my_folder_path], input=data) @@ -45,7 +46,17 @@ def test_deposit(monkeypatch): # Check files validator_keys_folder_path = os.path.join(my_folder_path, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME) _, _, key_files = next(os.walk(validator_keys_folder_path)) - assert len(key_files) == 2 + + def get_uuid(key_file): + keystore = Keystore.from_json(key_file) + return keystore.uuid + + all_uuid = [ + get_uuid(validator_keys_folder_path + '/' + key_file) + for key_file in key_files + if key_file.startswith('keystore') + ] + assert len(set(all_uuid)) == 5 # Clean up clean_key_folder(my_folder_path) From e9fa2192df374e3d2116c7c53bff268c970f944b Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 26 May 2020 21:09:20 +0800 Subject: [PATCH 2/2] Create uuid at execution time instead of class attribute --- eth2deposit/key_handling/keystore.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eth2deposit/key_handling/keystore.py b/eth2deposit/key_handling/keystore.py index 779f0f7..dde53cc 100644 --- a/eth2deposit/key_handling/keystore.py +++ b/eth2deposit/key_handling/keystore.py @@ -65,7 +65,7 @@ class Keystore(BytesDataclass): crypto: KeystoreCrypto = KeystoreCrypto() pubkey: str = '' path: str = '' - uuid: str = str(uuid4()) # Generate a new uuid + uuid: str = '' version: int = 4 def kdf(self, **kwargs: Any) -> bytes: @@ -96,6 +96,7 @@ class Keystore(BytesDataclass): kdf_salt: bytes=randbits(256).to_bytes(32, 'big'), aes_iv: bytes=randbits(128).to_bytes(16, 'big')) -> 'Keystore': keystore = cls() + keystore.uuid = str(uuid4()) keystore.crypto.kdf.params['salt'] = kdf_salt decryption_key = keystore.kdf(password=password, **keystore.crypto.kdf.params) keystore.crypto.cipher.params['iv'] = aes_iv