Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Fix tests on Windows #212

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/my_init
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ try:
main(args)
except KeyboardInterrupt:
warn("Init system aborted.")
exit(2)
sys.exit(2)
finally:
if args.kill_all_on_exit:
kill_all_processes(KILL_ALL_PROCESSES_TIMEOUT)
2 changes: 1 addition & 1 deletion tests/test_antler_proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from common import DUNES_EXE, TEST_PATH


TEST_PROJECT_DIR = TEST_PATH + "/" + "antler_test_dir"
TEST_PROJECT_DIR = os.path.join(TEST_PATH, "antler_test_dir")


def remove_existing():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
ACCT_NAME = "myaccount"

PROJECT_NAME = "test_app"
TEST_APP_DIR = TEST_PATH + "/" + PROJECT_NAME
TEST_APP_BLD_DIR = TEST_APP_DIR + "/build/" + PROJECT_NAME
TEST_APP_WASM = TEST_APP_BLD_DIR + "/" + PROJECT_NAME + ".wasm" # TEST_APP_BLD_DIR + "/test_app.wasm"
TEST_APP_DIR = os.path.join(TEST_PATH, PROJECT_NAME)
TEST_APP_BLD_DIR = os.path.join(TEST_APP_DIR, *["build", PROJECT_NAME])
TEST_APP_WASM = os.path.join(TEST_APP_BLD_DIR, PROJECT_NAME + ".wasm") # TEST_APP_BLD_DIR/test_app.wasm


@pytest.mark.destructive
Expand Down
42 changes: 21 additions & 21 deletions tests/test_list_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ def test_list_features():

# List of expected output lines from `dunes --list-features`.
expect_list = \
[b"GET_CODE_HASH",
b"CRYPTO_PRIMITIVES",
b"GET_BLOCK_NUM",
b"ACTION_RETURN_VALUE",
b"CONFIGURABLE_WASM_LIMITS2",
b"BLOCKCHAIN_PARAMETERS",
b"GET_SENDER",
b"FORWARD_SETCODE",
b"ONLY_BILL_FIRST_AUTHORIZER",
b"RESTRICT_ACTION_TO_SELF",
b"DISALLOW_EMPTY_PRODUCER_SCHEDULE",
b"FIX_LINKAUTH_RESTRICTION",
b"REPLACE_DEFERRED",
b"NO_DUPLICATE_DEFERRED_ID",
b"ONLY_LINK_TO_EXISTING_PERMISSION",
b"RAM_RESTRICTIONS",
b"WEBAUTHN_KEY",
b"WTMSIG_BLOCK_SIGNATURES"]
["GET_CODE_HASH",
"CRYPTO_PRIMITIVES",
"GET_BLOCK_NUM",
"ACTION_RETURN_VALUE",
"CONFIGURABLE_WASM_LIMITS2",
"BLOCKCHAIN_PARAMETERS",
"GET_SENDER",
"FORWARD_SETCODE",
"ONLY_BILL_FIRST_AUTHORIZER",
"RESTRICT_ACTION_TO_SELF",
"DISALLOW_EMPTY_PRODUCER_SCHEDULE",
"FIX_LINKAUTH_RESTRICTION",
"REPLACE_DEFERRED",
"NO_DUPLICATE_DEFERRED_ID",
"ONLY_LINK_TO_EXISTING_PERMISSION",
"RAM_RESTRICTIONS",
"WEBAUTHN_KEY",
"WTMSIG_BLOCK_SIGNATURES"]

# Convert the list to a useful comparison value.
expect = b''
expect = ''
for temp in expect_list:
expect = expect + temp + b'\n'
expect = expect + temp + '\n'

# Call the tool, check return code, check expected value.
completed_process = subprocess.run([DUNES_EXE, "--list-features"],
check=True, stdout=subprocess.PIPE)
assert completed_process.stdout == expect
assert completed_process.stdout.decode().replace('\r', '') == expect
43 changes: 24 additions & 19 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""


import os
import shutil # rmtree
import subprocess
import pytest
Expand All @@ -31,10 +32,10 @@
NODE_CHARLIE = "CHARLIE_NODE"

