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

input-output-hk / catalyst-libs / 16215577916

11 Jul 2025 08:32AM UTC coverage: 68.803% (+3.1%) from 65.707%
16215577916

Pull #338

github

web-flow
Merge a8b219ddd into 5c081f7d2
Pull Request #338: feat(rust/signed-doc): Implement new Catalyst Signed Doc

2897 of 3112 new or added lines in 39 files covered. (93.09%)

36 existing lines in 9 files now uncovered.

12895 of 18742 relevant lines covered (68.8%)

2209.98 hits per line

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

84.44
/rust/signed_doc/src/validator/utils.rs
1
//! Validation utility functions
2

3
use catalyst_types::problem_report::ProblemReport;
4

5
use crate::{
6
    providers::CatalystSignedDocumentProvider, CatalystSignedDocument, DocumentRef, DocumentRefs,
7
};
8

9
/// A helper validation document function, which validates a document from the
10
/// `ValidationDataProvider`.
11
pub(crate) async fn validate_provided_doc<Provider, Validator>(
86✔
12
    doc_ref: &DocumentRef, provider: &Provider, report: &ProblemReport, validator: Validator,
86✔
13
) -> anyhow::Result<bool>
86✔
14
where
86✔
15
    Provider: CatalystSignedDocumentProvider,
86✔
16
    Validator: Fn(CatalystSignedDocument) -> bool,
86✔
17
{
86✔
18
    const CONTEXT: &str = "Validation data provider";
19

20
    // General check for document ref
21

22
    // Getting the Signed Document instance from a doc ref.
23
    // The reference document must exist
24
    if let Some(doc) = provider.try_get_doc(doc_ref).await? {
86✔
25
        let id = doc
78✔
26
            .doc_id()
78✔
27
            .inspect_err(|_| report.missing_field("id", CONTEXT))?;
78✔
28

29
        let ver = doc
78✔
30
            .doc_ver()
78✔
31
            .inspect_err(|_| report.missing_field("ver", CONTEXT))?;
78✔
32
        // id and version must match the values in ref doc
33
        if &id != doc_ref.id() && &ver != doc_ref.ver() {
78✔
NEW
34
            report.invalid_value(
×
NEW
35
                "id and version",
×
NEW
36
                &format!("id: {id}, ver: {ver}"),
×
NEW
37
                &format!("id: {}, ver: {}", doc_ref.id(), doc_ref.ver()),
×
NEW
38
                CONTEXT,
×
NEW
39
            );
×
NEW
40
            return Ok(false);
×
41
        }
78✔
42
        Ok(validator(doc))
78✔
43
    } else {
44
        report.functional_validation(
8✔
45
            format!("Cannot retrieve a document {doc_ref}").as_str(),
8✔
46
            CONTEXT,
8✔
47
        );
8✔
48
        Ok(false)
8✔
49
    }
50
}
86✔
51

52
/// Validate the document references
53
/// Document all possible error in doc report (no fail fast)
54
pub(crate) async fn validate_doc_refs<Provider, Validator>(
83✔
55
    doc_refs: &DocumentRefs, provider: &Provider, report: &ProblemReport, validator: Validator,
83✔
56
) -> anyhow::Result<bool>
83✔
57
where
83✔
58
    Provider: CatalystSignedDocumentProvider,
83✔
59
    Validator: Fn(CatalystSignedDocument) -> bool,
83✔
60
{
83✔
61
    let mut all_valid = true;
83✔
62

63
    for dr in doc_refs.doc_refs() {
86✔
64
        let is_valid = validate_provided_doc(dr, provider, report, &validator).await?;
86✔
65
        if !is_valid {
86✔
66
            all_valid = false;
28✔
67
        }
58✔
68
    }
69
    Ok(all_valid)
83✔
70
}
83✔
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