Skip to content

Commit

Permalink
add module path to ContractArtifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
tomek0123456789 committed Jan 23, 2024
1 parent c531a6e commit 79ca306
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scarb/src/compiler/compilers/starknet_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,22 @@ struct ContractArtifacts {
id: String,
package_name: PackageName,
contract_name: String,
module_path: String,
artifacts: ContractArtifact,
}

impl ContractArtifacts {
fn new(package_name: &PackageName, contract_name: &str, contract_path: &str) -> Self {
fn new(
package_name: &PackageName,
contract_name: &str,
contract_path: &str,
module_path: String,
) -> Self {
Self {
id: short_hash((&package_name, &contract_path)),
package_name: package_name.clone(),
contract_name: contract_name.to_owned(),
module_path,
artifacts: ContractArtifact::default(),
}
}
Expand Down Expand Up @@ -216,6 +223,14 @@ impl Compiler for StarknetContractCompiler {
let compiler_config = build_compiler_config(&unit, ws);

let main_crate_ids = collect_main_crate_ids(&unit, db);
// main crate ids to definicja ze scarb.tomla glownego?
eprintln!("unit = {:#?}", unit);
eprintln!("unit.main_component() = {:#?}", unit.main_component());
eprintln!(
"unit.main_component().cairo_package_name() = {:#?}",
unit.main_component().cairo_package_name()
);
eprintln!("main_crate_ids = {:#?}", main_crate_ids);

let contracts = find_project_contracts(
db.upcast_mut(),
Expand Down Expand Up @@ -275,6 +290,7 @@ impl Compiler for StarknetContractCompiler {
&package_name,
&contract_name,
contract_selector.full_path().as_str(),
decl.module_id().full_path(db.upcast_mut()).clone(),
);

if props.sierra {
Expand Down
5 changes: 5 additions & 0 deletions scarb/tests/build_starknet_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use cairo_lang_starknet::contract_class::ContractClass;
use indoc::{formatdoc, indoc};
use itertools::Itertools;
use predicates::prelude::*;
use std::ops::Deref;

use scarb_test_support::command::Scarb;
use scarb_test_support::contracts::{BALANCE_CONTRACT, FORTY_TWO_CONTRACT, HELLO_CONTRACT};
Expand Down Expand Up @@ -77,6 +78,10 @@ fn compile_starknet_contract() {

t.child("target/dev/hello_Balance.contract_class.json")
.assert_is_json::<ContractClass>();
t.child("target/dev/hello.starknet_artifacts.json")
.assert(predicates::str::contains(
r#""module_path":"hello::Balance""#,
));
}

#[test]
Expand Down

0 comments on commit 79ca306

Please sign in to comment.