Skip to content

Fix #117 — Validate FeeConfig to reject zero and negative fees#196

Open
peace-cyber09 wants to merge 1 commit into
scout-off:mainfrom
peace-cyber09:fix-117
Open

Fix #117 — Validate FeeConfig to reject zero and negative fees#196
peace-cyber09 wants to merge 1 commit into
scout-off:mainfrom
peace-cyber09:fix-117

Conversation

@peace-cyber09
Copy link
Copy Markdown

PR: Fix #117 — Validate FeeConfig to reject zero and negative fees

Summary

initialize and update_fee_config previously accepted a FeeConfig with
any fee field set to 0 or a negative value, including contact_fee_stroops.
This would allow scouts to contact players for free and break subscription
pricing. This PR adds a validate_fee_config guard that rejects any such
configuration before it is stored on-chain.

Changes

contracts/scout_access/src/errors.rs

  • Added InvalidInput = 15 to ScoutAccessError.

contracts/scout_access/src/lib.rs

  • Added private helper validate_fee_config(config: &FeeConfig) -> Result<(), ScoutAccessError>:
    • Returns ScoutAccessError::InvalidInput if any of contact_fee_stroops,
      basic_sub_stroops, pro_sub_stroops, or elite_sub_stroops is <= 0.
    • Returns ScoutAccessError::InvalidInput if sub_duration_secs == 0.
  • Called validate_fee_config in initialize (before require_auth).
  • Called validate_fee_config in update_fee_config (after require_admin).
  • Added 11 unit tests covering every validation path:
Test Scenario
test_initialize_zero_contact_fee_returns_invalid_input contact_fee_stroops = 0InvalidInput
test_initialize_zero_basic_sub_returns_invalid_input basic_sub_stroops = 0InvalidInput
test_initialize_zero_pro_sub_returns_invalid_input pro_sub_stroops = 0InvalidInput
test_initialize_zero_elite_sub_returns_invalid_input elite_sub_stroops = 0InvalidInput
test_initialize_zero_sub_duration_returns_invalid_input sub_duration_secs = 0InvalidInput
test_initialize_negative_fee_returns_invalid_input contact_fee_stroops = -1InvalidInput
test_initialize_valid_fee_config_succeeds All fields positive → Ok(())
test_update_fee_config_zero_contact_fee_returns_invalid_input contact_fee_stroops = 0InvalidInput
test_update_fee_config_zero_subscription_fee_returns_invalid_input basic_sub_stroops = 0InvalidInput
test_update_fee_config_zero_duration_returns_invalid_input sub_duration_secs = 0InvalidInput
test_update_fee_config_valid_succeeds All fields positive → Ok(()), stored value verified

Acceptance Criteria

  • initialize with a zero contact fee returns InvalidInput (error code 15).
  • update_fee_config with a zero subscription fee returns InvalidInput.
  • Valid fee config succeeds in both initialize and update_fee_config.
  • Unit tests cover all validation cases.

Testing

cargo test -p scoutchain-scout-access

Related

Closes #117

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

@peace-cyber09 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.

FeeConfig has no validation; zero fees are accepted

1 participant