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

test: Add unit tests to artifacts.rs module #2680

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Abeeujah
Copy link

@Abeeujah Abeeujah commented Nov 16, 2024

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

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

Copy link
Member

@cptartur cptartur left a 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

Comment on lines 167 to 171
ScarbCommand::new_with_stdio()
.current_dir(temp.path())
.arg("test")
.run()
.unwrap();
Copy link
Member

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.

Comment on lines 157 to 165
#[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();
Copy link
Member

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

Suggested change
#[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();

Copy link
Member

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.

Comment on lines 173 to 193
// 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(),
];
Copy link
Member

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.

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests to artifacts.rs module
2 participants