diff --git a/rust/signed_doc/src/validator/rules/parameters.rs b/rust/signed_doc/src/validator/rules/parameters.rs index 80fc9447bd8..01aadfdbb5b 100644 --- a/rust/signed_doc/src/validator/rules/parameters.rs +++ b/rust/signed_doc/src/validator/rules/parameters.rs @@ -1,6 +1,5 @@ //! `parameters` rule type impl. -use super::doc_ref::referenced_doc_check; use crate::{ providers::CatalystSignedDocumentProvider, validator::utils::validate_doc_refs, CatalystSignedDocument, DocType, @@ -35,10 +34,30 @@ impl ParametersRule { { if let Some(parameters_ref) = doc.doc_meta().parameters() { let parameters_validator = |ref_doc: CatalystSignedDocument| { + let Ok(ref_doc_type) = ref_doc.doc_type() else { + doc.report().missing_field( + "type", + &format!("{context}, Referenced document must have type field"), + ); + return false; + }; + // Check that the type matches one of the expected ones - exp_parameters_type.iter().any(|exp_type| { - referenced_doc_check(&ref_doc, exp_type, "parameters", doc.report()) - }) + if exp_parameters_type + .iter() + .all(|exp_type| ref_doc_type != exp_type) + { + doc.report().invalid_value( + "parameters", + &ref_doc_type.to_string(), + &exp_parameters_type + .iter() + .fold(String::new(), |s, v| format!("{s}, {v}")), + &format!("{context}, Invalid referenced document type"), + ); + return false; + } + true }; return validate_doc_refs( parameters_ref, diff --git a/rust/signed_doc/tests/comment.rs b/rust/signed_doc/tests/comment.rs index c64848b246e..f96dab12c54 100644 --- a/rust/signed_doc/tests/comment.rs +++ b/rust/signed_doc/tests/comment.rs @@ -57,9 +57,9 @@ static COMMENT_TEMPLATE_DOC: LazyLock = LazyLock::new(|| "id": UuidV7::new(), "ver": UuidV7::new(), "parameters": { - "id": DUMMY_BRAND_DOC.doc_id().unwrap(), - "ver": DUMMY_BRAND_DOC.doc_ver().unwrap(), - } + "id": DUMMY_BRAND_DOC.doc_id().unwrap(), + "ver": DUMMY_BRAND_DOC.doc_ver().unwrap(), + } })) .unwrap() .with_json_content(&serde_json::json!({ @@ -167,6 +167,7 @@ async fn test_valid_comment_doc() { .await .unwrap(); assert!(is_valid); + assert!(!doc.problem_report().is_problematic()); } #[tokio::test] diff --git a/rust/signed_doc/tests/proposal.rs b/rust/signed_doc/tests/proposal.rs index 453f0df0e83..03f4d608644 100644 --- a/rust/signed_doc/tests/proposal.rs +++ b/rust/signed_doc/tests/proposal.rs @@ -41,9 +41,9 @@ static PROPOSAL_TEMPLATE_DOC: LazyLock = LazyLock::new(| "id": UuidV7::new(), "ver": UuidV7::new(), "parameters": { - "id": DUMMY_BRAND_DOC.doc_id().unwrap(), - "ver": DUMMY_BRAND_DOC.doc_ver().unwrap(), - } + "id": DUMMY_BRAND_DOC.doc_id().unwrap(), + "ver": DUMMY_BRAND_DOC.doc_ver().unwrap(), + }, })) .unwrap() .with_json_content(&serde_json::json!({ @@ -109,6 +109,7 @@ async fn test_valid_proposal_doc() { .await .unwrap(); assert!(is_valid); + assert!(!doc.problem_report().is_problematic()); } #[tokio::test] diff --git a/rust/signed_doc/tests/submission.rs b/rust/signed_doc/tests/submission.rs index 5ba7e924660..6436181064c 100644 --- a/rust/signed_doc/tests/submission.rs +++ b/rust/signed_doc/tests/submission.rs @@ -103,6 +103,7 @@ async fn test_valid_submission_action() { .await .unwrap(); assert!(is_valid); + assert!(!doc.problem_report().is_problematic()); } #[tokio::test]