From c1b029a6b196a1c9e98c04652cd5fe5337ed95b2 Mon Sep 17 00:00:00 2001 From: Trace Andreason Date: Sat, 20 Feb 2021 23:44:57 -0800 Subject: [PATCH 1/2] ink::test attributes in new template --- templates/new/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/new/lib.rs b/templates/new/lib.rs index c81744f8..4cb22b45 100644 --- a/templates/new/lib.rs +++ b/templates/new/lib.rs @@ -53,14 +53,14 @@ mod {{name}} { use super::*; /// We test if the default constructor does its job. - #[test] + #[ink::test] fn default_works() { let {{name}} = {{camel_name}}::default(); assert_eq!({{name}}.get(), false); } /// We test a simple use case of our contract. - #[test] + #[ink::test] fn it_works() { let mut {{name}} = {{camel_name}}::new(false); assert_eq!({{name}}.get(), false); -- GitLab From e4894944c8d33c2f08213013930fb7aae491ab65 Mon Sep 17 00:00:00 2001 From: Trace Andreason Date: Sun, 21 Feb 2021 12:32:03 -0800 Subject: [PATCH 2/2] no periods in new contract names --- src/cmd/new.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/cmd/new.rs b/src/cmd/new.rs index f294e3cf..b7412347 100644 --- a/src/cmd/new.rs +++ b/src/cmd/new.rs @@ -27,6 +27,10 @@ pub(crate) fn execute

(name: &str, dir: Option

) -> Result> where P: AsRef, { + if name.contains('.') { + anyhow::bail!("Contract names cannot contain periods"); + } + if name.contains('-') { anyhow::bail!("Contract names cannot contain hyphens"); } @@ -114,6 +118,19 @@ mod tests { }) } + #[test] + fn rejects_name_with_period() { + with_tmp_dir(|path| { + let result = execute("../xxx", Some(path)); + assert!(result.is_err(), "Should fail"); + assert_eq!( + result.err().unwrap().to_string(), + "Contract names cannot contain periods" + ); + Ok(()) + }) + } + #[test] fn contract_cargo_project_already_exists() { with_tmp_dir(|path| { -- GitLab