Skip to content

Fix 87#191

Open
Hydrax117 wants to merge 2 commits into
scout-off:mainfrom
Hydrax117:fix-87
Open

Fix 87#191
Hydrax117 wants to merge 2 commits into
scout-off:mainfrom
Hydrax117:fix-87

Conversation

@Hydrax117
Copy link
Copy Markdown

Pull Request — Issue #87

Title

test(progress): verify advance_level returns NotInitialized on uninitialized contract

Closes

Closes #87


Summary

No test existed to confirm that calling advance_level on a contract that has never been initialized returns the NotInitialized error. This PR adds fn test_advance_level_not_initialized() to cover that guard path. No production code was changed.


Changes

contracts/progress/src/lib.rs

Added fn test_advance_level_not_initialized() inside the #[cfg(test)] mod tests block.

#[test]
fn test_advance_level_not_initialized() {
    let env = Env::default();
    env.mock_all_auths();
    // Register the contract but deliberately skip initialize()
    let id = env.register_contract(None, ProgressContract);
    let client = ProgressContractClient::new(&env, &id);

    let caller = Address::generate(&env);
    let result = client.try_advance_level(&caller, &99u64, &1u32);

    assert_eq!(
        result,
        Err(Ok(ProgressError::NotInitialized))
    );
}

Acceptance Criteria

Criterion Status
Test exists fn test_advance_level_not_initialized added to mod tests
Contract deployed without initialize register_contract called, initialize deliberately skipped
advance_level attempted try_advance_level invoked
Returns NotInitialized assert_eq!(result, Err(Ok(ProgressError::NotInitialized)))
Test passes ✅ Assertion matches the error returned by require_initialized

Design Notes

  • Does not use setup() — the shared helper calls initialize, which would defeat the purpose of the test. The contract is registered inline and initialization is deliberately omitted.
  • Uses try_advance_level (the Result-returning client variant) rather than #[should_panic]. This pins the specific error variant so the test gives a precise failure message if the error code ever changes or the wrong guard fires, rather than passing on any panic.
  • Err(Ok(ProgressError::NotInitialized)) is the Soroban SDK's typed error shape: the outer Err means the invocation returned a contract error; the inner Ok means it decoded cleanly into the ProgressError enum.
  • Guard order in advance_level: require_not_paused runs before require_initialized. On an uninitialized contract the Paused key is absent and defaults to false, so execution reaches require_initialized and returns NotInitialized as expected.
  • player_id = 99 and milestone_ref = 1 are arbitrary values — the call never reaches the point where they matter.

How to Verify

# Run the new test in isolation
cargo test -p scoutchain-progress test_advance_level_not_initialized

# Full suite
cargo test --workspace

Expected output:

test tests::test_advance_level_not_initialized ... ok

Checklist

  • All contract tests pass: cargo test --workspace
  • Zero clippy warnings: cargo clippy --workspace -- -D warnings
  • Formatting clean: cargo fmt --all -- --check
  • No production code changed — test-only PR
  • Acceptance criteria fully covered

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

@Hydrax117 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Write test for advance_level when contract is not initialized

1 participant