staking-deposit-cli/test_deposit_script.py

82 lines
2.4 KiB
Python
Raw Permalink Normal View History

2020-05-12 08:08:49 +00:00
import asyncio
import os
2021-08-23 10:33:04 +00:00
# For not importing staking_deposit here
2020-05-12 08:08:49 +00:00
DEFAULT_VALIDATOR_KEYS_FOLDER_NAME = 'validator_keys'
async def main():
my_folder_path = os.path.join(os.getcwd(), 'TESTING_TEMP_FOLDER')
if not os.path.exists(my_folder_path):
os.mkdir(my_folder_path)
2020-05-12 08:32:17 +00:00
if os.name == 'nt': # Windows
2020-05-21 19:37:43 +00:00
run_script_cmd = 'sh deposit.sh'
else: # Mac or Linux
2020-05-21 19:37:43 +00:00
run_script_cmd = './deposit.sh'
install_cmd = run_script_cmd + ' install'
print('[INFO] Creating subprocess 1: installation:' , install_cmd)
proc = await asyncio.create_subprocess_shell(
install_cmd,
)
await proc.wait()
print('[INFO] Installed')
2020-05-12 08:32:17 +00:00
2020-05-12 08:08:49 +00:00
cmd_args = [
2021-04-06 12:48:52 +00:00
run_script_cmd,
'--language', 'english',
2021-04-27 13:18:28 +00:00
'--non_interactive',
2021-04-06 12:48:52 +00:00
'new-mnemonic',
2020-05-12 08:08:49 +00:00
'--num_validators', '1',
'--mnemonic_language', 'english',
'--chain', 'mainnet',
2020-09-29 14:24:18 +00:00
'--keystore_password', 'MyPassword',
2020-05-12 08:08:49 +00:00
'--folder', my_folder_path,
]
proc = await asyncio.create_subprocess_shell(
' '.join(cmd_args),
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
2020-05-12 08:32:17 +00:00
stderr=asyncio.subprocess.PIPE,
2020-05-12 08:08:49 +00:00
)
seed_phrase = ''
parsing = False
async for out in proc.stdout:
output = out.decode('utf-8').rstrip()
2021-02-23 12:37:04 +00:00
if output.startswith("This is your mnemonic"):
2020-05-12 08:08:49 +00:00
parsing = True
elif output.startswith("Please type your mnemonic"):
parsing = False
elif parsing:
seed_phrase += output
if len(seed_phrase) > 0:
encoded_phrase = seed_phrase.encode()
proc.stdin.write(encoded_phrase)
proc.stdin.write(b'\n')
print(output)
2020-05-12 08:32:17 +00:00
async for out in proc.stderr:
output = out.decode('utf-8').rstrip()
print(f'[stderr] {output}')
2020-05-12 08:08:49 +00:00
assert len(seed_phrase) > 0
# 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))
# Clean up
for key_file_name in key_files:
os.remove(os.path.join(validator_keys_folder_path, key_file_name))
os.rmdir(validator_keys_folder_path)
os.rmdir(my_folder_path)
2020-05-12 08:32:17 +00:00
if os.name == 'nt': # Windows
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())
else:
asyncio.run(main())