diff --git a/staking_deposit/cli/generate_keys.py b/staking_deposit/cli/generate_keys.py index 5f57a873..b79e03ec 100644 --- a/staking_deposit/cli/generate_keys.py +++ b/staking_deposit/cli/generate_keys.py @@ -70,6 +70,7 @@ def generate_keys_arguments_decorator(function: Callable[..., Any]) -> Callable[ lambda: load_text(['chain', 'prompt'], func='generate_keys_arguments_decorator'), list(ALL_CHAINS.keys()) ), + default=MAINNET, ), default=MAINNET, help=lambda: load_text(['chain', 'help'], func='generate_keys_arguments_decorator'), @@ -99,10 +100,12 @@ def generate_keys_arguments_decorator(function: Callable[..., Any]) -> Callable[ lambda: load_text(['arg_execution_address', 'prompt'], func='generate_keys_arguments_decorator'), lambda: load_text(['arg_execution_address', 'confirm'], func='generate_keys_arguments_decorator'), lambda: load_text(['arg_execution_address', 'mismatch'], func='generate_keys_arguments_decorator'), + default="", ), - default=None, + default="", help=lambda: load_text(['arg_execution_address', 'help'], func='generate_keys_arguments_decorator'), param_decls=['--execution_address', '--eth1_withdrawal_address'], + prompt=lambda: load_text(['arg_execution_address', 'prompt'], func='generate_keys_arguments_decorator'), ), ] for decorator in reversed(decorators): diff --git a/staking_deposit/cli/new_mnemonic.py b/staking_deposit/cli/new_mnemonic.py index f288aeac..2de2cb05 100644 --- a/staking_deposit/cli/new_mnemonic.py +++ b/staking_deposit/cli/new_mnemonic.py @@ -38,6 +38,7 @@ callback=captive_prompt_callback( lambda mnemonic_language: fuzzy_reverse_dict_lookup(mnemonic_language, MNEMONIC_LANG_OPTIONS), choice_prompt_func(lambda: load_text(['arg_mnemonic_language', 'prompt'], func='new_mnemonic'), languages), + default=lambda: load_text(['arg_mnemonic_language', 'default'], func='new_mnemonic'), ), default=lambda: load_text(['arg_mnemonic_language', 'default'], func='new_mnemonic'), help=lambda: load_text(['arg_mnemonic_language', 'help'], func='new_mnemonic'), diff --git a/staking_deposit/deposit.py b/staking_deposit/deposit.py index 66acaa91..bfdacb6c 100644 --- a/staking_deposit/deposit.py +++ b/staking_deposit/deposit.py @@ -34,6 +34,7 @@ def check_python_version() -> None: callback=captive_prompt_callback( lambda language: fuzzy_reverse_dict_lookup(language, INTL_LANG_OPTIONS), choice_prompt_func(lambda: 'Please choose your language', get_first_options(INTL_LANG_OPTIONS)), + default='English', ), default='English', help='The language you wish to use the CLI in.', diff --git a/staking_deposit/intl/en/cli/generate_keys.json b/staking_deposit/intl/en/cli/generate_keys.json index f49b65d6..4df4388f 100644 --- a/staking_deposit/intl/en/cli/generate_keys.json +++ b/staking_deposit/intl/en/cli/generate_keys.json @@ -19,7 +19,7 @@ }, "arg_execution_address": { "help": "The 20-byte (Eth1) execution address that will be used in withdrawal", - "prompt": "Please enter the 20-byte execution address for the new withdrawal credentials. Note that you CANNOT change it once you have set it on chain.", + "prompt": "Please enter the optional 20-byte execution address for the new withdrawal credentials. Note that you CANNOT change it once you have set it on chain.", "confirm": "Repeat your execution address for confirmation.", "mismatch": "Error: the two entered values do not match. Please type again." } diff --git a/staking_deposit/utils/click.py b/staking_deposit/utils/click.py index 1d92f967..9d51fa4b 100644 --- a/staking_deposit/utils/click.py +++ b/staking_deposit/utils/click.py @@ -85,6 +85,7 @@ def captive_prompt_callback( confirmation_prompt: Optional[Callable[[], str]]=None, confirmation_mismatch_msg: Callable[[], str]=lambda: '', hide_input: bool=False, + default: Any=None, ) -> Callable[[click.Context, str, str], Any]: ''' Traps the user in a prompt until the value chosen is acceptable @@ -109,7 +110,7 @@ def callback(ctx: click.Context, param: Any, user_input: str) -> Any: return processed_input except ValidationError as e: click.echo('\n[Error] ' + str(e)) - user_input = click.prompt(prompt(), hide_input=hide_input) + user_input = click.prompt(prompt(), hide_input=hide_input, default=default) return callback diff --git a/staking_deposit/utils/validation.py b/staking_deposit/utils/validation.py index 74091703..e227d027 100644 --- a/staking_deposit/utils/validation.py +++ b/staking_deposit/utils/validation.py @@ -129,7 +129,7 @@ def validate_int_range(num: Any, low: int, high: int) -> int: def validate_eth1_withdrawal_address(cts: click.Context, param: Any, address: str) -> HexAddress: - if address is None: + if address in ("", None): return None if not is_hex_address(address): raise ValidationError(load_text(['err_invalid_ECDSA_hex_addr'])) diff --git a/tests/test_cli/test_existing_mnemonic.py b/tests/test_cli/test_existing_mnemonic.py index d41ce464..f4debb0f 100644 --- a/tests/test_cli/test_existing_mnemonic.py +++ b/tests/test_cli/test_existing_mnemonic.py @@ -195,6 +195,7 @@ async def test_script() -> None: '--validator_start_index', '1', '--chain', 'mainnet', '--keystore_password', 'MyPassword', + '--eth1_withdrawal_address', '""', '--folder', my_folder_path, ] proc = await asyncio.create_subprocess_shell( @@ -242,6 +243,7 @@ async def test_script_abbreviated_mnemonic() -> None: '--validator_start_index', '1', '--chain', 'mainnet', '--keystore_password', 'MyPassword', + '--eth1_withdrawal_address', '""', '--folder', my_folder_path, ] proc = await asyncio.create_subprocess_shell( diff --git a/tests/test_cli/test_new_mnemonic.py b/tests/test_cli/test_new_mnemonic.py index 0e091dd3..18ee386c 100644 --- a/tests/test_cli/test_new_mnemonic.py +++ b/tests/test_cli/test_new_mnemonic.py @@ -36,7 +36,12 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str: inputs = ['english', 'english', '1', 'mainnet', 'MyPassword', 'MyPassword', 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'] data = '\n'.join(inputs) - result = runner.invoke(cli, ['new-mnemonic', '--folder', my_folder_path], input=data) + arguments = [ + 'new-mnemonic', + '--folder', my_folder_path, + '--eth1_withdrawal_address=""', + ] + result = runner.invoke(cli, arguments, input=data) assert result.exit_code == 0 # Check files @@ -291,6 +296,7 @@ async def test_script_bls_withdrawal() -> None: '--mnemonic_language', 'english', '--chain', 'mainnet', '--keystore_password', 'MyPassword', + '--eth1_withdrawal_address', '""', '--folder', my_folder_path, ] proc = await asyncio.create_subprocess_shell( @@ -375,6 +381,7 @@ async def test_script_abbreviated_mnemonic() -> None: '--mnemonic_language', 'english', '--chain', 'mainnet', '--keystore_password', 'MyPassword', + '--eth1_withdrawal_address', '""', '--folder', my_folder_path, ] proc = await asyncio.create_subprocess_shell( diff --git a/tests/test_cli/test_regeneration.py b/tests/test_cli/test_regeneration.py index 77687583..879051c7 100644 --- a/tests/test_cli/test_regeneration.py +++ b/tests/test_cli/test_regeneration.py @@ -35,7 +35,12 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str: my_password = "MyPassword" inputs = ['english', 'english', '2', 'mainnet', my_password, my_password, mock_mnemonic] data = '\n'.join(inputs) - result = runner.invoke(cli, ['new-mnemonic', '--folder', folder_path_1], input=data) + arguments = [ + 'new-mnemonic', + '--folder', folder_path_1, + '--eth1_withdrawal_address=""', + ] + result = runner.invoke(cli, arguments, input=data) assert result.exit_code == 0 # Check files @@ -60,7 +65,11 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str: mock_mnemonic, '1', '1', '2', 'mainnet', 'MyPassword', 'MyPassword'] data = '\n'.join(inputs) - arguments = ['existing-mnemonic', '--folder', folder_path_2] + arguments = [ + 'existing-mnemonic', + '--folder', folder_path_2, + '--eth1_withdrawal_address=""', + ] result = runner.invoke(cli, arguments, input=data) assert result.exit_code == 0