Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Withdrawal address prompt #27

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion staking_deposit/cli/generate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions staking_deposit/cli/new_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions staking_deposit/deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion staking_deposit/intl/en/cli/generate_keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Copy link
Member

@remyroy remyroy Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add something like this at the end of this message:

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. Use a wallet address that you will have full control over for the foreseeable future.

What do you think?

"confirm": "Repeat your execution address for confirmation.",
"mismatch": "Error: the two entered values do not match. Please type again."
}
Expand Down
3 changes: 2 additions & 1 deletion staking_deposit/utils/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion staking_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cli/test_existing_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_existing_mnemonic_bls_withdrawal() -> None:
arguments = [
'--language', 'english',
'existing-mnemonic',
'--eth1_withdrawal_address', '',
'--folder', my_folder_path,
'--mnemonic-password', 'TREZOR',
]
Expand Down Expand Up @@ -65,16 +66,14 @@ def test_existing_mnemonic_eth1_address_withdrawal() -> None:
eth1_withdrawal_address = '0x00000000219ab540356cBB839Cbe05303d7705Fa'
inputs = [
'TREZOR',
eth1_withdrawal_address,
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'2', '2', '5', 'mainnet', 'MyPassword', 'MyPassword']
'2', '2', '5', 'mainnet', 'MyPassword', 'MyPassword', eth1_withdrawal_address, eth1_withdrawal_address]
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'existing-mnemonic',
'--folder', my_folder_path,
'--mnemonic-password', 'TREZOR',
'--eth1_withdrawal_address', eth1_withdrawal_address,
]
result = runner.invoke(cli, arguments, input=data)

Expand Down Expand Up @@ -123,17 +122,16 @@ def test_existing_mnemonic_eth1_address_withdrawal_bad_checksum() -> None:

inputs = [
'TREZOR',
correct_eth1_withdrawal_address, correct_eth1_withdrawal_address,
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'2', '2', '5', 'mainnet', 'MyPassword', 'MyPassword'
'2', '2', '5', 'mainnet', 'MyPassword', 'MyPassword',
wrong_eth1_withdrawal_address, correct_eth1_withdrawal_address, correct_eth1_withdrawal_address
]
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'existing-mnemonic',
'--folder', my_folder_path,
'--mnemonic-password', 'TREZOR',
'--eth1_withdrawal_address', wrong_eth1_withdrawal_address,
]
result = runner.invoke(cli, arguments, input=data)

Expand Down Expand Up @@ -195,6 +193,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(
Expand Down Expand Up @@ -242,6 +241,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(
Expand Down
17 changes: 11 additions & 6 deletions tests/test_cli/test_new_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'--eth1_withdrawal_address', '',
'--folder', my_folder_path,
]
result = runner.invoke(cli, arguments, input=data)
assert result.exit_code == 0

# Check files
Expand Down Expand Up @@ -74,14 +79,13 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:

runner = CliRunner()
eth1_withdrawal_address = '0x00000000219ab540356cBB839Cbe05303d7705Fa'
inputs = [eth1_withdrawal_address, 'english', '1', 'mainnet', 'MyPassword', 'MyPassword',
inputs = ['english', '1', 'mainnet', 'MyPassword', 'MyPassword', eth1_withdrawal_address, eth1_withdrawal_address,
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about']
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'new-mnemonic',
'--folder', my_folder_path,
'--eth1_withdrawal_address', eth1_withdrawal_address,
]
result = runner.invoke(cli, arguments, input=data)
assert result.exit_code == 0
Expand Down Expand Up @@ -134,15 +138,14 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
wrong_eth1_withdrawal_address = '0x00000000219ab540356cBB839Cbe05303d7705FA'
correct_eth1_withdrawal_address = '0x00000000219ab540356cBB839Cbe05303d7705Fa'

inputs = [correct_eth1_withdrawal_address, correct_eth1_withdrawal_address,
'english', '1', 'mainnet', 'MyPassword', 'MyPassword',
inputs = ['english', '1', 'mainnet', 'MyPassword', 'MyPassword',
wrong_eth1_withdrawal_address, correct_eth1_withdrawal_address, correct_eth1_withdrawal_address,
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about']
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'new-mnemonic',
'--folder', my_folder_path,
'--eth1_withdrawal_address', wrong_eth1_withdrawal_address,
]
result = runner.invoke(cli, arguments, input=data)
assert result.exit_code == 0
Expand Down Expand Up @@ -291,6 +294,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(
Expand Down Expand Up @@ -375,6 +379,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(
Expand Down
13 changes: 11 additions & 2 deletions tests/test_cli/test_regeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'--eth1_withdrawal_address', '',
'--folder', folder_path_1,
]
result = runner.invoke(cli, arguments, input=data)
assert result.exit_code == 0

# Check files
Expand All @@ -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',
'--eth1_withdrawal_address', '',
'--folder', folder_path_2,
]
result = runner.invoke(cli, arguments, input=data)

assert result.exit_code == 0
Expand Down
Loading