CONFIG_PATH = TEST_PATH
CONFIG_FILE = TEST_PATH + "/config.ini"
CONFIG_FILE_CUST = TEST_PATH + "/mycustconfig001.ini"
CONFIG_FILE = os.path.join(TEST_PATH, "config.ini")
CONFIG_FILE_CUST = os.path.join(TEST_PATH, "mycustconfig001.ini")

EXPORT_DIR = TEST_PATH + "/temp"
EXPORT_DIR = os.path.join(TEST_PATH, "temp")

ALT_HTTP_ADDR="0.0.0.0:9991"
ALT_P2P_ADDR="0.0.0.0:9992"
Expand All @@ -52,7 +53,7 @@ def remove_all():
check=True, stdout=subprocess.PIPE)

# Convert the captured stdin to a list.
result_list = completed_process.stdout.decode().split("\n")
result_list = completed_process.stdout.decode().replace('\r', '').split("\n")

# Remove the header.
result_list.pop(0)
Expand Down Expand Up @@ -97,7 +98,7 @@ def validate_node_state( node_name, active_state, running_state ):
check=True, stdout=subprocess.PIPE)

# Convert the captured stdin to a list for comparison with expected output.
result_list = completed_process.stdout.decode().split("\n")
result_list = completed_process.stdout.decode().replace('\r', '').split("\n")

assert expect in result_list

Expand Down Expand Up @@ -176,7 +177,7 @@ def validate_node_list( node_list ):
check=True, stdout=subprocess.PIPE)

# Convert the captured stdin to a list for comparison with expected output.
result_list = completed_process.stdout.decode().split("\n")
result_list = completed_process.stdout.decode().replace('\r', '').split("\n")

# Iterate over the elements in the results list
for entry in result_list:
Expand All @@ -201,7 +202,7 @@ def expect_empty_verbose_list():

# Call the tool, check expected value.
completed_process = subprocess.run([DUNES_EXE, "--list"], check=True, stdout=subprocess.PIPE)
assert completed_process.stdout.decode() == empty_verbose_list
assert completed_process.stdout.decode().replace('\r', '') == empty_verbose_list


# pylint: disable=too-many-statements
Expand Down Expand Up @@ -242,13 +243,15 @@ def test_nodes():

# Test --get-active shows NODE_BRAVO
# Tests `--get-active`.
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode() == (NODE_BRAVO + "\n")
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode().replace('\r', '') \
== (NODE_BRAVO + "\n")

# Test --set-active works to switch to NODE_ALPHA and --get active returns the correct value.
# Tests `--set-active` switch active node while run state is left unchanged.
subprocess.run([DUNES_EXE, "--set-active", NODE_ALPHA], check=True)
validate_node_list([[NODE_ALPHA, True, False],[NODE_BRAVO, False, True]]) # Note this is TF,FT
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode() == (NODE_ALPHA + "\n")
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode().replace('\r', '') \
== (NODE_ALPHA + "\n")

# Remove NODE_ALPHA, ensure it is no longer in the list.
# Tests `--remove`.
Expand Down Expand Up @@ -318,7 +321,7 @@ def test_nodes():

# Test --export-node using standard filename.
subprocess.run([DUNES_EXE, "--export-node", NODE_ALPHA, EXPORT_DIR], check=True)
assert os.path.exists(EXPORT_DIR + "/" + NODE_ALPHA + ".tgz")
assert os.path.exists( os.path.join(EXPORT_DIR, NODE_ALPHA+".tgz") )

# Below check documents current behavior: node_bravo is active, however before exporting node_charlie was active.
# Fix this in issue https://github.com/AntelopeIO/DUNES/issues/159
Expand All @@ -327,16 +330,16 @@ def test_nodes():
[NODE_CHARLIE, False, True, DEFAULT_HTTP_ADDR, DEFAULT_P2P_ADDR, DEFAULT_SHIP_ADDR]])

