|
| 1 | +#![no_std] |
| 2 | +use soroban_sdk::contracterror; |
| 3 | + |
| 4 | +/// A stable catalog of errors for the markets smart contract. |
| 5 | +#[contracterror] |
| 6 | +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 7 | +#[repr(u32)] |
| 8 | +pub enum ContractError { |
| 9 | + /// Action is unauthorized; typically thrown when an admin action is invoked by a non-admin. |
| 10 | + Unauthorized = 1, |
| 11 | + /// Market not found; thrown when querying or interacting with a non-existent market. |
| 12 | + MarketNotFound = 2, |
| 13 | + /// Market is closed; thrown when trying to interact with a market that has already ended. |
| 14 | + MarketClosed = 3, |
| 15 | + /// Market already resolved; thrown when attempting to resolve a market more than once. |
| 16 | + MarketAlreadyResolved = 4, |
| 17 | + /// Market not resolved; thrown when attempting to claim winnings before resolution. |
| 18 | + MarketNotResolved = 5, |
| 19 | + /// Invalid outcome; thrown when the provided outcome is not supported by the market. |
| 20 | + InvalidOutcome = 6, |
| 21 | + /// Invalid configuration; thrown when market setup parameters are out of bounds. |
| 22 | + InvalidConfig = 7, |
| 23 | + /// Overflow; thrown when math operations overflow, preventing unsafe state changes. |
| 24 | + Overflow = 8, |
| 25 | + /// Stake too small; thrown when a deposit or bet is below the minimum threshold. |
| 26 | + StakeTooSmall = 9, |
| 27 | + /// Invalid State; thrown when a generic state transition fails. |
| 28 | + InvalidState = 10, |
| 29 | +} |
| 30 | + |
| 31 | +#[cfg(test)] |
| 32 | +mod tests { |
| 33 | + use super::*; |
| 34 | + |
| 35 | + #[test] |
| 36 | + fn test_error_variants() { |
| 37 | + assert_eq!(ContractError::Unauthorized as u32, 1); |
| 38 | + assert_eq!(ContractError::MarketNotFound as u32, 2); |
| 39 | + assert_eq!(ContractError::MarketClosed as u32, 3); |
| 40 | + assert_eq!(ContractError::MarketAlreadyResolved as u32, 4); |
| 41 | + assert_eq!(ContractError::MarketNotResolved as u32, 5); |
| 42 | + assert_eq!(ContractError::InvalidOutcome as u32, 6); |
| 43 | + assert_eq!(ContractError::InvalidConfig as u32, 7); |
| 44 | + assert_eq!(ContractError::Overflow as u32, 8); |
| 45 | + assert_eq!(ContractError::StakeTooSmall as u32, 9); |
| 46 | + assert_eq!(ContractError::InvalidState as u32, 10); |
| 47 | + } |
| 48 | +} |
0 commit comments