Skip to content

Commit

Permalink
sc-meta template tests from released tag
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Aug 18, 2023
1 parent 2447cb6 commit d9349f3
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/template-test-released.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions framework/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ path = "src/main.rs"

[features]
template-test-current = []
template-test-released = []

[dependencies]
tokio = { version = "1.24", features = ["full"] }
Expand Down
8 changes: 8 additions & 0 deletions framework/meta/src/cargo_toml_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion framework/meta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions framework/meta/src/template/template_adjuster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
71 changes: 63 additions & 8 deletions framework/meta/tests/template_test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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,
path::{Path, PathBuf},
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() {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit d9349f3

Please sign in to comment.