From c56d079915e14d383ca327d6ea8a38961214a6d9 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Mon, 20 Nov 2023 17:59:57 +0200 Subject: [PATCH 01/11] remove mets renaming in template --- .../cmd/standalone/template/template_adjuster.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/framework/meta/src/cmd/standalone/template/template_adjuster.rs b/framework/meta/src/cmd/standalone/template/template_adjuster.rs index 0cd3d97456..693b03faa7 100644 --- a/framework/meta/src/cmd/standalone/template/template_adjuster.rs +++ b/framework/meta/src/cmd/standalone/template/template_adjuster.rs @@ -10,7 +10,6 @@ use toml::value::Table; const TEST_DIRECTORY: &str = "./tests"; const ROOT_CARGO_TOML: &str = "./Cargo.toml"; const META_CARGO_TOML: &str = "./meta/Cargo.toml"; -const WASM_CARGO_TOML: &str = "./wasm/Cargo.toml"; pub struct TemplateAdjuster { pub metadata: TemplateMetadata, @@ -20,7 +19,6 @@ pub struct TemplateAdjuster { impl TemplateAdjuster { pub fn update_dependencies(&self) { self.update_dependencies_root(); - self.update_dependencies_wasm(); self.update_dependencies_meta(); } @@ -48,17 +46,6 @@ impl TemplateAdjuster { toml.save_to_file(&cargo_toml_path); } - fn update_dependencies_wasm(&self) { - let cargo_toml_path = self.target.contract_dir().join(WASM_CARGO_TOML); - let mut toml = CargoTomlContents::load_from_file(&cargo_toml_path); - - if !self.keep_paths { - remove_paths_from_deps(&mut toml, &[&self.metadata.name]); - } - - toml.save_to_file(&cargo_toml_path); - } - pub fn rename_template_to(&self) { self.rename_trait_to(); self.rename_in_cargo_toml_root(); From 2ff60c44c892d60dff784a1631dec6b627d83ffc Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Wed, 13 Dec 2023 22:42:31 +0200 Subject: [PATCH 02/11] Update wasm crate manually for version < 0.45.1. --- .../standalone/template/contract_creator.rs | 11 +++---- .../cmd/standalone/template/repo_version.rs | 9 ++++++ .../standalone/template/template_adjuster.rs | 30 ++++++++++++++++++- framework/meta/tests/template_test.rs | 6 ++-- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/framework/meta/src/cmd/standalone/template/contract_creator.rs b/framework/meta/src/cmd/standalone/template/contract_creator.rs index 5b7932492e..d8f1caabd2 100644 --- a/framework/meta/src/cmd/standalone/template/contract_creator.rs +++ b/framework/meta/src/cmd/standalone/template/contract_creator.rs @@ -11,12 +11,13 @@ use super::{ /// Creates a new contract on disk, from a template, given a name. pub fn create_contract(args: &TemplateArgs) { let version = get_repo_version(&args.tag); + let version_tag: String = version.get_tag(); let repo_temp_download = RepoSource::download_from_github(version, std::env::temp_dir()); let target = target_from_args(args); let creator = ContractCreator::new(&repo_temp_download, args.template.clone(), target, false); - creator.create_contract(); + creator.create_contract(version_tag); } fn target_from_args(args: &TemplateArgs) -> ContractCreatorTarget { @@ -71,9 +72,9 @@ impl<'a> ContractCreator<'a> { } } - pub fn create_contract(&self) { + pub fn create_contract(&self, args_tag: String) { self.copy_template(); - self.update_dependencies(); + self.update_dependencies(args_tag); self.rename_template(); } @@ -82,8 +83,8 @@ impl<'a> ContractCreator<'a> { .copy_template(self.target.contract_dir()); } - pub fn update_dependencies(&self) { - self.adjuster.update_dependencies(); + pub fn update_dependencies(&self, args_tag: String) { + self.adjuster.update_dependencies(args_tag); } pub fn rename_template(&self) { diff --git a/framework/meta/src/cmd/standalone/template/repo_version.rs b/framework/meta/src/cmd/standalone/template/repo_version.rs index 3eb798a66f..150c2bebc3 100644 --- a/framework/meta/src/cmd/standalone/template/repo_version.rs +++ b/framework/meta/src/cmd/standalone/template/repo_version.rs @@ -1,3 +1,5 @@ +use crate::version_history::LAST_TEMPLATE_VERSION; + pub enum RepoVersion { Master, Tag(String), @@ -23,4 +25,11 @@ impl RepoVersion { }, } } + + pub fn get_tag(&self) -> String { + match self { + RepoVersion::Master => LAST_TEMPLATE_VERSION.to_string(), + RepoVersion::Tag(tag) => tag.to_string(), + } + } } diff --git a/framework/meta/src/cmd/standalone/template/template_adjuster.rs b/framework/meta/src/cmd/standalone/template/template_adjuster.rs index 188871f0e0..7c23471766 100644 --- a/framework/meta/src/cmd/standalone/template/template_adjuster.rs +++ b/framework/meta/src/cmd/standalone/template/template_adjuster.rs @@ -5,11 +5,14 @@ use crate::{ }; use convert_case::{Case, Casing}; use ruplacer::Query; +use rustc_version::Version; use toml::value::Table; const TEST_DIRECTORY: &str = "./tests"; const ROOT_CARGO_TOML: &str = "./Cargo.toml"; const META_CARGO_TOML: &str = "./meta/Cargo.toml"; +const WASM_CARGO_TOML: &str = "./wasm/Cargo.toml"; +const TARGET_VERSION_0_45_1: Version = Version::new(0, 45, 1); pub struct TemplateAdjuster { pub metadata: TemplateMetadata, @@ -17,9 +20,10 @@ pub struct TemplateAdjuster { pub keep_paths: bool, } impl TemplateAdjuster { - pub fn update_dependencies(&self) { + pub fn update_dependencies(&self, args_tag: String) { self.update_dependencies_root(); self.update_dependencies_meta(); + self.update_dependencies_wasm(args_tag); } fn update_dependencies_root(&self) { @@ -46,6 +50,23 @@ impl TemplateAdjuster { toml.save_to_file(&cargo_toml_path); } + fn update_dependencies_wasm(&self, args_tag: String) { + if is_version_at_least_0_45_1(args_tag) { + println!(">>>>>>>>>>>>YES"); + return; + } + println!(">>>>>>>>>>>>YESSSSSSS"); + + let cargo_toml_path = self.target.contract_dir().join(WASM_CARGO_TOML); + let mut toml = CargoTomlContents::load_from_file(&cargo_toml_path); + + if !self.keep_paths { + remove_paths_from_deps(&mut toml, &[&self.metadata.name]); + } + + toml.save_to_file(&cargo_toml_path); + } + pub fn rename_template_to(&self) { self.rename_trait_to(); self.rename_in_cargo_toml_root(); @@ -177,6 +198,13 @@ impl TemplateAdjuster { } } +fn is_version_at_least_0_45_1(args_tag: String) -> bool { + match Version::parse(&args_tag) { + Ok(version) => version >= TARGET_VERSION_0_45_1, + Err(_error) => false, + } +} + fn wasm_file_name(name: &str) -> String { format!("{name}.wasm",) } diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index e7fc4b0230..631664361b 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -5,7 +5,7 @@ use multiversx_sc_meta::{ template_names_from_repo, ContractCreator, ContractCreatorTarget, RepoSource, RepoVersion, }, find_workspace::find_current_workspace, - version_history, + version_history::{self, LAST_TEMPLATE_VERSION}, }; const TEMPLATE_TEMP_DIR_NAME: &str = "template-test"; @@ -72,7 +72,7 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str) { target.clone(), true, ) - .create_contract(); + .create_contract(LAST_TEMPLATE_VERSION.to_string()); if BUILD_CONTRACTS { build_contract(&target); @@ -127,7 +127,7 @@ fn template_test_released(template_name: &str, new_name: &str) { target.clone(), false, ) - .create_contract(); + .create_contract(LAST_TEMPLATE_VERSION.to_string()); if BUILD_CONTRACTS { build_contract(&target); From 199f4e1775153ed2fd40139f671f0529c86cdd78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 14 Dec 2023 12:27:33 +0200 Subject: [PATCH 03/11] Back transfers: Add test that catches the problem The bug is when making multiple sync calls, the esdts from back transfers are not cleaned. --- .../promises-features/src/call_sync_bt.rs | 46 +++++++++++++++++++ .../tests/promises_feature_blackbox_test.rs | 28 +++++++++++ 2 files changed, 74 insertions(+) diff --git a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs index 9c9b293bbc..2476ab482d 100644 --- a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs +++ b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs @@ -14,12 +14,58 @@ pub trait BackTransfersFeatureModule { token_nonce: u64, amount: BigUint, ) { + let ((), back_transfers) = self + .vault_proxy() + .contract(to.clone()) + .retrieve_funds(token.clone(), token_nonce, amount.clone()) + .execute_on_dest_context_with_back_transfers::<()>(); + + require!( + back_transfers.esdt_payments.len() == 1, + "Only one ESDT payment expected" + ); + + self.back_transfers_event( + &back_transfers.total_egld_amount, + &back_transfers.esdt_payments.into_multi_value(), + ); + } + + #[endpoint] + fn forward_sync_retrieve_funds_multi_call_bt( + &self, + to: ManagedAddress, + token: EgldOrEsdtTokenIdentifier, + token_nonce: u64, + amount: BigUint, + ) { + let ((), back_transfers) = self + .vault_proxy() + .contract(to.clone()) + .retrieve_funds(token.clone(), token_nonce, amount.clone()) + .execute_on_dest_context_with_back_transfers::<()>(); + + require!( + back_transfers.esdt_payments.len() == 1, + "Only one ESDT payment expected" + ); + + self.back_transfers_event( + &back_transfers.total_egld_amount, + &back_transfers.esdt_payments.into_multi_value(), + ); + let ((), back_transfers) = self .vault_proxy() .contract(to) .retrieve_funds(token, token_nonce, amount) .execute_on_dest_context_with_back_transfers::<()>(); + require!( + back_transfers.esdt_payments.len() == 1, + "Only one ESDT payment expected" + ); + self.back_transfers_event( &back_transfers.total_egld_amount, &back_transfers.esdt_payments.into_multi_value(), diff --git a/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs b/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs index eb04c5e19f..4da6461dca 100644 --- a/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs +++ b/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs @@ -98,3 +98,31 @@ fn test_back_transfers() { CheckAccount::new().esdt_balance(TOKEN_ID_EXPR, token_amount), )); } + +#[test] +fn test_multi_call_back_transfers() { + let mut state = PromisesFeaturesTestState::new(); + let token_amount = BigUint::from(1000u64); + let half_token_amount = token_amount.clone() / 2u64; + let vault_address = state.vault_contract.to_address(); + + state.world.sc_call( + ScCallStep::new().from(USER_ADDRESS_EXPR).call( + state + .promises_features_contract + .forward_sync_retrieve_funds_multi_call_bt( + vault_address.clone(), + TOKEN_ID, + 0u64, + &half_token_amount, + ), + ), + ); + + state + .world + .check_state_step(CheckStateStep::new().put_account( + state.promises_features_contract, + CheckAccount::new().esdt_balance(TOKEN_ID_EXPR, token_amount), + )); +} From 10d48c1b1a8e90fd01a3638ed699c8f31370c55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 14 Dec 2023 13:06:27 +0200 Subject: [PATCH 04/11] Fix test --- .../composability/promises-features/src/call_sync_bt.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs index 2476ab482d..bc94257c6e 100644 --- a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs +++ b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs @@ -21,7 +21,7 @@ pub trait BackTransfersFeatureModule { .execute_on_dest_context_with_back_transfers::<()>(); require!( - back_transfers.esdt_payments.len() == 1, + back_transfers.esdt_payments.len() == 1 || back_transfers.total_egld_amount != 0, "Only one ESDT payment expected" ); @@ -46,7 +46,7 @@ pub trait BackTransfersFeatureModule { .execute_on_dest_context_with_back_transfers::<()>(); require!( - back_transfers.esdt_payments.len() == 1, + back_transfers.esdt_payments.len() == 1 || back_transfers.total_egld_amount != 0, "Only one ESDT payment expected" ); @@ -62,7 +62,7 @@ pub trait BackTransfersFeatureModule { .execute_on_dest_context_with_back_transfers::<()>(); require!( - back_transfers.esdt_payments.len() == 1, + back_transfers.esdt_payments.len() == 1 || back_transfers.total_egld_amount != 0, "Only one ESDT payment expected" ); From db4078bc8839657323704b39e25bde26bf89d97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 14 Dec 2023 13:07:17 +0200 Subject: [PATCH 05/11] back-transfers fix: do not of merge back transfers Instead of merge back transfers, create a new one. --- vm/src/tx_mock/tx_back_transfers.rs | 16 +++++----------- vm/src/vm_hooks/vh_impl/vh_debug_api.rs | 5 +---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/vm/src/tx_mock/tx_back_transfers.rs b/vm/src/tx_mock/tx_back_transfers.rs index c5d9b0ea6d..4f7921bf69 100644 --- a/vm/src/tx_mock/tx_back_transfers.rs +++ b/vm/src/tx_mock/tx_back_transfers.rs @@ -16,16 +16,13 @@ impl BackTransfers { } pub fn new_from_result( + &mut self, own_address: &VMAddress, result: &TxResult, builtin_functions: &BuiltinFunctionContainer, - ) -> Self { + ) { let mut bt = BackTransfers::default(); - if result.result_status != 0 { - return bt; - } - for call in &result.all_calls { // TODO: refactor, check type @@ -41,13 +38,10 @@ impl BackTransfers { } } - bt - } - - pub fn merge(&mut self, other: &BackTransfers) { - self.call_value += &other.call_value; - self.esdt_transfers.extend_from_slice(&other.esdt_transfers); + self.call_value = bt.call_value; + self.esdt_transfers = bt.esdt_transfers; } + } // func (host *vmHost) addNewBackTransfersFromVMOutput(vmOutput *vmcommon.VMOutput, parent, child []byte) { diff --git a/vm/src/vm_hooks/vh_impl/vh_debug_api.rs b/vm/src/vm_hooks/vh_impl/vh_debug_api.rs index cf950aff0b..004ab5cb82 100644 --- a/vm/src/vm_hooks/vh_impl/vh_debug_api.rs +++ b/vm/src/vm_hooks/vh_impl/vh_debug_api.rs @@ -239,10 +239,7 @@ impl DebugApiVMHooksHandler { let contract_address = &self.0.input_ref().to; let builtin_functions = &self.0.vm_ref.builtin_functions; - let current_back_transfers = - BackTransfers::new_from_result(contract_address, &tx_result, builtin_functions); - - self.back_transfers_lock().merge(¤t_back_transfers); + self.back_transfers_lock().new_from_result(contract_address, &tx_result, builtin_functions); tx_result.result_values } From f27f67fe6d92b7d7f4fcc6b33b9765d08408b1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 14 Dec 2023 19:27:30 +0200 Subject: [PATCH 06/11] Fixes after review --- .../promises-features/src/call_sync_bt.rs | 2 +- .../tests/promises_feature_blackbox_test.rs | 2 +- vm/src/tx_mock/tx_back_transfers.rs | 33 ------------------- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs index bc94257c6e..b8417acd2a 100644 --- a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs +++ b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs @@ -32,7 +32,7 @@ pub trait BackTransfersFeatureModule { } #[endpoint] - fn forward_sync_retrieve_funds_multi_call_bt( + fn forward_sync_retrieve_funds_bt_twice( &self, to: ManagedAddress, token: EgldOrEsdtTokenIdentifier, diff --git a/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs b/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs index 4da6461dca..87b682a53f 100644 --- a/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs +++ b/contracts/feature-tests/composability/tests/promises_feature_blackbox_test.rs @@ -110,7 +110,7 @@ fn test_multi_call_back_transfers() { ScCallStep::new().from(USER_ADDRESS_EXPR).call( state .promises_features_contract - .forward_sync_retrieve_funds_multi_call_bt( + .forward_sync_retrieve_funds_bt_twice( vault_address.clone(), TOKEN_ID, 0u64, diff --git a/vm/src/tx_mock/tx_back_transfers.rs b/vm/src/tx_mock/tx_back_transfers.rs index 4f7921bf69..b6ed57600e 100644 --- a/vm/src/tx_mock/tx_back_transfers.rs +++ b/vm/src/tx_mock/tx_back_transfers.rs @@ -43,36 +43,3 @@ impl BackTransfers { } } - -// func (host *vmHost) addNewBackTransfersFromVMOutput(vmOutput *vmcommon.VMOutput, parent, child []byte) { -// if vmOutput == nil || vmOutput.ReturnCode != vmcommon.Ok { -// return -// } -// callerOutAcc, ok := vmOutput.OutputAccounts[string(parent)] -// if !ok { -// return -// } - -// for _, transfer := range callerOutAcc.OutputTransfers { -// if !bytes.Equal(transfer.SenderAddress, child) { -// continue -// } -// if transfer.CallType == vm.AsynchronousCallBack { -// continue -// } - -// if transfer.Value.Cmp(vmhost.Zero) > 0 { -// if len(transfer.Data) == 0 { -// host.managedTypesContext.AddValueOnlyBackTransfer(transfer.Value) -// } -// continue -// } - -// esdtTransfers, isWithoutExec := host.isESDTTransferWithoutExecution(transfer.Data, parent, child) -// if !isWithoutExec { -// continue -// } - -// host.managedTypesContext.AddBackTransfers(esdtTransfers.ESDTTransfers) -// } -// } From 8ec8bd6614b3102f63d3c1878c3040e7079825f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 15 Dec 2023 08:42:29 +0200 Subject: [PATCH 07/11] Fix clippy on test --- .../composability/promises-features/src/call_sync_bt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs index b8417acd2a..d3cc048ccc 100644 --- a/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs +++ b/contracts/feature-tests/composability/promises-features/src/call_sync_bt.rs @@ -16,8 +16,8 @@ pub trait BackTransfersFeatureModule { ) { let ((), back_transfers) = self .vault_proxy() - .contract(to.clone()) - .retrieve_funds(token.clone(), token_nonce, amount.clone()) + .contract(to) + .retrieve_funds(token, token_nonce, amount) .execute_on_dest_context_with_back_transfers::<()>(); require!( From 3b0cd7a95a3cb881d0454e141880eaf133313397 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Fri, 15 Dec 2023 15:22:34 +0200 Subject: [PATCH 08/11] Add multiversx.json for ContractCreatorTarget { pub(crate) fn get_repo_version(args_tag: &Option) -> RepoVersion { if let Some(tag) = args_tag { - assert!(validate_template_tag(tag), "invalid template tag"); + assert!( + validate_template_tag(VERSION_0_43_0, tag), + "invalid template tag" + ); RepoVersion::Tag(tag.clone()) } else { RepoVersion::Tag(LAST_TEMPLATE_VERSION.to_string()) @@ -73,17 +78,17 @@ impl<'a> ContractCreator<'a> { } pub fn create_contract(&self, args_tag: String) { - self.copy_template(); - self.update_dependencies(args_tag); + self.copy_template(&args_tag); + self.update_dependencies(&args_tag); self.rename_template(); } - pub fn copy_template(&self) { + pub fn copy_template(&self, args_tag: &str) { self.template_source - .copy_template(self.target.contract_dir()); + .copy_template(self.target.contract_dir(), args_tag); } - pub fn update_dependencies(&self, args_tag: String) { + pub fn update_dependencies(&self, args_tag: &str) { self.adjuster.update_dependencies(args_tag); } diff --git a/framework/meta/src/cmd/standalone/template/copy_util.rs b/framework/meta/src/cmd/standalone/template/copy_util.rs index 2d324a5e56..1f9cfae1d2 100644 --- a/framework/meta/src/cmd/standalone/template/copy_util.rs +++ b/framework/meta/src/cmd/standalone/template/copy_util.rs @@ -1,8 +1,13 @@ use std::{ - fs::{self}, + fs::{self, OpenOptions}, + io::{BufWriter, Write}, path::{Path, PathBuf}, }; +use crate::version_history::validate_template_tag; + +const VERSION_0_44_0: usize = 39; + /// Will copy an entire folder according to a whitelist of allowed paths. /// /// The whitelist is expected to contain paths relative from the source path. @@ -10,8 +15,14 @@ use std::{ /// If a folder is whitelisted, then everything in the folder is considered whitelisted too. /// /// The function creates all necessary folder structure in the target, no additional preparation required. -pub fn whitelisted_deep_copy(source_root: &Path, target_root: &Path, whitelist: &[String]) { +pub fn whitelisted_deep_copy( + source_root: &Path, + target_root: &Path, + whitelist: &[String], + args_tag: &str, +) { perform_file_copy(source_root, &PathBuf::new(), target_root, whitelist); + create_multiversx_json_file(target_root, args_tag); } fn is_whitelisted(path: &Path, whitelist: &[String]) -> bool { @@ -72,6 +83,28 @@ fn perform_file_copy( } } +fn create_multiversx_json_file(target_root: &Path, args_tag: &str) { + if validate_template_tag(VERSION_0_44_0, args_tag) { + return; + } + + let file = OpenOptions::new() + .write(true) + .create(true) + .open(target_root.join("multiversx.json")) + .expect("Failed to open multiversx.json file"); + + let mut writer = BufWriter::new(file); + + writer + .write_all( + br#"{ + "language": "rust" +}"#, + ) + .unwrap(); +} + #[cfg(test)] mod test { use super::is_whitelisted; diff --git a/framework/meta/src/cmd/standalone/template/template_adjuster.rs b/framework/meta/src/cmd/standalone/template/template_adjuster.rs index 4f4bea7765..038082f811 100644 --- a/framework/meta/src/cmd/standalone/template/template_adjuster.rs +++ b/framework/meta/src/cmd/standalone/template/template_adjuster.rs @@ -1,18 +1,18 @@ use super::{template_metadata::TemplateMetadata, ContractCreatorTarget}; use crate::{ cmd::standalone::upgrade::upgrade_common::{rename_files, replace_in_files}, + version_history::validate_template_tag, CargoTomlContents, }; use convert_case::{Case, Casing}; use ruplacer::Query; -use rustc_version::Version; use toml::value::Table; const TEST_DIRECTORY: &str = "./tests"; const ROOT_CARGO_TOML: &str = "./Cargo.toml"; const META_CARGO_TOML: &str = "./meta/Cargo.toml"; const WASM_CARGO_TOML: &str = "./wasm/Cargo.toml"; -const TARGET_VERSION_0_45_0: Version = Version::new(0, 45, 0); +const VERSION_0_45_0: usize = 40; pub struct TemplateAdjuster { pub metadata: TemplateMetadata, @@ -20,7 +20,7 @@ pub struct TemplateAdjuster { pub keep_paths: bool, } impl TemplateAdjuster { - pub fn update_dependencies(&self, args_tag: String) { + pub fn update_dependencies(&self, args_tag: &str) { self.update_dependencies_root(); self.update_dependencies_meta(); self.update_dependencies_wasm(args_tag); @@ -50,8 +50,8 @@ impl TemplateAdjuster { toml.save_to_file(&cargo_toml_path); } - fn update_dependencies_wasm(&self, args_tag: String) { - if is_version_at_least_0_45_0(args_tag) { + fn update_dependencies_wasm(&self, args_tag: &str) { + if validate_template_tag(VERSION_0_45_0, args_tag) { return; } @@ -196,13 +196,6 @@ impl TemplateAdjuster { } } -fn is_version_at_least_0_45_0(args_tag: String) -> bool { - match Version::parse(&args_tag) { - Ok(version) => version >= TARGET_VERSION_0_45_0, - Err(_error) => false, - } -} - fn wasm_file_name(name: &str) -> String { format!("{name}.wasm",) } diff --git a/framework/meta/src/cmd/standalone/template/template_source.rs b/framework/meta/src/cmd/standalone/template/template_source.rs index 4637d26b11..e728bbddee 100644 --- a/framework/meta/src/cmd/standalone/template/template_source.rs +++ b/framework/meta/src/cmd/standalone/template/template_source.rs @@ -17,11 +17,12 @@ pub struct TemplateSource<'a> { } impl<'a> TemplateSource<'a> { - pub fn copy_template(&self, target_path: impl AsRef) { + pub fn copy_template(&self, target_path: impl AsRef, args_tag: &str) { whitelisted_deep_copy( &self.source_path, target_path.as_ref(), &self.metadata.files_include, + args_tag ); } } diff --git a/framework/meta/src/version_history.rs b/framework/meta/src/version_history.rs index 16105463b7..16bed180c4 100644 --- a/framework/meta/src/version_history.rs +++ b/framework/meta/src/version_history.rs @@ -55,13 +55,12 @@ pub const VERSIONS: &[&str] = &[ "0.45.1", ]; -/// We started supporting contract templates with version 0.43.0. -pub fn template_versions() -> &'static [&'static str] { - &VERSIONS[33..] +pub fn template_versions(start: usize) -> &'static [&'static str] { + &VERSIONS[start..] } -pub fn validate_template_tag(tag: &str) -> bool { - let versions = template_versions(); +pub fn validate_template_tag(start: usize, tag: &str) -> bool { + let versions = template_versions(start); versions.iter().any(|&tt| tt == tag) } @@ -110,9 +109,25 @@ pub mod tests { #[test] fn template_versions_test() { - assert_eq!(template_versions()[0], "0.43.0"); + assert_eq!(template_versions(33)[0], "0.43.0"); - assert!(validate_template_tag("0.43.0")); - assert!(!validate_template_tag("0.42.0")); + assert!(validate_template_tag(33, "0.43.0")); + assert!(!validate_template_tag(33, "0.42.0")); + } + + #[test] + fn template_versions_with_autogenerated_wasm() { + assert_eq!(template_versions(40)[0], "0.45.0"); + + assert!(validate_template_tag(40, "0.45.0")); + assert!(!validate_template_tag(40, "0.44.0")); + } + + #[test] + fn template_versions_with_autogenerated_multiversx_json() { + assert_eq!(template_versions(39)[0], "0.44.0"); + + assert!(validate_template_tag(39, "0.44.0")); + assert!(!validate_template_tag(39, "0.43.0")); } } From b77734c4b820d4dcdcaaa7b4d31297b2e9fc41af Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Mon, 18 Dec 2023 16:36:12 +0200 Subject: [PATCH 09/11] Refactor version functions and how it's added multiversx.json --- .../standalone/template/contract_creator.rs | 6 +-- .../src/cmd/standalone/template/copy_util.rs | 38 ++++---------- .../standalone/template/template_adjuster.rs | 5 +- .../standalone/template/template_source.rs | 2 +- framework/meta/src/version_history.rs | 51 +++++++++++++------ 5 files changed, 50 insertions(+), 52 deletions(-) diff --git a/framework/meta/src/cmd/standalone/template/contract_creator.rs b/framework/meta/src/cmd/standalone/template/contract_creator.rs index b71e0420f2..391eeabeeb 100644 --- a/framework/meta/src/cmd/standalone/template/contract_creator.rs +++ b/framework/meta/src/cmd/standalone/template/contract_creator.rs @@ -1,6 +1,6 @@ use crate::{ cli_args::TemplateArgs, - version_history::{validate_template_tag, LAST_TEMPLATE_VERSION}, + version_history::{validate_template_tag, LAST_TEMPLATE_VERSION, TEMPLATE_VERSIONS}, }; use super::{ @@ -8,8 +8,6 @@ use super::{ ContractCreatorTarget, RepoSource, RepoVersion, TemplateAdjuster, }; -const VERSION_0_43_0: usize = 33; - /// Creates a new contract on disk, from a template, given a name. pub fn create_contract(args: &TemplateArgs) { let version = get_repo_version(&args.tag); @@ -34,7 +32,7 @@ fn target_from_args(args: &TemplateArgs) -> ContractCreatorTarget { pub(crate) fn get_repo_version(args_tag: &Option) -> RepoVersion { if let Some(tag) = args_tag { assert!( - validate_template_tag(VERSION_0_43_0, tag), + validate_template_tag(tag, TEMPLATE_VERSIONS), "invalid template tag" ); RepoVersion::Tag(tag.clone()) diff --git a/framework/meta/src/cmd/standalone/template/copy_util.rs b/framework/meta/src/cmd/standalone/template/copy_util.rs index 1f9cfae1d2..9baf487a79 100644 --- a/framework/meta/src/cmd/standalone/template/copy_util.rs +++ b/framework/meta/src/cmd/standalone/template/copy_util.rs @@ -1,12 +1,9 @@ use std::{ - fs::{self, OpenOptions}, - io::{BufWriter, Write}, + fs::{self}, path::{Path, PathBuf}, }; -use crate::version_history::validate_template_tag; - -const VERSION_0_44_0: usize = 39; +use crate::version_history::{validate_template_tag, AUTOGENERATED_JSON}; /// Will copy an entire folder according to a whitelist of allowed paths. /// @@ -21,8 +18,13 @@ pub fn whitelisted_deep_copy( whitelist: &[String], args_tag: &str, ) { - perform_file_copy(source_root, &PathBuf::new(), target_root, whitelist); - create_multiversx_json_file(target_root, args_tag); + if validate_template_tag(args_tag, AUTOGENERATED_JSON) { + perform_file_copy(source_root, &PathBuf::new(), target_root, whitelist); + } else { + let mut tmp_whitelist = whitelist.to_vec(); + tmp_whitelist.push("multiversx.json".into()); + perform_file_copy(source_root, &PathBuf::new(), target_root, &tmp_whitelist); + } } fn is_whitelisted(path: &Path, whitelist: &[String]) -> bool { @@ -83,28 +85,6 @@ fn perform_file_copy( } } -fn create_multiversx_json_file(target_root: &Path, args_tag: &str) { - if validate_template_tag(VERSION_0_44_0, args_tag) { - return; - } - - let file = OpenOptions::new() - .write(true) - .create(true) - .open(target_root.join("multiversx.json")) - .expect("Failed to open multiversx.json file"); - - let mut writer = BufWriter::new(file); - - writer - .write_all( - br#"{ - "language": "rust" -}"#, - ) - .unwrap(); -} - #[cfg(test)] mod test { use super::is_whitelisted; diff --git a/framework/meta/src/cmd/standalone/template/template_adjuster.rs b/framework/meta/src/cmd/standalone/template/template_adjuster.rs index 038082f811..da2d5877eb 100644 --- a/framework/meta/src/cmd/standalone/template/template_adjuster.rs +++ b/framework/meta/src/cmd/standalone/template/template_adjuster.rs @@ -1,7 +1,7 @@ use super::{template_metadata::TemplateMetadata, ContractCreatorTarget}; use crate::{ cmd::standalone::upgrade::upgrade_common::{rename_files, replace_in_files}, - version_history::validate_template_tag, + version_history::{validate_template_tag, AUTOGENERATED_WASM}, CargoTomlContents, }; use convert_case::{Case, Casing}; @@ -12,7 +12,6 @@ const TEST_DIRECTORY: &str = "./tests"; const ROOT_CARGO_TOML: &str = "./Cargo.toml"; const META_CARGO_TOML: &str = "./meta/Cargo.toml"; const WASM_CARGO_TOML: &str = "./wasm/Cargo.toml"; -const VERSION_0_45_0: usize = 40; pub struct TemplateAdjuster { pub metadata: TemplateMetadata, @@ -51,7 +50,7 @@ impl TemplateAdjuster { } fn update_dependencies_wasm(&self, args_tag: &str) { - if validate_template_tag(VERSION_0_45_0, args_tag) { + if validate_template_tag(args_tag, AUTOGENERATED_WASM) { return; } diff --git a/framework/meta/src/cmd/standalone/template/template_source.rs b/framework/meta/src/cmd/standalone/template/template_source.rs index e728bbddee..eb71ec31eb 100644 --- a/framework/meta/src/cmd/standalone/template/template_source.rs +++ b/framework/meta/src/cmd/standalone/template/template_source.rs @@ -22,7 +22,7 @@ impl<'a> TemplateSource<'a> { &self.source_path, target_path.as_ref(), &self.metadata.files_include, - args_tag + args_tag, ); } } diff --git a/framework/meta/src/version_history.rs b/framework/meta/src/version_history.rs index 16bed180c4..4f04b5c726 100644 --- a/framework/meta/src/version_history.rs +++ b/framework/meta/src/version_history.rs @@ -8,6 +8,12 @@ pub const LAST_UPGRADE_VERSION: &str = LAST_VERSION; pub const LAST_TEMPLATE_VERSION: &str = LAST_VERSION; +pub const TEMPLATE_VERSIONS: &str = "template_version"; + +pub const AUTOGENERATED_WASM: &str = "autogenerated_wasm"; + +pub const AUTOGENERATED_JSON: &str = "autogenerated_json"; + /// Known versions for the upgrader. #[rustfmt::skip] pub const VERSIONS: &[&str] = &[ @@ -55,12 +61,27 @@ pub const VERSIONS: &[&str] = &[ "0.45.1", ]; -pub fn template_versions(start: usize) -> &'static [&'static str] { - &VERSIONS[start..] +/// We started supporting contract templates with version 0.43.0. +pub fn template_versions() -> &'static [&'static str] { + &VERSIONS[33..] +} + +pub fn template_versions_with_autogenerated_wasm() -> &'static [&'static str] { + &VERSIONS[40..] +} + +pub fn template_versions_with_autogenerated_json() -> &'static [&'static str] { + &VERSIONS[39..] } -pub fn validate_template_tag(start: usize, tag: &str) -> bool { - let versions = template_versions(start); +pub fn validate_template_tag(tag: &str, versions_provider: &str) -> bool { + let versions = match versions_provider { + TEMPLATE_VERSIONS => template_versions(), + AUTOGENERATED_WASM => template_versions_with_autogenerated_wasm(), + AUTOGENERATED_JSON => template_versions_with_autogenerated_json(), + _ => return false, + }; + versions.iter().any(|&tt| tt == tag) } @@ -109,25 +130,25 @@ pub mod tests { #[test] fn template_versions_test() { - assert_eq!(template_versions(33)[0], "0.43.0"); + assert_eq!(template_versions()[0], "0.43.0"); - assert!(validate_template_tag(33, "0.43.0")); - assert!(!validate_template_tag(33, "0.42.0")); + assert!(validate_template_tag("0.43.0", TEMPLATE_VERSIONS)); + assert!(!validate_template_tag("0.42.0", TEMPLATE_VERSIONS)); } #[test] - fn template_versions_with_autogenerated_wasm() { - assert_eq!(template_versions(40)[0], "0.45.0"); + fn template_versions_with_autogenerated_wasm_test() { + assert_eq!(template_versions_with_autogenerated_wasm()[0], "0.45.0"); - assert!(validate_template_tag(40, "0.45.0")); - assert!(!validate_template_tag(40, "0.44.0")); + assert!(validate_template_tag("0.45.0", AUTOGENERATED_WASM)); + assert!(!validate_template_tag("0.44.0", AUTOGENERATED_WASM)); } #[test] - fn template_versions_with_autogenerated_multiversx_json() { - assert_eq!(template_versions(39)[0], "0.44.0"); + fn template_versions_with_autogenerated_json_test() { + assert_eq!(template_versions_with_autogenerated_json()[0], "0.44.0"); - assert!(validate_template_tag(39, "0.44.0")); - assert!(!validate_template_tag(39, "0.43.0")); + assert!(validate_template_tag("0.44.0", AUTOGENERATED_JSON)); + assert!(!validate_template_tag("0.43.0", AUTOGENERATED_JSON)); } } From 16071048b7ef9b352d1f6469cca7638694726990 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Mon, 18 Dec 2023 17:15:11 +0200 Subject: [PATCH 10/11] Refactor version functions --- .../standalone/template/contract_creator.rs | 7 +--- .../src/cmd/standalone/template/copy_util.rs | 4 +- .../standalone/template/template_adjuster.rs | 4 +- framework/meta/src/version_history.rs | 41 +++++++++---------- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/framework/meta/src/cmd/standalone/template/contract_creator.rs b/framework/meta/src/cmd/standalone/template/contract_creator.rs index 391eeabeeb..9b493b89fc 100644 --- a/framework/meta/src/cmd/standalone/template/contract_creator.rs +++ b/framework/meta/src/cmd/standalone/template/contract_creator.rs @@ -1,6 +1,6 @@ use crate::{ cli_args::TemplateArgs, - version_history::{validate_template_tag, LAST_TEMPLATE_VERSION, TEMPLATE_VERSIONS}, + version_history::{validate_template_tag, LAST_TEMPLATE_VERSION}, }; use super::{ @@ -31,10 +31,7 @@ fn target_from_args(args: &TemplateArgs) -> ContractCreatorTarget { pub(crate) fn get_repo_version(args_tag: &Option) -> RepoVersion { if let Some(tag) = args_tag { - assert!( - validate_template_tag(tag, TEMPLATE_VERSIONS), - "invalid template tag" - ); + assert!(validate_template_tag(tag), "invalid template tag"); RepoVersion::Tag(tag.clone()) } else { RepoVersion::Tag(LAST_TEMPLATE_VERSION.to_string()) diff --git a/framework/meta/src/cmd/standalone/template/copy_util.rs b/framework/meta/src/cmd/standalone/template/copy_util.rs index 9baf487a79..6297a57682 100644 --- a/framework/meta/src/cmd/standalone/template/copy_util.rs +++ b/framework/meta/src/cmd/standalone/template/copy_util.rs @@ -3,7 +3,7 @@ use std::{ path::{Path, PathBuf}, }; -use crate::version_history::{validate_template_tag, AUTOGENERATED_JSON}; +use crate::version_history::validate_template_with_autogenerated_json; /// Will copy an entire folder according to a whitelist of allowed paths. /// @@ -18,7 +18,7 @@ pub fn whitelisted_deep_copy( whitelist: &[String], args_tag: &str, ) { - if validate_template_tag(args_tag, AUTOGENERATED_JSON) { + if validate_template_with_autogenerated_json(args_tag) { perform_file_copy(source_root, &PathBuf::new(), target_root, whitelist); } else { let mut tmp_whitelist = whitelist.to_vec(); diff --git a/framework/meta/src/cmd/standalone/template/template_adjuster.rs b/framework/meta/src/cmd/standalone/template/template_adjuster.rs index da2d5877eb..0075d522aa 100644 --- a/framework/meta/src/cmd/standalone/template/template_adjuster.rs +++ b/framework/meta/src/cmd/standalone/template/template_adjuster.rs @@ -1,7 +1,7 @@ use super::{template_metadata::TemplateMetadata, ContractCreatorTarget}; use crate::{ cmd::standalone::upgrade::upgrade_common::{rename_files, replace_in_files}, - version_history::{validate_template_tag, AUTOGENERATED_WASM}, + version_history::validate_template_with_autogenerated_wasm, CargoTomlContents, }; use convert_case::{Case, Casing}; @@ -50,7 +50,7 @@ impl TemplateAdjuster { } fn update_dependencies_wasm(&self, args_tag: &str) { - if validate_template_tag(args_tag, AUTOGENERATED_WASM) { + if validate_template_with_autogenerated_wasm(args_tag) { return; } diff --git a/framework/meta/src/version_history.rs b/framework/meta/src/version_history.rs index 4f04b5c726..d753d4c1c5 100644 --- a/framework/meta/src/version_history.rs +++ b/framework/meta/src/version_history.rs @@ -8,12 +8,6 @@ pub const LAST_UPGRADE_VERSION: &str = LAST_VERSION; pub const LAST_TEMPLATE_VERSION: &str = LAST_VERSION; -pub const TEMPLATE_VERSIONS: &str = "template_version"; - -pub const AUTOGENERATED_WASM: &str = "autogenerated_wasm"; - -pub const AUTOGENERATED_JSON: &str = "autogenerated_json"; - /// Known versions for the upgrader. #[rustfmt::skip] pub const VERSIONS: &[&str] = &[ @@ -66,23 +60,28 @@ pub fn template_versions() -> &'static [&'static str] { &VERSIONS[33..] } +pub fn validate_template_tag(tag: &str) -> bool { + template_versions().iter().any(|&tt| tt == tag) +} + pub fn template_versions_with_autogenerated_wasm() -> &'static [&'static str] { &VERSIONS[40..] } +pub fn validate_template_with_autogenerated_wasm(tag: &str) -> bool { + template_versions_with_autogenerated_wasm() + .iter() + .any(|&tt| tt == tag) +} + pub fn template_versions_with_autogenerated_json() -> &'static [&'static str] { &VERSIONS[39..] } -pub fn validate_template_tag(tag: &str, versions_provider: &str) -> bool { - let versions = match versions_provider { - TEMPLATE_VERSIONS => template_versions(), - AUTOGENERATED_WASM => template_versions_with_autogenerated_wasm(), - AUTOGENERATED_JSON => template_versions_with_autogenerated_json(), - _ => return false, - }; - - versions.iter().any(|&tt| tt == tag) +pub fn validate_template_with_autogenerated_json(tag: &str) -> bool { + template_versions_with_autogenerated_json() + .iter() + .any(|&tt| tt == tag) } pub struct VersionIterator { @@ -132,23 +131,23 @@ pub mod tests { fn template_versions_test() { assert_eq!(template_versions()[0], "0.43.0"); - assert!(validate_template_tag("0.43.0", TEMPLATE_VERSIONS)); - assert!(!validate_template_tag("0.42.0", TEMPLATE_VERSIONS)); + assert!(validate_template_tag("0.43.0")); + assert!(!validate_template_tag("0.42.0")); } #[test] fn template_versions_with_autogenerated_wasm_test() { assert_eq!(template_versions_with_autogenerated_wasm()[0], "0.45.0"); - assert!(validate_template_tag("0.45.0", AUTOGENERATED_WASM)); - assert!(!validate_template_tag("0.44.0", AUTOGENERATED_WASM)); + assert!(validate_template_with_autogenerated_wasm("0.45.0")); + assert!(!validate_template_with_autogenerated_wasm("0.44.0")); } #[test] fn template_versions_with_autogenerated_json_test() { assert_eq!(template_versions_with_autogenerated_json()[0], "0.44.0"); - assert!(validate_template_tag("0.44.0", AUTOGENERATED_JSON)); - assert!(!validate_template_tag("0.43.0", AUTOGENERATED_JSON)); + assert!(validate_template_with_autogenerated_json("0.44.0")); + assert!(!validate_template_with_autogenerated_json("0.43.0")); } } From 209c02e21b627dea907b2d3521f65fef820a9016 Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Mon, 18 Dec 2023 17:32:19 +0200 Subject: [PATCH 11/11] Rename version functions --- .../meta/src/cmd/standalone/template/copy_util.rs | 4 ++-- .../src/cmd/standalone/template/template_adjuster.rs | 4 ++-- framework/meta/src/version_history.rs | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/meta/src/cmd/standalone/template/copy_util.rs b/framework/meta/src/cmd/standalone/template/copy_util.rs index 6297a57682..f49911b6f1 100644 --- a/framework/meta/src/cmd/standalone/template/copy_util.rs +++ b/framework/meta/src/cmd/standalone/template/copy_util.rs @@ -3,7 +3,7 @@ use std::{ path::{Path, PathBuf}, }; -use crate::version_history::validate_template_with_autogenerated_json; +use crate::version_history::is_template_with_autogenerated_json; /// Will copy an entire folder according to a whitelist of allowed paths. /// @@ -18,7 +18,7 @@ pub fn whitelisted_deep_copy( whitelist: &[String], args_tag: &str, ) { - if validate_template_with_autogenerated_json(args_tag) { + if is_template_with_autogenerated_json(args_tag) { perform_file_copy(source_root, &PathBuf::new(), target_root, whitelist); } else { let mut tmp_whitelist = whitelist.to_vec(); diff --git a/framework/meta/src/cmd/standalone/template/template_adjuster.rs b/framework/meta/src/cmd/standalone/template/template_adjuster.rs index 0075d522aa..afaa20aebf 100644 --- a/framework/meta/src/cmd/standalone/template/template_adjuster.rs +++ b/framework/meta/src/cmd/standalone/template/template_adjuster.rs @@ -1,7 +1,7 @@ use super::{template_metadata::TemplateMetadata, ContractCreatorTarget}; use crate::{ cmd::standalone::upgrade::upgrade_common::{rename_files, replace_in_files}, - version_history::validate_template_with_autogenerated_wasm, + version_history::is_template_with_autogenerated_wasm, CargoTomlContents, }; use convert_case::{Case, Casing}; @@ -50,7 +50,7 @@ impl TemplateAdjuster { } fn update_dependencies_wasm(&self, args_tag: &str) { - if validate_template_with_autogenerated_wasm(args_tag) { + if is_template_with_autogenerated_wasm(args_tag) { return; } diff --git a/framework/meta/src/version_history.rs b/framework/meta/src/version_history.rs index d753d4c1c5..f2fb34c545 100644 --- a/framework/meta/src/version_history.rs +++ b/framework/meta/src/version_history.rs @@ -68,7 +68,7 @@ pub fn template_versions_with_autogenerated_wasm() -> &'static [&'static str] { &VERSIONS[40..] } -pub fn validate_template_with_autogenerated_wasm(tag: &str) -> bool { +pub fn is_template_with_autogenerated_wasm(tag: &str) -> bool { template_versions_with_autogenerated_wasm() .iter() .any(|&tt| tt == tag) @@ -78,7 +78,7 @@ pub fn template_versions_with_autogenerated_json() -> &'static [&'static str] { &VERSIONS[39..] } -pub fn validate_template_with_autogenerated_json(tag: &str) -> bool { +pub fn is_template_with_autogenerated_json(tag: &str) -> bool { template_versions_with_autogenerated_json() .iter() .any(|&tt| tt == tag) @@ -139,15 +139,15 @@ pub mod tests { fn template_versions_with_autogenerated_wasm_test() { assert_eq!(template_versions_with_autogenerated_wasm()[0], "0.45.0"); - assert!(validate_template_with_autogenerated_wasm("0.45.0")); - assert!(!validate_template_with_autogenerated_wasm("0.44.0")); + assert!(is_template_with_autogenerated_wasm("0.45.0")); + assert!(!is_template_with_autogenerated_wasm("0.44.0")); } #[test] fn template_versions_with_autogenerated_json_test() { assert_eq!(template_versions_with_autogenerated_json()[0], "0.44.0"); - assert!(validate_template_with_autogenerated_json("0.44.0")); - assert!(!validate_template_with_autogenerated_json("0.43.0")); + assert!(is_template_with_autogenerated_json("0.44.0")); + assert!(!is_template_with_autogenerated_json("0.43.0")); } }