Repository navigation
test: add buy and sell revert path integration tests - #608
Merged
Chucks1093 merged 1 commit intoJul 29, 2026
Merged
Conversation
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
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. |
Closed
5 tasks
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
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.buy_keywith an attached amount one stroop below the current price; asserts the call reverts withContractError::InsufficientPaymentand that key supply and buyer holdings are unchanged.sell_keysettles 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 withContractError::InsufficientBalancewhile leaving holder balance and creator supply unchanged.setup()helper that deploys the contract and seeds a creator.Implementation note
The contract's
sell_keyentrypoint 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 failedInsufficientPaymentwhen the payment is 1 stroop shortInsufficientBalancewhen the sell exceeds holdingscargo fmt --all -- --checkcleancargo clippy --test buy_sell_revert_paths -- -D warningscleanCloses #571