Skip to content

Commit

Permalink
Replace custom test directory setup and clean up with the tempfile mo…
Browse files Browse the repository at this point in the history
…dule features
  • Loading branch information
remyroy committed Jun 12, 2024
1 parent 42b216b commit 32f21f5
Show file tree
Hide file tree
Showing 12 changed files with 1,432 additions and 1,642 deletions.
106 changes: 50 additions & 56 deletions test_binary_btec_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,70 @@
import os
import sys

from tempfile import TemporaryDirectory

# For not importing ethstaker_deposit here
DEFAULT_VALIDATOR_KEYS_FOLDER_NAME = 'bls_to_execution_changes'


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'
with TemporaryDirectory() as my_folder_path:

cmd_args = [
run_script_cmd,
'--language', 'english',
'--non_interactive',
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
'--chain', 'mainnet',
'--mnemonic', '\"sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry\"',
'--bls_withdrawal_credentials_list', '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
'--validator_indices', '1',
'--execution_address', '0x3434343434343434343434343434343434343434',
]
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("***Using the tool"):
parsing = True
elif output.startswith("This is your mnemonic"):
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)
if os.name == 'nt': # Windows
run_script_cmd = ".\\" + binary_file_path + '\deposit.exe'
else: # Mac or Linux
run_script_cmd = './' + binary_file_path + '/deposit'

async for out in proc.stderr:
output = out.decode('utf-8').rstrip()
print(f'[stderr] {output}')
cmd_args = [
run_script_cmd,
'--language', 'english',
'--non_interactive',
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
'--chain', 'mainnet',
'--mnemonic', '\"sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry\"',
'--bls_withdrawal_credentials_list', '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
'--validator_indices', '1',
'--execution_address', '0x3434343434343434343434343434343434343434',
]
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("***Using the tool"):
parsing = True
elif output.startswith("This is your mnemonic"):
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)

assert len(seed_phrase) > 0
async for out in proc.stderr:
output = out.decode('utf-8').rstrip()
print(f'[stderr] {output}')

await proc.wait()
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))
await proc.wait()

# 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)
# 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))


if os.name == 'nt': # Windows
Expand Down
98 changes: 46 additions & 52 deletions test_binary_deposit_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,66 @@
import os
import sys

from tempfile import TemporaryDirectory

# For not importing ethstaker_deposit 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'
with TemporaryDirectory() as my_folder_path:

cmd_args = [
run_script_cmd,
'--language', 'english',
'--non_interactive',
'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 mnemonic"):
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)
if os.name == 'nt': # Windows
run_script_cmd = ".\\" + binary_file_path + '\deposit.exe'
else: # Mac or Linux
run_script_cmd = './' + binary_file_path + '/deposit'

async for out in proc.stderr:
output = out.decode('utf-8').rstrip()
print(f'[stderr] {output}')
cmd_args = [
run_script_cmd,
'--language', 'english',
'--non_interactive',
'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 mnemonic"):
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)

assert len(seed_phrase) > 0
async for out in proc.stderr:
output = out.decode('utf-8').rstrip()
print(f'[stderr] {output}')

await proc.wait()
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))
await proc.wait()

# 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)
# 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))


if os.name == 'nt': # Windows
Expand Down
123 changes: 59 additions & 64 deletions test_btec_script.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,77 @@
import asyncio
import os

from tempfile import TemporaryDirectory

# For not importing ethstaker_deposit here
DEFAULT_VALIDATOR_KEYS_FOLDER_NAME = 'bls_to_execution_changes'


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)

if os.name == 'nt': # Windows
run_script_cmd = 'sh deposit.sh'
else: # Mac or Linux
run_script_cmd = './deposit.sh'
# Prepare folder
with TemporaryDirectory() as my_folder_path:

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')
if os.name == 'nt': # Windows
run_script_cmd = 'sh deposit.sh'
else: # Mac or Linux
run_script_cmd = './deposit.sh'

cmd_args = [
run_script_cmd,
'--language', 'english',
'--non_interactive',
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
'--chain', 'mainnet',
'--mnemonic', '\"sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry\"',
'--bls_withdrawal_credentials_list', '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
'--validator_indices', '1',
'--execution_address', '0x3434343434343434343434343434343434343434',
]
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("***Using the tool"):
parsing = True
elif output.startswith("This is your mnemonic"):
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)
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')

async for out in proc.stderr:
output = out.decode('utf-8').rstrip()
print(f'[stderr] {output}')
cmd_args = [
run_script_cmd,
'--language', 'english',
'--non_interactive',
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
'--chain', 'mainnet',
'--mnemonic', '\"sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry\"',
'--bls_withdrawal_credentials_list', '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
'--validator_indices', '1',
'--execution_address', '0x3434343434343434343434343434343434343434',
]
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("***Using the tool"):
parsing = True
elif output.startswith("This is your mnemonic"):
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)

assert len(seed_phrase) > 0
async for out in proc.stderr:
output = out.decode('utf-8').rstrip()
print(f'[stderr] {output}')

await proc.wait()
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))
await proc.wait()

# 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)
# 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))


if os.name == 'nt': # Windows
Expand Down
Loading

0 comments on commit 32f21f5

Please sign in to comment.