diff --git a/.pylintrc b/.pylintrc index bb94eebd..03c7daac 100644 --- a/.pylintrc +++ b/.pylintrc @@ -73,7 +73,7 @@ ignored-modules= # Control the amount of potential inferred values when inferring a single # object. This can help the performance when dealing with large functions or # complex, nested conditions. -limit-inference-results=100 +limit-inference-results=160 # List of plugins (as comma separated values of python module names) to load, # usually to register additional checkers. @@ -328,8 +328,8 @@ indent-after-paren=4 indent-string=' ' # Maximum number of characters on a single line. -# 140 was chosen to work nicely on 14" laptops. -max-line-length=140 +# 160 was chosen to work nicely on 16" laptops. +max-line-length=160 # Maximum number of lines in a module. max-module-lines=1000 diff --git a/src/dunes/__main__.py b/src/dunes/__main__.py index 8a21ca00..17f6f9a3 100644 --- a/src/dunes/__main__.py +++ b/src/dunes/__main__.py @@ -100,7 +100,19 @@ def load_all_modules_from_dir(plugin_dir): handle_simple_args() - dunes_sys = dunes(args) + # Set container name. pylint: disable=invalid-name + container_name = None + if args.container_name is not None: + container_name = args.container_name[0] + + # Set image name. pylint: disable=invalid-name + image_name = None + if args.image_name is not None: + image_name = args.image_name[0] + if args.start_container is None: + parser.exit_with_help_message("--image-name is only valid with --start-container") + + dunes_sys = dunes(container_name, image_name, args) for module in modules: if hasattr(module, 'set_dunes'): diff --git a/src/dunes/args.py b/src/dunes/args.py index 503412b5..d9b2423d 100644 --- a/src/dunes/args.py +++ b/src/dunes/args.py @@ -46,6 +46,8 @@ def __init__(self): description='''DUNES: Docker Utilities for Node Execution and Subsystems. dunes [ARGUMENTS] -- runs any number of commandline commands in the container. Example: dunes -- cleos --help''') + self._parser.add_argument('-C', '--container-name', nargs=1, metavar="", + help="Use only the container named CONTAINER_NAME for operations.") self._parser.add_argument('-s', '--start', nargs=1, metavar="", help='start a new node with a given name.') self._parser.add_argument('-c', '--config', nargs=1, metavar="", @@ -119,6 +121,8 @@ def __init__(self): help='Stop the current Docker container.') self._parser.add_argument('--start-container', action='store_true', help='Start the current Docker container.') + self._parser.add_argument('--image-name', nargs=1, metavar="", + help="Use IMAGE_NAME when starting the container. Only valid for --start-container.") self._parser.add_argument('--set-core-contract', metavar="", help='Set the core contract to the specified account ' '(use `eosio` as account for normal system setup).') @@ -225,11 +229,21 @@ def add_antler_arguments(self): @staticmethod def is_forwarding(): - return len(sys.argv) > 1 and sys.argv[1] == '--' + try: + index = sys.argv.index('--') + return index == 1 or (index in [2,3] and (sys.argv[1][:2] == '-C' or sys.argv[1][:16] == '--container-name')) + except ValueError: + return False + @staticmethod def get_forwarded_args(): - return sys.argv[2:] + try: + index = sys.argv.index('--') + return sys.argv[index+1:] + except ValueError: + return None + def parse(self): try: diff --git a/src/dunes/docker.py b/src/dunes/docker.py index 8520e73f..e9304b10 100644 --- a/src/dunes/docker.py +++ b/src/dunes/docker.py @@ -7,51 +7,93 @@ class docker_error(Exception): pass +IMAGES_BASE_URL = 'ghcr.io/antelopeio/' +CONTAINER_NAME = 'dunes_container' +IMAGE_NAME = 'dunes:latest' + class docker: - _container = "" - _image = "" + _container = CONTAINER_NAME + _image = None _cl_args = None - _dunes_url = 'ghcr.io/antelopeio/dunes:latest' + _dunes_url = "" def __init__(self, container, image, cl_args): - self._container = container - self._image = image + # pylint: disable=too-many-branches self._cl_args = cl_args + if container is not None: + self._container = container + + + # Get list of all containers, search for this container in the list and set some values. + container_found = False + stdout,_,_ = self.execute_docker_cmd(['container', 'ls', '-a']) + for line in stdout.split('\n'): + if self._container in line: + container_found = True + entries = line.split() + if len(entries) > 1: + self._image = entries[1] + + # Test to see if the container is running. + container_running = False + if container_found: + # Get the list of running containers. + stdout,_,_ = self.execute_docker_cmd(['container', 'ls']) + container_running = self._container in stdout + + # Sanity check users image input. + if image is not None: + if self._image is None: + self._image = image + elif self._image != image: + raise docker_error + self._image = image + + # Set image name in the case user didn't set it and there's no container. + if self._image is None: + self._image = IMAGE_NAME + + # Set url. + self._dunes_url = IMAGES_BASE_URL+self._image + + # No need to continue if the container is already running! + if container_running: + return - # check if container is running - stdout, stderr, exit_code = self.execute_docker_cmd(['container', 'ls']) - - # if container is not in the list then create one - if self._container not in stdout: - # check if container is stopped - stdout, stderr, exit_code = self.execute_docker_cmd( - ['container', 'ls', '-a']) + # If we found the container, try to start it. + if container_found: + self.execute_docker_cmd(['container', 'start', self._container]) + # Get the list of running containers and see what our status is: + stdout,stderr,_ = self.execute_docker_cmd(['container', 'ls']) if self._container in stdout: - self.execute_docker_cmd( - ['container', 'start', self._container]) - else: - # download DUNES image - dunes_image = subprocess.check_output(['docker', 'images', '-q', self._image], - stderr=None, encoding='utf-8') - - if dunes_image == '': - print('Downloading DUNES image') - self.upgrade() - with subprocess.Popen(['docker', 'tag', self._dunes_url, 'dunes:latest']) as proc: - proc.communicate() - - # start a new container - print("Creating docker container [" + self._container + "]") - host_dir = '/' - if platform.system() == 'Windows': - host_dir = 'C:/' - - self.execute_docker_cmd( - ['run', '-p', '127.0.0.1:8888:8888/tcp', '-p', '127.0.0.1:9876:9876/tcp', '-p', - '127.0.0.1:8080:8080/tcp', '-p', '127.0.0.1:3000:3000/tcp', '-p', - '127.0.0.1:8000:8000/tcp', '-v', host_dir + ':/host', '-d', '--name=' + self._container, - self._image, 'tail', '-f', '/dev/null']) + return + raise docker_error(f"Failed to start {self._container}.\n{stderr}") + + # No container was found, so we need to start one. + # Test to see if desired image is available locally. + dunes_image = subprocess.check_output(['docker', 'images', '-q', self._image], stderr=None, encoding='utf-8') + # Nope, try to download it. + if dunes_image == '': + print('Downloading DUNES image') + self.upgrade() + + # Create the new container. + print("Creating docker container [" + self._container + "]") + host_dir = '/' + if platform.system() == 'Windows': + host_dir = 'C:/' + self.execute_docker_cmd(['run', + '-p', '127.0.0.1:8888:8888/tcp', + '-p', '127.0.0.1:9876:9876/tcp', + '-p', '127.0.0.1:8080:8080/tcp', + '-p', '127.0.0.1:3000:3000/tcp', + '-p', '127.0.0.1:8000:8000/tcp', + '-v', host_dir + ':/host', + '-d', '--name=' + self._container, + self._image, + 'tail', '-f', '/dev/null']) + @staticmethod def abs_host_path(directory): @@ -220,5 +262,10 @@ def execute_bg_cmd(self, cmd): return self.execute_cmd(cmd + ['&']) def upgrade(self): + # Pull the new image and give it a local tag. + print(f"['docker', 'pull', {self._dunes_url}]") with subprocess.Popen(['docker', 'pull', self._dunes_url]) as proc: proc.communicate() + if self._dunes_url != self._image: + with subprocess.Popen(['docker', 'tag', self._dunes_url, self._image]) as proc: + proc.communicate() diff --git a/src/dunes/dunes.py b/src/dunes/dunes.py index 314fd1ac..1eb03950 100644 --- a/src/dunes/dunes.py +++ b/src/dunes/dunes.py @@ -55,9 +55,9 @@ class dunes: _token_priv_key = "5JPJoZXizFVi19wHkboX5fwwEU2jZVvtSJpQkQu3uqgNu8LNdQN" _token_pub_key = "EOS6v86d8DAxjfGu92CLrnEzq7pySpVWYV2LjaxPaDJJvyf9Vpx5R" - def __init__(self, cl_args): + def __init__(self, container_name=None, image_name=None, cl_args=None): self._cl_args = cl_args - self._docker = docker('dunes_container', 'dunes:latest', cl_args) + self._docker = docker(container_name, image_name, cl_args) self._wallet_pw = self.get_wallet_pw() self._context = context(self._docker) diff --git a/tests/README.md b/tests/README.md index df739589..fb4a7246 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,7 +2,7 @@ # WARNING -These tests are destructive. Do NOT run them when there is important data in your container! +Some of these tests are destructive. Avoid running them when there is important data in your container! ## Getting Started diff --git a/tests/a100_generate_container_image_test.py b/tests/a100_generate_container_image_test.py index 2585729e..b9eed410 100644 --- a/tests/a100_generate_container_image_test.py +++ b/tests/a100_generate_container_image_test.py @@ -10,7 +10,13 @@ import subprocess import pytest -from common import TEST_PATH, DUNES_EXE, DUNES_ROOT +from common import TEST_PATH, DUNES_EXE, DUNES_ROOT, stop_dunes_containers + + +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + def get_short_hash(): @@ -57,9 +63,9 @@ def remove_images(repo_name): # Remove {repo_name}:* images. images = subprocess.check_output(['docker', 'images', '-q', repo_name], stderr=None, encoding='utf-8').strip().split('\n') + images = list(set(images)) # Remove duplicates. for myimg in images: - # pylint: disable=subprocess-run-check - subprocess.run(['docker', 'image', 'rm', myimg, '--force'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, check=False) + subprocess.run(['docker', 'image', 'rm', myimg, '--force'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, check=True) def remove_tagged_image(tag): @@ -81,6 +87,7 @@ def clean_destructive(): # Remove an existing container, then images. # Send output to subprocess.DEVNULL since we EXPECT docker might tell us containers and images don't exist. # pylint: disable=subprocess-run-check, line-too-long + subprocess.run(['docker', 'container', 'stop', 'dunes_container'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, check=False) subprocess.run(['docker', 'container', 'rm', 'dunes_container', '--force'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, check=False) # Remove dunes:* images. remove_images('dunes') diff --git a/tests/common.py b/tests/common.py index 09bbc674..129be034 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,5 +1,6 @@ import os import platform +import subprocess # Find path for tests, root, and executable: TEST_PATH = os.path.dirname(os.path.abspath(__file__)) @@ -16,3 +17,34 @@ DEFAULT_HTTP_ADDR = "0.0.0.0:8888" DEFAULT_P2P_ADDR = "0.0.0.0:9876" DEFAULT_SHIP_ADDR = "0.0.0.0:8080" + + +# Constants for test container and images +TEST_CONTAINER_NAME = 'dunes_regression_test_container' +TEST_IMAGE_NAME = 'dunes:latest' + + + +def stop_dunes_containers(): + """Stop any container with 'dune' in the name.""" + + # Get the list of RUNNING containers. + completed_process = subprocess.run(['docker','container','ls'], check=False, stdout=subprocess.PIPE) + + # Parse the list for container names. + for line in completed_process.stdout.decode().split('\n'): + # On a given line, NAME is the final column. + strings = line.split() + index = len(strings)-1 + if index < 1: + continue + name = strings[index] + + # Test for 'dune' (backwards compatible name) in name. + if 'dune' in name: + subprocess.run(['docker', 'container', 'stop', name], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, check=False) + + +def destroy_test_container(): + """Destroy any existing test containers.""" + subprocess.run(['docker', 'container', 'rm', TEST_CONTAINER_NAME, '--force'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, check=False) diff --git a/tests/container.py b/tests/container.py index 0407a6bd..ed62553d 100644 --- a/tests/container.py +++ b/tests/container.py @@ -7,7 +7,7 @@ class container: _container_name = "" _image_name = "" - def __init__(self, container_name='dunes_container', image_name='dunes:latest'): + def __init__(self, container_name, image_name): self._container_name = container_name self._image_name = image_name self._debug = True diff --git a/tests/test_antler_proj.py b/tests/test_antler_proj.py index 0e10ce6f..31c9d1b8 100644 --- a/tests/test_antler_proj.py +++ b/tests/test_antler_proj.py @@ -23,7 +23,7 @@ import subprocess import pytest -from common import DUNES_EXE, TEST_PATH +from common import DUNES_EXE, TEST_PATH, stop_dunes_containers TEST_PROJECT_DIR = os.path.join(TEST_PATH, "antler_test_dir") @@ -37,6 +37,11 @@ def remove_existing(): shutil.rmtree(TEST_PROJECT_DIR) +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + @pytest.mark.skip(reason="Skipped until the release of antler-proj. " "See details in https://github.com/AntelopeIO/DUNES/issues/134") @pytest.mark.safe diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 080dc2b9..ca0e49e5 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=duplicate-code """Test DUNES bootstrap @@ -12,7 +13,7 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, stop_dunes_containers # Globals NODE_NAME = "my_node" @@ -20,25 +21,31 @@ ACCT_NAME2 = "myaccount2" -@pytest.mark.destructive +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + +@pytest.mark.safe def test_booststrap(): # Remove any existing containers. - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--destroy-container"], check=True) # Start the new node. - subprocess.run([DUNES_EXE, "--start", NODE_NAME], check=True) + subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--start", NODE_NAME], check=True) # Create an account. - subprocess.run([DUNES_EXE, "--create-account", ACCT_NAME], check=True) + subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--create-account", ACCT_NAME], check=True) - account_results = subprocess.run([DUNES_EXE, "--", "cleos", "get", "account", ACCT_NAME], check=True, stdout=subprocess.PIPE) + account_results = subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--", "cleos", "get", "account", ACCT_NAME], \ + check=True, stdout=subprocess.PIPE) assert b'created:' in account_results.stdout # Create a key. Get it to a var as well. public_key = None private_key = None - stdout_result = subprocess.run([DUNES_EXE, "--create-key"], check=True, stdout=subprocess.PIPE) + stdout_result = subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--create-key"], check=True, stdout=subprocess.PIPE) result_list = stdout_result.stdout.decode().split("\n") for entry in result_list: # ignore empty entries. @@ -53,20 +60,24 @@ def test_booststrap(): assert private_key is not None # Import the key. - subprocess.run([DUNES_EXE, "--import-dev-key", private_key], check=True) + subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--import-dev-key", private_key], check=True) # Bootstrap the system. - subprocess.run([DUNES_EXE, "--bootstrap-system"], check=True) + subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--bootstrap-system"], check=True) # Create a second account - subprocess.run([DUNES_EXE, "--create-account", ACCT_NAME2], check=True) + subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--create-account", ACCT_NAME2], check=True) # Creation of second account should now be successful - second_account_results = subprocess.run([DUNES_EXE, "--", "cleos", "get", "account", ACCT_NAME2], + second_account_results = subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--", "cleos", "get", "account", ACCT_NAME2], check=True, stdout=subprocess.PIPE) assert b'created:' in second_account_results.stdout # Verify that "Create New Account" has been deployed - results = subprocess.run([DUNES_EXE, "--", "cleos", "get", "abi", "eosio"], + results = subprocess.run([DUNES_EXE, "-C", TEST_CONTAINER_NAME, "--", "cleos", "get", "abi", "eosio"], check=True, stdout=subprocess.PIPE) assert b'Create New Account' in results.stdout + + +if __name__ == "__main__": + test_booststrap() diff --git a/tests/test_bootstrap_full.py b/tests/test_bootstrap_full.py index 8205da4f..c9b16808 100644 --- a/tests/test_bootstrap_full.py +++ b/tests/test_bootstrap_full.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=duplicate-code """Test DUNES bootstrap @@ -12,7 +13,7 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, stop_dunes_containers # Globals NODE_NAME = "my_node" @@ -20,26 +21,31 @@ ACCT_NAME2 = "myaccount2" -@pytest.mark.destructive +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + +@pytest.mark.safe def test_booststrap(): # Remove any existing containers. - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) # Start the new node. - subprocess.run([DUNES_EXE, "--start", NODE_NAME], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_NAME], check=True) # Create an account. - subprocess.run([DUNES_EXE, "--create-account", ACCT_NAME], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-account", ACCT_NAME], check=True) - account_results = subprocess.run([DUNES_EXE, "--", "cleos", "get", "account", ACCT_NAME], + account_results = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--", "cleos", "get", "account", ACCT_NAME], check=True, stdout=subprocess.PIPE) assert b'created:' in account_results.stdout # Create a key. Get it to a var as well. public_key = None private_key = None - stdout_result = subprocess.run([DUNES_EXE, "--create-key"], check=True, stdout=subprocess.PIPE) + stdout_result = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-key"], check=True, stdout=subprocess.PIPE) result_list = stdout_result.stdout.decode().split("\n") for entry in result_list: # ignore empty entries. @@ -54,30 +60,30 @@ def test_booststrap(): assert private_key is not None # Import the key. - subprocess.run([DUNES_EXE, "--import-dev-key", private_key], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--import-dev-key", private_key], check=True) # Bootstrap the system. - subprocess.run([DUNES_EXE, "--bootstrap-system-full"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--bootstrap-system-full"], check=True) # Create a second account should fail because of not enough RAM - subprocess.run([DUNES_EXE, "--create-account", ACCT_NAME2], check=False) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-account", ACCT_NAME2], check=False) - second_account_results = subprocess.run([DUNES_EXE, "--", "cleos", "get", "account", ACCT_NAME2], + second_account_results = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--", "cleos", "get", "account", ACCT_NAME2], check=False, stdout=subprocess.PIPE) assert b'created:' not in second_account_results.stdout # Create an example account with RAM - subprocess.run([DUNES_EXE, "--system-newaccount", ACCT_NAME2, "eosio", + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--system-newaccount", ACCT_NAME2, "eosio", "EOS8C5BLCX2LrmcRLHMC8bN5mML4aFSHrZvyijzfLy48tiije6nTt", "5KNitA34Usr2EVLQKtFrwAJVhyB2F3U7fDHEuP2ee2zZ16w7PeB", "--", "--stake-net", "1.0000 SYS", "--stake-cpu", "1.0000 SYS", "--buy-ram-bytes", "3000"], check=True) # Creation of second account should now be successful - second_account_results = subprocess.run([DUNES_EXE, "--", "cleos", "get", "account", ACCT_NAME2], + second_account_results = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--", "cleos", "get", "account", ACCT_NAME2], check=True, stdout=subprocess.PIPE) assert b'created:' in second_account_results.stdout - results = subprocess.run([DUNES_EXE, "--get-table", "eosio.token", "eosio", "accounts"], + results = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--get-table", "eosio.token", "eosio", "accounts"], check=True, stdout=subprocess.PIPE) assert b'"rows"' in results.stdout diff --git a/tests/test_container.py b/tests/test_container.py index 310746e0..4b6281ef 100644 --- a/tests/test_container.py +++ b/tests/test_container.py @@ -7,32 +7,37 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, TEST_IMAGE_NAME, stop_dunes_containers from container import container -@pytest.mark.destructive +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + +@pytest.mark.safe def test_container_actions(): """ Test the start, stop, and destroy action for containers. """ - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) # Remove any container that already exists. if cntr.exists(): - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) # Create/start the container. - subprocess.run([DUNES_EXE, "--start-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start-container"], check=True) assert cntr.check_status("running") is True # Stop the container. - subprocess.run([DUNES_EXE, "--stop-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--stop-container"], check=True) assert cntr.check_status("exited") is True # Restart the container. - subprocess.run([DUNES_EXE, "--start-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start-container"], check=True) assert cntr.check_status("running") is True # Destroy the container. - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) assert cntr.exists() is False diff --git a/tests/test_debug.py b/tests/test_debug.py index 58984c87..5f0134b9 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -11,7 +11,12 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, stop_dunes_containers + + +@pytest.mark.safe +def test_init(): + stop_dunes_containers() @pytest.mark.safe diff --git a/tests/test_deploy.py b/tests/test_deploy.py index 7c8e249c..9b0777eb 100644 --- a/tests/test_deploy.py +++ b/tests/test_deploy.py @@ -12,7 +12,7 @@ import subprocess import pytest -from common import DUNES_EXE, TEST_PATH +from common import DUNES_EXE, TEST_PATH, TEST_CONTAINER_NAME, stop_dunes_containers # Globals NODE_NAME = "my_node" @@ -24,30 +24,35 @@ TEST_APP_WASM = os.path.join(TEST_APP_BLD_DIR, PROJECT_NAME + ".wasm") # TEST_APP_BLD_DIR/test_app.wasm -@pytest.mark.destructive +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + +@pytest.mark.safe def test_deploy(): """Test `--deploy` key.""" # Remove any existing containers and old build directories. - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) if os.path.exists(TEST_APP_DIR): print("Removing TEST_APP_DIR: ", TEST_APP_DIR) shutil.rmtree(TEST_APP_DIR) # Create a new node and an account. - subprocess.run([DUNES_EXE, "--start", NODE_NAME], check=True) - subprocess.run([DUNES_EXE, "--create-account", ACCT_NAME], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_NAME], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-account", ACCT_NAME], check=True) # Create and build a test app. - subprocess.run([DUNES_EXE, "--create-cmake-app", PROJECT_NAME, TEST_PATH], check=True) - subprocess.run([DUNES_EXE, "--cmake-build", TEST_APP_DIR], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-cmake-app", PROJECT_NAME, TEST_PATH], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--cmake-build", TEST_APP_DIR], check=True) assert os.path.isfile(TEST_APP_WASM) is True - subprocess.run([DUNES_EXE, "--deploy", TEST_APP_BLD_DIR, ACCT_NAME], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--deploy", TEST_APP_BLD_DIR, ACCT_NAME], check=True) # Send the action and search for a response in the result. # ./dunes --debug --send-action myaccount hi ["test"] eosio@active - results = subprocess.run([DUNES_EXE, "--send-action", ACCT_NAME, "hi", '["test"]', "eosio@active"], + results = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--send-action", ACCT_NAME, "hi", '["test"]', "eosio@active"], check=True, stdout=subprocess.PIPE) assert b'>> Name : test' in results.stdout diff --git a/tests/test_keys.py b/tests/test_keys.py index 03399c6b..f51c8857 100644 --- a/tests/test_keys.py +++ b/tests/test_keys.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=duplicate-code """Test DUNES Version @@ -10,23 +11,29 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, TEST_IMAGE_NAME, stop_dunes_containers from container import container +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) + cntr.start() + @pytest.mark.safe def test_create_and_import_keys(): """Test `--create-key` and `--import-dev-key` key.""" # Ensure a container exists. - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) if not cntr.exists(): assert cntr.create(), "Failed to create a container. You probably need to create and image with `bootstrap.py`." # Create a key. Get it to a var as well. public_key = None private_key = None - stdout_result = subprocess.run([DUNES_EXE, "--create-key"], check=True, stdout=subprocess.PIPE) + stdout_result = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-key"], check=True, stdout=subprocess.PIPE) result_list = stdout_result.stdout.decode().split("\n") for entry in result_list: # ignore empty entries. @@ -42,4 +49,4 @@ def test_create_and_import_keys(): assert private_key is not None # Import the key. - subprocess.run([DUNES_EXE, "--import-dev-key", private_key], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--import-dev-key", private_key], check=True) diff --git a/tests/test_leap_cdt_contracts_change.py b/tests/test_leap_cdt_contracts_change.py index 7ab68017..97d88631 100644 --- a/tests/test_leap_cdt_contracts_change.py +++ b/tests/test_leap_cdt_contracts_change.py @@ -10,18 +10,23 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, stop_dunes_containers, destroy_test_container + + +@pytest.mark.safe +def test_init(): + stop_dunes_containers() def switch_versions_call(cdt, leap, contracts): """Build the version update command.""" if cdt: - subprocess.run( [DUNES_EXE,'--cdt',cdt], check=True) + subprocess.run( [DUNES_EXE, '-C', TEST_CONTAINER_NAME, '--cdt', cdt], check=True) if leap: - subprocess.run( [DUNES_EXE,'--leap',leap], check=True) + subprocess.run( [DUNES_EXE, '-C', TEST_CONTAINER_NAME, '--leap', leap], check=True) if contracts: - subprocess.run( [DUNES_EXE,'--contracts',contracts], check=True) + subprocess.run( [DUNES_EXE, '-C', TEST_CONTAINER_NAME, '--contracts', contracts], check=True) def switch_versions(cdt=None, leap=None, contracts=None): @@ -29,58 +34,54 @@ def switch_versions(cdt=None, leap=None, contracts=None): switch_versions_call(cdt, leap, contracts) - container_name = 'dunes_container' - # Test the versions are in the container. if cdt: # Try to get CDT version info from inside the container and test it matches. # pylint: disable=line-too-long - completed_process = subprocess.run(['docker', 'exec', '-i', container_name, '/usr/bin/ls', '/usr/opt/cdt'], check=False, stdout=subprocess.PIPE) + completed_process = subprocess.run(['docker', 'exec', '-i', TEST_CONTAINER_NAME, '/usr/bin/ls', '/usr/opt/cdt'], check=False, stdout=subprocess.PIPE) assert cdt in completed_process.stdout.decode() if leap: # Try to get LEAP version info from inside the container and test it matches. # pylint: disable=line-too-long - completed_process = subprocess.run(['docker', 'exec', '-i', container_name, 'leap-util', 'version', 'client'], check=False, stdout=subprocess.PIPE) + completed_process = subprocess.run(['docker', 'exec', '-i', TEST_CONTAINER_NAME, 'leap-util', 'version', 'client'], check=False, stdout=subprocess.PIPE) assert leap in completed_process.stdout.decode() if contracts: # Try to get contracts version info from inside the container and test it matches. # pylint: disable=line-too-long - completed_process = subprocess.run(['docker', 'exec', '-i', container_name, 'cat', '/app/reference-contracts/VERSION.DUNES.txt'], check=False, stdout=subprocess.PIPE) + completed_process = subprocess.run(['docker', 'exec', '-i', TEST_CONTAINER_NAME, 'cat', '/app/reference-contracts/VERSION.DUNES.txt'], check=False, stdout=subprocess.PIPE) assert contracts in completed_process.stdout.decode() -@pytest.mark.destructive +@pytest.mark.safe def test_begin(): - # Start a container. - subprocess.run([DUNES_EXE, "--start-container"], check=True) + # Start a test container. + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start-container"], check=True) -@pytest.mark.destructive +@pytest.mark.safe def test_combo1(): switch_versions(cdt='3.0.1', leap='3.2.1', contracts='2ae64b0b9a9096a3d25339c3df364e08fde66258') -@pytest.mark.destructive +@pytest.mark.safe def test_combo2(): switch_versions(cdt='3.1.0', leap='4.0.0', contracts='bd6c0b1a5086c8826a2840e7b8b5e1adaff00314') -@pytest.mark.destructive +@pytest.mark.safe def test_leap1(): switch_versions(leap='3.2.1') -@pytest.mark.destructive +@pytest.mark.safe def test_cdt1(): switch_versions(cdt='3.0.1') -@pytest.mark.destructive +@pytest.mark.safe def test_contracts1(): switch_versions(contracts='2ae64b0b9a9096a3d25339c3df364e08fde66258') -@pytest.mark.destructive +@pytest.mark.safe def test_end(): - # Just call with the latest. - switch_versions_call("latest", "latest", "latest") - + destroy_test_container() if __name__ == "__main__": @@ -90,4 +91,3 @@ def test_end(): test_leap1() test_cdt1() test_contracts1() - test_end() diff --git a/tests/test_list_features.py b/tests/test_list_features.py index ef39c780..6fc176c3 100644 --- a/tests/test_list_features.py +++ b/tests/test_list_features.py @@ -10,7 +10,12 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, stop_dunes_containers + + +@pytest.mark.safe +def test_init(): + stop_dunes_containers() @pytest.mark.safe @@ -43,7 +48,7 @@ def test_list_features(): for temp in expect_list: expect = expect + temp + '\n' + subprocess.run([DUNES_EXE, "--start-container"], check=True, stdout=subprocess.PIPE) # Call the tool, check return code, check expected value. - completed_process = subprocess.run([DUNES_EXE, "--list-features"], - check=True, stdout=subprocess.PIPE) + completed_process = subprocess.run([DUNES_EXE, "--list-features"], check=True, stdout=subprocess.PIPE) assert completed_process.stdout.decode().replace('\r', '') == expect diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 7301a877..0acb59a6 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -8,27 +8,32 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, TEST_IMAGE_NAME, stop_dunes_containers, destroy_test_container from container import container -@pytest.mark.destructive +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + destroy_test_container() + +@pytest.mark.safe def test_monitor(): """Test `--monitor` key.""" # Remove any container that already exists. - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) if cntr.exists(): - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) # This will start a container; however, there will be NO active node, so it will fail. - results = subprocess.run([DUNES_EXE, "--monitor"], capture_output=True, check=False) + results = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--monitor"], capture_output=True, check=False) assert results.returncode != 0 assert cntr.check_status("running") is True # Start a node. - subprocess.run([DUNES_EXE, "--start", "my_node"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", "my_node"], check=True) # Now try to monitor again. - results = subprocess.run([DUNES_EXE, "--monitor"], capture_output=True, check=False) + results = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--monitor"], capture_output=True, check=False) assert b'server_version' in results.stdout diff --git a/tests/test_nodes.py b/tests/test_nodes.py index 44837aa1..798ff374 100644 --- a/tests/test_nodes.py +++ b/tests/test_nodes.py @@ -45,11 +45,16 @@ ALT_SHIP_ADDR_CUST="0.0.0.0:9998" +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + def remove_all(): """ Remove any existing nodes. """ # Call dunes, check the return is True. - completed_process = subprocess.run([DUNES_EXE, "--simple-list"], + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--simple-list"], check=True, stdout=subprocess.PIPE) # Convert the captured stdin to a list. @@ -66,7 +71,7 @@ def remove_all(): # Remove the entry name = entry.split('|')[0] print("Removing: ", name) - subprocess.run([DUNES_EXE, "--remove", name], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--remove", name], check=True) def validate_node_state( node_name, active_state, running_state ): @@ -94,7 +99,7 @@ def validate_node_state( node_name, active_state, running_state ): expect += DEFAULT_HTTP_ADDR + "|" + DEFAULT_P2P_ADDR + "|" + DEFAULT_SHIP_ADDR # Call dunes, check the return is True. - completed_process = subprocess.run([DUNES_EXE, "--simple-list"], + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--simple-list"], check=True, stdout=subprocess.PIPE) # Convert the captured stdin to a list for comparison with expected output. @@ -173,7 +178,7 @@ def validate_node_list( node_list ): expect_list.append(temp) # Call dunes, check the return is True. - completed_process = subprocess.run([DUNES_EXE, "--simple-list"], + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--simple-list"], check=True, stdout=subprocess.PIPE) # Convert the captured stdin to a list for comparison with expected output. @@ -201,20 +206,20 @@ def expect_empty_verbose_list(): "---------------------------------------------------------------------------------\n" # Call the tool, check expected value. - completed_process = subprocess.run([DUNES_EXE, "--list"], check=True, stdout=subprocess.PIPE) + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--list"], check=True, stdout=subprocess.PIPE) assert completed_process.stdout.decode().replace('\r', '') == empty_verbose_list # pylint: disable=too-many-statements -@pytest.mark.destructive +@pytest.mark.safe def test_nodes(): """Run the tests.""" # Remove any container that already exists and create a fresh one. - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) if cntr.exists(): - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) - subprocess.run([DUNES_EXE, "--start-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start-container"], check=True) # Ensure there are no existing nodes. # Tests `--simple-list` and `--list` @@ -224,77 +229,78 @@ def test_nodes(): # Create a node and test its state. # Tests `--start` when the node needs to be created. - subprocess.run([DUNES_EXE, "--start", NODE_ALPHA], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_ALPHA], check=True) validate_node_state(NODE_ALPHA, True, True) # Stop the node and test its state. # Tests `--stop` - subprocess.run([DUNES_EXE, "--stop", NODE_ALPHA], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--stop", NODE_ALPHA], check=True) validate_node_state(NODE_ALPHA, True, False) # Restart the node and test its state. # Tests `--start` when the node already exists. - subprocess.run([DUNES_EXE, "--start", NODE_ALPHA], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_ALPHA], check=True) validate_node_state(NODE_ALPHA, True, True) # Create a 2nd node and test the state of both nodes. # Tests the behavior of `--start` on an already active, running node. - subprocess.run([DUNES_EXE, "--start", NODE_BRAVO], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_BRAVO], check=True) validate_node_state(NODE_BRAVO, True, True) validate_node_list([[NODE_ALPHA, False, False],[NODE_BRAVO, True, True]]) # Test --get-active shows NODE_BRAVO # Tests `--get-active`. - assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode().replace('\r', '') \ - == (NODE_BRAVO + "\n") + assert subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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().replace('\r', '') \ - == (NODE_ALPHA + "\n") + assert subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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`. - subprocess.run([DUNES_EXE, "--remove", NODE_ALPHA], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--remove", NODE_ALPHA], check=True) validate_node_list([[NODE_BRAVO, False, True]]) # Note the state of NODE_BRAVO is FT # Remove anything to get to a clean slate. remove_all() # Test `--start` where start includes a config path. - subprocess.run([DUNES_EXE, "--start", NODE_ALPHA, "--config", CONFIG_PATH], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_ALPHA, "--config", CONFIG_PATH], check=True) validate_node_list([[NODE_ALPHA, True, True, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR]]) # Test `--start` where start includes a config file named config.ini - subprocess.run([DUNES_EXE, "--start", NODE_BRAVO, "--config", CONFIG_FILE], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_BRAVO, "--config", CONFIG_FILE], 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,"--stop", NODE_BRAVO], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--stop", NODE_BRAVO], check=True) validate_node_list([[NODE_ALPHA, False, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR], [NODE_BRAVO, True, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR]]) # Test `--start` where start includes a config file with customized name mycustconfig001.ini - subprocess.run([DUNES_EXE, "--start", NODE_BRAVO, "--config", CONFIG_FILE_CUST], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_BRAVO, "--config", CONFIG_FILE_CUST], 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_CUST, ALT_P2P_ADDR_CUST, ALT_SHIP_ADDR_CUST]]) # stop and then start NODE_BRAVO again using standard config.ini - subprocess.run([DUNES_EXE,"--stop", NODE_BRAVO], check=True) - subprocess.run([DUNES_EXE, "--start", NODE_BRAVO, "--config", CONFIG_FILE], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--stop", NODE_BRAVO], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_BRAVO, "--config", CONFIG_FILE], 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]]) # Test `--start` with invalid config file path. # pylint: disable=subprocess-run-check - completed_process = subprocess.run([DUNES_EXE, "--start", NODE_ALPHA, "--config", "unknown_config"], check=False) + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_ALPHA, "--config", "unknown_config"], \ + check=False) assert completed_process.returncode != 0 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]]) # Test `--config` alone. # pylint: disable=subprocess-run-check - completed_process = subprocess.run([DUNES_EXE, "--config", "unknown_config"], check=False) + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--config", "unknown_config"], check=False) assert completed_process.returncode != 0 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]]) @@ -311,7 +317,7 @@ def test_nodes(): os.mkdir(EXPORT_DIR) # Just add an additional node for export. - subprocess.run([DUNES_EXE, "--start", NODE_CHARLIE], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", 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]]) @@ -320,7 +326,7 @@ def test_nodes(): # export to TEST_PATH, TEST_PATH/my_file.tgz, TEST_PATH/does_not_exist_yet/my_file.tgz # Test --export-node using standard filename. - subprocess.run([DUNES_EXE, "--export-node", NODE_ALPHA, EXPORT_DIR], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--export-node", NODE_ALPHA, EXPORT_DIR], check=True) 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. @@ -330,7 +336,8 @@ 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, os.path.join(EXPORT_DIR, "bravo_export.tgz")], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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], @@ -338,7 +345,8 @@ def test_nodes(): [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, os.path.join(EXPORT_DIR, *["new_path","charlie_export.tgz"])], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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], @@ -350,14 +358,17 @@ def test_nodes(): # Test --import-node # Import each node from the export tests and - subprocess.run([DUNES_EXE, "--import-node", os.path.join(EXPORT_DIR, "ALPHA_NODE.tgz"), NODE_ALPHA], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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", os.path.join(EXPORT_DIR, "bravo_export.tgz"), NODE_BRAVO], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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", os.path.join(EXPORT_DIR, *["new_path","charlie_export.tgz"]), NODE_CHARLIE], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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]]) @@ -366,15 +377,15 @@ def test_nodes(): remove_all() -@pytest.mark.destructive +@pytest.mark.safe def test_start_active_node(): """start_active_node""" # Remove any container that already exists and create a fresh one. - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) if cntr.exists(): - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) - subprocess.run([DUNES_EXE, "--start-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start-container"], check=True) # Ensure there are no existing nodes. # Tests `--simple-list` and `--list` @@ -384,33 +395,33 @@ def test_start_active_node(): # Create a node and test its state. # Tests `--start` when the node needs to be created. - subprocess.run([DUNES_EXE, "--start", NODE_ALPHA], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_ALPHA], check=True) validate_node_state(NODE_ALPHA, True, True) # Create a 2nd node and test the state of both nodes. - subprocess.run([DUNES_EXE, "--start", NODE_BRAVO], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_BRAVO], check=True) validate_node_state(NODE_BRAVO, True, True) validate_node_list([[NODE_ALPHA, False, False], [NODE_BRAVO, True, True]]) # Create a 3rd node - subprocess.run([DUNES_EXE, "--start", NODE_CHARLIE], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_CHARLIE], check=True) validate_node_state(NODE_CHARLIE, True, True) validate_node_list([[NODE_ALPHA, False, False], [NODE_BRAVO, False, False], [NODE_CHARLIE, True, True]]) # Test --get-active shows NODE_BRAVO # Tests `--get-active`. - assert subprocess.run([DUNES_EXE, "--get-active"], check=True, stdout=subprocess.PIPE).stdout.decode().replace('\r', '') \ - == (NODE_CHARLIE + "\n") + assert subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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().replace('\r', '') \ - == (NODE_ALPHA + "\n") + assert subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--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) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_ALPHA], check=True) validate_node_state(NODE_ALPHA, True, True) validate_node_list([[NODE_ALPHA, True, True], [NODE_BRAVO, False, False], [NODE_CHARLIE, False, False]]) @@ -418,15 +429,15 @@ def test_start_active_node(): remove_all() -@pytest.mark.destructive +@pytest.mark.safe def test_node_start_rmdirtydb(): """test dune --start with --rmdirtydb""" # Remove any container that already exists and create a fresh one. - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) if cntr.exists(): - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) - subprocess.run([DUNES_EXE, "--start-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start-container"], check=True) # Ensure there are no existing nodes. remove_all() @@ -434,12 +445,12 @@ def test_node_start_rmdirtydb(): expect_empty_verbose_list() # Create NODE_ALPHA - res = subprocess.run([DUNES_EXE,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=True) + res = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=True) assert b'no action for --rmdirtydb, because node [ ALPHA_NODE ] has never run before' in res.stdout validate_node_state(NODE_ALPHA, True, True) # verify already running - res = subprocess.run([DUNES_EXE,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=True) + res = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=True) assert b'no action for --rmdirtydb, because node [ ALPHA_NODE ] is already running' in res.stdout validate_node_state(NODE_ALPHA, True, True) @@ -452,27 +463,27 @@ def test_node_start_rmdirtydb(): validate_node_state(NODE_ALPHA, True, False) # start NODE_ALPHA to verify the node fails to start - res = subprocess.run([DUNES_EXE,"--start", NODE_ALPHA], stdout=subprocess.PIPE, check=False) + res = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_ALPHA], stdout=subprocess.PIPE, check=False) assert b'database dirty flag set' in res.stdout validate_node_state(NODE_ALPHA, True, False) # start NODE_ALPHA with --rmdirtydb to verify the node starts successfully - res = subprocess.run([DUNES_EXE,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=False) + res = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=False) assert res.returncode == 0 assert b'Found the database dirty flag for node [ ALPHA_NODE ]' in res.stdout assert b'using --replay-blockchain of nodeos to clean the dirty flag' in res.stdout validate_node_state(NODE_ALPHA, True, True) # stop NODE_ALPHA and then bring it up again, verify no dirty database flag set - subprocess.run([DUNES_EXE,"--stop", NODE_ALPHA], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--stop", NODE_ALPHA], check=True) validate_node_state(NODE_ALPHA, True, False) - res = subprocess.run([DUNES_EXE,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=False) + res = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_ALPHA, "--rmdirtydb"], stdout=subprocess.PIPE, check=False) assert res.returncode == 0 assert b'no action for --rmdirtydb, because node [ ALPHA_NODE ] dirty database flag is not yet set' in res.stdout validate_node_state(NODE_ALPHA, True, True) # Use similar steps to test the 2nd node NODE_BRAVO - subprocess.run([DUNES_EXE,"--start", NODE_BRAVO, "--rmdirtydb"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_BRAVO, "--rmdirtydb"], check=True) validate_node_state(NODE_BRAVO, True, True) pid_node = cntr.find_pid('/app/nodes/' + NODE_BRAVO + ' ') @@ -482,12 +493,12 @@ def test_node_start_rmdirtydb(): assert pid_node == -1 validate_node_state(NODE_BRAVO, True, False) - res = subprocess.run([DUNES_EXE,"--start", NODE_BRAVO], stdout=subprocess.PIPE, check=False) + res = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_BRAVO], stdout=subprocess.PIPE, check=False) assert b'database dirty flag set' in res.stdout validate_node_state(NODE_BRAVO, True, False) # start NODE_BRAVO with --rmdirtydb to verify the node starts successfully - res = subprocess.run([DUNES_EXE,"--start", NODE_BRAVO, "--rmdirtydb"], stdout=subprocess.PIPE, check=False) + res = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_BRAVO, "--rmdirtydb"], stdout=subprocess.PIPE, check=False) assert res.returncode == 0 assert b'Found the database dirty flag for node [ BRAVO_NODE ]' in res.stdout assert b'using --replay-blockchain of nodeos to clean the dirty flag' in res.stdout @@ -497,20 +508,20 @@ def test_node_start_rmdirtydb(): remove_all() # Test --rmdirtydb can be used together with --config in --start - subprocess.run([DUNES_EXE,"--start", NODE_ALPHA, "--config", CONFIG_PATH, "--rmdirtydb"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_ALPHA, "--config", CONFIG_PATH, "--rmdirtydb"], check=True) validate_node_list([[NODE_ALPHA, True, True, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR]]) # use standard config.ini - subprocess.run([DUNES_EXE,"--start", NODE_BRAVO, "--config", CONFIG_FILE, "--rmdirtydb"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--start", NODE_BRAVO, "--config", CONFIG_FILE, "--rmdirtydb"], 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,"--stop", NODE_BRAVO], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME,"--stop", NODE_BRAVO], check=True) validate_node_list([[NODE_ALPHA, False, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR], [NODE_BRAVO, True, False, ALT_HTTP_ADDR, ALT_P2P_ADDR, ALT_SHIP_ADDR]]) # use customized .ini - subprocess.run([DUNES_EXE, "--start", NODE_BRAVO, "--config", CONFIG_FILE_CUST, "--rmdirtydb"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", NODE_BRAVO, "--config", CONFIG_FILE_CUST, "--rmdirtydb"], 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_CUST, ALT_P2P_ADDR_CUST, ALT_SHIP_ADDR_CUST]]) diff --git a/tests/test_plugin.py b/tests/test_plugin.py index d9af4eb7..7cb27205 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -10,7 +10,7 @@ import subprocess import pytest -from common import DUNES_EXE, DUNES_ROOT, TEST_PATH +from common import DUNES_EXE, DUNES_ROOT, TEST_PATH, stop_dunes_containers src_hello = os.path.join(DUNES_ROOT, *['plugin_example', 'dunes_hello']) @@ -23,6 +23,11 @@ +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + def remove_all(): """Remove all the test plugins""" shutil.rmtree(dst_hello, ignore_errors=True) diff --git a/tests/test_project.py b/tests/test_project.py index ee2edba3..2c5cab15 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -16,7 +16,7 @@ import subprocess import pytest -from common import DUNES_EXE,TEST_PATH +from common import DUNES_EXE, TEST_PATH, TEST_CONTAINER_NAME, TEST_IMAGE_NAME, stop_dunes_containers from container import container @@ -26,10 +26,15 @@ TEST_APP_WASM = os.path.join(TEST_APP_BLD_DIR, PROJECT_NAME+".wasm") # TEST_APP_BLD_DIR/test_app.wasm" +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + def remove_existing(): """ Remove an existing `./test_app` dir. """ - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) cntr.stop() if os.path.exists(TEST_APP_DIR): @@ -56,7 +61,7 @@ def test_create_cmake_app(): 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) + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-cmake-app", PROJECT_NAME, TEST_PATH], check=True) assert completed_process.returncode == 0 assert os.path.isdir(TEST_APP_DIR) is True @@ -84,7 +89,7 @@ def test_create_bare_app(): 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) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-bare-app", PROJECT_NAME, TEST_PATH], check=True) assert os.path.isdir(TEST_APP_DIR) is True # Actual file list. @@ -106,18 +111,18 @@ def test_cmake_and_ctest(): remove_existing() # Create the cmake app, test it exists. - subprocess.run([DUNES_EXE, "--create-cmake-app", PROJECT_NAME, TEST_PATH], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--create-cmake-app", PROJECT_NAME, TEST_PATH], check=True) assert os.path.isdir(TEST_APP_DIR) is True # Build the app, test that the expected output file is created. - subprocess.run([DUNES_EXE, "--cmake-build", TEST_APP_DIR], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--cmake-build", TEST_APP_DIR], check=True) assert os.path.isfile(TEST_APP_WASM) is True # Test that CTest files are run. # @TODO - This should be updated to create and test some PASSING tests. # @TODO - This should be updated to create and test some FAILING tests. with subprocess.Popen( - [DUNES_EXE, "--debug", "--ctest", TEST_APP_DIR, "--", "--no-tests=ignore"], + [DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--debug", "--ctest", TEST_APP_DIR, "--", "--no-tests=ignore"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8") as proc: stdout, _ = proc.communicate() @@ -131,5 +136,5 @@ def test_gdb(): """Test `--gdb` key.""" # Simply ensure gdb is run. - proc = subprocess.run([DUNES_EXE, "--gdb", "/bin/sh"], capture_output=True, encoding="utf-8", check=True) + proc = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--gdb", "/bin/sh"], capture_output=True, encoding="utf-8", check=True) assert "GNU gdb" in proc.stdout diff --git a/tests/test_remainder.py b/tests/test_remainder.py index 7b883968..68af098e 100644 --- a/tests/test_remainder.py +++ b/tests/test_remainder.py @@ -9,18 +9,23 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, TEST_IMAGE_NAME, stop_dunes_containers from container import container -@pytest.mark.destructive +@pytest.mark.safe +def test_init(): + stop_dunes_containers() + + +@pytest.mark.safe def test_unused(): """Test the warning for unused arguments""" # Remove any container that already exists. - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) if cntr.exists(): - subprocess.run([DUNES_EXE, "--destroy-container"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--destroy-container"], check=True) # List of expected values. expect_list = \ @@ -29,7 +34,7 @@ def test_unused(): ] # Call DUNES with improper arguments - completed_process = subprocess.run([DUNES_EXE, "--start", "my_node", "config.ini"], + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--start", "my_node", "config.ini"], check=True, stdout=subprocess.PIPE) # Test for expected values in the captured output. @@ -48,7 +53,7 @@ def test_no_warning(): ] # Call DUNES. - completed_process = subprocess.run([DUNES_EXE, "--gdb", "/usr/bin/echo", "Hello"], + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--gdb", "/usr/bin/echo", "Hello"], check=True, stdout=subprocess.PIPE) # Test values are NOT in the captured output. diff --git a/tests/test_version_choosing.py b/tests/test_version_choosing.py index 308e90a9..73210ef6 100644 --- a/tests/test_version_choosing.py +++ b/tests/test_version_choosing.py @@ -7,7 +7,12 @@ import subprocess import pytest -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, stop_dunes_containers + + +@pytest.mark.safe +def test_init(): + stop_dunes_containers() @pytest.mark.safe @@ -22,14 +27,14 @@ def test_version_choosing(): ] # Ignore checking return code, because eventually we don't choose any version - completed_process = subprocess.run([DUNES_EXE, "--leap"], check=False, stdout=subprocess.PIPE) + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--leap"], check=False, stdout=subprocess.PIPE) # Test for expected values in the captured output. for expect in expect_list: assert expect in completed_process.stdout # Ignore checking return code, because eventually we don't choose any version - completed_process = subprocess.run([DUNES_EXE, "--cdt"], check=False, stdout=subprocess.PIPE) + completed_process = subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--cdt"], check=False, stdout=subprocess.PIPE) # Test for expected values in the captured output. for expect in expect_list: diff --git a/tests/test_version_selector.py b/tests/test_version_selector.py index b63a09a6..3ba1c362 100644 --- a/tests/test_version_selector.py +++ b/tests/test_version_selector.py @@ -9,7 +9,7 @@ import pytest sys.path.insert(1, sys.path.append(dirname(realpath(__file__)) + "/../src/dunes")) -# pylint: disable=wrong-import-position +# pylint: disable=wrong-import-position, import-error import version_selector @patch('version_selector.available_versions_from_url') diff --git a/tests/test_wallet.py b/tests/test_wallet.py index 8621705e..8547a611 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -11,7 +11,12 @@ import pytest from container import container -from common import DUNES_EXE +from common import DUNES_EXE, TEST_CONTAINER_NAME, TEST_IMAGE_NAME, stop_dunes_containers + + +@pytest.mark.safe +def test_init(): + stop_dunes_containers() def tar_dir(file_name, directory): @@ -26,16 +31,16 @@ def untar(file_name): def test_export(): """Test `--export-wallet` key.""" - subprocess.run([DUNES_EXE, "--export-wallet"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--export-wallet"], check=True) assert os.path.exists("wallet.tgz") is True -@pytest.mark.destructive +@pytest.mark.safe def test_import(): """Test `--import-wallet` key.""" - cntr = container('dunes_container', 'dunes:latest') + cntr = container(TEST_CONTAINER_NAME, TEST_IMAGE_NAME) cntr.rm_file("/app/wallet.tgz") @@ -51,7 +56,7 @@ def test_import(): tar_dir("wallet", "_wallet") # Use wallet.tgz created by successfully finished test of export - subprocess.run([DUNES_EXE, "--debug", "--import-wallet", "./wallet.tgz"], check=True) + subprocess.run([DUNES_EXE, '-C', TEST_CONTAINER_NAME, "--debug", "--import-wallet", "./wallet.tgz"], check=True) os.remove("wallet.tgz") shutil.rmtree("_wallet") diff --git a/tests/z9999_image_bootstrap_test.py b/tests/z9999_image_bootstrap_test.py index 9e864aa1..edc13cc6 100644 --- a/tests/z9999_image_bootstrap_test.py +++ b/tests/z9999_image_bootstrap_test.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=duplicate-code """Test image bootstrap with various versions of CDT, leap, and reference-contracts.