Skip to content

Commit a29d1db

Browse files
committed
wip
1 parent aafdbc1 commit a29d1db

File tree

7 files changed

+138
-0
lines changed

7 files changed

+138
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use super::*;
2+
3+
pub fn brand_parameters_doc() -> anyhow::Result<CatalystSignedDocument> {
4+
let doc = Builder::new()
5+
.with_json_metadata(serde_json::json!({
6+
"content-type": ContentType::Json.to_string(),
7+
"id": UuidV7::new(),
8+
"ver": UuidV7::new(),
9+
"type": doc_types::BRAND_PARAMETERS.clone(),
10+
}))?
11+
.empty_content()?
12+
.build()?;
13+
Ok(doc)
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use super::*;
2+
3+
pub fn campaign_parameters_doc() -> anyhow::Result<CatalystSignedDocument> {
4+
let doc = Builder::new()
5+
.with_json_metadata(serde_json::json!({
6+
"content-type": ContentType::Json.to_string(),
7+
"id": UuidV7::new(),
8+
"ver": UuidV7::new(),
9+
"type": doc_types::CAMPAIGN_PARAMETERS.clone(),
10+
}))?
11+
.empty_content()?
12+
.build()?;
13+
Ok(doc)
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use super::*;
2+
3+
pub fn category_parameters_doc() -> anyhow::Result<CatalystSignedDocument> {
4+
let doc = Builder::new()
5+
.with_json_metadata(serde_json::json!({
6+
"content-type": ContentType::Json.to_string(),
7+
"id": UuidV7::new(),
8+
"ver": UuidV7::new(),
9+
"type": doc_types::CATEGORY_PARAMETERS.clone(),
10+
}))?
11+
.empty_content()?
12+
.build()?;
13+
Ok(doc)
14+
}

rust/signed_doc/tests/common/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#![allow(dead_code)]
22

3+
pub mod brand_parameters;
4+
pub mod campaign_parameters;
5+
pub mod category_parameters;
36
pub mod dummies;
7+
pub mod proposal;
8+
pub mod proposal_comment_form_template;
9+
pub mod proposal_form_template;
410

511
use std::str::FromStr;
612

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use catalyst_signed_doc::providers::tests::TestCatalystProvider;
2+
use ed25519_dalek::ed25519::signature::Signer;
3+
4+
use super::*;
5+
6+
/// Creates a Proposal doc, contain all fields mention in the document spec (except
7+
/// 'collaborators' and 'revocations')
8+
pub fn proposal_doc(
9+
template_doc: &CatalystSignedDocument,
10+
parameters_doc: &CatalystSignedDocument,
11+
provider: &mut TestCatalystProvider,
12+
) -> anyhow::Result<CatalystSignedDocument> {
13+
let id = UuidV7::new();
14+
let (sk, pk, kid) = create_dummy_key_pair(RoleId::Proposer)?;
15+
provider.add_pk(kid.clone(), pk);
16+
17+
Ok(Builder::new()
18+
.with_json_metadata(serde_json::json!({
19+
"content-type": ContentType::Json.to_string(),
20+
"content-encoding": ContentEncoding::Brotli.to_string(),
21+
"type": doc_types::PROPOSAL.clone(),
22+
"id": id,
23+
"ver": id,
24+
"template": {
25+
"id": template_doc.doc_id()?,
26+
"ver": template_doc.doc_ver()?,
27+
},
28+
"parameters": {
29+
"id": parameters_doc.doc_id()?,
30+
"ver": parameters_doc.doc_ver()?,
31+
}
32+
}))?
33+
.with_json_content(&serde_json::json!({}))?
34+
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
35+
.build()?)
36+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use super::*;
2+
3+
pub fn proposal_comment_form_template_doc(
4+
parameters_doc: &CatalystSignedDocument
5+
) -> anyhow::Result<CatalystSignedDocument> {
6+
let doc = Builder::new()
7+
.with_json_metadata(serde_json::json!({
8+
"content-type": ContentType::Json.to_string(),
9+
"content-encoding": ContentEncoding::Brotli.to_string(),
10+
"type": doc_types::PROPOSAL_COMMENT_FORM_TEMPLATE.clone(),
11+
"id": UuidV7::new(),
12+
"ver": UuidV7::new(),
13+
"parameters": {
14+
"id": parameters_doc.doc_id()?,
15+
"ver": parameters_doc.doc_ver()?,
16+
}
17+
}))?
18+
.with_json_content(&serde_json::json!({
19+
"$schema": "http://json-schema.org/draft-07/schema#",
20+
"type": "object",
21+
"properties": {},
22+
"required": [],
23+
"additionalProperties": false
24+
}))?
25+
.build()?;
26+
Ok(doc)
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use super::*;
2+
3+
pub fn proposal_form_template_doc(
4+
parameters_doc: &CatalystSignedDocument
5+
) -> anyhow::Result<CatalystSignedDocument> {
6+
let doc = Builder::new()
7+
.with_json_metadata(serde_json::json!({
8+
"content-type": ContentType::Json.to_string(),
9+
"content-encoding": ContentEncoding::Brotli.to_string(),
10+
"type": doc_types::PROPOSAL_FORM_TEMPLATE.clone(),
11+
"id": UuidV7::new(),
12+
"ver": UuidV7::new(),
13+
"parameters": {
14+
"id": parameters_doc.doc_id()?,
15+
"ver": parameters_doc.doc_ver()?,
16+
},
17+
}))?
18+
.with_json_content(&serde_json::json!({
19+
"$schema": "http://json-schema.org/draft-07/schema#",
20+
"type": "object",
21+
"properties": {},
22+
"required": [],
23+
"additionalProperties": false
24+
}))?
25+
.build()?;
26+
Ok(doc)
27+
}

0 commit comments

Comments
 (0)