Skip to content

test(core): add unit tests for charge() failure paths #2

Description

@Demilade10

Description

Add unit tests covering charge() failure scenarios that are not yet tested, so regressions in error handling are caught automatically instead of relying on manual testing.

Requirements and Context

  • The happy path (create_plan -> approve -> subscribe -> charge) is already verified end-to-end on testnet
  • Failure paths are currently untested and need explicit coverage
  • Tests must use the existing test env setup, mock auth, and token contract setup patterns already present in the test module
  • allowance expiration_ledger is capped at 3,000,000 ledgers - useful for constructing the expired allowance test case

Suggested Execution

Branch name: test/charge-failure-paths

Files to touch:

  • src/test.rs (or wherever the existing test module lives - add new test functions)

Example commit message: test(core): add unit tests for charge failure paths

Test and Commit

  • Test: charge() fails when allowance is insufficient
  • Test: charge() fails when allowance has expired (past expiration_ledger)
  • Test: charge() fails when called before the billing interval has elapsed
  • Test: charge() fails when subscription has been cancelled
  • Test: charge() fails when called by an unauthorized address
  • All new and existing tests pass with cargo test
  • Tests follow existing naming and structure conventions in the test module
  • Include test output in the PR

Guidelines

Complexity

Trivial - 100 points

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions