• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / catalyst-libs / 16646523141

31 Jul 2025 10:28AM UTC coverage: 67.341% (+3.8%) from 63.544%
16646523141

push

github

web-flow
feat(rust/signed-doc): Implement new Catalyst Signed Doc (#338)

* chore: add new line to open pr

Signed-off-by: bkioshn <bkioshn@gmail.com>

* chore: revert

Signed-off-by: bkioshn <bkioshn@gmail.com>

* feat(rust/signed-doc): add new type `DocType` (#339)

* feat(signed-doc): add new type DocType

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): add conversion policy

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): doc type

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): doc type error

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): seperate test

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): format

Signed-off-by: bkioshn <bkioshn@gmail.com>

---------

Signed-off-by: bkioshn <bkioshn@gmail.com>

* feat(rust/signed-doc): Add initial decoding tests for the Catalyst Signed Documents (#349)

* wip

* wip

* fix fmt

* fix spelling

* fix clippy

* fix(rust/signed-doc): Apply new `DocType` (#347)

* feat(signed-doc): add new type DocType

Signed-off-by: bkioshn <bkioshn@gmail.com>

* wip: apply doctype

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): add more function to DocType

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): map old doctype to new doctype

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): add eq to uuidv4

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): fix validator

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): minor fixes

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(catalyst-types): add hash to uuidv4

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): decoding test

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): doctype

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): minor fixes

Signed-off-by: bkioshn <bkioshn@gmail.com>

* chore(sign-doc): fix comment

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(catalyst-types): add froms... (continued)

2453 of 2675 new or added lines in 38 files covered. (91.7%)

19 existing lines in 7 files now uncovered.

11312 of 16798 relevant lines covered (67.34%)

2525.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.64
/rust/signed_doc/src/metadata/doc_type.rs
1
//! Document Type.
2

3
use std::{
4
    fmt::{Display, Formatter},
5
    hash::Hash,
6
    ops::Deref,
7
    str::FromStr,
8
};
9

10
use catalyst_types::uuid::{CborContext, Uuid, UuidV4};
11
use minicbor::{Decode, Decoder, Encode};
12

13
/// Document type - `UUIDv4`.
14
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
15
pub struct DocType(UuidV4);
16

17
impl Deref for DocType {
18
    type Target = UuidV4;
19

NEW
20
    fn deref(&self) -> &Self::Target {
×
NEW
21
        &self.0
×
NEW
22
    }
×
23
}
24

25
impl DocType {
26
    /// A const alternative impl of `TryFrom<Uuid>`
27
    ///
28
    /// # Errors
29
    ///  - `catalyst_types::uuid::InvalidUuidV4`
NEW
30
    pub const fn try_from_uuid(uuid: Uuid) -> Result<Self, catalyst_types::uuid::InvalidUuidV4> {
×
NEW
31
        match UuidV4::try_from_uuid(uuid) {
×
NEW
32
            Ok(v) => Ok(Self(v)),
×
NEW
33
            Err(err) => Err(err),
×
34
        }
NEW
35
    }
×
36
}
37

38
impl From<UuidV4> for DocType {
39
    fn from(value: UuidV4) -> Self {
32✔
40
        DocType(value)
32✔
41
    }
32✔
42
}
43

44
impl TryFrom<Uuid> for DocType {
45
    type Error = catalyst_types::uuid::InvalidUuidV4;
46

NEW
47
    fn try_from(value: Uuid) -> Result<Self, Self::Error> {
×
NEW
48
        UuidV4::try_from(value).map(Into::into)
×
NEW
49
    }
×
50
}
51

52
impl FromStr for DocType {
53
    type Err = catalyst_types::uuid::UuidV4ParsingError;
54

NEW
55
    fn from_str(s: &str) -> Result<Self, Self::Err> {
×
NEW
56
        s.parse::<UuidV4>().map(Self)
×
NEW
57
    }
×
58
}
59

