Skip to content

Commit

Permalink
feat(dojo-lang): add warnings for migrations with prints (#2316)
Browse files Browse the repository at this point in the history
* add warnings for migrations with prints

* fix: formatting and diagnostic text

---------

Co-authored-by: glihm <dev@glihm.net>
  • Loading branch information
jsanchez556 and glihm authored Aug 24, 2024
1 parent a3ddf39 commit 599e368
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ use std::ops::DerefMut;
use anyhow::{anyhow, Context, Result};
use cairo_lang_compiler::db::RootDatabase;
use cairo_lang_defs::db::DefsGroup;
use cairo_lang_defs::ids::{ModuleId, ModuleItemId, TopLevelLanguageElementId};
use cairo_lang_defs::ids::{
ModuleId, ModuleItemId, NamedLanguageElementId, TopLevelLanguageElementId,
};
use cairo_lang_filesystem::db::FilesGroup;
use cairo_lang_filesystem::ids::{CrateId, CrateLongId};
use cairo_lang_formatter::format_string;
use cairo_lang_semantic::db::SemanticGroup;
use cairo_lang_starknet::compile::compile_prepared_db;
use cairo_lang_starknet::contract::{find_contracts, ContractDeclaration};
use cairo_lang_starknet_classes::abi;
use cairo_lang_starknet_classes::allowed_libfuncs::{AllowedLibfuncsError, ListSelector};
use cairo_lang_starknet_classes::contract_class::ContractClass;
use cairo_lang_utils::UpcastMut;
use camino::Utf8PathBuf;
Expand Down Expand Up @@ -127,13 +130,36 @@ impl Compiler for DojoCompiler {
};

let mut compiled_classes: HashMap<String, (Felt, ContractClass)> = HashMap::new();
let list_selector = ListSelector::default();

for (decl, class) in zip(contracts, classes) {
let contract_name = decl.submodule_id.name(db.upcast_mut());

// note that the qualified path is in snake case while
// the `full_path()` method of StructId uses the original struct name case.
// (see in `get_dojo_model_artifacts`)
let qualified_path = decl.module_id().full_path(db.upcast_mut());

match class.validate_version_compatible(list_selector.clone()) {
Ok(()) => {}
Err(AllowedLibfuncsError::UnsupportedLibfunc {
invalid_libfunc,
allowed_libfuncs_list_name: _,
}) => {
let diagnostic = format! {r#"
Contract `{contract_name}` ({qualified_path}) includes `{invalid_libfunc}` function that is not allowed in the default libfuncs for public Starknet networks (mainnet, sepolia).
It will work on Katana, but don't forget to remove it before deploying on a public Starknet network.
"#};

ws.config().ui().warn(diagnostic);
}
Err(e) => {
return Err(e).with_context(|| {
format!("Failed to check allowed libfuncs for contract: {}", contract_name)
});
}
}

let class_hash = compute_class_hash_of_contract_class(&class).with_context(|| {
format!("problem computing class hash for contract `{}`", qualified_path.clone())
})?;
Expand Down

0 comments on commit 599e368

Please sign in to comment.