ink_e2e/
error.rs

1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::fmt;
16
17/// An error occurred while interacting with the E2E backend.
18///
19/// We only convey errors here that are caused by the contract's testing logic. For
20/// anything concerning the execution environment (like inability to communicate with node
21/// or runtime, fetch the nonce, account info, etc.) we panic.
22#[derive(Debug, thiserror::Error)]
23pub enum Error<DispatchError: fmt::Debug + fmt::Display> {
24    /// No contract with the given name found in scope.
25    #[error("Contract not found: {0}")]
26    ContractNotFound(String),
27    /// The `instantiate_with_code` dry run failed.
28    #[error("Instantiate dry-run error: {0}")]
29    InstantiateDryRun(DryRunError<DispatchError>),
30    #[error("Instantiate extrinsic error: {0}")]
31    InstantiateExtrinsic(DispatchError),
32    /// The `upload` dry run failed.
33    #[error("Upload dry-run error: {0}")]
34    UploadDryRun(DispatchError),
35    /// The `upload` extrinsic failed.
36    #[error("Upload extrinsic error: {0}")]
37    UploadExtrinsic(DispatchError),
38    /// The `call` dry run failed.
39    #[error("Call dry-run error: {0}")]
40    CallDryRun(DryRunError<DispatchError>),
41    /// The `call` extrinsic failed.
42    /// The `call` extrinsic failed.
43    #[error("Call extrinsic error: {0}")]
44    CallExtrinsic(DispatchError),
45    /// The `remove_code` extrinsic failed.
46    #[error("Remove code extrinsic error: {0}")]
47    RemoveCodeExtrinsic(DispatchError),
48    /// Error fetching account balance.
49    #[error("Fetching account Balance error: {0}")]
50    Balance(String),
51    /// Decoding failed.
52    #[error("Decoding failed: {0}")]
53    Decoding(String),
54}
55
56/// Error during a dry run RPC invocation.
57#[derive(Debug)]
58pub struct DryRunError<DispatchError: fmt::Display + fmt::Debug> {
59    pub error: DispatchError,
60}
61
62impl<DispatchError> fmt::Display for DryRunError<DispatchError>
63where
64    DispatchError: fmt::Display + fmt::Debug,
65{
66    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67        <Self as fmt::Debug>::fmt(self, f)
68    }
69}
70
71/// Dummy error type for sandbox_client
72#[derive(Debug, thiserror::Error)]
73pub struct SandboxErr {
74    msg: String,
75}
76
77impl SandboxErr {
78    /// Create a new `SandboxErr` with the given message.
79    #[allow(dead_code)]
80    pub fn new(msg: String) -> Self {
81        Self { msg }
82    }
83}
84
85impl From<String> for SandboxErr {
86    fn from(msg: String) -> Self {
87        Self { msg }
88    }
89}
90
91impl fmt::Display for SandboxErr {
92    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93        write!(f, "SandboxErr: {}", self.msg)
94    }
95}