-
Notifications
You must be signed in to change notification settings - Fork 15
feat(reputation-contract): implement penalize_expert for dispute pena… #64
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ pub enum ReputationError { | |
| NotInitialized = 1, | ||
| AlreadyInitialized = 2, | ||
| ContractPaused = 3, | ||
| NotAuthorized = 8, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,3 +52,75 @@ fn test_unpause_restores_transfer_admin() { | |
| let new_admin = Address::generate(&env); | ||
| client.transfer_admin(&new_admin); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_penalize_expert_by_admin() { | ||
| let (env, admin, vault, client) = setup(); | ||
| client.init(&admin, &vault); | ||
| let expert = Address::generate(&env); | ||
|
|
||
| // Admin should be able to penalize | ||
| client.penalize_expert(&expert, &50); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_penalize_expert_by_vault() { | ||
| let (env, admin, vault, client) = setup(); | ||
| client.init(&admin, &vault); | ||
| let _expert = Address::generate(&env); | ||
|
|
||
| // Vault should be able to penalize | ||
| env.mock_all_auths(); | ||
| // Simulate vault calling by mocking auth context | ||
| client.penalize_expert(&_expert, &50); | ||
| } | ||
|
Comment on lines
+56
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Admin vs vault authorization is not actually distinguished in these tests. Both tests execute the same call pattern and only verify “no error”, so they do not prove the vault-specific authorization path independently. 🤖 Prompt for AI Agents |
||
|
|
||
| #[test] | ||
| fn test_penalize_expert_unauthorized() { | ||
| let (env, admin, vault, client) = setup(); | ||
| client.init(&admin, &vault); | ||
| let _expert = Address::generate(&env); | ||
|
|
||
| // Create a new environment without mocking all auths to test unauthorized access | ||
| let env_strict = Env::default(); | ||
| let contract_id = env_strict.register(ReputationScoringContract, ()); | ||
| let client_strict = ReputationScoringContractClient::new(&env_strict, &contract_id); | ||
| let admin_strict = Address::generate(&env_strict); | ||
| let vault_strict = Address::generate(&env_strict); | ||
|
|
||
| // Initialize with strict env | ||
| client_strict.init(&admin_strict, &vault_strict); | ||
|
|
||
| let expert_strict = Address::generate(&env_strict); | ||
| let _unauthorized = Address::generate(&env_strict); | ||
|
|
||
| // Unauthorized address should not be able to penalize (no auth mocking for this env) | ||
| assert!(client_strict.try_penalize_expert(&expert_strict, &50).is_err()); | ||
| } | ||
|
Comment on lines
+79
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unauthorized test should assert the specific contract error.
🤖 Prompt for AI Agents |
||
|
|
||
| #[test] | ||
| fn test_penalize_expert_score_underflow_protection() { | ||
| let (env, admin, vault, client) = setup(); | ||
| client.init(&admin, &vault); | ||
| let expert = Address::generate(&env); | ||
|
|
||
| // Penalize with more points than current score (default score is 0) | ||
| // Should result in score of 0, not underflow | ||
| client.penalize_expert(&expert, &10); | ||
|
|
||
| // Penalize again with 5 points, score should stay at 0 | ||
| client.penalize_expert(&expert, &5); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_penalize_expert_partial_deduction() { | ||
| let (env, admin, vault, client) = setup(); | ||
| client.init(&admin, &vault); | ||
| let expert = Address::generate(&env); | ||
|
|
||
| // First penalize to set a score (100 - 30 = 70) | ||
| client.penalize_expert(&expert, &30); | ||
|
|
||
| // Second penalize (70 - 20 = 50) | ||
| client.penalize_expert(&expert, &20); | ||
| } | ||
|
Comment on lines
+102
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Score-behavior tests have no assertions and one invalid precondition. These tests never assert resulting score values, and the “partial deduction” case assumes an initial score of 100 but never initializes it, so it does not verify the intended math. 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authorization logic misses the vault path and never returns
NotAuthorized.Line 62 enforces admin auth only. This does not satisfy the required “admin or vault” authorization behavior, and there is no branch returning
ReputationError::NotAuthorizedwhen caller is neither.🤖 Prompt for AI Agents