Skip to content

test(learn-token): add unit tests for increase_allowance overflow and boundaries (#501) - #517

Open
lmduy2612 wants to merge 1 commit into
ChainLearnOfficial:mainfrom
lmduy2612:fix/increase-allowance-overflow-check-501
Open

lmduy2612 wants to merge 1 commit into
ChainLearnOfficial:mainfrom
lmduy2612:fix/increase-allowance-overflow-check-501

Conversation

@lmduy2612

Copy link
Copy Markdown

Summary of Changes

Closes #501.

This PR adds comprehensive unit test coverage for increase_allowance in contracts/learn-token, explicitly asserting overflow behavior and edge-case boundary conditions:

  1. test_increase_allowance_overflow_panics:

    • Tests increasing allowance when current allowance is near i128::MAX such that current_amount + amount > i128::MAX.
    • Asserts panic with "allowance overflow".
  2. test_increase_allowance_at_exact_i128_max_succeeds:

    • Tests increasing allowance precisely up to i128::MAX (e.g. i128::MAX - 50 + 50 == i128::MAX).
    • Verifies allowance equals i128::MAX with no panic.
  3. test_increase_allowance_from_i128_max_panics_on_any_positive:

    • Tests attempting to add any positive amount (+1) when allowance is already at i128::MAX.
    • Asserts panic with "allowance overflow".
  4. test_increase_allowance_rejects_negative_amount:

    • Asserts panic with "negative amount" when negative value is supplied.
  5. test_increase_allowance_rejects_expired_ledger:

    • Asserts panic with "expiration_ledger must be in the future" when expiration ledger is not strictly greater than current ledger.

Verification

  • Run cargo test --test token_tests: All 83 unit tests passing.
  • Clippy: 0 warnings in token_tests.rs.

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.

increase_allowance can overflow when adding to existing allowance

2 participants