Skip to content

Commit

Permalink
Fixes to the scripts and startups - does not touch cpp files. (#3849)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-White-UK committed Oct 31, 2023
1 parent c8792ff commit 769b257
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 57 deletions.
2 changes: 1 addition & 1 deletion tests/Zilliqa/test_zilliqa_NAT.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def run_start():
return

dev_root += "/Zilliqa"
fp = dev_root + "/" + "constants_local.xml.native"
fp = dev_root + "/" + "constants.xml"

if not os.path.exists(fp):
print( fp +" not found")
Expand Down
2 changes: 1 addition & 1 deletion tests/Zilliqa/test_zilliqa_late.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def run_start():
keys_file = open(LOCAL_RUN_FOLDER + 'keys.txt', "w")
for x in range(0, count):
keys_file.write(keypairs[x] + '\n')
shutil.copyfile('constants_local.xml.native', LOCAL_RUN_FOLDER + testfolders_list[x] + '/constants.xml')
shutil.copyfile('constants.xml', LOCAL_RUN_FOLDER + testfolders_list[x] + '/constants.xml')
shutil.copyfile('dsnodes.xml', LOCAL_RUN_FOLDER + testfolders_list[x] + '/dsnodes.xml')
keys_file.close()

Expand Down
51 changes: 42 additions & 9 deletions tests/Zilliqa/test_zilliqa_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import xml.etree.cElementTree as ET

NODE_LISTEN_PORT = 5001
NODE_LOOKUP_PORT = 23456
STATUS_SERVER_LISTEN_PORT = 4301
LOCAL_RUN_FOLDER = './local_run/'
REJOIN_DS_GUARD_RUN_FOLDER = './dsguard_rejoin_local_run/'
Expand Down Expand Up @@ -270,13 +271,7 @@ def run_start(numdsnodes):
testfolders_list = get_immediate_subdirectories(LOCAL_RUN_FOLDER)
count = len(testfolders_list)

dev_root = os.getenv("DEV_TREE_ROOT")
if dev_root is None:
print("DEV_TREE_ROOT is not set")
return

dev_root += "/Zilliqa"
fp = dev_root + "/" + "constants_local.xml.native"
fp = "constants.xml"

if not os.path.exists(fp):
print( fp +" not found")
Expand All @@ -296,6 +291,10 @@ def run_start(numdsnodes):
shutil.copyfile(fp, LOCAL_RUN_FOLDER + testfolders_list[x] + '/constants.xml')
ipc_path = "/tmp/zilliqa" + str(NODE_LISTEN_PORT + x) + ".sock"
status_server_port = str(STATUS_SERVER_LISTEN_PORT + x)

'''patch_lookup_pubkey(LOCAL_RUN_FOLDER + testfolders_list[x] + '/dsnodes.xml', keypairs)'''
'''patch_seed_pubkey(LOCAL_RUN_FOLDER + testfolders_list[x] + '/dsnodes.xml', keypairs)'''

patch_param_in_xml(LOCAL_RUN_FOLDER + testfolders_list[x] + '/constants.xml', ipc_path, status_server_port)

shutil.copyfile('dsnodes.xml', LOCAL_RUN_FOLDER + testfolders_list[x] + '/dsnodes.xml')
Expand Down Expand Up @@ -328,14 +327,48 @@ def patch_param_in_xml(filepath, ipc_path, status_server_port):
tree.write(filepath)


def patch_lookup_pubkey(filepath, keypairs):
root = ET.parse(filepath).getroot()
td = root.find('lookups')
if td:
root.remove(td)
root.append(ET.Element('lookups'))
td = root.find('lookups')
p = ET.SubElement(td, "peer")
ET.SubElement(p, "pubkey").text = keypairs[0].split(" ")[0]
ET.SubElement(p, "ip").text = '127.0.0.1'
ET.SubElement(p, "port").text = str(NODE_LISTEN_PORT)
ET.SubElement(p, "hostname").text = None

tree = ET.ElementTree(root)
tree.write(filepath)


def patch_seed_pubkey(filepath, keypairs):
root = ET.parse(filepath).getroot()
td = root.find('upper_seed')
if td:
root.remove(td)
root.append(ET.Element('upper_seed'))
td = root.find('upper_seed')
p = ET.SubElement(td, "peer")
ET.SubElement(p, "pubkey").text = keypairs[0].split(" ")[0]
ET.SubElement(p, "ip").text = '127.0.0.1'
ET.SubElement(p, "port").text = str(NODE_LISTEN_PORT)
ET.SubElement(p, "hostname").text = None

tree = ET.ElementTree(root)
tree.write(filepath)


# To rejoin ds guard index 2
def run_start_dsguard2():
testfolders_list = get_immediate_subdirectories(REJOIN_DS_GUARD_RUN_FOLDER)
count = len(testfolders_list)

for x in range(0, count):
shutil.copyfile('dsnodes.xml', REJOIN_DS_GUARD_RUN_FOLDER + testfolders_list[x] + '/dsnodes.xml')
shutil.copyfile('constants_local.xml.native', REJOIN_DS_GUARD_RUN_FOLDER + testfolders_list[x] + '/constants.xml')
shutil.copyfile('constants.xml', REJOIN_DS_GUARD_RUN_FOLDER + testfolders_list[x] + '/constants.xml')

# These keys are non critical and are only used for testing purposes
keypairs = "021D99F2E5ACBA39ED5ACC5DCA5EE2ADDE780FFD998E1DBF440FE364C3BE360A7B 50C26000FCC08867FC3B9C03385015179E4B63282CB356014233BB1877FCDBDD"
Expand Down Expand Up @@ -364,7 +397,7 @@ def run_start_validateBackupDB():
keypair = keypairs[0].split(" ")
shutil.copyfile('ds_whitelist.xml', LOCAL_RUN_FOLDER + testfolders_list[0] + '/ds_whitelist.xml')
shutil.copyfile('shard_whitelist.xml', LOCAL_RUN_FOLDER + testfolders_list[0] + '/shard_whitelist.xml')
shutil.copyfile('constants_local.xml.native', LOCAL_RUN_FOLDER + testfolders_list[0] + '/constants.xml')
shutil.copyfile('constants.xml', LOCAL_RUN_FOLDER + testfolders_list[0] + '/constants.xml')
shutil.copyfile('dsnodes.xml', LOCAL_RUN_FOLDER + testfolders_list[0] + '/dsnodes.xml')
shutil.copyfile('config_normal.xml', LOCAL_RUN_FOLDER + testfolders_list[0] + '/config.xml')
os.system('cd ' + LOCAL_RUN_FOLDER + testfolders_list[0] + '; echo \"' + keypair[0] + ' ' + keypair[
Expand Down
72 changes: 30 additions & 42 deletions tests/Zilliqa/test_zilliqa_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from subprocess import Popen, PIPE
import xml.etree.cElementTree as ET

NODE_LISTEN_PORT = 40092
NODE_LISTEN_PORT = 23456
LOCAL_RUN_FOLDER = './lookup_local_run/'
LOCAL_FOLDER = "./"

Expand Down Expand Up @@ -91,6 +91,8 @@ def run_setup(numnodes, printnodes):
testfolders_list = get_immediate_subdirectories(LOCAL_RUN_FOLDER)
count = len(testfolders_list)



if printnodes:
for x in range(0, count):
print('[Node ' + str(x + 1).ljust(3) + '] [Port ' + str(NODE_LISTEN_PORT + x) + '] ' + LOCAL_RUN_FOLDER +
Expand All @@ -105,28 +107,17 @@ def run_setup(numnodes, printnodes):
keypairs.append(output.strip())
keypairs.sort()

''' Only deals with one instance for now '''

patch_lookup_pubkey(LOCAL_FOLDER + "/constants_local.xml", keypairs, count)
patch_lookup_port(LOCAL_FOLDER + "/constants_local.xml", NODE_LISTEN_PORT, count)
patch_seed_pubkey(LOCAL_FOLDER + "/constants_local.xml", keypairs, count)
patch_seed_port(LOCAL_FOLDER + "/constants_local.xml", NODE_LISTEN_PORT, count)
patch_lookup_pubkey(LOCAL_FOLDER + "constants.xml", keypairs)
patch_seed_pubkey(LOCAL_FOLDER + "constants.xml", keypairs)

nodes = ET.Element("nodes")

# Store sorted keys list in text file
keys_file = open(LOCAL_RUN_FOLDER + 'lookup_keys.txt', "w")
for x in range(0, count):
keys_file.write(keypairs[x] + '\n')
keypair = keypairs[x].split(" ")
if x < count:
peer = ET.SubElement(nodes, "peer")
ET.SubElement(peer, "pubk").text = keypair[0]
ET.SubElement(peer, "ip").text = '127.0.0.1'
ET.SubElement(peer, "port").text = str(NODE_LISTEN_PORT + x)
keys_file.close()


def patch_constants_xml(filepath, read_txn=False):
root = ET.parse(filepath).getroot()

Expand Down Expand Up @@ -156,40 +147,36 @@ def run_gentxn(batch=100):
os.system('cd ' + GENTXN_WORKING_DIR + '; ./gentxn --begin 0 --end {}'.format(batch))


def patch_lookup_pubkey(filepath, keypairs, count):
def patch_lookup_pubkey(filepath, keypairs):
root = ET.parse(filepath).getroot()
td = root.find('lookups')
elems = td.findall('peer/pubkey')
for x in range(0, count):
keypair = keypairs[x].split(" ")
elems[x].text = keypair[0]
if td:
root.remove(td)
root.append(ET.Element('lookups'))
td = root.find('lookups')
p = ET.SubElement(td, "peer")
ET.SubElement(p, "pubkey").text = keypairs[0].split(" ")[0]
ET.SubElement(p, "ip").text = '127.0.0.1'
ET.SubElement(p, "port").text = str(NODE_LISTEN_PORT)
ET.SubElement(p, "hostname").text = None

tree = ET.ElementTree(root)
tree.write(filepath)


def patch_seed_pubkey(filepath, keypairs, count):
def patch_seed_pubkey(filepath, keypairs):
root = ET.parse(filepath).getroot()
td = root.find('upper_seed')
elems = td.findall('peer/pubkey')
for x in range(0, count):
keypair = keypairs[x].split(" ")
elems[x].text = keypair[0]
tree = ET.ElementTree(root)
tree.write(filepath)
def patch_lookup_port(filepath, port, count):
root = ET.parse(filepath).getroot()
td = root.find('lookups')
elems = td.findall('peer/port')
for x in range(0, count):
elems[x].text = str(port)
tree = ET.ElementTree(root)
tree.write(filepath)
def patch_seed_port(filepath, port, count):
root = ET.parse(filepath).getroot()
if td:
root.remove(td)
root.append(ET.Element('upper_seed'))
td = root.find('upper_seed')
elems = td.findall('peer/port')
for x in range(0, count):
elems[x].text = str(port)
p = ET.SubElement(td, "peer")
ET.SubElement(p, "pubkey").text = keypairs[0].split(" ")[0]
ET.SubElement(p, "ip").text = '127.0.0.1'
ET.SubElement(p, "port").text = str(NODE_LISTEN_PORT)
ET.SubElement(p, "hostname").text = None

tree = ET.ElementTree(root)
tree.write(filepath)

Expand All @@ -202,14 +189,13 @@ def run_start():
print("DEV_TREE_ROOT is not set")
return

dev_root += "/Zilliqa"
fp = dev_root + "/" + "constants_local.xml.native"

fp = LOCAL_FOLDER + "constants.xml"

if not os.path.exists(fp):
print( fp +" not found")
return


# Load the keypairs
keypairs = []
with open(LOCAL_RUN_FOLDER + 'lookup_keys.txt', "r") as f:
Expand All @@ -230,6 +216,8 @@ def run_start():
# Launch node zilliqa process
for x in range(0, count):
keypair = keypairs[x].split(" ")
start_str = ' --privk ' + keypair[1] + ' --pubk ' + keypair[0] + ' --address ' + '127.0.0.1' + ' --port ' + str(NODE_LISTEN_PORT + x) + ' --identity ' + 'lookup-' + str(x)
print(start_str)
os.system('cd ' + LOCAL_RUN_FOLDER + testfolders_list[x] + '; echo \"' + keypair[0] + ' ' + keypair[
1] + '\" > mykey.txt' + '; ulimit -n 65535; ulimit -Sc unlimited; ulimit -Hc unlimited; $(pwd)/lzilliqa ' +
' --privk ' + keypair[1] + ' --pubk ' + keypair[0] + ' --address ' + '127.0.0.1' + ' --port ' +
Expand Down
2 changes: 1 addition & 1 deletion tests/Zilliqa/test_zilliqa_seedpub.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def run_start():
return

dev_root += "/Zilliqa"
fp = dev_root + "/" + "constants_local.xml.native"
fp = dev_root + "/" + "constants.xml"

if not os.path.exists(fp):
print( fp +" not found")
Expand Down
16 changes: 15 additions & 1 deletion tests/native/prepare_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,49 @@ def update_xml_files(source_file, target_file):
if not DEV_TREE_ROOT:
print("DEV_TREE_ROOT is not set")
os.abort()
else:
print("DEV_TREE_ROOT: " + DEV_TREE_ROOT)

general = root.find('general')
if general:
general.find('LOOKUP_NODE_MODE').text = 'false'
general.find('DEBUG_LEVEL').text = '4'
else:
print("Failed to find general")

scilla_root = root.find('smart_contract')
if scilla_root:
scilla_root.find('SCILLA_ROOT').text = DEV_TREE_ROOT +'/scilla'
scilla_root.find('ENABLE_SCILLA_MULTI_VERSION').text = 'false'

else:
print("Failed to find smart_contract")
jsonrpc = root.find('jsonrpc')
if jsonrpc:
jsonrpc.find('EVM_SERVER_BINARY').text = DEV_TREE_ROOT + '/Zilliqa/evm-ds/target/release/evm-ds'
jsonrpc.find('ENABLE_STATUS_RPC').text = 'false'
jsonrpc.find('LOOKUP_RPC_PORT').text = "4201"
else:
print("Failed to find jsonrpc")

metric = root.find('metric/zilliqa')
if metric:
metric.find('METRIC_ZILLIQA_PROVIDER').text = 'NONE'
metric.find('METRIC_ZILLIQA_MASK').text = 'NONE'
else:
print("Failed to find metric")

trace = root.find('trace/zilliqa')
if trace:
trace.find('TRACE_ZILLIQA_PROVIDER').text = 'NONE'
trace.find('TRACE_ZILLIQA_MASK').text = 'NONE'
else:
print("Failed to find trace")

logging = root.find('logging/zilliqa')
if logging:
logging.find('LOGGING_ZILLIQA_PROVIDER').text = 'NONE'
else:
print("Failed to find logging")

tree = ET.ElementTree(root)
tree.write(target_file)
Expand Down
3 changes: 1 addition & 2 deletions tests/native/start_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ echo "DEV_TREE_ROOT: $DEV_TREE_ROOT"

# takes a copy of constants.xml and constants_local.xml and prepares new versions with .native extension

python ./tests/native/prepare_constants.py $DEV_TREE_ROOT/Zilliqa/constants.xml $DEV_TREE_ROOT/Zilliqa/constants.xml.native
python ./tests/native/prepare_constants.py $DEV_TREE_ROOT/Zilliqa/constants_local.xml $DEV_TREE_ROOT/Zilliqa/constants_local.xml.native
python ./tests/native/prepare_constants.py constants.xml constants.xml

./tests/Node/pre_run.sh && ./tests/Node/test_node_lookup.sh && ./tests/Node/test_node_simple.sh

0 comments on commit 769b257

Please sign in to comment.