Skip to content

test: add buy and sell revert path integration tests - #608

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
ogazboiz:feat/issue-571-revert-path-tests
Jul 29, 2026
Merged

Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
ogazboiz:feat/issue-571-revert-path-tests

Conversation

@ogazboiz

Copy link
Copy Markdown
Contributor

Summary

Adds a consolidated integration test binary (creator-keys/tests/buy_sell_revert_paths.rs) covering the two most critical trading failure paths — buying with insufficient XLM and selling more keys than a holder owns — behind a single shared setup helper, so the revert-path assertion pattern stays consistent across buy and sell.

  • Insufficient buy: invokes buy_key with an attached amount one stroop below the current price; asserts the call reverts with ContractError::InsufficientPayment and that key supply and buyer holdings are unchanged.
  • Oversell: seeds a holder with exactly two keys via buy transactions, then attempts to sell three. sell_key settles one key per call (there is no quantity argument), so the three-key sell is issued as three sequential sells; the first two drain the position and the third — the oversell — is asserted to revert with ContractError::InsufficientBalance while leaving holder balance and creator supply unchanged.
  • Both test cases use a shared setup() helper that deploys the contract and seeds a creator.

Implementation note

The contract's sell_key entrypoint settles a single key per call, so the "sell quantity 3" scenario is modeled as three sequential single-key sells where the third exceeds the holder's holdings. This keeps the test faithful to the actual contract API; no production logic was changed.

Test plan

  • cargo test -p creator-keys --test buy_sell_revert_paths — 2 passed, 0 failed
  • Buy reverts with InsufficientPayment when the payment is 1 stroop short
  • Supply and buyer holdings unchanged after the failed buy
  • Sell reverts with InsufficientBalance when the sell exceeds holdings
  • Holder balance and creator supply unchanged after the failed oversell
  • Shared setup helper used by both test cases
  • cargo fmt --all -- --check clean
  • cargo clippy --test buy_sell_revert_paths -- -D warnings clean

Closes #571

Add a consolidated integration test binary covering the two most critical
trading failure paths behind a single shared setup helper:

- Insufficient buy: buying one stroop below the current price reverts with
  InsufficientPayment and leaves supply and buyer holdings unchanged.
- Oversell: a holder owning exactly two keys cannot sell a third; the oversell
  reverts with InsufficientBalance and mutates no state. Since sell_key settles
  one key per call, the three-key sell is issued as three sequential sells and
  the third (the oversell) is asserted to fail.

Both cases use a shared setup() helper that deploys the contract and seeds a
creator, keeping the revert-path assertion pattern consistent across buy and
sell.

Closes accesslayerorg#571
@Chucks1093

Copy link
Copy Markdown
Member

I see what you have done here, the buy and sell failure paths are properly tested so edge cases like insufficient funds and out-of-stock are caught early. Nice one.

@Chucks1093
Chucks1093 merged commit 029c082 into accesslayerorg:main Jul 29, 2026
1 check passed
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.

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

2 participants