Skip to content

Latest commit

 

History

History
174 lines (126 loc) · 4.01 KB

PR_COMMENT_82.md

File metadata and controls

174 lines (126 loc) · 4.01 KB

⚠️ Test Compilation Failures

Hi! Thanks for adding error handling tests. The build passes but the tests fail to compile. Here are the issues:


🔴 Compilation Errors

1. Missing Test Helper Function

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:

  1. Remove the import (line 4) since it's not used in the tests, or
  2. Add the function to fixtures.rs if you need it

Recommended: Just remove line 4:

// Remove this line:
use crate::tests::fixtures::create_test_env;

2. Using Standard Rust vec! Instead of Soroban Vec

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, ""))),
];

3. Unused Imports (Warnings)

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;

📝 Summary of Required Changes

File: dongle-smartcontract/src/tests/error_handling_tests.rs

  1. Line 4: Remove the unused import:

    // Delete this line:
    use crate::tests::fixtures::create_test_env;
  2. Line 335: Change vec![...] to [...]

  3. Line 377: Change vec![...] to [...]

File: dongle-smartcontract/src/project_registry.rs

  1. Line 1: Remove require_owner_auth from imports

  2. Line 3: Remove publish_project_updated_event from imports


✅ Testing

After making these changes:

cargo test

All tests should compile and pass.


👍 What's Good About This PR

  • 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!