diff --git a/src/cmd/new.rs b/src/cmd/new.rs index f294e3cf30f4466fc2607d13b4574365bdc5f5ca..b7412347ed672dd53b783998115380075726d1bc 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| { diff --git a/templates/new/lib.rs b/templates/new/lib.rs index c81744f882d3a6d40682656220c434b7cc3ccf78..4cb22b451bb82857a0a2e54019025881bbe4ccf6 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);