From 0fe2f96f83ae843c7d982892018c4188be9a9571 Mon Sep 17 00:00:00 2001 From: Abeeujah Date: Mon, 20 Jan 2025 13:50:16 +0100 Subject: [PATCH 1/5] test: Add unit tests to artifacts.rs module --- .github/workflows/ci.yml | 2 + crates/scarb-api/src/artifacts.rs | 121 +++++++++++++++++- .../scarb-api/src/artifacts/representation.rs | 4 +- 3 files changed, 123 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c644924a4..e630096397 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,8 @@ jobs: cargo test --package forge --features scarb_2_8_3 e2e::features - run: | cargo test --package scarb-api --features scarb_2_8_3 get_starknet_artifacts_path + - run: | + cargo test --package scarb-api --features scarb_2_8_3 test_load_contracts_artifacts test-forge-runner: name: Test Forge Runner diff --git a/crates/scarb-api/src/artifacts.rs b/crates/scarb-api/src/artifacts.rs index 75632b56d2..66e2fb5c8a 100644 --- a/crates/scarb-api/src/artifacts.rs +++ b/crates/scarb-api/src/artifacts.rs @@ -34,7 +34,6 @@ impl StarknetArtifactsFiles { } } - // TODO(#2625) add unit tests pub(crate) fn load_contracts_artifacts( self, ) -> Result> { @@ -61,7 +60,6 @@ impl StarknetArtifactsFiles { } } -// TODO(#2625) add unit tests fn unique_artifacts( artifact_representations: Vec, current_artifacts: &HashMap, @@ -92,3 +90,122 @@ fn compile_artifact_at_path(path: &Utf8Path) -> Result Date: Mon, 20 Jan 2025 15:28:08 +0100 Subject: [PATCH 2/5] requested changes cleanup --- crates/scarb-api/src/artifacts.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/scarb-api/src/artifacts.rs b/crates/scarb-api/src/artifacts.rs index 66e2fb5c8a..6536051805 100644 --- a/crates/scarb-api/src/artifacts.rs +++ b/crates/scarb-api/src/artifacts.rs @@ -197,14 +197,12 @@ mod tests { // Load the contracts let result = artifacts_files.load_contracts_artifacts(); - println!("{result:?}"); // Ensure no errors and non-empty result assert!(result.is_ok()); // Assert the Contract Artifacts are loaded. let artifacts_map = result.unwrap(); - assert!(!artifacts_map.is_empty()); assert!(artifacts_map.contains_key("ERC20")); assert!(artifacts_map.contains_key("HelloStarknet")); } From cae0bbf288dcba40bd057866f26d54e1e7ce85fa Mon Sep 17 00:00:00 2001 From: Abeeujah Date: Mon, 20 Jan 2025 13:50:16 +0100 Subject: [PATCH 3/5] test: Add unit tests to artifacts.rs module --- .github/workflows/ci.yml | 2 + crates/scarb-api/src/artifacts.rs | 121 +++++++++++++++++- .../scarb-api/src/artifacts/representation.rs | 4 +- 3 files changed, 123 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c644924a4..e630096397 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,8 @@ jobs: cargo test --package forge --features scarb_2_8_3 e2e::features - run: | cargo test --package scarb-api --features scarb_2_8_3 get_starknet_artifacts_path + - run: | + cargo test --package scarb-api --features scarb_2_8_3 test_load_contracts_artifacts test-forge-runner: name: Test Forge Runner diff --git a/crates/scarb-api/src/artifacts.rs b/crates/scarb-api/src/artifacts.rs index 75632b56d2..66e2fb5c8a 100644 --- a/crates/scarb-api/src/artifacts.rs +++ b/crates/scarb-api/src/artifacts.rs @@ -34,7 +34,6 @@ impl StarknetArtifactsFiles { } } - // TODO(#2625) add unit tests pub(crate) fn load_contracts_artifacts( self, ) -> Result> { @@ -61,7 +60,6 @@ impl StarknetArtifactsFiles { } } -// TODO(#2625) add unit tests fn unique_artifacts( artifact_representations: Vec, current_artifacts: &HashMap, @@ -92,3 +90,122 @@ fn compile_artifact_at_path(path: &Utf8Path) -> Result Date: Mon, 20 Jan 2025 15:28:08 +0100 Subject: [PATCH 4/5] requested changes cleanup --- crates/scarb-api/src/artifacts.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/scarb-api/src/artifacts.rs b/crates/scarb-api/src/artifacts.rs index 66e2fb5c8a..6536051805 100644 --- a/crates/scarb-api/src/artifacts.rs +++ b/crates/scarb-api/src/artifacts.rs @@ -197,14 +197,12 @@ mod tests { // Load the contracts let result = artifacts_files.load_contracts_artifacts(); - println!("{result:?}"); // Ensure no errors and non-empty result assert!(result.is_ok()); // Assert the Contract Artifacts are loaded. let artifacts_map = result.unwrap(); - assert!(!artifacts_map.is_empty()); assert!(artifacts_map.contains_key("ERC20")); assert!(artifacts_map.contains_key("HelloStarknet")); } From affa83fc9000d9d84c870395f778d566d89e59ee Mon Sep 17 00:00:00 2001 From: Abeeujah Date: Tue, 21 Jan 2025 15:18:06 +0100 Subject: [PATCH 5/5] load_contracts_artifacts test result unwrapped --- crates/scarb-api/src/artifacts.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/scarb-api/src/artifacts.rs b/crates/scarb-api/src/artifacts.rs index 6536051805..8b3e2c74b7 100644 --- a/crates/scarb-api/src/artifacts.rs +++ b/crates/scarb-api/src/artifacts.rs @@ -196,14 +196,10 @@ mod tests { let artifacts_files = StarknetArtifactsFiles::new(base_file, other_files); // Load the contracts - let result = artifacts_files.load_contracts_artifacts(); - - // Ensure no errors and non-empty result - assert!(result.is_ok()); + let result = artifacts_files.load_contracts_artifacts().unwrap(); // Assert the Contract Artifacts are loaded. - let artifacts_map = result.unwrap(); - assert!(artifacts_map.contains_key("ERC20")); - assert!(artifacts_map.contains_key("HelloStarknet")); + assert!(result.contains_key("ERC20")); + assert!(result.contains_key("HelloStarknet")); } }