Skip to main content

wasm_dbms_api/dbms/
transaction.rs

1use serde::{Deserialize, Serialize};
2
3/// Type alias for Transaction ID
4pub type TransactionId = u64;
5
6/// An enum representing possible errors that can occur during transaction operations.
7#[derive(Debug, thiserror::Error, Serialize, Deserialize)]
8#[cfg_attr(feature = "candid", derive(candid::CandidType))]
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    #[cfg(feature = "candid")]
26    #[test]
27    fn test_should_candid_encode_decode_transaction_error() {
28        let error = TransactionError::NoActiveTransaction;
29        let encoded = candid::encode_one(&error).expect("failed to encode");
30        let decoded: TransactionError = candid::decode_one(&encoded).expect("failed to decode");
31        assert!(matches!(decoded, TransactionError::NoActiveTransaction));
32    }
33}