Skip to content

Commit bdaca74

Browse files
authored
Fix passing non-existent profile to scarb (#1695)
<!-- Reference any GitHub issues resolved by this PR --> Closes #1693 ## Introduced changes <!-- A brief description of the changes --> - fixes a bug, where we allowed passing non existent profile to scarb, which resulted with missing artifacts error ## Checklist <!-- Make sure all of these are complete --> - [X] Linked relevant issue - [X] Updated relevant documentation - [X] Added relevant tests - [X] Performed self-review of the code - [X] Added changes to `CHANGELOG.md`
1 parent 7f2ff86 commit bdaca74

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Cast
11+
12+
#### Changed
13+
14+
- fixed a bug where a profile was passed to scarb even when it did not exist
15+
1016
### Forge
1117

1218
#### Added
19+
1320
- `map_string_error` for use with dispatchers, which automatically converts string errors from the syscall result (read more [here](https://foundry-rs.github.io/starknet-foundry/testing/contracts#handling-errors))
1421

1522
## [0.17.0] - 2024-02-07

crates/sncast/src/helpers/scarb_utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::response::print::print_as_warning;
12
use anyhow::{anyhow, Context, Result};
23
use camino::{Utf8Path, Utf8PathBuf};
34
use scarb_api::{
@@ -154,7 +155,15 @@ pub fn build_and_load_artifacts(
154155
build(package, config).map_err(|e| anyhow!(format!("Failed to build using scarb; {e}")))?;
155156

156157
let metadata = get_scarb_metadata_with_deps(&config.scarb_toml_path)?;
157-
get_contracts_map(&metadata, &package.id, Some(&config.profile))
158+
if metadata.profiles.contains(&config.profile) {
159+
get_contracts_map(&metadata, &package.id, Some(&config.profile))
160+
} else {
161+
let profile = &config.profile;
162+
print_as_warning(&anyhow!(
163+
"Profile {profile} does not exist in scarb, using default 'dev' profile."
164+
));
165+
get_contracts_map(&metadata, &package.id, None)
166+
}
158167
}
159168

160169
#[cfg(test)]

crates/sncast/tests/data/files/correct_snfoundry.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ keystore = "../keystore"
2121
url = "http://127.0.0.1:5055/rpc"
2222
accounts-file = "../account-file"
2323
account = "user3"
24+
25+
[sncast.profile5]
26+
url = "http://127.0.0.1:5055/rpc"
27+
account = "user8"

crates/sncast/tests/e2e/declare.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use crate::helpers::fixtures::{
55
};
66
use indoc::indoc;
77
use snapbox::cmd::{cargo_bin, Command};
8+
use sncast::helpers::constants::CONFIG_FILENAME;
89
use starknet::core::types::TransactionReceipt::Declare;
10+
use std::fs;
911

1012
#[tokio::test]
1113
async fn test_happy_case() {
@@ -360,3 +362,39 @@ async fn test_worskpaces_package_no_contract() {
360362
error: Failed to find whatever artifact in starknet_artifacts.json file[..]
361363
"});
362364
}
365+
366+
#[tokio::test]
367+
async fn test_no_scarb_profile() {
368+
let contract_path =
369+
duplicate_contract_directory_with_salt(CONTRACTS_DIR.to_string() + "/map", "put", "69");
370+
fs::copy(
371+
"tests/data/files/correct_snfoundry.toml",
372+
contract_path.path().join(CONFIG_FILENAME),
373+
)
374+
.expect("Failed to copy config file to temp dir");
375+
let accounts_json_path = get_accounts_path("tests/data/accounts/accounts.json");
376+
let args = vec![
377+
"--url",
378+
URL,
379+
"--accounts-file",
380+
accounts_json_path.as_str(),
381+
"--profile",
382+
"profile5",
383+
"declare",
384+
"--contract-name",
385+
"Map",
386+
"--max-fee",
387+
"99999999999999999",
388+
];
389+
390+
let snapbox = Command::new(cargo_bin!("sncast"))
391+
.current_dir(contract_path.path())
392+
.args(args);
393+
snapbox.assert().success().stdout_matches(indoc! {r"
394+
...
395+
Warning: Profile profile5 does not exist in scarb, using default 'dev' profile.
396+
command: declare
397+
class_hash: [..]
398+
transaction_hash: [..]
399+
"});
400+
}

0 commit comments

Comments
 (0)