Skip to content

Commit

Permalink
chain sim - sc-meta test-interactors
Browse files Browse the repository at this point in the history
  • Loading branch information
BiancaIalangi committed Oct 9, 2024
1 parent 3146233 commit 6815700
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
slow-tests:
@docker compose -f docker-compose.yml build
@docker compose -f docker-compose.yml up & cargo test --features chain_simulator --quiet
@docker compose -f docker-compose.yml up & sc-meta test-interactors
@docker compose -f docker-compose.yml down -v
1 change: 1 addition & 0 deletions contracts/examples/adder/interact/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ path = ".."
[dependencies.multiversx-sc-snippets]
version = "0.53.2"
path = "../../../../framework/snippets"
features = ["chain_simulator"]

[features]
chain_simulator = []
15 changes: 15 additions & 0 deletions framework/meta/src/cli/cli_args_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub enum StandaloneCliAction {
#[command(name = "test", about = "Runs cargo test")]
Test(TestArgs),

#[command(name = "test-interactors", about = "Runs cargo test for interactors")]
TestInteractors(TestInteractorsArgs),

#[command(name = "test-coverage", about = "Run test coverage and output report")]
TestCoverage(TestCoverageArgs),

Expand Down Expand Up @@ -99,6 +102,18 @@ pub struct InfoArgs {
pub ignore: Vec<String>,
}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct TestInteractorsArgs {
/// Target directory where to generate contract integration tests.
/// Will be current directory if not specified.
#[arg(short, long, verbatim_doc_comment)]
pub path: Option<String>,

/// This arg prints the entire output of the vm.
/// Default value will be "false" if not specified
#[arg(short, long, default_value = "false", verbatim_doc_comment)]
pub nocapture: bool,
}
#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct TestArgs {
/// Target directory where to generate contract integration tests.
Expand Down
2 changes: 2 additions & 0 deletions framework/meta/src/cli/cli_standalone_main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::cli::{StandaloneCliAction, StandaloneCliArgs};
use crate::cmd::retrieve_address::retrieve_address;
use crate::cmd::test_interactors::test_interactors;
use crate::cmd::wallet::wallet;
use clap::Parser;

Expand Down Expand Up @@ -35,6 +36,7 @@ pub async fn cli_main_standalone() {
test_gen_tool(args);
},
Some(StandaloneCliAction::Test(args)) => test(args),
Some(StandaloneCliAction::TestInteractors(args)) => test_interactors(args),
Some(StandaloneCliAction::TestCoverage(args)) => {
test_coverage(args);
},
Expand Down
1 change: 1 addition & 0 deletions framework/meta/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ pub mod scen_test_gen;
pub mod template;
pub mod test;
pub mod test_coverage;
pub mod test_interactors;
pub mod upgrade;
pub mod wallet;
43 changes: 43 additions & 0 deletions framework/meta/src/cmd/test_interactors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::process::Command;

use colored::Colorize;

use crate::cli::TestInteractorsArgs;

pub fn test_interactors(args: &TestInteractorsArgs) {
let path = args.path.as_deref().unwrap_or("./");
let command = "cargo";
let mut command_args = Vec::new();

let no_capture = args.nocapture;

command_args.push("test");

command_args.extend(["--features", "chain_simulator"]);

if no_capture {
command_args.extend(["--", "--nocapture"]);
}

let args_str = command_args.join(" ");

println!(
"{}\n{}",
format!("Running tests in {path} ...").green(),
format!("Executing {command} {args_str} ...").green()
);

let status = Command::new(command)
.args(command_args.clone())
.current_dir(path)
.status()
.unwrap_or_else(|_| {
panic!(
"{}",
format!("Failed to run program: {command} {args_str}").bright_red()
)
});

println!("Process finished with: {status}");
assert!(status.success());
}
3 changes: 3 additions & 0 deletions framework/snippets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ env_logger = "0.11"
futures = "0.3"
anyhow = "1.0.44"

[features]
chain_simulator = []

[dependencies.multiversx-sc-scenario]
version = "=0.53.2"
path = "../scenario"
Expand Down

0 comments on commit 6815700

Please sign in to comment.