Skip to content

Commit 1cbeb58

Browse files
authored
feat(rust/signed-doc): Brand Parameters Form Template, Brand Parameters, Proposal Comment Form Template etc. integration tests (#572)
* wip * update ContentTypeRule, add ContentType::SchemaJson validation * wip * add proposa comment form template integration tests * wip * add brand_parameters_form_template * wip * cleanup * add brand_parameters document tests * add campaign_parameters_form_template integration tests * add campaign_parameters integration test * fix fmt * add category parameters form template tests * wip * add category_parameters tests
1 parent 03fe144 commit 1cbeb58

23 files changed

+1622
-127
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
//! Integration test for brand parameters document validation part.
2+
//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/docs/brand_parameters>
3+
4+
use catalyst_signed_doc::{providers::tests::TestCatalystProvider, *};
5+
use catalyst_types::catalyst_id::role_index::RoleId;
6+
use ed25519_dalek::ed25519::signature::Signer;
7+
use test_case::test_case;
8+
9+
use crate::common::{
10+
brand_parameters_doc, brand_parameters_form_template_doc, create_dummy_key_pair,
11+
};
12+
13+
mod common;
14+
15+
#[test_case(
16+
|provider| {
17+
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
18+
brand_parameters_doc(&template, provider)
19+
}
20+
=> true
21+
;
22+
"valid document"
23+
)]
24+
#[test_case(
25+
|provider| {
26+
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
27+
let id = UuidV7::new();
28+
let (sk, _, kid) = create_dummy_key_pair(RoleId::Role0)
29+
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
30+
Builder::new()
31+
.with_json_metadata(serde_json::json!({
32+
"content-type": ContentType::Json,
33+
"content-encoding": ContentEncoding::Brotli,
34+
"id": id,
35+
"ver": id,
36+
"type": doc_types::BRAND_PARAMETERS.clone(),
37+
"template": {
38+
"id": template.doc_id()?,
39+
"ver": template.doc_ver()?,
40+
},
41+
}))?
42+
.with_json_content(&serde_json::json!({}))?
43+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
44+
.build()
45+
}
46+
=> false
47+
;
48+
"wrong role"
49+
)]
50+
#[test_case(
51+
|provider| {
52+
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
53+
let id = UuidV7::new();
54+
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
55+
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
56+
Builder::new()
57+
.with_json_metadata(serde_json::json!({
58+
"content-type": ContentType::Json,
59+
"content-encoding": ContentEncoding::Brotli,
60+
"id": id,
61+
"ver": id,
62+
"type": doc_types::BRAND_PARAMETERS.clone(),
63+
"template": {
64+
"id": template.doc_id()?,
65+
"ver": template.doc_ver()?,
66+
},
67+
}))?
68+
.empty_content()?
69+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
70+
.build()
71+
}
72+
=> false
73+
;
74+
"empty content"
75+
)]
76+
#[test_case(
77+
|provider| {
78+
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
79+
let id = UuidV7::new();
80+
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
81+
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
82+
Builder::new()
83+
.with_json_metadata(serde_json::json!({
84+
"content-type": ContentType::Json,
85+
"content-encoding": ContentEncoding::Brotli,
86+
"id": id,
87+
"ver": id,
88+
"type": doc_types::BRAND_PARAMETERS.clone(),
89+
"template": {
90+
"id": template.doc_id()?,
91+
"ver": template.doc_ver()?,
92+
},
93+
}))?
94+
.with_json_content(&serde_json::json!({}))?
95+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
96+
.build()
97+
}
98+
=> true
99+
;
100+
"missing 'content-encoding' (optional)"
101+
)]
102+
#[test_case(
103+
|provider| {
104+
let id = UuidV7::new();
105+
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
106+
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
107+
Builder::new()
108+
.with_json_metadata(serde_json::json!({
109+
"content-type": ContentType::Json,
110+
"content-encoding": ContentEncoding::Brotli,
111+
"id": id,
112+
"ver": id,
113+
"type": doc_types::BRAND_PARAMETERS.clone(),
114+
}))?
115+
.with_json_content(&serde_json::json!({}))?
116+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
117+
.build()
118+
}
119+
=> false
120+
;
121+
"missing 'template'"
122+
)]
123+
#[tokio::test]
124+
#[allow(clippy::unwrap_used)]
125+
async fn test_brand_parameters_doc(
126+
doc_gen: impl FnOnce(&mut TestCatalystProvider) -> anyhow::Result<CatalystSignedDocument>
127+
) -> bool {
128+
let mut provider = TestCatalystProvider::default();
129+
130+
let doc = doc_gen(&mut provider).unwrap();
131+
assert_eq!(
132+
*doc.doc_type().unwrap(),
133+
doc_types::BRAND_PARAMETERS.clone()
134+
);
135+
136+
let is_valid = validator::validate(&doc, &provider).await.unwrap();
137+
assert_eq!(is_valid, !doc.problem_report().is_problematic());
138+
println!("{:?}", doc.problem_report());
139+
is_valid
140+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//! Integration test for brand parameters form template document validation part.
2+
//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/docs/brand_parameters_form_template>
3+
4+
use catalyst_signed_doc::{providers::tests::TestCatalystProvider, *};
5+
use catalyst_types::catalyst_id::role_index::RoleId;
6+
use ed25519_dalek::ed25519::signature::Signer;
7+
use test_case::test_case;
8+
9+
use crate::common::{brand_parameters_form_template_doc, create_dummy_key_pair};
10+
11+
mod common;
12+
13+
#[test_case(
14+
|provider| {
15+
brand_parameters_form_template_doc(provider)
16+
}
17+
=> true
18+
;
19+
"valid document"
20+
)]
21+
#[test_case(
22+
|provider| {
23+
let id = UuidV7::new();
24+
let (sk, _, kid) = create_dummy_key_pair(RoleId::Role0)
25+
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
26+
Builder::new()
27+
.with_json_metadata(serde_json::json!({
28+
"content-type": ContentType::SchemaJson,
29+
"content-encoding": ContentEncoding::Brotli,
30+
"id": id,
31+
"ver": id,
32+
"type": doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone(),
33+
}))?
34+
.with_json_content(&serde_json::json!({}))?
35+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
36+
.build()
37+
}
38+
=> false
39+
;
40+
"wrong role"
41+
)]
42+
#[test_case(
43+
|provider| {
44+
let id = UuidV7::new();
45+
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
46+
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
47+
Builder::new()
48+
.with_json_metadata(serde_json::json!({
49+
"content-type": ContentType::SchemaJson,
50+
"content-encoding": ContentEncoding::Brotli,
51+
"id": id,
52+
"ver": id,
53+
"type": doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone(),
54+
}))?
55+
.empty_content()?
56+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
57+
.build()
58+
}
59+
=> false
60+
;
61+
"empty content"
62+
)]
63+
#[test_case(
64+
|provider| {
65+
let id = UuidV7::new();
66+
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
67+
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
68+
Builder::new()
69+
.with_json_metadata(serde_json::json!({
70+
"content-type": ContentType::SchemaJson,
71+
"id": id,
72+
"ver": id,
73+
"type": doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone(),
74+
}))?
75+
.with_json_content(&serde_json::json!({}))?
76+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
77+
.build()
78+
}
79+
=> true
80+
;
81+
"missing 'content-encoding' (optional)"
82+
)]
83+
#[tokio::test]
84+
#[allow(clippy::unwrap_used)]
85+
async fn test_brand_parameters_form_template_doc(
86+
doc_gen: impl FnOnce(&mut TestCatalystProvider) -> anyhow::Result<CatalystSignedDocument>
87+
) -> bool {
88+
let mut provider = TestCatalystProvider::default();
89+
90+
let doc = doc_gen(&mut provider).unwrap();
91+
assert_eq!(
92+
*doc.doc_type().unwrap(),
93+
doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone()
94+
);
95+
96+
let is_valid = validator::validate(&doc, &provider).await.unwrap();
97+
assert_eq!(is_valid, !doc.problem_report().is_problematic());
98+
println!("{:?}", doc.problem_report());
99+
is_valid
100+
}

0 commit comments

Comments
 (0)