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 ink_revive_types::evm::CallTrace;
16use std::fmt;
17
18/// An error occurred while interacting with the E2E backend.
19///
20/// We only convey errors here that are caused by the contract's testing logic. For
21/// anything concerning the execution environment (like inability to communicate with node
22/// or runtime, fetch the nonce, account info, etc.) we panic.
23#[derive(Debug, thiserror::Error)]
24pub enum Error<DispatchError: fmt::Debug + fmt::Display> {
25 /// No contract with the given name found in scope.
26 #[error("Contract not found: {0}")]
27 ContractNotFound(String),
28 /// The `instantiate_with_code` dry run failed.
29 #[error("Instantiate dry-run error: {0}")]
30 InstantiateDryRun(DryRunError<DispatchError>),
31 #[error("Instantiate extrinsic error: {0} {1:?}")]
32 InstantiateExtrinsic(DispatchError, Option<CallTrace>),
33 /// The `upload` dry run failed.
34 #[error("Upload dry-run error: {0}")]
35 UploadDryRun(DispatchError),
36 /// The `upload` extrinsic failed.
37 #[error("Upload extrinsic error: {0}")]
38 UploadExtrinsic(DispatchError, Option<CallTrace>),
39 /// The `call` dry run failed.
40 #[error("Call dry-run error: {0}")]
41 CallDryRun(DryRunError<DispatchError>),
42 /// The `call` extrinsic failed.
43 #[error("Call extrinsic error: {0}")]
44 CallExtrinsic(DispatchError, Option<CallTrace>),
45 /// The `remove_code` extrinsic failed.
46 #[error("Remove code extrinsic error: {0}")]
47 RemoveCodeExtrinsic(DispatchError, Option<CallTrace>),
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 /// Other error.
55 #[error("Other error: {0}")]
56 Other(String),
57}
58
59/// Error during a dry run RPC invocation.
60#[derive(Debug)]
61pub struct DryRunError<DispatchError: fmt::Display + fmt::Debug> {
62 pub error: DispatchError,
63}
64
65impl<DispatchError> fmt::Display for DryRunError<DispatchError>
66where
67 DispatchError: fmt::Display + fmt::Debug,
68{
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 <Self as fmt::Debug>::fmt(self, f)
71 }
72}