Skip to content

Add integration tests for buy and sell revert paths covering insufficient funds and oversell #571

Closed

Description

@Chucks1093

Summary

The two most critical failure paths in the trading contract — buying with insufficient XLM and selling more keys than a holder owns — both lack integration test coverage. Addressing them in a single issue ensures the revert path test pattern is consistent across buy and sell.

Scope

  • Insufficient buy: invoke buy with attached amount 1 stroop below the current price; assert revert with the insufficient-funds error code; assert key supply and buyer holdings unchanged
  • Oversell: set up a holder with exactly 2 keys via buy transactions; invoke sell with quantity 3; assert revert with the insufficient-balance error code; assert holder still owns 2 keys and creator supply unchanged
  • Both test cases should use a shared setup helper that deploys the contract and seeds a creator

Acceptance Criteria

  • Buy reverts with insufficient-funds error code when amount is 1 stroop short
  • Supply and buyer holdings unchanged after failed buy
  • Sell reverts with insufficient-balance error code when quantity exceeds holdings
  • Holder balance and creator supply unchanged after failed sell
  • Shared setup helper used by both test cases

ETA: 12 hours


Coordinate on Telegram

Activity

  1. Silver36-ship-it commented on Jul 23, 2026

    @Silver36-ship-it

    I would love to work on this professionally, please assign it to me

  2. ogazboiz commented on Jul 23, 2026

    @ogazboiz
    Contributor

    I'd like to take this one. I write Soroban contract tests in Rust regularly, and revert-path coverage is exactly the kind of testing I prioritize, since the failure paths are where funds actually get protected. The two cases are clear: for the insufficient buy I'd read the current price from the contract and attach exactly price minus 1 stroop so the test stays correct even if the bonding curve or pricing changes, assert the typed insufficient-funds error (matching on the error code, not just any panic), then assert supply and buyer holdings are untouched; for the oversell, seed a holder with exactly 2 keys through real buy calls rather than storage injection so the setup goes through the same path production does, sell 3, assert the insufficient-balance error code, and confirm the holder still has 2 and creator supply is unchanged. Both sit on a shared setup helper that deploys the contract, registers a creator, and funds the test accounts, so future revert tests reuse the same scaffold and the pattern stays consistent as the issue asks. The post-revert state assertions matter as much as the error codes here, since a revert that still mutated state would be the worse bug, and that's exactly what these tests would catch. The 12-hour ETA is comfortable, I'll coordinate in the Telegram as well. Please assign it to me and I'll get started.

  3. grantfox-oss commented on Jul 23, 2026

    @grantfox-oss

    🦊 GrantFox — @ogazboiz has been assigned to this issue as part of the Official Campaign | FWC26 campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #571)
    2. Your PR will be reviewed by the accesslayerorg maintainers

    Good luck! Track your progress on GrantFox.

  4. grantfox-oss commented on Jul 29, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox as part of the Official Campaign | FWC26 campaign!

    @ogazboiz's PR #608 was approved and merged by @Chucks1093.

    🏆 @ogazboiz: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (519 total points). Track your full progress on GrantFox.

    👏 Great work, @ogazboiz! Keep contributing to accesslayerorg.

  5. added a commit that references this issue on Jul 31, 2026
    50a38eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions