fix(scout_access): replace expect("overflow") with ScoutAccessError::Overflow#2
Merged
Merged
Conversation
…Overflow
Replace two .expect("overflow") calls with .ok_or(ScoutAccessError::Overflow)?
so overflow conditions return a typed error instead of panicking:
- subscribe: u64 timestamp + sub_duration_secs
- log_trial_offer: u32 trial counter increment
Add test_log_trial_offer_overflow_returns_error: seeds TrialCounter at
u32::MAX via env.as_contract and asserts try_log_trial_offer returns
Err(Ok(ScoutAccessError::Overflow)).
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.
Summary
Replaces both
.expect("overflow")calls inscout_access/src/lib.rswith.ok_or(ScoutAccessError::Overflow)?so overflow conditions surface as a typed contract error instead of causing a runtime panic.Changes
contracts/scout_access/src/lib.rssubscribe— timestamp addition:log_trial_offer— trial counter increment:Both functions already return
Result<_, ScoutAccessError>so the?operator propagates cleanly with no signature changes.New test —
test_log_trial_offer_overflow_returns_errorSeeds
DataKey::TrialCounter(1)atu32::MAXviaenv.as_contract, then callstry_log_trial_offerand asserts the result isErr(Ok(ScoutAccessError::Overflow)). No fee is collected and no state is written.What was not changed