Skip to content

Commit

Permalink
Adding exit transaction keystore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valefar-on-discord committed Apr 21, 2024
1 parent 0b83533 commit 24f89fd
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions tests/test_cli/test_exit_transaction_keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
from staking_deposit.deposit import cli
from staking_deposit.settings import get_chain_setting
from staking_deposit.utils.constants import DEFAULT_EXIT_TRANSACTION_FOLDER_NAME

from staking_deposit.utils.intl import (
load_text,
)
from tests.test_cli.helpers import (
clean_exit_transaction_folder,
read_json_file,
verify_file_permission,
)


def test_exit_transaction_menmonic() -> None:
def test_exit_transaction_keystore() -> None:
# Prepare folder
my_folder_path = os.path.join(os.getcwd(), 'TESTING_TEMP_FOLDER')
exit_transaction_folder_path = os.path.join(my_folder_path, DEFAULT_EXIT_TRANSACTION_FOLDER_NAME)
Expand Down Expand Up @@ -79,3 +81,76 @@ def test_exit_transaction_menmonic() -> None:

# Clean up
clean_exit_transaction_folder(my_folder_path)


def test_invalid_keystore_path() -> None:
my_folder_path = os.path.join(os.getcwd(), 'TESTING_TEMP_FOLDER')
clean_exit_transaction_folder(my_folder_path)

runner = CliRunner()
inputs = []
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--non_interactive',
'exit-transaction-keystore',
'--output_folder', my_folder_path,
'--chain', "mainnet",
'--keystore', "invalid_keystore_path",
'--keystore_password', "password",
'--validator_index', '1',
'--epoch', '1234',
]
result = runner.invoke(cli, arguments, input=data)

assert result.exit_code == 2


def test_invalid_keystore_password() -> None:
# Prepare folder
my_folder_path = os.path.join(os.getcwd(), 'TESTING_TEMP_FOLDER')
exit_transaction_folder_path = os.path.join(my_folder_path, DEFAULT_EXIT_TRANSACTION_FOLDER_NAME)
clean_exit_transaction_folder(my_folder_path)
if not os.path.exists(my_folder_path):
os.mkdir(my_folder_path)
if not os.path.exists(exit_transaction_folder_path):
os.mkdir(exit_transaction_folder_path)

# Shared parameters
chain = 'mainnet'
keystore_password = 'solo-stakers'

# Prepare credential
credential = Credential(
mnemonic='aban aban aban aban aban aban aban aban aban aban aban abou',
mnemonic_password='',
index=0,
amount=0,
chain_setting=get_chain_setting(chain),
hex_eth1_withdrawal_address=None
)

# Save keystore file
keystore_filepath = credential.save_signing_keystore(keystore_password, exit_transaction_folder_path)
runner = CliRunner()
inputs = []
data = '\n'.join(inputs)
arguments = [
'--language', 'english',
'--non_interactive',
'exit-transaction-keystore',
'--output_folder', my_folder_path,
'--chain', chain,
'--keystore', keystore_filepath,
'--keystore_password', "incorrect_password",
'--validator_index', '1',
'--epoch', '1234',
]
result = runner.invoke(cli, arguments, input=data)

assert result.exit_code == 1

mnemonic_json_file = os.path.join(os.getcwd(), 'staking_deposit/cli/', 'exit_transaction_keystore.json')
assert load_text(['arg_exit_transaction_keystore_keystore_password', 'mismatch'], mnemonic_json_file, 'exit_transaction_keystore') in result.output

clean_exit_transaction_folder(my_folder_path)

0 comments on commit 24f89fd

Please sign in to comment.