Skip to content

Commit

Permalink
remove vmtools and contract test command
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Feb 5, 2024
1 parent 106bde2 commit eebfcef
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 138 deletions.
13 changes: 6 additions & 7 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ usage: mxpy contract COMMAND [-h] ...
Build, deploy, upgrade and interact with Smart Contracts
COMMANDS:
{new,templates,build,clean,test,report,deploy,call,upgrade,query,verify,reproducible-build}
{new,templates,build,clean,report,deploy,call,upgrade,query,verify,reproducible-build}
OPTIONS:
-h, --help show this help message and exit
Expand All @@ -69,7 +69,6 @@ new Create a new Smart Contract project based on a te
templates List the available Smart Contract templates.
build Build a Smart Contract project.
clean Clean a Smart Contract project.
test Run scenarios (tests).
report Print a detailed report of the smart contracts.
deploy Deploy a Smart Contract.
call Interact with a Smart Contract (execute function).
Expand Down Expand Up @@ -1263,11 +1262,11 @@ usage: mxpy deps install [-h] ...
Install dependencies or multiversx-sdk modules.
positional arguments:
{all,rust,golang,vmtools,testwallets} the dependency to install
{all,rust,golang,testwallets} the dependency to install
options:
-h, --help show this help message and exit
--overwrite whether to overwrite an existing installation
-h, --help show this help message and exit
--overwrite whether to overwrite an existing installation
```
### Dependencies.Check
Expand All @@ -1280,10 +1279,10 @@ usage: mxpy deps check [-h] ...
Check whether a dependency is installed.
positional arguments:
{all,rust,golang,vmtools,testwallets} the dependency to check
{all,rust,golang,testwallets} the dependency to check
options:
-h, --help show this help message and exit
-h, --help show this help message and exit
```
## Group **Configuration**
Expand Down
19 changes: 0 additions & 19 deletions multiversx_sdk_cli/cli_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ def setup_parser(args: List[str], subparsers: Any) -> Any:
sub.add_argument("--path", default=os.getcwd(), help="the project directory (default: current directory)")
sub.set_defaults(func=clean)

sub = cli_shared.add_command_subparser(subparsers, "contract", "test", "Run scenarios (tests).")
_add_project_arg(sub)
sub.add_argument("--directory", default="scenarios",
help="🗀 the directory containing the tests (default: %(default)s)")
sub.add_argument("--wildcard", required=False, help="wildcard to match only specific test files")
_add_recursive_arg(sub)
sub.set_defaults(func=run_tests)

sub = cli_shared.add_command_subparser(subparsers, "contract", "report", "Print a detailed report of the smart contracts.")
sub.add_argument("--skip-build", action="store_true", default=False, help="skips the step of building of the wasm contracts")
sub.add_argument("--skip-twiggy", action="store_true", default=False, help="skips the steps of building the debug wasm files and running twiggy")
Expand Down Expand Up @@ -213,10 +205,6 @@ def _add_build_options_args(sub: Any):
help="for rust projects, optionally specify the suffix of the wasm bytecode output file")


def _add_recursive_arg(sub: Any):
sub.add_argument("-r", "--recursive", dest="recursive", action="store_true", help="locate projects recursively")


def _add_bytecode_arg(sub: Any):
sub.add_argument("--bytecode", type=str, required=True,
help="the file containing the WASM bytecode")
Expand Down Expand Up @@ -300,13 +288,6 @@ def do_report(args: Any):
projects.do_report(args, args_dict)


def run_tests(args: Any):
check_if_rust_is_installed()
project_paths = get_project_paths(args)
for project in project_paths:
projects.run_tests(project, args)


def deploy(args: Any):
logger.debug("deploy")
cli_shared.check_guardian_and_options_args(args)
Expand Down
5 changes: 0 additions & 5 deletions multiversx_sdk_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any, Dict, List

from multiversx_sdk_cli import errors, utils
from multiversx_sdk_cli.ux import show_warning

