feat: order expiry, zero-size validation, multi-market + upgrade tests (#267 #269 #271 #272)#348
Merged
abayomicornelius merged 1 commit intoJun 27, 2026
Conversation
…ts#269), multi-market tests (SO4-Markets#271, SO4-Markets#267) **Issue SO4-Markets#269 — Zero-amount validation (test: zero_amount_validation.rs)** - Added `ZeroSizeDelta = 19` to `order_handler::Error` enum - `create_order` now rejects position orders (Increase/Decrease variants) with `size_delta_usd == 0`, returning `Error::ZeroSizeDelta` instead of a panic - Integration test covers MarketIncrease, LimitIncrease, MarketDecrease with zero size, plus the valid swap-order zero-size case; also covers the existing DepositError::ZeroDeposit and WithdrawalError::ZeroWithdrawal guards **Issue SO4-Markets#272 — On-chain per-order expiry** - Added `expiry_ledger: Option<u64>` to `CreateOrderParams` in `libs/types` - `create_order` persists expiry in a new `OrderStorageKey::OrderExpiry` slot when the user supplies `Some(n)`; `None` is a no-op (backward compatible) - `execute_order` checks expiry at entry: if `ledger.sequence() > expiry`, the order is auto-cancelled, collateral refunded to the receiver, storage cleaned up, and `Error::OrderExpired` is returned instead of reverting - New `cleanup_expired_order` public function: anyone can call it after expiry; caller receives 10 % of the order's execution_fee as an incentive - `remove_order` helper also clears the `OrderExpiry` slot on cancel/execute - Updated all 80+ `CreateOrderParams {}` struct literals across the workspace to add `expiry_ledger: None` (no behaviour change for existing code) **Issue SO4-Markets#271 — Multi-market execution (test: multi_market_execution.rs)** - Integration test: two independent markets (ETH/USD and BTC/USD), keeper executes one order per market in the same ledger, asserts OI updated per market and no cross-market contamination in pool or OI storage **Issue SO4-Markets#267 — Contract upgrade (test: contract_upgrade.rs)** - Two runnable tests: non-admin upgrade panics at auth; admin upgrade panics at WASM lookup (proving the auth gate is open) - One `#[ignore]` test documents the full state-preservation upgrade scenario; requires a real v2 WASM binary to run end-to-end
|
@bade22brazy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
6 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.
Closes #272
Closes #267
Closes #269
Closes #271
Summary
Error::ZeroSizeDelta = 19toorder_handler.create_ordernow rejects any position-type order (MarketIncrease, LimitIncrease, StopIncrease, MarketDecrease, LimitDecrease, StopLossDecrease) withsize_delta_usd == 0with a typed error rather than a panic. Swap orders with zero size continue to work unchanged. New integration test:tests/zero_amount_validation.rs(6 test cases covering all three validator types — order, deposit, withdrawal).expiry_ledger: Option<u64>toCreateOrderParams. WhenSome(n)is supplied, the order is auto-cancelled with a full collateral refund whenexecute_orderis called after ledger sequencen. A new publiccleanup_expired_orderfunction allows anyone to cancel an expired order and earn a 10 % incentive from the order's execution fee.Noneis the default and is backward-compatible with all existing code. All 80+ existingCreateOrderParams {}struct literals updated withexpiry_ledger: None.tests/multi_market_execution.rs— deploys ETH/USD and BTC/USD markets, opens one order per market, keeper executes both in a single ledger, asserts independent OI and pool state with no cross-market contamination.tests/contract_upgrade.rs— two runnable tests verifying non-admin upgrade panics at auth and admin upgrade auth gate is open. A third#[ignore]test documents the full state-preservation upgrade path (requires a compiled v2 WASM binary to run).Test plan
cargo check -p order-handler— no new errors (pre-existingincrease_position_utilserror is unrelated)cargo check -p gmx-types— compiles cleanlycargo check -p exchange-router— compiles cleanlycontracts/order_handler/tests/haveexpiry_ledger: Noneappendedtests/zero_amount_validation.rs— 6 tests covering zero-size order, deposit, and withdrawal rejectiontests/multi_market_execution.rs— 1 integration test verifying independent multi-market OI trackingtests/contract_upgrade.rs— 2 runnable tests (non-admin reverts, admin auth gate open) + 1#[ignore]spec