# Test --export-node using provided filename.
subprocess.run([DUNES_EXE, "--export-node", NODE_BRAVO, EXPORT_DIR + "/bravo_export.tgz"], check=True)
assert os.path.exists(EXPORT_DIR + "/bravo_export.tgz")
subprocess.run([DUNES_EXE, "--export-node", NODE_BRAVO, os.path.join(EXPORT_DIR, "bravo_export.tgz")], check=True)
assert os.path.exists( os.path.join(EXPORT_DIR,"bravo_export.tgz") )

validate_node_list([[NODE_ALPHA, False, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR],
[NODE_BRAVO, True, True, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR],
[NODE_CHARLIE, False, True, DEFAULT_HTTP_ADDR, DEFAULT_P2P_ADDR, DEFAULT_SHIP_ADDR]])

# Test --export-node using non-existing path.
subprocess.run([DUNES_EXE, "--export-node", NODE_CHARLIE, EXPORT_DIR + "/new_path/charlie_export.tgz"], check=True)
assert os.path.exists(EXPORT_DIR + "/new_path/charlie_export.tgz")
subprocess.run([DUNES_EXE, "--export-node", NODE_CHARLIE, os.path.join(EXPORT_DIR, *["new_path","charlie_export.tgz"])], check=True)
assert os.path.exists( os.path.join(EXPORT_DIR, *["new_path","charlie_export.tgz"]) )

