Fix #117 — Validate FeeConfig to reject zero and negative fees#196
Open
peace-cyber09 wants to merge 1 commit into
Open
Fix #117 — Validate FeeConfig to reject zero and negative fees#196peace-cyber09 wants to merge 1 commit into
peace-cyber09 wants to merge 1 commit into
Conversation
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Fix #117 — Validate FeeConfig to reject zero and negative fees
Summary
initializeandupdate_fee_configpreviously accepted aFeeConfigwithany fee field set to
0or a negative value, includingcontact_fee_stroops.This would allow scouts to contact players for free and break subscription
pricing. This PR adds a
validate_fee_configguard that rejects any suchconfiguration before it is stored on-chain.
Changes
contracts/scout_access/src/errors.rsInvalidInput = 15toScoutAccessError.contracts/scout_access/src/lib.rsvalidate_fee_config(config: &FeeConfig) -> Result<(), ScoutAccessError>:ScoutAccessError::InvalidInputif any ofcontact_fee_stroops,basic_sub_stroops,pro_sub_stroops, orelite_sub_stroopsis<= 0.ScoutAccessError::InvalidInputifsub_duration_secs == 0.validate_fee_configininitialize(beforerequire_auth).validate_fee_configinupdate_fee_config(afterrequire_admin).test_initialize_zero_contact_fee_returns_invalid_inputcontact_fee_stroops = 0→InvalidInputtest_initialize_zero_basic_sub_returns_invalid_inputbasic_sub_stroops = 0→InvalidInputtest_initialize_zero_pro_sub_returns_invalid_inputpro_sub_stroops = 0→InvalidInputtest_initialize_zero_elite_sub_returns_invalid_inputelite_sub_stroops = 0→InvalidInputtest_initialize_zero_sub_duration_returns_invalid_inputsub_duration_secs = 0→InvalidInputtest_initialize_negative_fee_returns_invalid_inputcontact_fee_stroops = -1→InvalidInputtest_initialize_valid_fee_config_succeedsOk(())test_update_fee_config_zero_contact_fee_returns_invalid_inputcontact_fee_stroops = 0→InvalidInputtest_update_fee_config_zero_subscription_fee_returns_invalid_inputbasic_sub_stroops = 0→InvalidInputtest_update_fee_config_zero_duration_returns_invalid_inputsub_duration_secs = 0→InvalidInputtest_update_fee_config_valid_succeedsOk(()), stored value verifiedAcceptance Criteria
initializewith a zero contact fee returnsInvalidInput(error code 15).update_fee_configwith a zero subscription fee returnsInvalidInput.initializeandupdate_fee_config.Testing
cargo test -p scoutchain-scout-accessRelated
Closes #117