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    #[error("Call extrinsic error: {0}")]
43    CallExtrinsic(DispatchError),
44    /// The `remove_code` extrinsic failed.
45    #[error("Remove code extrinsic error: {0}")]
46    RemoveCodeExtrinsic(DispatchError),
47    /// Error fetching account balance.
48    #[error("Fetching account Balance error: {0}")]
49    Balance(String),
50    /// Decoding failed.
51    #[error("Decoding failed: {0}")]
52    Decoding(String),
53    /// Other error.
54    #[error("Other error: {0}")]
55    Other(String),
56}
57
58/// Error during a dry run RPC invocation.
59#[derive(Debug)]
60pub struct DryRunError<DispatchError: fmt::Display + fmt::Debug> {
61    pub error: DispatchError,
62}
63
64impl<DispatchError> fmt::Display for DryRunError<DispatchError>
65where
66    DispatchError: fmt::Display + fmt::Debug,
67{
68    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69        <Self as fmt::Debug>::fmt(self, f)
70    }
71}
72
73/// Dummy error type for sandbox_client
74#[derive(Debug, thiserror::Error)]
75pub struct SandboxErr {
76    msg: String,
77}
78
79impl SandboxErr {
80    /// Create a new `SandboxErr` with the given message.
81    #[allow(dead_code)]
82    pub fn new(msg: String) -> Self {
83        Self { msg }
84    }
85}
86
87impl From<String> for SandboxErr {
88    fn from(msg: String) -> Self {
89        Self { msg }
90    }
91}
92
93impl fmt::Display for SandboxErr {
94    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95        write!(f, "SandboxErr: {}", self.msg)
96    }
97}