1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
//! Home of the Auction contract's [`enum@Error`] type.
use alloc::vec::Vec;
use core::{
convert::{TryFrom, TryInto},
fmt::{self, Display, Formatter},
result,
};
use crate::{
bytesrepr::{self, FromBytes, ToBytes, U8_SERIALIZED_LENGTH},
CLType, CLTyped,
};
/// Errors which can occur while executing the Auction contract.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(test, derive(strum::EnumIter))]
#[repr(u8)]
#[non_exhaustive]
pub enum Error {
/// Unable to find named key in the contract's named keys.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(0, Error::MissingKey as u8);
/// ```
MissingKey = 0,
/// Given named key contains invalid variant.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(1, Error::InvalidKeyVariant as u8);
/// ```
InvalidKeyVariant = 1,
/// Value under an uref does not exist. This means the installer contract didn't work properly.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(2, Error::MissingValue as u8);
/// ```
MissingValue = 2,
/// ABI serialization issue while reading or writing.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(3, Error::Serialization as u8);
/// ```
Serialization = 3,
/// Triggered when contract was unable to transfer desired amount of tokens into a bid purse.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(4, Error::TransferToBidPurse as u8);
/// ```
TransferToBidPurse = 4,
/// User passed invalid amount of tokens which might result in wrong values after calculation.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(5, Error::InvalidAmount as u8);
/// ```
InvalidAmount = 5,
/// Unable to find a bid by account hash in `active_bids` map.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(6, Error::BidNotFound as u8);
/// ```
BidNotFound = 6,
/// Validator's account hash was not found in the map.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(7, Error::ValidatorNotFound as u8);
/// ```
ValidatorNotFound = 7,
/// Delegator's account hash was not found in the map.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(8, Error::DelegatorNotFound as u8);
/// ```
DelegatorNotFound = 8,
/// Storage problem.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(9, Error::Storage as u8);
/// ```
Storage = 9,
/// Raised when system is unable to bond.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(10, Error::Bonding as u8);
/// ```
Bonding = 10,
/// Raised when system is unable to unbond.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(11, Error::Unbonding as u8);
/// ```
Unbonding = 11,
/// Raised when Mint contract is unable to release founder stake.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(12, Error::ReleaseFounderStake as u8);
/// ```
ReleaseFounderStake = 12,
/// Raised when the system is unable to determine purse balance.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(13, Error::GetBalance as u8);
/// ```
GetBalance = 13,
/// Raised when an entry point is called from invalid account context.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(14, Error::InvalidContext as u8);
/// ```
InvalidContext = 14,
/// Raised whenever a validator's funds are still locked in but an attempt to withdraw was
/// made.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(15, Error::ValidatorFundsLocked as u8);
/// ```
ValidatorFundsLocked = 15,
/// Raised when caller is not the system account.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(16, Error::InvalidCaller as u8);
/// ```
InvalidCaller = 16,
/// Raised when function is supplied a public key that does match the caller's or does not have
/// an associated account.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(17, Error::InvalidPublicKey as u8);
/// ```
InvalidPublicKey = 17,
/// Validator is not not bonded.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(18, Error::BondNotFound as u8);
/// ```
BondNotFound = 18,
/// Unable to create purse.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(19, Error::CreatePurseFailed as u8);
/// ```
CreatePurseFailed = 19,
/// Attempted to unbond an amount which was too large.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(20, Error::UnbondTooLarge as u8);
/// ```
UnbondTooLarge = 20,
/// Attempted to bond with a stake which was too small.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(21, Error::BondTooSmall as u8);
/// ```
BondTooSmall = 21,
/// Raised when rewards are to be distributed to delegators, but the validator has no
/// delegations.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(22, Error::MissingDelegations as u8);
/// ```
MissingDelegations = 22,
/// The validators returned by the consensus component should match
/// current era validators when distributing rewards.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(23, Error::MismatchedEraValidators as u8);
/// ```
MismatchedEraValidators = 23,
/// Failed to mint reward tokens.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(24, Error::MintReward as u8);
/// ```
MintReward = 24,
/// Invalid number of validator slots.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(25, Error::InvalidValidatorSlotsValue as u8);
/// ```
InvalidValidatorSlotsValue = 25,
/// Failed to reduce total supply.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(26, Error::MintReduceTotalSupply as u8);
/// ```
MintReduceTotalSupply = 26,
/// Triggered when contract was unable to transfer desired amount of tokens into a delegators
/// purse.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(27, Error::TransferToDelegatorPurse as u8);
/// ```
TransferToDelegatorPurse = 27,
/// Triggered when contract was unable to perform a transfer to distribute validators reward.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(28, Error::ValidatorRewardTransfer as u8);
/// ```
ValidatorRewardTransfer = 28,
/// Triggered when contract was unable to perform a transfer to distribute delegators rewards.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(29, Error::DelegatorRewardTransfer as u8);
/// ```
DelegatorRewardTransfer = 29,
/// Failed to transfer desired amount while withdrawing delegators reward.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(30, Error::WithdrawDelegatorReward as u8);
/// ```
WithdrawDelegatorReward = 30,
/// Failed to transfer desired amount while withdrawing validators reward.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(31, Error::WithdrawValidatorReward as u8);
/// ```
WithdrawValidatorReward = 31,
/// Failed to transfer desired amount into unbonding purse.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(32, Error::TransferToUnbondingPurse as u8);
/// ```
TransferToUnbondingPurse = 32,
/// Failed to record era info.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(33, Error::RecordEraInfo as u8);
/// ```
RecordEraInfo = 33,
/// Failed to create a [`crate::CLValue`].
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(34, Error::CLValue as u8);
/// ```
CLValue = 34,
/// Missing seigniorage recipients for given era.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(35, Error::MissingSeigniorageRecipients as u8);
/// ```
MissingSeigniorageRecipients = 35,
/// Failed to transfer funds.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(36, Error::Transfer as u8);
/// ```
Transfer = 36,
/// Delegation rate exceeds rate.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(37, Error::DelegationRateTooLarge as u8);
/// ```
DelegationRateTooLarge = 37,
/// Raised whenever a delegator's funds are still locked in but an attempt to undelegate was
/// made.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(38, Error::DelegatorFundsLocked as u8);
/// ```
DelegatorFundsLocked = 38,
/// An arithmetic overflow has occurred.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(39, Error::ArithmeticOverflow as u8);
/// ```
ArithmeticOverflow = 39,
/// Execution exceeded the gas limit.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(40, Error::GasLimit as u8);
/// ```
GasLimit = 40,
/// Too many frames on the runtime stack.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(41, Error::RuntimeStackOverflow as u8);
/// ```
RuntimeStackOverflow = 41,
/// An error that is raised when there is an error in the mint contract that cannot
/// be mapped to a specific auction error.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(42, Error::MintError as u8);
/// ```
MintError = 42,
/// The validator has exceeded the maximum amount of delegators allowed.
/// NOTE: This variant is no longer in use.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(43, Error::ExceededDelegatorSizeLimit as u8);
/// ```
ExceededDelegatorSizeLimit = 43,
/// The global delegator capacity for the auction has been reached.
/// NOTE: This variant is no longer in use.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(44, Error::GlobalDelegatorCapacityReached as u8);
/// ```
GlobalDelegatorCapacityReached = 44,
/// The delegated amount is below the minimum allowed.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(45, Error::DelegationAmountTooSmall as u8);
/// ```
DelegationAmountTooSmall = 45,
/// Runtime stack error.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(46, Error::RuntimeStack as u8);
/// ```
RuntimeStack = 46,
/// An error that is raised on private chain only when a `disable_auction_bids` flag is set to
/// `true`.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(47, Error::AuctionBidsDisabled as u8);
/// ```
AuctionBidsDisabled = 47,
/// Error getting accumulation purse.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(48, Error::GetAccumulationPurse as u8);
/// ```
GetAccumulationPurse = 48,
/// Failed to transfer desired amount into administrators account.
/// ```
/// # use casper_types::system::auction::Error;
/// assert_eq!(49, Error::TransferToAdministrator as u8);
/// ```
TransferToAdministrator = 49,
}
impl Display for Error {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
match self {
Error::MissingKey => formatter.write_str("Missing key"),
Error::InvalidKeyVariant => formatter.write_str("Invalid key variant"),
Error::MissingValue => formatter.write_str("Missing value"),
Error::Serialization => formatter.write_str("Serialization error"),
Error::TransferToBidPurse => formatter.write_str("Transfer to bid purse error"),
Error::InvalidAmount => formatter.write_str("Invalid amount"),
Error::BidNotFound => formatter.write_str("Bid not found"),
Error::ValidatorNotFound => formatter.write_str("Validator not found"),
Error::DelegatorNotFound => formatter.write_str("Delegator not found"),
Error::Storage => formatter.write_str("Storage error"),
Error::Bonding => formatter.write_str("Bonding error"),
Error::Unbonding => formatter.write_str("Unbonding error"),
Error::ReleaseFounderStake => formatter.write_str("Unable to release founder stake"),
Error::GetBalance => formatter.write_str("Unable to get purse balance"),
Error::InvalidContext => formatter.write_str("Invalid context"),
Error::ValidatorFundsLocked => formatter.write_str("Validator's funds are locked"),
Error::InvalidCaller => formatter.write_str("Function must be called by system account"),
Error::InvalidPublicKey => formatter.write_str("Supplied public key does not match caller's public key or has no associated account"),
Error::BondNotFound => formatter.write_str("Validator's bond not found"),
Error::CreatePurseFailed => formatter.write_str("Unable to create purse"),
Error::UnbondTooLarge => formatter.write_str("Unbond is too large"),
Error::BondTooSmall => formatter.write_str("Bond is too small"),
Error::MissingDelegations => formatter.write_str("Validators has not received any delegations"),
Error::MismatchedEraValidators => formatter.write_str("Mismatched era validator sets to distribute rewards"),
Error::MintReward => formatter.write_str("Failed to mint rewards"),
Error::InvalidValidatorSlotsValue => formatter.write_str("Invalid number of validator slots"),
Error::MintReduceTotalSupply => formatter.write_str("Failed to reduce total supply"),
Error::TransferToDelegatorPurse => formatter.write_str("Transfer to delegators purse error"),
Error::ValidatorRewardTransfer => formatter.write_str("Reward transfer to validator error"),
Error::DelegatorRewardTransfer => formatter.write_str("Rewards transfer to delegator error"),
Error::WithdrawDelegatorReward => formatter.write_str("Withdraw delegator reward error"),
Error::WithdrawValidatorReward => formatter.write_str("Withdraw validator reward error"),
Error::TransferToUnbondingPurse => formatter.write_str("Transfer to unbonding purse error"),
Error::RecordEraInfo => formatter.write_str("Record era info error"),
Error::CLValue => formatter.write_str("CLValue error"),
Error::MissingSeigniorageRecipients => formatter.write_str("Missing seigniorage recipients for given era"),
Error::Transfer => formatter.write_str("Transfer error"),
Error::DelegationRateTooLarge => formatter.write_str("Delegation rate too large"),
Error::DelegatorFundsLocked => formatter.write_str("Delegator's funds are locked"),
Error::ArithmeticOverflow => formatter.write_str("Arithmetic overflow"),
Error::GasLimit => formatter.write_str("Execution exceeded the gas limit"),
Error::RuntimeStackOverflow => formatter.write_str("Runtime stack overflow"),
Error::MintError => formatter.write_str("An error in the mint contract execution"),
Error::ExceededDelegatorSizeLimit => formatter.write_str("The amount of delegators per validator has been exceeded"),
Error::GlobalDelegatorCapacityReached => formatter.write_str("The global delegator capacity has been reached"),
Error::DelegationAmountTooSmall => formatter.write_str("The delegated amount is below the minimum allowed"),
Error::RuntimeStack => formatter.write_str("Runtime stack error"),
Error::AuctionBidsDisabled => formatter.write_str("Auction bids are disabled"),
Error::GetAccumulationPurse => formatter.write_str("Get accumulation purse error"),
Error::TransferToAdministrator => formatter.write_str("Transfer to administrator error"),
}
}
}
impl CLTyped for Error {
fn cl_type() -> CLType {
CLType::U8
}
}
// This error type is not intended to be used by third party crates.
#[doc(hidden)]
#[derive(Debug, PartialEq, Eq)]
pub struct TryFromU8ForError(());
// This conversion is not intended to be used by third party crates.
#[doc(hidden)]
impl TryFrom<u8> for Error {
type Error = TryFromU8ForError;
fn try_from(value: u8) -> result::Result<Self, Self::Error> {
match value {
d if d == Error::MissingKey as u8 => Ok(Error::MissingKey),
d if d == Error::InvalidKeyVariant as u8 => Ok(Error::InvalidKeyVariant),
d if d == Error::MissingValue as u8 => Ok(Error::MissingValue),
d if d == Error::Serialization as u8 => Ok(Error::Serialization),
d if d == Error::TransferToBidPurse as u8 => Ok(Error::TransferToBidPurse),
d if d == Error::InvalidAmount as u8 => Ok(Error::InvalidAmount),
d if d == Error::BidNotFound as u8 => Ok(Error::BidNotFound),
d if d == Error::ValidatorNotFound as u8 => Ok(Error::ValidatorNotFound),
d if d == Error::DelegatorNotFound as u8 => Ok(Error::DelegatorNotFound),
d if d == Error::Storage as u8 => Ok(Error::Storage),
d if d == Error::Bonding as u8 => Ok(Error::Bonding),
d if d == Error::Unbonding as u8 => Ok(Error::Unbonding),
d if d == Error::ReleaseFounderStake as u8 => Ok(Error::ReleaseFounderStake),
d if d == Error::GetBalance as u8 => Ok(Error::GetBalance),
d if d == Error::InvalidContext as u8 => Ok(Error::InvalidContext),
d if d == Error::ValidatorFundsLocked as u8 => Ok(Error::ValidatorFundsLocked),
d if d == Error::InvalidCaller as u8 => Ok(Error::InvalidCaller),
d if d == Error::InvalidPublicKey as u8 => Ok(Error::InvalidPublicKey),
d if d == Error::BondNotFound as u8 => Ok(Error::BondNotFound),
d if d == Error::CreatePurseFailed as u8 => Ok(Error::CreatePurseFailed),
d if d == Error::UnbondTooLarge as u8 => Ok(Error::UnbondTooLarge),
d if d == Error::BondTooSmall as u8 => Ok(Error::BondTooSmall),
d if d == Error::MissingDelegations as u8 => Ok(Error::MissingDelegations),
d if d == Error::MismatchedEraValidators as u8 => Ok(Error::MismatchedEraValidators),
d if d == Error::MintReward as u8 => Ok(Error::MintReward),
d if d == Error::InvalidValidatorSlotsValue as u8 => {
Ok(Error::InvalidValidatorSlotsValue)
}
d if d == Error::MintReduceTotalSupply as u8 => Ok(Error::MintReduceTotalSupply),
d if d == Error::TransferToDelegatorPurse as u8 => Ok(Error::TransferToDelegatorPurse),
d if d == Error::ValidatorRewardTransfer as u8 => Ok(Error::ValidatorRewardTransfer),
d if d == Error::DelegatorRewardTransfer as u8 => Ok(Error::DelegatorRewardTransfer),
d if d == Error::WithdrawDelegatorReward as u8 => Ok(Error::WithdrawDelegatorReward),
d if d == Error::WithdrawValidatorReward as u8 => Ok(Error::WithdrawValidatorReward),
d if d == Error::TransferToUnbondingPurse as u8 => Ok(Error::TransferToUnbondingPurse),
d if d == Error::RecordEraInfo as u8 => Ok(Error::RecordEraInfo),
d if d == Error::CLValue as u8 => Ok(Error::CLValue),
d if d == Error::MissingSeigniorageRecipients as u8 => {
Ok(Error::MissingSeigniorageRecipients)
}
d if d == Error::Transfer as u8 => Ok(Error::Transfer),
d if d == Error::DelegationRateTooLarge as u8 => Ok(Error::DelegationRateTooLarge),
d if d == Error::DelegatorFundsLocked as u8 => Ok(Error::DelegatorFundsLocked),
d if d == Error::ArithmeticOverflow as u8 => Ok(Error::ArithmeticOverflow),
d if d == Error::GasLimit as u8 => Ok(Error::GasLimit),
d if d == Error::RuntimeStackOverflow as u8 => Ok(Error::RuntimeStackOverflow),
d if d == Error::MintError as u8 => Ok(Error::MintError),
d if d == Error::ExceededDelegatorSizeLimit as u8 => {
Ok(Error::ExceededDelegatorSizeLimit)
}
d if d == Error::GlobalDelegatorCapacityReached as u8 => {
Ok(Error::GlobalDelegatorCapacityReached)
}
d if d == Error::DelegationAmountTooSmall as u8 => Ok(Error::DelegationAmountTooSmall),
d if d == Error::RuntimeStack as u8 => Ok(Error::RuntimeStack),
d if d == Error::AuctionBidsDisabled as u8 => Ok(Error::AuctionBidsDisabled),
d if d == Error::GetAccumulationPurse as u8 => Ok(Error::GetAccumulationPurse),
d if d == Error::TransferToAdministrator as u8 => Ok(Error::TransferToAdministrator),
_ => Err(TryFromU8ForError(())),
}
}
}
impl ToBytes for Error {
fn to_bytes(&self) -> result::Result<Vec<u8>, bytesrepr::Error> {
let value = *self as u8;
value.to_bytes()
}
fn serialized_length(&self) -> usize {
U8_SERIALIZED_LENGTH
}
}
impl FromBytes for Error {
fn from_bytes(bytes: &[u8]) -> result::Result<(Self, &[u8]), bytesrepr::Error> {
let (value, rem): (u8, _) = FromBytes::from_bytes(bytes)?;
let error: Error = value
.try_into()
// In case an Error variant is unable to be determined it would return an
// Error::Formatting as if its unable to be correctly deserialized.
.map_err(|_| bytesrepr::Error::Formatting)?;
Ok((error, rem))
}
}
impl From<bytesrepr::Error> for Error {
fn from(_: bytesrepr::Error) -> Self {
Error::Serialization
}
}
// This error type is not intended to be used by third party crates.
#[doc(hidden)]
pub enum PurseLookupError {
KeyNotFound,
KeyUnexpectedType,
}
impl From<PurseLookupError> for Error {
fn from(error: PurseLookupError) -> Self {
match error {
PurseLookupError::KeyNotFound => Error::MissingKey,
PurseLookupError::KeyUnexpectedType => Error::InvalidKeyVariant,
}
}
}
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
use super::Error;
#[test]
fn error_forward_trips() {
for expected_error_variant in Error::iter() {
assert_eq!(
Error::try_from(expected_error_variant as u8),
Ok(expected_error_variant)
)
}
}
#[test]
fn error_backward_trips() {
for u8 in 0..=u8::max_value() {
match Error::try_from(u8) {
Ok(error_variant) => {
assert_eq!(u8, error_variant as u8, "Error code mismatch")
}
Err(_) => continue,
};
}
}
}