sui_json_rpc/
error.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::authority_state::StateReadError;
5use fastcrypto::error::FastCryptoError;
6use hyper::header::InvalidHeaderValue;
7use itertools::Itertools;
8use jsonrpsee::core::ClientError as RpcError;
9use jsonrpsee::types::error::INTERNAL_ERROR_CODE;
10use jsonrpsee::types::{ErrorObject, ErrorObjectOwned};
11use std::collections::BTreeMap;
12use sui_json_rpc_api::{TRANSACTION_EXECUTION_CLIENT_ERROR_CODE, TRANSIENT_ERROR_CODE};
13use sui_name_service::NameServiceError;
14use sui_types::committee::{QUORUM_THRESHOLD, TOTAL_VOTING_POWER};
15use sui_types::error::{
16    ErrorCategory, SuiError, SuiErrorKind, SuiObjectResponseError, UserInputError,
17};
18use sui_types::quorum_driver_types::QuorumDriverError;
19use thiserror::Error;
20use tokio::task::JoinError;
21
22pub type RpcInterimResult<T = ()> = Result<T, Error>;
23
24#[derive(Debug, Error)]
25pub enum Error {
26    #[error(transparent)]
27    SuiError(SuiError),
28
29    #[error(transparent)]
30    InternalError(#[from] anyhow::Error),
31
32    #[error("Deserialization error: {0}")]
33    BcsError(#[from] bcs::Error),
34    #[error("Unexpected error: {0}")]
35    UnexpectedError(String),
36
37    #[error(transparent)]
38    RPCServerError(#[from] jsonrpsee::core::ClientError),
39
40    #[error(transparent)]
41    RPCError(#[from] jsonrpsee::types::ErrorObjectOwned),
42
43    #[error(transparent)]
44    RegisterMethodError(#[from] jsonrpsee::server::RegisterMethodError),
45
46    #[error(transparent)]
47    InvalidHeaderValue(#[from] InvalidHeaderValue),
48
49    #[error(transparent)]
50    UserInputError(#[from] UserInputError),
51
52    #[error(transparent)]
53    EncodingError(#[from] eyre::Report),
54
55    #[error(transparent)]
56    TokioJoinError(#[from] JoinError),
57
58    #[error(transparent)]
59    QuorumDriverError(#[from] QuorumDriverError),
60
61    #[error(transparent)]
62    FastCryptoError(#[from] FastCryptoError),
63
64    #[error(transparent)]
65    SuiObjectResponseError(#[from] SuiObjectResponseError),
66
67    #[error(transparent)]
68    SuiRpcInputError(#[from] SuiRpcInputError),
69
70    // TODO(wlmyng): convert StateReadError::Internal message to generic internal error message.
71    #[error(transparent)]
72    StateReadError(#[from] StateReadError),
73
74    #[error("Unsupported Feature: {0}")]
75    UnsupportedFeature(String),
76
77    #[error("transparent")]
78    NameServiceError(#[from] NameServiceError),
79}
80
81impl From<SuiErrorKind> for Error {
82    fn from(e: SuiErrorKind) -> Self {
83        match e {
84            SuiErrorKind::UserInputError { error } => Self::UserInputError(error),
85            SuiErrorKind::SuiObjectResponseError { error } => Self::SuiObjectResponseError(error),
86            SuiErrorKind::UnsupportedFeatureError { error } => Self::UnsupportedFeature(error),
87            SuiErrorKind::IndexStoreNotAvailable => Self::UnsupportedFeature(
88                "Required indexes are not available on this node".to_string(),
89            ),
90            other => Self::SuiError(SuiError(Box::new(other))),
91        }
92    }
93}
94
95impl From<SuiError> for Error {
96    fn from(e: SuiError) -> Self {
97        e.into_inner().into()
98    }
99}
100
101fn invalid_params<E: std::fmt::Display>(e: E) -> ErrorObjectOwned {
102    ErrorObject::owned(
103        jsonrpsee::types::error::ErrorCode::InvalidParams.code(),
104        e.to_string(),
105        None::<()>,
106    )
107}
108
109fn failed<E: std::fmt::Display>(e: E) -> ErrorObjectOwned {
110    ErrorObject::owned(
111        jsonrpsee::types::error::CALL_EXECUTION_FAILED_CODE,
112        e.to_string(),
113        None::<()>,
114    )
115}
116
117impl From<Error> for ErrorObjectOwned {
118    /// `InvalidParams`/`INVALID_PARAMS_CODE` for client errors.
119    fn from(e: Error) -> ErrorObjectOwned {
120        match e {
121            Error::UserInputError(_) => invalid_params(e),
122            Error::UnsupportedFeature(_) => invalid_params(e),
123            Error::SuiObjectResponseError(err) => match err {
124                SuiObjectResponseError::NotExists { .. }
125                | SuiObjectResponseError::DynamicFieldNotFound { .. }
126                | SuiObjectResponseError::Deleted { .. }
127                | SuiObjectResponseError::DisplayError { .. } => invalid_params(err),
128                _ => failed(err),
129            },
130            Error::NameServiceError(err) => match err {
131                NameServiceError::ExceedsMaxLength { .. }
132                | NameServiceError::InvalidHyphens
133                | NameServiceError::InvalidLength { .. }
134                | NameServiceError::InvalidUnderscore
135                | NameServiceError::LabelsEmpty
136                | NameServiceError::InvalidSeparator => invalid_params(err),
137                _ => failed(err),
138            },
139            Error::SuiRpcInputError(err) => invalid_params(err),
140            Error::SuiError(sui_error) => match sui_error.as_inner() {
141                SuiErrorKind::TransactionNotFound { .. }
142                | SuiErrorKind::TransactionsNotFound { .. }
143                | SuiErrorKind::TransactionEventsNotFound { .. } => invalid_params(sui_error),
144                _ => failed(sui_error),
145            },
146            Error::StateReadError(err) => match err {
147                StateReadError::Client(_) => invalid_params(err),
148                _ => ErrorObject::owned(
149                    jsonrpsee::types::error::INTERNAL_ERROR_CODE,
150                    err.to_string(),
151                    None::<()>,
152                ),
153            },
154            Error::QuorumDriverError(err) => {
155                match err {
156                    QuorumDriverError::InvalidUserSignature(err) => ErrorObject::owned(
157                        TRANSACTION_EXECUTION_CLIENT_ERROR_CODE,
158                        format!("Invalid user signature: {err}"),
159                        None::<()>,
160                    ),
161                    QuorumDriverError::TxAlreadyFinalizedWithDifferentUserSignatures => {
162                        ErrorObject::owned(
163                            TRANSACTION_EXECUTION_CLIENT_ERROR_CODE,
164                            "The transaction is already finalized but with different user signatures",
165                            None::<()>,
166                        )
167                    }
168                    QuorumDriverError::TimeoutBeforeFinality
169                    | QuorumDriverError::TimeoutBeforeFinalityWithErrors { .. }
170                    | QuorumDriverError::FailedWithTransientErrorAfterMaximumAttempts { .. } => {
171                        ErrorObject::owned(TRANSIENT_ERROR_CODE, err.to_string(), None::<()>)
172                    }
173                    QuorumDriverError::ObjectsDoubleUsed { conflicting_txes } => {
174                        let weights: Vec<u64> =
175                            conflicting_txes.values().map(|(_, stake)| *stake).collect();
176                        let remaining: u64 = TOTAL_VOTING_POWER - weights.iter().sum::<u64>();
177
178                        // better version of above
179                        let reason = if weights.iter().all(|w| remaining + w < QUORUM_THRESHOLD) {
180                            "equivocated until the next epoch"
181                        } else {
182                            "reserved for another transaction"
183                        };
184
185                        let error_message = format!(
186                            "Failed to sign transaction by a quorum of validators because one or more of its objects is {reason}. Other transactions locking these objects:\n{}",
187                            conflicting_txes
188                                .iter()
189                                .sorted_by(|(_, (_, a)), (_, (_, b))| b.cmp(a))
190                                .map(|(digest, (o, stake))| {
191                                    let objects = o
192                                        .iter()
193                                        .map(|(_, obj_ref)| format!("    - {}", obj_ref.0))
194                                        .join("\n");
195
196                                    format!(
197                                        "- {} (stake {}.{})\n{}",
198                                        digest,
199                                        stake / 100,
200                                        stake % 100,
201                                        objects,
202                                    )
203                                })
204                                .join("\n"),
205                        );
206
207                        let new_map = conflicting_txes
208                            .into_iter()
209                            .map(|(digest, (pairs, _))| {
210                                (
211                                    digest,
212                                    pairs.into_iter().map(|(_, obj_ref)| obj_ref).collect(),
213                                )
214                            })
215                            .collect::<BTreeMap<_, Vec<_>>>();
216
217                        ErrorObject::owned(
218                            TRANSACTION_EXECUTION_CLIENT_ERROR_CODE,
219                            error_message,
220                            Some(new_map),
221                        )
222                    }
223                    QuorumDriverError::NonRecoverableTransactionError { errors } => {
224                        let new_errors: Vec<String> = errors
225                            .into_iter()
226                            // sort by total stake, descending, so users see the most prominent one first
227                            .sorted_by(|(_, a, _), (_, b, _)| b.cmp(a))
228                            .filter_map(|(err, _, _)| {
229                                match err.as_inner() {
230                                    // Special handling of UserInputError:
231                                    // ObjectNotFound and DependentPackageNotFound are considered
232                                    // retryable errors but they have different treatment
233                                    // in AuthorityAggregator.
234                                    // The optimal fix would be to examine if the total stake
235                                    // of ObjectNotFound/DependentPackageNotFound exceeds the
236                                    // quorum threshold, but it takes a Committee here.
237                                    // So, we take an easier route and consider them non-retryable
238                                    // at all. Combining this with the sorting above, clients will
239                                    // see the dominant error first.
240                                    SuiErrorKind::UserInputError { error } => {
241                                        Some(error.to_string())
242                                    }
243                                    _ => {
244                                        if err.is_retryable().0 {
245                                            None
246                                        } else {
247                                            Some(err.to_string())
248                                        }
249                                    }
250                                }
251                            })
252                            .collect();
253
254                        assert!(
255                            !new_errors.is_empty(),
256                            "NonRecoverableTransactionError should have at least one non-retryable error"
257                        );
258
259                        let mut error_list = vec![];
260
261                        for err in new_errors.iter() {
262                            error_list.push(format!("- {}", err));
263                        }
264
265                        let error_msg = format!(
266                            "Transaction validator signing failed due to issues with transaction inputs, please review the errors and try again:\n{}",
267                            error_list.join("\n")
268                        );
269
270                        ErrorObject::owned(
271                            TRANSACTION_EXECUTION_CLIENT_ERROR_CODE,
272                            error_msg,
273                            None::<()>,
274                        )
275                    }
276                    QuorumDriverError::QuorumDriverInternalError(_) => ErrorObject::owned(
277                        INTERNAL_ERROR_CODE,
278                        "Internal error occurred while executing transaction.",
279                        None::<()>,
280                    ),
281                    QuorumDriverError::SystemOverload { .. }
282                    | QuorumDriverError::SystemOverloadRetryAfter { .. } => {
283                        ErrorObject::owned(TRANSIENT_ERROR_CODE, err.to_string(), None::<()>)
284                    }
285                    QuorumDriverError::TransactionFailed { category, details } => {
286                        let code = match category {
287                            ErrorCategory::Internal => INTERNAL_ERROR_CODE,
288                            ErrorCategory::Aborted => TRANSIENT_ERROR_CODE,
289                            ErrorCategory::InvalidTransaction => {
290                                TRANSACTION_EXECUTION_CLIENT_ERROR_CODE
291                            }
292                            ErrorCategory::LockConflict => TRANSACTION_EXECUTION_CLIENT_ERROR_CODE,
293                            ErrorCategory::ValidatorOverloaded => TRANSIENT_ERROR_CODE,
294                            ErrorCategory::Unavailable => INTERNAL_ERROR_CODE,
295                        };
296                        ErrorObject::owned(code, details, None::<()>)
297                    }
298                }
299            }
300            _ => failed(e),
301        }
302    }
303}
304
305#[derive(Debug, Error)]
306pub enum SuiRpcInputError {
307    #[error("Input contains duplicates")]
308    ContainsDuplicates,
309
310    #[error("Input exceeds limit of {0}")]
311    SizeLimitExceeded(String),
312
313    #[error("{0}")]
314    GenericNotFound(String),
315
316    #[error("{0}")]
317    GenericInvalid(String),
318
319    #[error(
320        "request_type` must set to `None` or `WaitForLocalExecution` if effects is required in the response"
321    )]
322    InvalidExecuteTransactionRequestType,
323
324    #[error("Unsupported protocol version requested. Min supported: {0}, max supported: {1}")]
325    ProtocolVersionUnsupported(u64, u64),
326
327    #[error("{0}")]
328    CannotParseSuiStructTag(String),
329
330    #[error(transparent)]
331    Base64(#[from] eyre::Report),
332
333    #[error("Deserialization error: {0}")]
334    Bcs(#[from] bcs::Error),
335
336    #[error(transparent)]
337    FastCryptoError(#[from] FastCryptoError),
338
339    #[error(transparent)]
340    Anyhow(#[from] anyhow::Error),
341
342    #[error(transparent)]
343    UserInputError(#[from] UserInputError),
344}
345
346impl From<SuiRpcInputError> for RpcError {
347    fn from(e: SuiRpcInputError) -> Self {
348        RpcError::Call(invalid_params(e))
349    }
350}
351
352impl From<SuiRpcInputError> for ErrorObjectOwned {
353    fn from(e: SuiRpcInputError) -> Self {
354        invalid_params(e)
355    }
356}
357
358#[cfg(test)]
359mod tests {
360    use super::*;
361    use expect_test::expect;
362    use jsonrpsee::types::ErrorObjectOwned;
363    use sui_types::base_types::AuthorityName;
364    use sui_types::base_types::ObjectID;
365    use sui_types::base_types::ObjectRef;
366    use sui_types::base_types::SequenceNumber;
367    use sui_types::committee::StakeUnit;
368    use sui_types::crypto::AuthorityPublicKey;
369    use sui_types::crypto::AuthorityPublicKeyBytes;
370    use sui_types::digests::ObjectDigest;
371    use sui_types::digests::TransactionDigest;
372
373    fn test_object_ref(id: u8) -> ObjectRef {
374        (
375            ObjectID::from_single_byte(id),
376            SequenceNumber::from_u64(0),
377            ObjectDigest::new([id; 32]),
378        )
379    }
380
381    mod match_quorum_driver_error_tests {
382        use sui_types::error::SuiErrorKind;
383
384        use super::*;
385
386        #[test]
387        fn test_invalid_user_signature() {
388            let quorum_driver_error = QuorumDriverError::InvalidUserSignature(
389                SuiErrorKind::InvalidSignature {
390                    error: "Test inner invalid signature".to_string(),
391                }
392                .into(),
393            );
394
395            let error_object: ErrorObjectOwned =
396                Error::QuorumDriverError(quorum_driver_error).into();
397            let expected_code = expect!["-32002"];
398            expected_code.assert_eq(&error_object.code().to_string());
399            let expected_message = expect![
400                "Invalid user signature: Signature is not valid: Test inner invalid signature"
401            ];
402            expected_message.assert_eq(error_object.message());
403        }
404
405        #[test]
406        fn test_timeout_before_finality() {
407            let quorum_driver_error = QuorumDriverError::TimeoutBeforeFinality;
408
409            let error_object: ErrorObjectOwned =
410                Error::QuorumDriverError(quorum_driver_error).into();
411            let expected_code = expect!["-32050"];
412            expected_code.assert_eq(&error_object.code().to_string());
413            let expected_message = expect!["Transaction timed out before reaching finality"];
414            expected_message.assert_eq(error_object.message());
415        }
416
417        #[test]
418        fn test_failed_with_transient_error_after_maximum_attempts() {
419            let quorum_driver_error =
420                QuorumDriverError::FailedWithTransientErrorAfterMaximumAttempts {
421                    total_attempts: 10,
422                };
423
424            let error_object: ErrorObjectOwned =
425                Error::QuorumDriverError(quorum_driver_error).into();
426            let expected_code = expect!["-32050"];
427            expected_code.assert_eq(&error_object.code().to_string());
428            let expected_message = expect![
429                "Transaction failed to reach finality with transient error after 10 attempts."
430            ];
431            expected_message.assert_eq(error_object.message());
432        }
433
434        #[test]
435        fn test_objects_double_used() {
436            use sui_types::crypto::VerifyingKey;
437            let mut conflicting_txes: BTreeMap<
438                TransactionDigest,
439                (Vec<(AuthorityName, ObjectRef)>, StakeUnit),
440            > = BTreeMap::new();
441            let tx_digest = TransactionDigest::from([1; 32]);
442            let object_ref = test_object_ref(0);
443
444            // 4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi has enough stake to escape equivocation
445            let stake_unit: StakeUnit = 8000;
446            let authority_name = AuthorityPublicKeyBytes([0; AuthorityPublicKey::LENGTH]);
447            conflicting_txes.insert(tx_digest, (vec![(authority_name, object_ref)], stake_unit));
448
449            // 8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR stake below quorum threshold
450            let tx_digest = TransactionDigest::from([2; 32]);
451            let stake_unit: StakeUnit = 500;
452            let authority_name = AuthorityPublicKeyBytes([1; AuthorityPublicKey::LENGTH]);
453            conflicting_txes.insert(tx_digest, (vec![(authority_name, object_ref)], stake_unit));
454
455            let quorum_driver_error = QuorumDriverError::ObjectsDoubleUsed { conflicting_txes };
456
457            let error_object: ErrorObjectOwned =
458                Error::QuorumDriverError(quorum_driver_error).into();
459            let expected_code = expect!["-32002"];
460            expected_code.assert_eq(&error_object.code().to_string());
461            println!("error_object.message() {}", error_object.message());
462            let expected_message = expect![[r#"
463                Failed to sign transaction by a quorum of validators because one or more of its objects is reserved for another transaction. Other transactions locking these objects:
464                - 4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi (stake 80.0)
465                    - 0x0000000000000000000000000000000000000000000000000000000000000000
466                - 8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR (stake 5.0)
467                    - 0x0000000000000000000000000000000000000000000000000000000000000000"#]];
468            expected_message.assert_eq(error_object.message());
469            let expected_data = expect![[
470                r#"{"4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi":[["0x0000000000000000000000000000000000000000000000000000000000000000",0,"11111111111111111111111111111111"]],"8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR":[["0x0000000000000000000000000000000000000000000000000000000000000000",0,"11111111111111111111111111111111"]]}"#
471            ]];
472            let actual_data = error_object.data().unwrap().to_string();
473            expected_data.assert_eq(&actual_data);
474        }
475
476        #[test]
477        fn test_objects_double_used_equivocated() {
478            use sui_types::crypto::VerifyingKey;
479            let mut conflicting_txes: BTreeMap<
480                TransactionDigest,
481                (Vec<(AuthorityName, ObjectRef)>, StakeUnit),
482            > = BTreeMap::new();
483            let tx_digest = TransactionDigest::from([1; 32]);
484            let object_ref_1 = test_object_ref(0);
485            let object_ref_2 = test_object_ref(1);
486
487            // 4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi has lower stake at 10
488            let stake_unit: StakeUnit = 4000;
489            let authority_name = AuthorityPublicKeyBytes([0; AuthorityPublicKey::LENGTH]);
490            conflicting_txes.insert(
491                tx_digest,
492                (
493                    vec![
494                        (authority_name, object_ref_1),
495                        (authority_name, object_ref_2),
496                    ],
497                    stake_unit,
498                ),
499            );
500
501            // 8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR is a higher stake and should be first in the list
502            let tx_digest = TransactionDigest::from([2; 32]);
503            let stake_unit: StakeUnit = 5000;
504            let authority_name = AuthorityPublicKeyBytes([1; AuthorityPublicKey::LENGTH]);
505            conflicting_txes.insert(
506                tx_digest,
507                (
508                    vec![
509                        (authority_name, object_ref_1),
510                        (authority_name, object_ref_2),
511                    ],
512                    stake_unit,
513                ),
514            );
515
516            let quorum_driver_error = QuorumDriverError::ObjectsDoubleUsed { conflicting_txes };
517
518            let error_object: ErrorObjectOwned =
519                Error::QuorumDriverError(quorum_driver_error).into();
520            let expected_code = expect!["-32002"];
521            expected_code.assert_eq(&error_object.code().to_string());
522            let expected_message = expect![[r#"
523                Failed to sign transaction by a quorum of validators because one or more of its objects is equivocated until the next epoch. Other transactions locking these objects:
524                - 8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR (stake 50.0)
525                    - 0x0000000000000000000000000000000000000000000000000000000000000000
526                    - 0x0000000000000000000000000000000000000000000000000000000000000001
527                - 4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi (stake 40.0)
528                    - 0x0000000000000000000000000000000000000000000000000000000000000000
529                    - 0x0000000000000000000000000000000000000000000000000000000000000001"#]];
530            expected_message.assert_eq(error_object.message());
531            let expected_data = expect![[
532                r#"{"4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi":[["0x0000000000000000000000000000000000000000000000000000000000000000",0,"11111111111111111111111111111111"],["0x0000000000000000000000000000000000000000000000000000000000000001",0,"4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi"]],"8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR":[["0x0000000000000000000000000000000000000000000000000000000000000000",0,"11111111111111111111111111111111"],["0x0000000000000000000000000000000000000000000000000000000000000001",0,"4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi"]]}"#
533            ]];
534            let actual_data = error_object.data().unwrap().to_string();
535            expected_data.assert_eq(&actual_data);
536        }
537
538        #[test]
539        fn test_non_recoverable_transaction_error() {
540            let quorum_driver_error = QuorumDriverError::NonRecoverableTransactionError {
541                errors: vec![
542                    (
543                        SuiErrorKind::UserInputError {
544                            error: UserInputError::GasBalanceTooLow {
545                                gas_balance: 10,
546                                needed_gas_amount: 100,
547                            },
548                        }
549                        .into(),
550                        0,
551                        vec![],
552                    ),
553                    (
554                        SuiErrorKind::UserInputError {
555                            error: UserInputError::ObjectVersionUnavailableForConsumption {
556                                provided_obj_ref: test_object_ref(0),
557                                current_version: 10.into(),
558                            },
559                        }
560                        .into(),
561                        0,
562                        vec![],
563                    ),
564                ],
565            };
566
567            let error_object: ErrorObjectOwned =
568                Error::QuorumDriverError(quorum_driver_error).into();
569            let expected_code = expect!["-32002"];
570            expected_code.assert_eq(&error_object.code().to_string());
571            let expected_message = expect![
572                "Transaction validator signing failed due to issues with transaction inputs, please review the errors and try again:\n- Balance of gas object 10 is lower than the needed amount: 100\n- Object ID 0x0000000000000000000000000000000000000000000000000000000000000000 Version 0x0 Digest 11111111111111111111111111111111 is not available for consumption, current version: 0xa"
573            ];
574            expected_message.assert_eq(error_object.message());
575        }
576
577        #[test]
578        fn test_non_recoverable_transaction_error_with_transient_errors() {
579            let quorum_driver_error = QuorumDriverError::NonRecoverableTransactionError {
580                errors: vec![
581                    (
582                        SuiErrorKind::UserInputError {
583                            error: UserInputError::ObjectNotFound {
584                                object_id: test_object_ref(0).0,
585                                version: None,
586                            },
587                        }
588                        .into(),
589                        0,
590                        vec![],
591                    ),
592                    (
593                        SuiErrorKind::RpcError("Hello".to_string(), "Testing".to_string()).into(),
594                        0,
595                        vec![],
596                    ),
597                ],
598            };
599
600            let error_object: ErrorObjectOwned =
601                Error::QuorumDriverError(quorum_driver_error).into();
602            let expected_code = expect!["-32002"];
603            expected_code.assert_eq(&error_object.code().to_string());
604            let expected_message = expect![
605                "Transaction validator signing failed due to issues with transaction inputs, please review the errors and try again:\n- Could not find the referenced object 0x0000000000000000000000000000000000000000000000000000000000000000 at version None"
606            ];
607            expected_message.assert_eq(error_object.message());
608        }
609
610        #[test]
611        fn test_quorum_driver_internal_error() {
612            let quorum_driver_error = QuorumDriverError::QuorumDriverInternalError(
613                SuiErrorKind::UnexpectedMessage("test".to_string()).into(),
614            );
615
616            let error_object: ErrorObjectOwned =
617                Error::QuorumDriverError(quorum_driver_error).into();
618            let expected_code = expect!["-32603"];
619            expected_code.assert_eq(&error_object.code().to_string());
620            let expected_message = expect!["Internal error occurred while executing transaction."];
621            expected_message.assert_eq(error_object.message());
622        }
623
624        #[test]
625        fn test_system_overload() {
626            let quorum_driver_error = QuorumDriverError::SystemOverload {
627                overloaded_stake: 10,
628                errors: vec![(
629                    SuiErrorKind::UnexpectedMessage("test".to_string()).into(),
630                    0,
631                    vec![],
632                )],
633            };
634
635            let error_object: ErrorObjectOwned =
636                Error::QuorumDriverError(quorum_driver_error).into();
637            let expected_code = expect!["-32050"];
638            expected_code.assert_eq(&error_object.code().to_string());
639            let expected_message = expect![
640                "Transaction is not processed because 10 of validators by stake are overloaded with certificates pending execution."
641            ];
642            expected_message.assert_eq(error_object.message());
643        }
644    }
645}