use core::{
convert::TryFrom,
fmt::{self, Debug, Formatter},
};
use crate::{
account::{
AddKeyFailure, RemoveKeyFailure, SetThresholdFailure, TryFromIntError, UpdateKeyFailure,
},
addressable_entity::{self, MessageTopicError, TryFromSliceForAccountHashError},
bytesrepr, contracts,
system::{auction, handle_payment, mint},
CLValueError,
};
const RESERVED_ERROR_MAX: u32 = u16::MAX as u32;
const POS_ERROR_OFFSET: u32 = RESERVED_ERROR_MAX - u8::MAX as u32;
const MINT_ERROR_OFFSET: u32 = (POS_ERROR_OFFSET - 1) - u8::MAX as u32;
const HEADER_ERROR_OFFSET: u32 = (MINT_ERROR_OFFSET - 1) - u8::MAX as u32;
const AUCTION_ERROR_OFFSET: u32 = (HEADER_ERROR_OFFSET - 1) - u8::MAX as u32;
const USER_ERROR_MIN: u32 = RESERVED_ERROR_MAX + 1;
const USER_ERROR_MAX: u32 = 2 * RESERVED_ERROR_MAX + 1;
const MINT_ERROR_MIN: u32 = MINT_ERROR_OFFSET;
const MINT_ERROR_MAX: u32 = POS_ERROR_OFFSET - 1;
const HP_ERROR_MIN: u32 = POS_ERROR_OFFSET;
const HP_ERROR_MAX: u32 = RESERVED_ERROR_MAX;
const HEADER_ERROR_MIN: u32 = HEADER_ERROR_OFFSET;
const HEADER_ERROR_MAX: u32 = HEADER_ERROR_OFFSET + u8::MAX as u32;
const AUCTION_ERROR_MIN: u32 = AUCTION_ERROR_OFFSET;
const AUCTION_ERROR_MAX: u32 = AUCTION_ERROR_OFFSET + u8::MAX as u32;
#[derive(Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ApiError {
None,
MissingArgument,
InvalidArgument,
Deserialize,
Read,
ValueNotFound,
ContractNotFound,
GetKey,
UnexpectedKeyVariant,
UnexpectedContractRefVariant,
InvalidPurseName,
InvalidPurse,
UpgradeContractAtURef,
Transfer,
NoAccessRights,
CLTypeMismatch,
EarlyEndOfStream,
Formatting,
LeftOverBytes,
OutOfMemory,
MaxKeysLimit,
DuplicateKey,
PermissionDenied,
MissingKey,
ThresholdViolation,
KeyManagementThreshold,
DeploymentThreshold,
InsufficientTotalWeight,
InvalidSystemContract,
PurseNotCreated,
Unhandled,
BufferTooSmall,
HostBufferEmpty,
HostBufferFull,
AllocLayout,
DictionaryItemKeyExceedsLength,
InvalidDictionaryItemKey,
MissingSystemContractHash,
ExceededRecursionDepth,
NonRepresentableSerialization,
AuctionError(u8),
ContractHeader(u8),
Mint(u8),
HandlePayment(u8),
User(u16),
MessageTopicAlreadyRegistered,
MaxTopicsNumberExceeded,
MaxTopicNameSizeExceeded,
MessageTopicNotRegistered,
MessageTopicFull,
MessageTooLarge,
MaxMessagesPerBlockExceeded,
NotAllowedToAddContractVersion,
InvalidDelegationAmountLimits,
InvalidCallerInfoRequest,
}
impl From<bytesrepr::Error> for ApiError {
fn from(error: bytesrepr::Error) -> Self {
match error {
bytesrepr::Error::EarlyEndOfStream => ApiError::EarlyEndOfStream,
bytesrepr::Error::Formatting => ApiError::Formatting,
bytesrepr::Error::LeftOverBytes => ApiError::LeftOverBytes,
bytesrepr::Error::OutOfMemory => ApiError::OutOfMemory,
bytesrepr::Error::NotRepresentable => ApiError::NonRepresentableSerialization,
bytesrepr::Error::ExceededRecursionDepth => ApiError::ExceededRecursionDepth,
}
}
}
impl From<AddKeyFailure> for ApiError {
fn from(error: AddKeyFailure) -> Self {
match error {
AddKeyFailure::MaxKeysLimit => ApiError::MaxKeysLimit,
AddKeyFailure::DuplicateKey => ApiError::DuplicateKey,
AddKeyFailure::PermissionDenied => ApiError::PermissionDenied,
}
}
}
impl From<UpdateKeyFailure> for ApiError {
fn from(error: UpdateKeyFailure) -> Self {
match error {
UpdateKeyFailure::MissingKey => ApiError::MissingKey,
UpdateKeyFailure::PermissionDenied => ApiError::PermissionDenied,
UpdateKeyFailure::ThresholdViolation => ApiError::ThresholdViolation,
}
}
}
impl From<RemoveKeyFailure> for ApiError {
fn from(error: RemoveKeyFailure) -> Self {
match error {
RemoveKeyFailure::MissingKey => ApiError::MissingKey,
RemoveKeyFailure::PermissionDenied => ApiError::PermissionDenied,
RemoveKeyFailure::ThresholdViolation => ApiError::ThresholdViolation,
}
}
}
impl From<SetThresholdFailure> for ApiError {
fn from(error: SetThresholdFailure) -> Self {
match error {
SetThresholdFailure::KeyManagementThreshold => ApiError::KeyManagementThreshold,
SetThresholdFailure::DeploymentThreshold => ApiError::DeploymentThreshold,
SetThresholdFailure::PermissionDeniedError => ApiError::PermissionDenied,
SetThresholdFailure::InsufficientTotalWeight => ApiError::InsufficientTotalWeight,
}
}
}
impl From<CLValueError> for ApiError {
fn from(error: CLValueError) -> Self {
match error {
CLValueError::Serialization(bytesrepr_error) => bytesrepr_error.into(),
CLValueError::Type(_) => ApiError::CLTypeMismatch,
}
}
}
impl From<addressable_entity::Error> for ApiError {
fn from(error: addressable_entity::Error) -> Self {
ApiError::ContractHeader(error as u8)
}
}
impl From<contracts::Error> for ApiError {
fn from(error: contracts::Error) -> Self {
ApiError::ContractHeader(error as u8)
}
}
impl From<auction::Error> for ApiError {
fn from(error: auction::Error) -> Self {
ApiError::AuctionError(error as u8)
}
}
#[doc(hidden)]
impl From<TryFromIntError> for ApiError {
fn from(_error: TryFromIntError) -> Self {
ApiError::Unhandled
}
}
impl From<TryFromSliceForAccountHashError> for ApiError {
fn from(_error: TryFromSliceForAccountHashError) -> Self {
ApiError::Deserialize
}
}
impl From<mint::Error> for ApiError {
fn from(error: mint::Error) -> Self {
ApiError::Mint(error as u8)
}
}
impl From<handle_payment::Error> for ApiError {
fn from(error: handle_payment::Error) -> Self {
ApiError::HandlePayment(error as u8)
}
}
impl From<MessageTopicError> for ApiError {
fn from(error: MessageTopicError) -> Self {
match error {
MessageTopicError::DuplicateTopic => ApiError::MessageTopicAlreadyRegistered,
MessageTopicError::MaxTopicsExceeded => ApiError::MaxTopicsNumberExceeded,
MessageTopicError::TopicNameSizeExceeded => ApiError::MaxTopicNameSizeExceeded,
}
}
}
impl From<ApiError> for u32 {
fn from(error: ApiError) -> Self {
match error {
ApiError::None => 1,
ApiError::MissingArgument => 2,
ApiError::InvalidArgument => 3,
ApiError::Deserialize => 4,
ApiError::Read => 5,
ApiError::ValueNotFound => 6,
ApiError::ContractNotFound => 7,
ApiError::GetKey => 8,
ApiError::UnexpectedKeyVariant => 9,
ApiError::UnexpectedContractRefVariant => 10,
ApiError::InvalidPurseName => 11,
ApiError::InvalidPurse => 12,
ApiError::UpgradeContractAtURef => 13,
ApiError::Transfer => 14,
ApiError::NoAccessRights => 15,
ApiError::CLTypeMismatch => 16,
ApiError::EarlyEndOfStream => 17,
ApiError::Formatting => 18,
ApiError::LeftOverBytes => 19,
ApiError::OutOfMemory => 20,
ApiError::MaxKeysLimit => 21,
ApiError::DuplicateKey => 22,
ApiError::PermissionDenied => 23,
ApiError::MissingKey => 24,
ApiError::ThresholdViolation => 25,
ApiError::KeyManagementThreshold => 26,
ApiError::DeploymentThreshold => 27,
ApiError::InsufficientTotalWeight => 28,
ApiError::InvalidSystemContract => 29,
ApiError::PurseNotCreated => 30,
ApiError::Unhandled => 31,
ApiError::BufferTooSmall => 32,
ApiError::HostBufferEmpty => 33,
ApiError::HostBufferFull => 34,
ApiError::AllocLayout => 35,
ApiError::DictionaryItemKeyExceedsLength => 36,
ApiError::InvalidDictionaryItemKey => 37,
ApiError::MissingSystemContractHash => 38,
ApiError::ExceededRecursionDepth => 39,
ApiError::NonRepresentableSerialization => 40,
ApiError::MessageTopicAlreadyRegistered => 41,
ApiError::MaxTopicsNumberExceeded => 42,
ApiError::MaxTopicNameSizeExceeded => 43,
ApiError::MessageTopicNotRegistered => 44,
ApiError::MessageTopicFull => 45,
ApiError::MessageTooLarge => 46,
ApiError::MaxMessagesPerBlockExceeded => 47,
ApiError::NotAllowedToAddContractVersion => 48,
ApiError::InvalidDelegationAmountLimits => 49,
ApiError::InvalidCallerInfoRequest => 50,
ApiError::AuctionError(value) => AUCTION_ERROR_OFFSET + u32::from(value),
ApiError::ContractHeader(value) => HEADER_ERROR_OFFSET + u32::from(value),
ApiError::Mint(value) => MINT_ERROR_OFFSET + u32::from(value),
ApiError::HandlePayment(value) => POS_ERROR_OFFSET + u32::from(value),
ApiError::User(value) => RESERVED_ERROR_MAX + 1 + u32::from(value),
}
}
}
impl From<u32> for ApiError {
fn from(value: u32) -> ApiError {
match value {
1 => ApiError::None,
2 => ApiError::MissingArgument,
3 => ApiError::InvalidArgument,
4 => ApiError::Deserialize,
5 => ApiError::Read,
6 => ApiError::ValueNotFound,
7 => ApiError::ContractNotFound,
8 => ApiError::GetKey,
9 => ApiError::UnexpectedKeyVariant,
10 => ApiError::UnexpectedContractRefVariant,
11 => ApiError::InvalidPurseName,
12 => ApiError::InvalidPurse,
13 => ApiError::UpgradeContractAtURef,
14 => ApiError::Transfer,
15 => ApiError::NoAccessRights,
16 => ApiError::CLTypeMismatch,
17 => ApiError::EarlyEndOfStream,
18 => ApiError::Formatting,
19 => ApiError::LeftOverBytes,
20 => ApiError::OutOfMemory,
21 => ApiError::MaxKeysLimit,
22 => ApiError::DuplicateKey,
23 => ApiError::PermissionDenied,
24 => ApiError::MissingKey,
25 => ApiError::ThresholdViolation,
26 => ApiError::KeyManagementThreshold,
27 => ApiError::DeploymentThreshold,
28 => ApiError::InsufficientTotalWeight,
29 => ApiError::InvalidSystemContract,
30 => ApiError::PurseNotCreated,
31 => ApiError::Unhandled,
32 => ApiError::BufferTooSmall,
33 => ApiError::HostBufferEmpty,
34 => ApiError::HostBufferFull,
35 => ApiError::AllocLayout,
36 => ApiError::DictionaryItemKeyExceedsLength,
37 => ApiError::InvalidDictionaryItemKey,
38 => ApiError::MissingSystemContractHash,
39 => ApiError::ExceededRecursionDepth,
40 => ApiError::NonRepresentableSerialization,
41 => ApiError::MessageTopicAlreadyRegistered,
42 => ApiError::MaxTopicsNumberExceeded,
43 => ApiError::MaxTopicNameSizeExceeded,
44 => ApiError::MessageTopicNotRegistered,
45 => ApiError::MessageTopicFull,
46 => ApiError::MessageTooLarge,
47 => ApiError::MaxMessagesPerBlockExceeded,
48 => ApiError::NotAllowedToAddContractVersion,
49 => ApiError::InvalidDelegationAmountLimits,
50 => ApiError::InvalidCallerInfoRequest,
USER_ERROR_MIN..=USER_ERROR_MAX => ApiError::User(value as u16),
HP_ERROR_MIN..=HP_ERROR_MAX => ApiError::HandlePayment(value as u8),
MINT_ERROR_MIN..=MINT_ERROR_MAX => ApiError::Mint(value as u8),
HEADER_ERROR_MIN..=HEADER_ERROR_MAX => ApiError::ContractHeader(value as u8),
AUCTION_ERROR_MIN..=AUCTION_ERROR_MAX => ApiError::AuctionError(value as u8),
_ => ApiError::Unhandled,
}
}
}
impl Debug for ApiError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
ApiError::None => write!(f, "ApiError::None")?,
ApiError::MissingArgument => write!(f, "ApiError::MissingArgument")?,
ApiError::InvalidArgument => write!(f, "ApiError::InvalidArgument")?,
ApiError::Deserialize => write!(f, "ApiError::Deserialize")?,
ApiError::Read => write!(f, "ApiError::Read")?,
ApiError::ValueNotFound => write!(f, "ApiError::ValueNotFound")?,
ApiError::ContractNotFound => write!(f, "ApiError::ContractNotFound")?,
ApiError::GetKey => write!(f, "ApiError::GetKey")?,
ApiError::UnexpectedKeyVariant => write!(f, "ApiError::UnexpectedKeyVariant")?,
ApiError::UnexpectedContractRefVariant => {
write!(f, "ApiError::UnexpectedContractRefVariant")?
}
ApiError::InvalidPurseName => write!(f, "ApiError::InvalidPurseName")?,
ApiError::InvalidPurse => write!(f, "ApiError::InvalidPurse")?,
ApiError::UpgradeContractAtURef => write!(f, "ApiError::UpgradeContractAtURef")?,
ApiError::Transfer => write!(f, "ApiError::Transfer")?,
ApiError::NoAccessRights => write!(f, "ApiError::NoAccessRights")?,
ApiError::CLTypeMismatch => write!(f, "ApiError::CLTypeMismatch")?,
ApiError::EarlyEndOfStream => write!(f, "ApiError::EarlyEndOfStream")?,
ApiError::Formatting => write!(f, "ApiError::Formatting")?,
ApiError::LeftOverBytes => write!(f, "ApiError::LeftOverBytes")?,
ApiError::OutOfMemory => write!(f, "ApiError::OutOfMemory")?,
ApiError::MaxKeysLimit => write!(f, "ApiError::MaxKeysLimit")?,
ApiError::DuplicateKey => write!(f, "ApiError::DuplicateKey")?,
ApiError::PermissionDenied => write!(f, "ApiError::PermissionDenied")?,
ApiError::MissingKey => write!(f, "ApiError::MissingKey")?,
ApiError::ThresholdViolation => write!(f, "ApiError::ThresholdViolation")?,
ApiError::KeyManagementThreshold => write!(f, "ApiError::KeyManagementThreshold")?,
ApiError::DeploymentThreshold => write!(f, "ApiError::DeploymentThreshold")?,
ApiError::InsufficientTotalWeight => write!(f, "ApiError::InsufficientTotalWeight")?,
ApiError::InvalidSystemContract => write!(f, "ApiError::InvalidSystemContract")?,
ApiError::PurseNotCreated => write!(f, "ApiError::PurseNotCreated")?,
ApiError::Unhandled => write!(f, "ApiError::Unhandled")?,
ApiError::BufferTooSmall => write!(f, "ApiError::BufferTooSmall")?,
ApiError::HostBufferEmpty => write!(f, "ApiError::HostBufferEmpty")?,
ApiError::HostBufferFull => write!(f, "ApiError::HostBufferFull")?,
ApiError::AllocLayout => write!(f, "ApiError::AllocLayout")?,
ApiError::DictionaryItemKeyExceedsLength => {
write!(f, "ApiError::DictionaryItemKeyTooLarge")?
}
ApiError::InvalidDictionaryItemKey => write!(f, "ApiError::InvalidDictionaryItemKey")?,
ApiError::MissingSystemContractHash => write!(f, "ApiError::MissingContractHash")?,
ApiError::NonRepresentableSerialization => {
write!(f, "ApiError::NonRepresentableSerialization")?
}
ApiError::MessageTopicAlreadyRegistered => {
write!(f, "ApiError::MessageTopicAlreadyRegistered")?
}
ApiError::MaxTopicsNumberExceeded => write!(f, "ApiError::MaxTopicsNumberExceeded")?,
ApiError::MaxTopicNameSizeExceeded => write!(f, "ApiError::MaxTopicNameSizeExceeded")?,
ApiError::MessageTopicNotRegistered => {
write!(f, "ApiError::MessageTopicNotRegistered")?
}
ApiError::MessageTopicFull => write!(f, "ApiError::MessageTopicFull")?,
ApiError::MessageTooLarge => write!(f, "ApiError::MessageTooLarge")?,
ApiError::MaxMessagesPerBlockExceeded => {
write!(f, "ApiError::MaxMessagesPerBlockExceeded")?
}
ApiError::NotAllowedToAddContractVersion => {
write!(f, "ApiError::NotAllowedToAddContractVersion")?
}
ApiError::InvalidDelegationAmountLimits => {
write!(f, "ApiError::InvalidDelegationAmountLimits")?
}
ApiError::InvalidCallerInfoRequest => write!(f, "ApiError::InvalidCallerInfoRequest")?,
ApiError::ExceededRecursionDepth => write!(f, "ApiError::ExceededRecursionDepth")?,
ApiError::AuctionError(value) => write!(
f,
"ApiError::AuctionError({:?})",
auction::Error::try_from(*value).map_err(|_err| fmt::Error)?
)?,
ApiError::ContractHeader(value) => write!(
f,
"ApiError::ContractHeader({:?})",
addressable_entity::Error::try_from(*value).map_err(|_err| fmt::Error)?
)?,
ApiError::Mint(value) => write!(
f,
"ApiError::Mint({:?})",
mint::Error::try_from(*value).map_err(|_err| fmt::Error)?
)?,
ApiError::HandlePayment(value) => write!(
f,
"ApiError::HandlePayment({:?})",
handle_payment::Error::try_from(*value).map_err(|_err| fmt::Error)?
)?,
ApiError::User(value) => write!(f, "ApiError::User({})", value)?,
}
write!(f, " [{}]", u32::from(*self))
}
}
impl fmt::Display for ApiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ApiError::User(value) => write!(f, "User error: {}", value),
ApiError::ContractHeader(value) => write!(f, "Contract header error: {}", value),
ApiError::Mint(value) => write!(f, "Mint error: {}", value),
ApiError::HandlePayment(value) => write!(f, "Handle Payment error: {}", value),
_ => <Self as Debug>::fmt(self, f),
}
}
}
#[doc(hidden)]
pub fn i32_from<T>(result: Result<(), T>) -> i32
where
ApiError: From<T>,
{
match result {
Ok(()) => 0,
Err(error) => {
let api_error = ApiError::from(error);
u32::from(api_error) as i32
}
}
}
pub fn result_from(value: i32) -> Result<(), ApiError> {
match value {
0 => Ok(()),
_ => Err(ApiError::from(value as u32)),
}
}
#[cfg(test)]
mod tests {
use super::*;
fn round_trip(result: Result<(), ApiError>) {
let code = i32_from(result);
assert_eq!(result, result_from(code));
}
#[test]
fn error_values() {
assert_eq!(65_024_u32, u32::from(ApiError::Mint(0))); assert_eq!(65_279_u32, u32::from(ApiError::Mint(u8::MAX)));
assert_eq!(65_280_u32, u32::from(ApiError::HandlePayment(0))); assert_eq!(65_535_u32, u32::from(ApiError::HandlePayment(u8::MAX)));
assert_eq!(65_536_u32, u32::from(ApiError::User(0))); assert_eq!(131_071_u32, u32::from(ApiError::User(u16::MAX))); }
#[test]
fn error_descriptions_getkey() {
assert_eq!("ApiError::GetKey [8]", &format!("{:?}", ApiError::GetKey));
assert_eq!("ApiError::GetKey [8]", &format!("{}", ApiError::GetKey));
}
#[test]
fn error_descriptions_contract_header() {
assert_eq!(
"ApiError::ContractHeader(PreviouslyUsedVersion) [64769]",
&format!(
"{:?}",
ApiError::ContractHeader(addressable_entity::Error::PreviouslyUsedVersion as u8)
)
);
assert_eq!(
"Contract header error: 0",
&format!("{}", ApiError::ContractHeader(0))
);
assert_eq!(
"Contract header error: 255",
&format!("{}", ApiError::ContractHeader(u8::MAX))
);
}
#[test]
fn error_descriptions_mint() {
assert_eq!(
"ApiError::Mint(InsufficientFunds) [65024]",
&format!("{:?}", ApiError::Mint(0))
);
assert_eq!("Mint error: 0", &format!("{}", ApiError::Mint(0)));
assert_eq!("Mint error: 255", &format!("{}", ApiError::Mint(u8::MAX)));
}
#[test]
fn error_descriptions_handle_payment() {
assert_eq!(
"ApiError::HandlePayment(NotBonded) [65280]",
&format!(
"{:?}",
ApiError::HandlePayment(handle_payment::Error::NotBonded as u8)
)
);
}
#[test]
fn error_descriptions_handle_payment_display() {
assert_eq!(
"Handle Payment error: 0",
&format!(
"{}",
ApiError::HandlePayment(handle_payment::Error::NotBonded as u8)
)
);
}
#[test]
fn error_descriptions_user_errors() {
assert_eq!(
"ApiError::User(0) [65536]",
&format!("{:?}", ApiError::User(0))
);
assert_eq!("User error: 0", &format!("{}", ApiError::User(0)));
assert_eq!(
"ApiError::User(65535) [131071]",
&format!("{:?}", ApiError::User(u16::MAX))
);
assert_eq!(
"User error: 65535",
&format!("{}", ApiError::User(u16::MAX))
);
}
#[test]
fn error_edge_cases() {
assert_eq!(Err(ApiError::Unhandled), result_from(i32::MAX));
assert_eq!(
Err(ApiError::ContractHeader(255)),
result_from(MINT_ERROR_OFFSET as i32 - 1)
);
assert_eq!(Err(ApiError::Unhandled), result_from(-1));
assert_eq!(Err(ApiError::Unhandled), result_from(i32::MIN));
}
#[test]
fn error_round_trips() {
round_trip(Ok(()));
round_trip(Err(ApiError::None));
round_trip(Err(ApiError::MissingArgument));
round_trip(Err(ApiError::InvalidArgument));
round_trip(Err(ApiError::Deserialize));
round_trip(Err(ApiError::Read));
round_trip(Err(ApiError::ValueNotFound));
round_trip(Err(ApiError::ContractNotFound));
round_trip(Err(ApiError::GetKey));
round_trip(Err(ApiError::UnexpectedKeyVariant));
round_trip(Err(ApiError::UnexpectedContractRefVariant));
round_trip(Err(ApiError::InvalidPurseName));
round_trip(Err(ApiError::InvalidPurse));
round_trip(Err(ApiError::UpgradeContractAtURef));
round_trip(Err(ApiError::Transfer));
round_trip(Err(ApiError::NoAccessRights));
round_trip(Err(ApiError::CLTypeMismatch));
round_trip(Err(ApiError::EarlyEndOfStream));
round_trip(Err(ApiError::Formatting));
round_trip(Err(ApiError::LeftOverBytes));
round_trip(Err(ApiError::OutOfMemory));
round_trip(Err(ApiError::MaxKeysLimit));
round_trip(Err(ApiError::DuplicateKey));
round_trip(Err(ApiError::PermissionDenied));
round_trip(Err(ApiError::MissingKey));
round_trip(Err(ApiError::ThresholdViolation));
round_trip(Err(ApiError::KeyManagementThreshold));
round_trip(Err(ApiError::DeploymentThreshold));
round_trip(Err(ApiError::InsufficientTotalWeight));
round_trip(Err(ApiError::InvalidSystemContract));
round_trip(Err(ApiError::PurseNotCreated));
round_trip(Err(ApiError::Unhandled));
round_trip(Err(ApiError::BufferTooSmall));
round_trip(Err(ApiError::HostBufferEmpty));
round_trip(Err(ApiError::HostBufferFull));
round_trip(Err(ApiError::AllocLayout));
round_trip(Err(ApiError::NonRepresentableSerialization));
round_trip(Err(ApiError::ContractHeader(0)));
round_trip(Err(ApiError::ContractHeader(u8::MAX)));
round_trip(Err(ApiError::Mint(0)));
round_trip(Err(ApiError::Mint(u8::MAX)));
round_trip(Err(ApiError::HandlePayment(0)));
round_trip(Err(ApiError::HandlePayment(u8::MAX)));
round_trip(Err(ApiError::User(0)));
round_trip(Err(ApiError::User(u16::MAX)));
round_trip(Err(ApiError::AuctionError(0)));
round_trip(Err(ApiError::AuctionError(u8::MAX)));
round_trip(Err(ApiError::MessageTopicAlreadyRegistered));
round_trip(Err(ApiError::MaxTopicsNumberExceeded));
round_trip(Err(ApiError::MaxTopicNameSizeExceeded));
round_trip(Err(ApiError::MessageTopicNotRegistered));
round_trip(Err(ApiError::MessageTopicFull));
round_trip(Err(ApiError::MessageTooLarge));
round_trip(Err(ApiError::NotAllowedToAddContractVersion));
round_trip(Err(ApiError::InvalidDelegationAmountLimits));
}
}