Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: templates errors #329

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/pop-contracts/src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
create_template_contract(name, canonicalized_path, template)
}

pub fn is_valid_contract_name(name: &str) -> Result<(), Error> {

Check warning on line 30 in crates/pop-contracts/src/new.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a function

warning: missing documentation for a function --> crates/pop-contracts/src/new.rs:30:1 | 30 | pub fn is_valid_contract_name(name: &str) -> Result<(), Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: requested on the command line with `-W missing-docs`
if !name.chars().all(|c| c.is_alphanumeric() || c == '_') {
return Err(Error::InvalidName(
"Contract names can only contain alphanumeric characters and underscores".to_owned(),
Expand Down Expand Up @@ -99,6 +99,15 @@
replacements_in_contract.insert(template_name.as_str(), name);
replacements_in_contract.insert(template.name(), &name_in_camel_case);
replace_in_file(file_path, replacements_in_contract)?;
// Replace name in the e2e_tests.rs file if exists.
if path.join("e2e_tests.rs").exists() {
file_path = path.join("e2e_tests.rs");
let name_in_camel_case = name.to_upper_camel_case();
let mut replacements_in_contract = HashMap::new();
replacements_in_contract.insert(template_name.as_str(), name);
replacements_in_contract.insert(template.name(), &name_in_camel_case);
replace_in_file(file_path, replacements_in_contract)?;
}
Ok(())
}

Expand Down Expand Up @@ -187,6 +196,20 @@
mod erc20
"#
)?;

let e2e_code = temp_dir.path().join("e2e_tests.rs");
let mut e2e_code_file = fs::File::create(e2e_code.clone())?;
writeln!(
e2e_code_file,
r#"
#[ink_e2e::test]
let contract = client
.instantiate("erc20", &ink_e2e::alice(), &mut constructor)
.submit()
.await
.expect("erc20 instantiate failed");
"#
)?;
Ok(temp_dir)
}
#[test]
Expand All @@ -200,6 +223,10 @@
let generated_code =
fs::read_to_string(temp_dir.path().join("lib.rs")).expect("Could not read file");
assert!(generated_code.contains("mod my_contract"));
let generated_e2e_code =
fs::read_to_string(temp_dir.path().join("e2e_tests.rs")).expect("Could not read file");
assert!(generated_e2e_code
.contains(".instantiate(\"my_contract\", &ink_e2e::alice(), &mut constructor)"));

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-contracts/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
message = "Examples",
detailed_message = "Contract examples for ink!."
)]
Examples,

Check warning on line 19 in crates/pop-contracts/src/templates.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-contracts/src/templates.rs:19:2 | 19 | Examples, | ^^^^^^^^
#[strum(
ascii_case_insensitive,
serialize = "erc",
message = "ERC",
detailed_message = "ERC-based contracts in ink!."
)]
Erc,

Check warning on line 26 in crates/pop-contracts/src/templates.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-contracts/src/templates.rs:26:2 | 26 | Erc, | ^^^
#[strum(
ascii_case_insensitive,
serialize = "psp",
message = "PSP",
detailed_message = "PSP-based contracts in ink!."
)]
Psp,

Check warning on line 33 in crates/pop-contracts/src/templates.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-contracts/src/templates.rs:33:2 | 33 | Psp, | ^^^
}

impl Type<Contract> for ContractType {
Expand All @@ -57,7 +57,7 @@
PartialEq,
VariantArray,
)]
pub enum Contract {

Check warning on line 60 in crates/pop-contracts/src/templates.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an enum

warning: missing documentation for an enum --> crates/pop-contracts/src/templates.rs:60:1 | 60 | pub enum Contract { | ^^^^^^^^^^^^^^^^^
/// A minimalist contract template.
#[default]
#[strum(
Expand Down Expand Up @@ -104,7 +104,7 @@
serialize = "PSP34",
message = "Psp34",
detailed_message = "The implementation of the PSP34 standard in ink!",
props(Type = "PSP", Repository = "https://github.com/Cardinal-Cryptography/PSP34")
props(Type = "PSP", Repository = "https://github.com/r0gue-io/PSP34")
)]
PSP34,
/// Domain name service example implemented in ink!
Expand Down Expand Up @@ -162,7 +162,7 @@
("erc721".to_string(), "https://github.com/use-ink/ink-examples"),
("erc1155".to_string(), "https://github.com/use-ink/ink-examples"),
("PSP22".to_string(), "https://github.com/Cardinal-Cryptography/PSP22"),
("PSP34".to_string(), "https://github.com/Cardinal-Cryptography/PSP34"),
("PSP34".to_string(), "https://github.com/r0gue-io/PSP34"),
("dns".to_string(), "https://github.com/use-ink/ink-examples"),
("cross-contract-calls".to_string(), "https://github.com/use-ink/ink-examples"),
("multisig".to_string(), "https://github.com/use-ink/ink-examples"),
Expand Down
Loading