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

input-output-hk / catalyst-libs / 15818491411

23 Jun 2025 07:53AM UTC coverage: 67.389%. First build
15818491411

Pull #368

github

web-flow
Merge a11569d76 into 8460d7899
Pull Request #368: fix(rust/signed-doc): Apply new document ref and fix validation rules

479 of 497 new or added lines in 13 files covered. (96.38%)

12593 of 18687 relevant lines covered (67.39%)

2376.18 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>(
66✔
12
    doc_ref: &DocumentRef, provider: &Provider, report: &ProblemReport, validator: Validator,
66✔
13
) -> anyhow::Result<bool>
66✔
14
where
66✔
15
    Provider: CatalystSignedDocumentProvider,
66✔
16
    Validator: Fn(CatalystSignedDocument) -> bool,
66✔
17
{
66✔
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? {
66✔
25
        let id = doc
52✔
26
            .doc_id()
52✔
27
            .inspect_err(|_| report.missing_field("id", CONTEXT))?;
52✔
28

29
        let ver = doc
52✔
30
            .doc_ver()
52✔
31
            .inspect_err(|_| report.missing_field("ver", CONTEXT))?;
52✔
32
        // id and version must match the values in ref doc
33
        if &id != doc_ref.id() && &ver != doc_ref.ver() {
52✔
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
        }
52✔
42
        Ok(validator(doc))
52✔
43
    } else {
44
        report.functional_validation(
14✔
45
            format!("Cannot retrieve a document {doc_ref}").as_str(),
14✔
46
            CONTEXT,
14✔
47
        );
14✔
48
        Ok(false)
14✔
49
    }
50
}
66✔
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>(
63✔
55
    doc_refs: &DocumentRefs, provider: &Provider, report: &ProblemReport, validator: Validator,
63✔
56
) -> anyhow::Result<bool>
63✔
57
where
63✔
58
    Provider: CatalystSignedDocumentProvider,
63✔
59
    Validator: Fn(CatalystSignedDocument) -> bool,
63✔
60
{
63✔
61
    let mut all_valid = true;
63✔
62

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