SDK_PATH = Path("~/multiversx-sdk").expanduser().resolve()
LOCAL_CONFIG_PATH = Path("mxpy.json").resolve()
Expand Down Expand Up @@ -143,10 +142,6 @@ def _guard_valid_config_deletion(name: str):

def get_defaults() -> Dict[str, Any]:
return {
"dependencies.vmtools.tag": "v1.5.24",
"dependencies.vmtools.urlTemplate.linux": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.osx": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.vmtools.urlTemplate.windows": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz",
"dependencies.rust.tag": "nightly-2023-12-11",
"dependencies.golang.resolution": "SDK",
"dependencies.golang.tag": "go1.20.7",
Expand Down
4 changes: 1 addition & 3 deletions multiversx_sdk_cli/dependencies/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from multiversx_sdk_cli import config, errors
from multiversx_sdk_cli.dependencies.modules import (DependencyModule,
GolangModule, Rust,
TestWalletsModule,
VMToolsModule)
TestWalletsModule)

logger = logging.getLogger("install")

Expand Down Expand Up @@ -51,7 +50,6 @@ def get_all_deps() -> List[DependencyModule]:
return [
Rust(key="rust"),
GolangModule(key="golang"),
VMToolsModule(key="vmtools"),
TestWalletsModule(key="testwallets")
]

Expand Down
53 changes: 0 additions & 53 deletions multiversx_sdk_cli/dependencies/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,59 +135,6 @@ def _get_archive_path(self, tag: str) -> Path:
return archive


class VMToolsModule(StandaloneModule):
def __init__(self, key: str, aliases: List[str] = []):
super().__init__(key, aliases)
self.repo_name = 'mx-chain-vm-go'
self.organisation = 'multiversx'

def _post_install(self, tag: str):
dependencies.install_module('golang')

self.build_binary(tag, 'test')
self.make_binary_symlink_in_parent_folder(tag, 'test', 'run-scenarios')
self.copy_libwasmer_in_parent_directory(tag)

def build_binary(self, tag: str, binary_name: str):
source_folder = self.binary_source_folder(tag, binary_name)
golang = dependencies.get_module_by_key("golang")
golang_env = golang.get_env()
myprocess.run_process(['go', 'build'], cwd=source_folder, env=golang_env)

def binary_source_folder(self, tag: str, binary_name: str):
directory = self.get_source_directory(tag)
return directory / 'cmd' / binary_name

def make_binary_symlink_in_parent_folder(self, tag: str, binary_name: str, symlink_name: str):
source_folder = self.binary_source_folder(tag, binary_name)
binary = source_folder / binary_name

parent = self.get_parent_directory()
symlink = parent / symlink_name

symlink.unlink(missing_ok=True)
symlink.symlink_to(binary)

def copy_libwasmer_in_parent_directory(self, tag: str):
libwasmer_directory = self.get_source_directory(tag) / 'wasmer'
cmd_test_directory = self.get_source_directory(tag) / 'cmd' / 'test'
parent_directory = self.get_parent_directory()
for f in libwasmer_directory.iterdir():
if f.suffix in ['.dylib', '.so', '.dll']:
# Copy the dynamic library near the "run-scenarios" symlink
shutil.copy(f, parent_directory)
# Though, also copy the dynamic library near the target executable (seems to be necessary on MacOS)
shutil.copy(f, cmd_test_directory)

def get_env(self) -> Dict[str, str]:
return dict()

def get_source_directory(self, tag: str) -> Path:
directory = self.get_directory(tag)
first_subdirectory = next(directory.iterdir())
return first_subdirectory


class GolangModule(StandaloneModule):
def _post_install(self, tag: str):
parent_directory = self.get_parent_directory()
Expand Down
4 changes: 2 additions & 2 deletions multiversx_sdk_cli/projects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from multiversx_sdk_cli.projects.core import (build_project, clean_project,
load_project, run_tests)
load_project)
from multiversx_sdk_cli.projects.project_base import Project
from multiversx_sdk_cli.projects.project_rust import ProjectRust
from multiversx_sdk_cli.projects.report.do_report import do_report
from multiversx_sdk_cli.projects.templates import Contract

