-
Notifications
You must be signed in to change notification settings - Fork 177
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
test: Add unit tests to artifacts.rs module #2680
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work so far. The test_unique_artifacts
looks good, left some suggestions for improving test_load_contracts_artifacts
crates/scarb-api/src/artifacts.rs
Outdated
ScarbCommand::new_with_stdio() | ||
.current_dir(temp.path()) | ||
.arg("test") | ||
.run() | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary if you run scarb build --test
.
crates/scarb-api/src/artifacts.rs
Outdated
#[test] | ||
fn test_load_contracts_artifacts() { | ||
let temp = crate::tests::setup_package("basic_package"); | ||
|
||
ScarbCommand::new_with_stdio() | ||
.current_dir(temp.path()) | ||
.arg("build") | ||
.run() | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to test creating StarknetArtifactFiles
with both base and other files, we need scarb version of at least 2.8.3, and we need to build artifacts with the test target
#[test] | |
fn test_load_contracts_artifacts() { | |
let temp = crate::tests::setup_package("basic_package"); | |
ScarbCommand::new_with_stdio() | |
.current_dir(temp.path()) | |
.arg("build") | |
.run() | |
.unwrap(); | |
#[test] | |
#[cfg_attr(not(feature = "scarb_2_8_3"), ignore)] | |
fn test_load_contracts_artifacts() { | |
let temp = crate::tests::setup_package("basic_package"); | |
ScarbCommand::new_with_stdio() | |
.current_dir(temp.path()) | |
.arg("build") | |
.arg("--test") | |
.run() | |
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you will get two .test.starknet_artifcats.json
files. One for unittest and one for integrationtest target.
crates/scarb-api/src/artifacts.rs
Outdated
// Define path to the generated artifacts | ||
let base_artifacts_path = temp.to_path_buf().join("target").join("dev"); | ||
|
||
// Get the base artifact | ||
let base_file = Utf8PathBuf::from_path_buf( | ||
base_artifacts_path.join("basic_package.starknet_artifacts.json"), | ||
) | ||
.unwrap(); | ||
|
||
// Load other artifact files and add them to the temporary directory | ||
let other_files = vec![ | ||
Utf8PathBuf::from_path_buf( | ||
base_artifacts_path | ||
.join("basic_package_integrationtest.test.starknet_artifacts.json"), | ||
) | ||
.unwrap(), | ||
Utf8PathBuf::from_path_buf( | ||
base_artifacts_path.join("basic_package_unittest.test.starknet_artifacts.json"), | ||
) | ||
.unwrap(), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible in foundry to use both starknet_artifacts.json
and .test.starknet_artiacts.json
files.
As a base_file, we'd use basic_package_integrationtest.test.starknet_artifacts.json
(you can take a look at get_starknet_artifacts_paths_from_test_targets
function, we try to get artifact with test_type INTEGRATION_TEST_TYPE
if possible as default) and basic_package_unittest.test.starknet_artifacts.json
as other_files
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cptartur I've implemented the requested changes
Closes #2625
Introduced changes
Tests directory in
crates/scarb-api/tests/data/basic_package
for integration tests starknet artifacts.Integration tests artifacts only get built when there's a tests directory in a cairo package
Checklist
CHANGELOG.md