forked from ethereum/staking-deposit-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#198 from ethereum/test-binaries
- Loading branch information
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import asyncio | ||
import os | ||
import sys | ||
|
||
|
||
# For not importing eth2deposit here | ||
DEFAULT_VALIDATOR_KEYS_FOLDER_NAME = 'validator_keys' | ||
|
||
|
||
async def main(argv): | ||
binary_file_path = argv[1] | ||
my_folder_path = os.path.join(os.getcwd(), 'TESTING_TEMP_FOLDER') | ||
if not os.path.exists(my_folder_path): | ||
os.mkdir(my_folder_path) | ||
|
||
if os.name == 'nt': # Windows | ||
run_script_cmd = ".\\" + binary_file_path + '\deposit.exe' | ||
else: # Mac or Linux | ||
run_script_cmd = './' + binary_file_path + '/deposit' | ||
|
||
cmd_args = [ | ||
run_script_cmd + ' new-mnemonic', | ||
'--num_validators', '1', | ||
'--mnemonic_language', 'english', | ||
'--chain', 'mainnet', | ||
'--keystore_password', 'MyPassword', | ||
'--folder', my_folder_path, | ||
] | ||
proc = await asyncio.create_subprocess_shell( | ||
' '.join(cmd_args), | ||
stdin=asyncio.subprocess.PIPE, | ||
stdout=asyncio.subprocess.PIPE, | ||
stderr=asyncio.subprocess.PIPE, | ||
) | ||
seed_phrase = '' | ||
parsing = False | ||
async for out in proc.stdout: | ||
output = out.decode('utf-8').rstrip() | ||
if output.startswith("This is your seed phrase."): | ||
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) | ||
|
||
async for out in proc.stderr: | ||
output = out.decode('utf-8').rstrip() | ||
print(f'[stderr] {output}') | ||
|
||
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) | ||
|
||
|
||
if os.name == 'nt': # Windows | ||
loop = asyncio.ProactorEventLoop() | ||
asyncio.set_event_loop(loop) | ||
loop.run_until_complete(main(sys.argv)) | ||
else: | ||
asyncio.run(main(sys.argv)) |