Skip to main content

ic_dbms_api/dbms/
transaction.rs

1use candid::CandidType;
2use serde::{Deserialize, Serialize};
3
4/// Type alias for Transaction ID
5pub type TransactionId = candid::Nat;
6
7/// An enum representing possible errors that can occur during transaction operations.
8#[derive(Debug, thiserror::Error, CandidType, Serialize, Deserialize)]
9pub enum TransactionError {
10    #[error("No active transaction")]
11    NoActiveTransaction,
12}
13
14#[cfg(test)]
15mod test {
16
17    use super::*;
18
19    #[test]
20    fn test_should_display_transaction_error() {
21        let error = TransactionError::NoActiveTransaction;
22        assert_eq!(error.to_string(), "No active transaction");
23    }
24
25    #[test]
26    fn test_should_candid_encode_decode_transaction_error() {
27        let error = TransactionError::NoActiveTransaction;
28        let encoded = candid::encode_one(&error).expect("failed to encode");
29        let decoded: TransactionError = candid::decode_one(&encoded).expect("failed to decode");
30        assert!(matches!(decoded, TransactionError::NoActiveTransaction));
31    }
32}