__all__ = ["build_project", "clean_project", "do_report", "run_tests", "load_project", "Project", "ProjectRust", "Contract"]
__all__ = ["build_project", "clean_project", "do_report", "load_project", "Project", "ProjectRust", "Contract"]
17 changes: 2 additions & 15 deletions multiversx_sdk_cli/projects/core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from pathlib import Path
from typing import Any, List
from typing import List

from multiversx_sdk_cli import dependencies, errors, guards
from multiversx_sdk_cli import errors, guards
from multiversx_sdk_cli.projects import shared
from multiversx_sdk_cli.projects.constants import (OLD_PROJECT_CONFIG_FILENAME,
PROJECT_CONFIG_FILENAME)
Expand Down Expand Up @@ -42,19 +42,6 @@ def clean_project(directory: Path):
logger.info("Project cleaned.")


def run_tests(project_path: Path, args: Any):
directory = Path(args.directory)
wildcard = args.wildcard

logger.info("run_tests.project: %s", project_path)

dependencies.install_module("vmtools")

guards.is_directory(project_path)
project = load_project(project_path)
project.run_tests(directory, wildcard)


def get_project_paths_recursively(base_path: Path) -> List[Path]:
guards.is_directory(base_path)
old_markers = list(base_path.glob(f"**/{OLD_PROJECT_CONFIG_FILENAME}"))
Expand Down
24 changes: 2 additions & 22 deletions multiversx_sdk_cli/projects/project_base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import glob
import logging
import shutil
from abc import abstractmethod
from os import path
from pathlib import Path
from typing import Any, Dict, List, Union, cast, final
from typing import Any, Dict, List, Union, final

from multiversx_sdk_cli import dependencies, errors, myprocess, utils
from multiversx_sdk_cli.dependencies.modules import StandaloneModule
from multiversx_sdk_cli import dependencies, errors, utils
from multiversx_sdk_cli.projects.constants import PROJECT_CONFIG_FILENAME
from multiversx_sdk_cli.projects.interfaces import IProject
from multiversx_sdk_cli.projects.migrations import migrate_project_config_file
Expand Down Expand Up @@ -129,24 +127,6 @@ def ensure_config_file(self) -> None:
def default_config(self) -> Dict[str, Any]:
return dict()

def run_tests(self, tests_directory: Path, wildcard: str = ""):
vmtools = cast(StandaloneModule, dependencies.get_module_by_key("vmtools"))
tool_env = vmtools.get_env()
tool = path.join(vmtools.get_parent_directory(), "run-scenarios")
test_folder = self.directory / tests_directory

if not wildcard:
args = [tool, str(test_folder)]
myprocess.run_process(args, env=tool_env)
else:
pattern = test_folder / wildcard
test_files = glob.glob(str(pattern))

for test_file in test_files:
print("Run test for:", test_file)
args = [tool, test_file]
myprocess.run_process(args, env=tool_env)


def glob_files(folder: Path, pattern: str) -> List[Path]:
files = folder.rglob(pattern)
Expand Down
12 changes: 0 additions & 12 deletions multiversx_sdk_cli/tests/test_cli_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ def test_deps_check_rust():
assert which_twiggy and Path.is_file(Path(which_twiggy))


@pytest.mark.skip_on_windows
def test_deps_install_vmtools():
return_code = main(["deps", "install", "vmtools"])
assert return_code == 0


@pytest.mark.skip_on_windows
def test_deps_check_vmtools():
return_code = main(["deps", "check", "vmtools"])
assert return_code == 0


def test_deps_install_testwallets():
return_code = main(["deps", "install", "testwallets"])
assert return_code == 0
Expand Down

0 comments on commit eebfcef

Please sign in to comment.