validate_node_list([[NODE_ALPHA, False, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR],
[NODE_BRAVO, False, True, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR],
Expand All @@ -347,14 +350,14 @@ def test_nodes():

# Test --import-node
# Import each node from the export tests and
subprocess.run([DUNES_EXE, "--import-node", EXPORT_DIR + "/ALPHA_NODE.tgz", NODE_ALPHA], check=True)
subprocess.run([DUNES_EXE, "--import-node", os.path.join(EXPORT_DIR, "ALPHA_NODE.tgz"), NODE_ALPHA], check=True)
validate_node_list([[NODE_ALPHA, True, True, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR]])

subprocess.run([DUNES_EXE, "--import-node", EXPORT_DIR + "/bravo_export.tgz", NODE_BRAVO], check=True)
subprocess.run([DUNES_EXE, "--import-node", os.path.join(EXPORT_DIR, "bravo_export.tgz"), NODE_BRAVO], check=True)
validate_node_list([[NODE_ALPHA, False, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR],
[NODE_BRAVO, True, True, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR]])

subprocess.run([DUNES_EXE, "--import-node", EXPORT_DIR + "/new_path/charlie_export.tgz", NODE_CHARLIE], check=True)
subprocess.run([DUNES_EXE, "--import-node", os.path.join(EXPORT_DIR, *["new_path","charlie_export.tgz"]), NODE_CHARLIE], check=True)
validate_node_list([[NODE_ALPHA, False, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR],
[NODE_BRAVO, False, True, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR],
[NODE_CHARLIE, True, True, DEFAULT_HTTP_ADDR, DEFAULT_P2P_ADDR, DEFAULT_SHIP_ADDR]])
Expand Down Expand Up @@ -396,13 +399,15 @@ def test_start_active_node():

# Test --get-active shows NODE_BRAVO
# Tests `--get-active`.
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode() == (NODE_CHARLIE + "\n")
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode().replace('\r', '') \
== (NODE_CHARLIE + "\n")

# Test --set-active works to switch to NODE_ALPHA and --get active returns the correct value.
# Tests `--set-active` switch active node while run state is left unchanged.
subprocess.run([DUNES_EXE, "--set-active", NODE_ALPHA], check=True)
validate_node_list([[NODE_ALPHA, True, False], [NODE_BRAVO, False, False], [NODE_CHARLIE, False, True]]) # Note this is TF,FT
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode() == (NODE_ALPHA + "\n")
assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode().replace('\r', '') \
== (NODE_ALPHA + "\n")

# Make sure you can start active node
subprocess.run([DUNES_EXE, "--start", NODE_ALPHA], check=True)
Expand Down
40 changes: 19 additions & 21 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@


PROJECT_NAME = "test_app"
TEST_APP_DIR = TEST_PATH + "/" + PROJECT_NAME
TEST_APP_BLD_DIR = TEST_APP_DIR + "/build/" + PROJECT_NAME
TEST_APP_WASM = TEST_APP_BLD_DIR + "/" + PROJECT_NAME + ".wasm" # TEST_APP_BLD_DIR + "/test_app.wasm"
TEST_APP_DIR = os.path.join(TEST_PATH, PROJECT_NAME)
TEST_APP_BLD_DIR = os.path.join(TEST_APP_DIR, *["build", PROJECT_NAME])
TEST_APP_WASM = os.path.join(TEST_APP_BLD_DIR, PROJECT_NAME+".wasm") # TEST_APP_BLD_DIR/test_app.wasm"


def remove_existing():
Expand All @@ -44,17 +44,16 @@ def test_create_cmake_app():
remove_existing()

# Expected files.
filelist = [TEST_APP_DIR + '/',
TEST_APP_DIR + '/src',
TEST_APP_DIR + '/src/' + PROJECT_NAME + '.cpp',
TEST_APP_DIR + '/src/CMakeLists.txt',
TEST_APP_DIR + '/include',
TEST_APP_DIR + '/include/' + PROJECT_NAME + '.hpp',
TEST_APP_DIR + '/ricardian',
TEST_APP_DIR + '/ricardian/' + PROJECT_NAME + '.contracts.md',
TEST_APP_DIR + '/build',
TEST_APP_DIR + '/CMakeLists.txt',
TEST_APP_DIR + '/README.txt']
filelist = [os.path.join(TEST_APP_DIR, 'src'),
os.path.join(TEST_APP_DIR, *['src', PROJECT_NAME+'.cpp']),
os.path.join(TEST_APP_DIR, *['src', 'CMakeLists.txt']),
os.path.join(TEST_APP_DIR, 'include'),
os.path.join(TEST_APP_DIR, *['include', PROJECT_NAME+'.hpp']),
os.path.join(TEST_APP_DIR, 'ricardian'),
os.path.join(TEST_APP_DIR, *['ricardian', PROJECT_NAME+'.contracts.md']),
os.path.join(TEST_APP_DIR, 'build'),
os.path.join(TEST_APP_DIR, 'CMakeLists.txt'),
os.path.join(TEST_APP_DIR, 'README.txt')]

# Create the test app.
completed_process = subprocess.run([DUNES_EXE, "--create-cmake-app", PROJECT_NAME, TEST_PATH], check=True)
Expand All @@ -67,7 +66,7 @@ def test_create_cmake_app():
# Sort the lists and compare.
filelist.sort()
lst.sort()
assert filelist == lst
assert filelist == lst[1:]

# Cleanup
shutil.rmtree(TEST_APP_DIR)
Expand All @@ -80,11 +79,10 @@ def test_create_bare_app():
remove_existing()

# Expected file list.
filelist = [TEST_APP_DIR + '/',
TEST_APP_DIR + '/' + PROJECT_NAME + '.hpp',
TEST_APP_DIR + '/' + PROJECT_NAME + '.cpp',
TEST_APP_DIR + '/' + PROJECT_NAME + '.contracts.md',
TEST_APP_DIR + '/README.txt']
filelist = [os.path.join(TEST_APP_DIR, PROJECT_NAME+'.hpp'),
os.path.join(TEST_APP_DIR, PROJECT_NAME+'.cpp'),
os.path.join(TEST_APP_DIR, PROJECT_NAME+'.contracts.md'),
os.path.join(TEST_APP_DIR, 'README.txt')]

subprocess.run([DUNES_EXE, "--create-bare-app", PROJECT_NAME, TEST_PATH], check=True)
assert os.path.isdir(TEST_APP_DIR) is True
Expand All @@ -95,7 +93,7 @@ def test_create_bare_app():
# Sort and compare expected and actual.
filelist.sort()
lst.sort()
assert filelist == lst
assert filelist == lst[1:]

# Cleanup
shutil.rmtree(TEST_APP_DIR)
Expand Down