60
impl TryFrom<String> for DocType {
61
    type Error = catalyst_types::uuid::UuidV4ParsingError;
62

NEW
63
    fn try_from(s: String) -> Result<Self, Self::Error> {
×
NEW
64
        s.parse()
×
NEW
65
    }
×
66
}
67

68
impl Display for DocType {
69
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
8✔
70
        write!(f, "{}", self.0)
8✔
71
    }
8✔
72
}
73

74
impl Decode<'_, ()> for DocType {
75
    fn decode(d: &mut Decoder, _ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
126✔
76
        UuidV4::decode(d, &mut CborContext::Tagged)
126✔
77
            .map_err(|e| {
126✔
78
                minicbor::decode::Error::message(format!(
4✔
79
                    "DocType decoding Cannot decode single UUIDv4: {e}"
4✔
80
                ))
81
            })
4✔
82
            .map(Self)
126✔
83
    }
126✔
84
}
85

86
impl<C> Encode<C> for DocType {
87
    fn encode<W: minicbor::encode::Write>(
124✔
88
        &self, e: &mut minicbor::Encoder<W>, _ctx: &mut C,
124✔
89
    ) -> Result<(), minicbor::encode::Error<W::Error>> {
124✔
90
        self.0.encode(e, &mut CborContext::Tagged)
124✔
91
    }
124✔
92
}
93

94
#[cfg(test)]
95
mod tests {
96
    use catalyst_types::uuid::UuidV7;
97
    use minicbor::Encoder;
98
    use test_case::test_case;
99

100
    use super::*;
101

102
    #[test_case(
103
        {
104
            Encoder::new(Vec::new())
105
        } ;
106
        "Invalid empty CBOR bytes"
107
    )]
108
    #[test_case(
109
        {
110
            let mut e = Encoder::new(Vec::new());
111
            e.encode_with(UuidV4::new(), &mut CborContext::Untagged).unwrap();
112
            e
113
        } ;
114
        "Invalid untagged uuid v4"
115
    )]
116
    #[test_case(
117
        {
118
            let mut e = Encoder::new(Vec::new());
119
            e.encode_with(UuidV7::new(), &mut CborContext::Tagged).unwrap();
120
            e
121
        } ;
122
        "Invalid tagged uuid v7"
123
    )]
124
    fn test_invalid_cbor_decode(e: Encoder<Vec<u8>>) {
3✔
125
        assert!(DocType::decode(&mut Decoder::new(e.into_writer().as_slice()), &mut ()).is_err());
3✔
126
    }
3✔
127

128
    #[test_case(
129
        |uuid: UuidV4| {
1✔
130
            let mut e = Encoder::new(Vec::new());
1✔
131
            e.encode_with(uuid, &mut CborContext::Tagged).unwrap();
1✔
132
            e
1✔
133
        } ;
1✔
134
        "Valid uuid v4"
135
    )]
136
    fn test_valid_cbor_decode(e_gen: impl FnOnce(UuidV4) -> Encoder<Vec<u8>>) {
1✔
137
        let uuid = UuidV4::new();
1✔
138
        let e = e_gen(uuid);
1✔
139

140
        let doc_type =
1✔
141
            DocType::decode(&mut Decoder::new(e.into_writer().as_slice()), &mut ()).unwrap();
1✔
142
        assert_eq!(doc_type.0, uuid);
1✔
143
    }
1✔
144

145
    #[test_case(
146
        serde_json::json!(UuidV4::new()) ;
147
        "Document type old format"
148
    )]
149
    fn test_json_valid_serde(json: serde_json::Value) {
1✔
150
        let refs: DocType = serde_json::from_value(json).unwrap();
1✔
151
        let json_from_refs = serde_json::to_value(&refs).unwrap();
1✔
152
        assert_eq!(refs, serde_json::from_value(json_from_refs).unwrap());
1✔
153
    }
1✔
154
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc