diff --git a/.github/workflows/template-test.yml b/.github/workflows/template-test-current.yml similarity index 88% rename from .github/workflows/template-test.yml rename to .github/workflows/template-test-current.yml index aa6427e9d2..bafe90216d 100644 --- a/.github/workflows/template-test.yml +++ b/.github/workflows/template-test-current.yml @@ -12,7 +12,7 @@ permissions: jobs: template_test: - name: Template tool test + name: Template tool test - current (unreleased) templates runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/template-test-released.yml b/.github/workflows/template-test-released.yml new file mode 100644 index 0000000000..5e256dd39f --- /dev/null +++ b/.github/workflows/template-test-released.yml @@ -0,0 +1,26 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +permissions: + checks: write + pull-requests: write + +jobs: + template_test: + name: Template tool test - released contracts + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + default: true + toolchain: nightly-2023-08-08 + - name: Run template tool test + run: | + cd framework/meta + cargo test --features template-test-released diff --git a/.gitignore b/.gitignore index 3f6e39d9a1..e50fdfaa61 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,6 @@ my-vm-tests.sh quick.sh twiggy* template-test -template-test-current # Zip output with example wasm binaries examples-wasm.zip diff --git a/framework/meta/Cargo.toml b/framework/meta/Cargo.toml index f6fb8b4764..c035a2aeb2 100644 --- a/framework/meta/Cargo.toml +++ b/framework/meta/Cargo.toml @@ -22,6 +22,7 @@ path = "src/main.rs" [features] template-test-current = [] +template-test-released = [] [dependencies] tokio = { version = "1.24", features = ["full"] } diff --git a/framework/meta/src/cargo_toml_contents.rs b/framework/meta/src/cargo_toml_contents.rs index 00d388f7b2..2a7c944208 100644 --- a/framework/meta/src/cargo_toml_contents.rs +++ b/framework/meta/src/cargo_toml_contents.rs @@ -84,6 +84,10 @@ impl CargoTomlContents { } } + pub fn has_dependencies(&self) -> bool { + self.toml_value.get(CARGO_TOML_DEPENDENCIES).is_some() + } + pub fn dependencies_mut(&mut self) -> &mut Table { self.toml_value .get_mut(CARGO_TOML_DEPENDENCIES) @@ -92,6 +96,10 @@ impl CargoTomlContents { .expect("malformed crate Cargo.toml") } + pub fn has_dev_dependencies(&self) -> bool { + self.toml_value.get(CARGO_TOML_DEV_DEPENDENCIES).is_some() + } + pub fn dev_dependencies_mut(&mut self) -> &mut Table { self.toml_value .get_mut(CARGO_TOML_DEV_DEPENDENCIES) diff --git a/framework/meta/src/lib.rs b/framework/meta/src/lib.rs index 71790e2b01..8d62eaf391 100644 --- a/framework/meta/src/lib.rs +++ b/framework/meta/src/lib.rs @@ -8,7 +8,7 @@ mod mxsc_file_json; mod print_util; pub mod template; mod tools; -mod version_history; +pub mod version_history; #[macro_use] extern crate lazy_static; diff --git a/framework/meta/src/template/template_adjuster.rs b/framework/meta/src/template/template_adjuster.rs index 20082163b3..44eb30a7c3 100644 --- a/framework/meta/src/template/template_adjuster.rs +++ b/framework/meta/src/template/template_adjuster.rs @@ -218,6 +218,10 @@ pub fn remove_paths_from_deps_map(deps_map: &mut Table, ignore_deps: &[&str]) { } pub fn remove_paths_from_deps(toml: &mut CargoTomlContents, ignore_deps: &[&str]) { - remove_paths_from_deps_map(toml.dependencies_mut(), ignore_deps); - remove_paths_from_deps_map(toml.dev_dependencies_mut(), ignore_deps); + if toml.has_dependencies() { + remove_paths_from_deps_map(toml.dependencies_mut(), ignore_deps); + } + if toml.has_dev_dependencies() { + remove_paths_from_deps_map(toml.dev_dependencies_mut(), ignore_deps); + } } diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index 075abf33d3..9dbe02cc88 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -1,5 +1,8 @@ -use multiversx_sc_meta::template::{ - template_names_from_repo, ContractCreator, ContractCreatorTarget, RepoSource, +use multiversx_sc_meta::{ + template::{ + template_names_from_repo, ContractCreator, ContractCreatorTarget, RepoSource, RepoVersion, + }, + version_history, }; use std::{ fs, @@ -7,8 +10,8 @@ use std::{ process::Command, }; -const TEMPLATE_TEMP_DIR_NAME: &str = "template-test-current"; -const BUILD_CONTRACTS: bool = false; +const TEMPLATE_TEMP_DIR_NAME: &str = "template-test"; +const BUILD_CONTRACTS: bool = true; #[test] fn test_template_list() { @@ -45,7 +48,8 @@ fn template_test_current_empty() { } /// Recreates the folder structure in `contracts`, on the same level. -/// This way, the relative paths are still valid in this case, and we can test the templates with the versions on the current branch. +/// This way, the relative paths are still valid in this case, +/// and we can test the templates with the framework version of the current branch. fn template_test_current(template_name: &str, sub_path: &str, new_name: &str) { let workspace_path = find_workspace(); let target = ContractCreatorTarget { @@ -57,14 +61,65 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str) { prepare_target_dir(&target); - let downloader = ContractCreator::new( + ContractCreator::new( &repo_source, template_name.to_string(), target.clone(), true, - ); + ) + .create_contract(); + + if BUILD_CONTRACTS { + build_contract(&target); + } + cargo_test(&target); +} + +#[tokio::test] +#[cfg_attr(not(feature = "template-test-released"), ignore)] +async fn template_test_released_adder() { + template_test_released("adder", "released-adder").await; +} + +#[tokio::test] +#[cfg_attr(not(feature = "template-test-released"), ignore)] +async fn template_test_released_crypto_zombies() { + template_test_released("crypto-zombies", "released-crypto-zombies").await; +} + +#[tokio::test] +#[cfg_attr(not(feature = "template-test-released"), ignore)] +async fn template_test_released_empty() { + template_test_released("empty", "released-empty").await; +} + +/// These tests fully replicate the templating process. They +/// - download the last released version of the repo, +/// - create proper contracts, +/// - build the newly created contracts (to wasm) +/// - run all tests (including Go scenarios) on them. +async fn template_test_released(template_name: &str, new_name: &str) { + let workspace_path = find_workspace(); + let target = ContractCreatorTarget { + target_path: workspace_path.join(TEMPLATE_TEMP_DIR_NAME), + new_name: new_name.to_string(), + }; - downloader.create_contract(); + let repo_source = RepoSource::download_from_github( + RepoVersion::Tag(version_history::LAST_TEMPLATE_VERSION.to_string()), + std::env::temp_dir(), + ) + .await; + + prepare_target_dir(&target); + + ContractCreator::new( + &repo_source, + template_name.to_string(), + target.clone(), + false, + ) + .create_contract(); if BUILD_CONTRACTS { build_contract(&target);