Hi! Thanks for adding error handling tests. The build passes but the tests fail to compile. Here are the issues:
error[E0432]: unresolved import `crate::tests::fixtures::create_test_env`
--> dongle-smartcontract/src/tests/error_handling_tests.rs:4:5
|
4 | use crate::tests::fixtures::create_test_env;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `create_test_env` in `tests::fixtures`
Problem: The test file imports create_test_env from fixtures, but this function doesn't exist.
Fix: Either:
- Remove the import (line 4) since it's not used in the tests, or
- Add the function to
fixtures.rsif you need it
Recommended: Just remove line 4:
// Remove this line:
use crate::tests::fixtures::create_test_env;error: cannot find macro `vec` in this scope
--> dongle-smartcontract/src/tests/error_handling_tests.rs:335:22
|
335 | let test_cases = vec![
| ^^^
Problem: The code uses Rust's standard vec! macro, but in Soroban tests you need to use Soroban's Vec type or standard Rust vectors for test data.
Fix: Since these are just test case tuples (not Soroban contract data), use standard Rust vectors by importing from std:
Add to the top of the file (after line 1):
#[cfg(test)]
extern crate std;
use std::vec;Or alternatively, convert to arrays:
Line 335-339 - Change from:
let test_cases = vec![
("", "desc", "cat", ContractError::InvalidProjectName),
("name", "", "cat", ContractError::InvalidProjectDescription),
("name", "desc", "", ContractError::InvalidProjectCategory),
];To:
let test_cases = [
("", "desc", "cat", ContractError::InvalidProjectName),
("name", "", "cat", ContractError::InvalidProjectDescription),
("name", "desc", "", ContractError::InvalidProjectCategory),
];Line 377-380 - Change from:
let invalid_updates = vec![
(Some(String::from_str(&env, "")), None, None),
(None, Some(String::from_str(&env, "")), None),
(None, None, Some(String::from_str(&env, ""))),
];To:
let invalid_updates = [
(Some(String::from_str(&env, "")), None, None),
(None, Some(String::from_str(&env, "")), None),
(None, None, Some(String::from_str(&env, ""))),
];warning: unused import: `require_owner_auth`
--> dongle-smartcontract/src/project_registry.rs:1:19
warning: unused import: `publish_project_updated_event`
--> dongle-smartcontract/src/project_registry.rs:3:55
Fix: Remove unused imports from project_registry.rs:
Line 1 - Change from:
use crate::auth::{require_owner_auth, require_self_auth};To:
use crate::auth::require_self_auth;Line 3 - Change from:
use crate::events::{publish_project_registered_event, publish_project_updated_event};To:
use crate::events::publish_project_registered_event;-
Line 4: Remove the unused import:
// Delete this line: use crate::tests::fixtures::create_test_env;
-
Line 335: Change
vec![...]to[...] -
Line 377: Change
vec![...]to[...]
-
Line 1: Remove
require_owner_authfrom imports -
Line 3: Remove
publish_project_updated_eventfrom imports
After making these changes:
cargo testAll tests should compile and pass.
- Comprehensive error handling tests
- Tests for empty/invalid inputs
- Tests for update operations
- Good test coverage for edge cases
- Proper use of typed errors instead of panics
Just needs these small fixes to compile! 🚀
Let me know if you need any clarification!