Skip to content

Commit 0d1280f

Browse files
committed
wip
1 parent 7715499 commit 0d1280f

20 files changed

+344
-354
lines changed

rust/signed_doc/src/providers.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub mod tests {
6262
CatalystId, CatalystIdProvider, CatalystSignedDocument, CatalystSignedDocumentProvider,
6363
VerifyingKey,
6464
};
65-
use crate::{DocLocator, DocumentRef};
65+
use crate::DocumentRef;
6666

6767
/// Simple testing implementation of `CatalystSignedDocumentProvider`,
6868
#[derive(Default, Debug)]
@@ -74,28 +74,30 @@ pub mod tests {
7474
}
7575

7676
impl TestCatalystProvider {
77-
/// Inserts document into the `TestCatalystSignedDocumentProvider` where
78-
/// if document reference is provided use that value.
79-
/// if not use the id and version of the provided doc.
77+
/// Inserts document into the `TestCatalystSignedDocumentProvider`.
8078
///
8179
/// # Errors
8280
/// Returns error if document reference is not provided and its fail to create one
8381
/// from the given doc.
8482
pub fn add_document(
8583
&mut self,
86-
doc_ref: Option<DocumentRef>,
8784
doc: &CatalystSignedDocument,
8885
) -> anyhow::Result<()> {
89-
if let Some(dr) = doc_ref {
90-
self.signed_doc.insert(dr, doc.clone());
91-
} else {
92-
let cid = doc.to_cid_v1()?;
93-
let dr = DocumentRef::new(doc.doc_id()?, doc.doc_ver()?, DocLocator::from(cid));
94-
self.signed_doc.insert(dr, doc.clone());
95-
}
86+
let dr = doc.doc_ref()?;
87+
self.signed_doc.insert(dr, doc.clone());
9688
Ok(())
9789
}
9890

91+
/// Inserts document into the `TestCatalystSignedDocumentProvider` using provided
92+
/// `DocumentRef` as key.
93+
pub fn add_document_with_ref(
94+
&mut self,
95+
doc_ref: DocumentRef,
96+
doc: &CatalystSignedDocument,
97+
) {
98+
self.signed_doc.insert(doc_ref, doc.clone());
99+
}
100+
99101
/// Inserts signing key into the `TestVerifyingKeyProvider`
100102
pub fn add_sk(
101103
&mut self,

rust/signed_doc/src/validator/rules/chain/tests.rs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ async fn test_without_chaining_documents() {
7575
Chain::new(-1, Some(first_doc_ref.clone()))
7676
))
7777
.build();
78-
let last_doc_ref = last.doc_ref().unwrap();
79-
80-
provider.add_document(Some(first_doc_ref), &first).unwrap();
81-
provider.add_document(Some(last_doc_ref), &last).unwrap();
78+
provider.add_document(&first).unwrap();
8279
8380
(provider, last)
8481
} => true;
@@ -122,12 +119,9 @@ async fn test_without_chaining_documents() {
122119
Chain::new(-2, Some(intermediate_doc_ref.clone()))
123120
))
124121
.build();
125-
let last_doc_ref = last.doc_ref().unwrap();
126-
127-
provider.add_document(Some(first_doc_ref), &first).unwrap();
128-
provider.add_document(Some(intermediate_doc_ref), &intermediate).unwrap();
129-
provider.add_document(Some(last_doc_ref), &last).unwrap();
130-
122+
provider.add_document(&first).unwrap();
123+
provider.add_document(&intermediate).unwrap();
124+
131125
(provider, last)
132126
} => true;
133127
"valid intermediate chained documents (0, 1, -2)"
@@ -170,11 +164,8 @@ async fn test_valid_chained_documents(
170164
Chain::new(-1, Some(first_doc_ref.clone()))
171165
))
172166
.build();
173-
let last_doc_ref = last.doc_ref().unwrap();
174-
175-
provider.add_document(Some(first_doc_ref), &first).unwrap();
176-
provider.add_document(Some(last_doc_ref), &last).unwrap();
177-
167+
provider.add_document(&first).unwrap();
168+
178169
(provider, last)
179170
} => false;
180171
"not have the same id as the document being chained to"
@@ -207,11 +198,8 @@ async fn test_valid_chained_documents(
207198
Chain::new(-1, Some(first_doc_ref.clone()))
208199
))
209200
.build();
210-
let last_doc_ref = last.doc_ref().unwrap();
211-
212-
provider.add_document(Some(first_doc_ref), &first).unwrap();
213-
provider.add_document(Some(last_doc_ref), &last).unwrap();
214-
201+
provider.add_document(&first).unwrap();
202+
215203
(provider, last)
216204
} => false;
217205
"not have a ver that is greater than the ver being chained to"
@@ -245,11 +233,8 @@ async fn test_valid_chained_documents(
245233
Chain::new(-1, Some(first_doc_ref.clone()))
246234
))
247235
.build();
248-
let last_doc_ref = last.doc_ref().unwrap();
249-
250-
provider.add_document(Some(first_doc_ref), &first).unwrap();
251-
provider.add_document(Some(last_doc_ref), &last).unwrap();
252-
236+
provider.add_document(&first).unwrap();
237+
253238
(provider, last)
254239
} => false;
255240
"not the same type as the chained document"
@@ -282,10 +267,7 @@ async fn test_valid_chained_documents(
282267
Chain::new(-2, Some(first_doc_ref.clone()))
283268
))
284269
.build();
285-
let last_doc_ref = last.doc_ref().unwrap();
286-
287-
provider.add_document(Some(first_doc_ref), &first).unwrap();
288-
provider.add_document(Some(last_doc_ref), &last).unwrap();
270+
provider.add_document(&first).unwrap();
289271
290272
(provider, last)
291273
} => false;

rust/signed_doc/src/validator/rules/doc_ref/tests.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
1616
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
1717
.build();
18-
provider.add_document(None, &ref_doc).unwrap();
18+
provider.add_document(&ref_doc).unwrap();
1919
2020
Builder::new()
2121
.with_metadata_field(SupportedField::Ref(
@@ -34,19 +34,19 @@ use crate::{
3434
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
3535
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
3636
.build();
37-
provider.add_document(None, &ref_doc_1).unwrap();
37+
provider.add_document(&ref_doc_1).unwrap();
3838
let ref_doc_2 = Builder::new()
3939
.with_metadata_field(SupportedField::Id(UuidV7::new()))
4040
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
4141
.with_metadata_field(SupportedField::Type(exp_types[1].clone()))
4242
.build();
43-
provider.add_document(None, &ref_doc_2).unwrap();
43+
provider.add_document(&ref_doc_2).unwrap();
4444
let ref_doc_3 = Builder::new()
4545
.with_metadata_field(SupportedField::Id(UuidV7::new()))
4646
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
4747
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
4848
.build();
49-
provider.add_document(None, &ref_doc_3).unwrap();
49+
provider.add_document(&ref_doc_3).unwrap();
5050
5151
Builder::new()
5252
.with_metadata_field(SupportedField::Ref(
@@ -70,19 +70,19 @@ use crate::{
7070
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
7171
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
7272
.build();
73-
provider.add_document(None, &ref_doc_1).unwrap();
73+
provider.add_document(&ref_doc_1).unwrap();
7474
let ref_doc_2 = Builder::new()
7575
.with_metadata_field(SupportedField::Id(UuidV7::new()))
7676
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
7777
.with_metadata_field(SupportedField::Type(exp_types[1].clone()))
7878
.build();
79-
provider.add_document(None, &ref_doc_2).unwrap();
79+
provider.add_document(&ref_doc_2).unwrap();
8080
let ref_doc_3 = Builder::new()
8181
.with_metadata_field(SupportedField::Id(UuidV7::new()))
8282
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
8383
.with_metadata_field(SupportedField::Type(UuidV4::new().into()))
8484
.build();
85-
provider.add_document(None, &ref_doc_3).unwrap();
85+
provider.add_document(&ref_doc_3).unwrap();
8686
8787
Builder::new()
8888
.with_metadata_field(SupportedField::Ref(
@@ -106,18 +106,18 @@ use crate::{
106106
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
107107
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
108108
.build();
109-
provider.add_document(None, &ref_doc_1).unwrap();
109+
provider.add_document(&ref_doc_1).unwrap();
110110
let ref_doc_2 = Builder::new()
111111
.with_metadata_field(SupportedField::Id(UuidV7::new()))
112112
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
113113
.with_metadata_field(SupportedField::Type(exp_types[1].clone()))
114114
.build();
115-
provider.add_document(None, &ref_doc_2).unwrap();
115+
provider.add_document(&ref_doc_2).unwrap();
116116
let ref_doc_3 = Builder::new()
117117
.with_metadata_field(SupportedField::Id(UuidV7::new()))
118118
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
119119
.build();
120-
provider.add_document(None, &ref_doc_3).unwrap();
120+
provider.add_document(&ref_doc_3).unwrap();
121121
122122
Builder::new()
123123
.with_metadata_field(SupportedField::Ref(
@@ -141,7 +141,13 @@ use crate::{
141141
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
142142
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
143143
.build();
144-
provider.add_document(Some(create_dummy_doc_ref()), &ref_doc).unwrap();
144+
let new_ref = create_dummy_doc_ref();
145+
let new_ref = DocumentRef::new(
146+
ref_doc.doc_id().unwrap(),
147+
ref_doc.doc_ver().unwrap(),
148+
new_ref.doc_locator().clone()
149+
);
150+
provider.add_document_with_ref(new_ref, &ref_doc);
145151
146152
Builder::new()
147153
.with_metadata_field(SupportedField::Ref(
@@ -204,7 +210,7 @@ async fn ref_multiple_specified_test(
204210
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
205211
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
206212
.build();
207-
provider.add_document(None, &ref_doc).unwrap();
213+
provider.add_document(&ref_doc).unwrap();
208214
209215
Builder::new()
210216
.with_metadata_field(SupportedField::Ref(
@@ -223,19 +229,19 @@ async fn ref_multiple_specified_test(
223229
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
224230
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
225231
.build();
226-
provider.add_document(None, &ref_doc_1).unwrap();
232+
provider.add_document(&ref_doc_1).unwrap();
227233
let ref_doc_2 = Builder::new()
228234
.with_metadata_field(SupportedField::Id(UuidV7::new()))
229235
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
230236
.with_metadata_field(SupportedField::Type(exp_types[1].clone()))
231237
.build();
232-
provider.add_document(None, &ref_doc_2).unwrap();
238+
provider.add_document(&ref_doc_2).unwrap();
233239
let ref_doc_3 = Builder::new()
234240
.with_metadata_field(SupportedField::Id(UuidV7::new()))
235241
.with_metadata_field(SupportedField::Ver(UuidV7::new()))
236242
.with_metadata_field(SupportedField::Type(exp_types[0].clone()))
237243
.build();
238-
provider.add_document(None, &ref_doc_3).unwrap();
244+
provider.add_document(&ref_doc_3).unwrap();
239245
240246
Builder::new()
241247
.with_metadata_field(SupportedField::Ref(

rust/signed_doc/src/validator/rules/ownership/tests/collaborators_field_based.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::{
3636
.add_signature(|m| sk.sign(&m).to_vec(), kid.clone())
3737
.unwrap()
3838
.build();
39-
provider.add_document(None, &doc).unwrap();
39+
provider.add_document(&doc).unwrap();
4040
4141
Builder::new()
4242
.with_metadata_field(SupportedField::Id(id))
@@ -59,7 +59,7 @@ use crate::{
5959
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
6060
.unwrap()
6161
.build();
62-
provider.add_document(None, &doc).unwrap();
62+
provider.add_document(&doc).unwrap();
6363
6464
Builder::new()
6565
.with_metadata_field(SupportedField::Id(id))
@@ -84,7 +84,7 @@ use crate::{
8484
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
8585
.unwrap()
8686
.build();
87-
provider.add_document(None, &doc).unwrap();
87+
provider.add_document(&doc).unwrap();
8888
8989
Builder::new()
9090
.with_metadata_field(SupportedField::Id(id))
@@ -131,7 +131,7 @@ use crate::{
131131
.add_signature(|m| sk.sign(&m).to_vec(), kid.clone())
132132
.unwrap()
133133
.build();
134-
provider.add_document(None, &doc).unwrap();
134+
provider.add_document(&doc).unwrap();
135135
136136
let (sk, kid) = create_dummy_key_pair(RoleId::Role0);
137137
Builder::new()
@@ -154,7 +154,7 @@ use crate::{
154154
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
155155
.unwrap()
156156
.build();
157-
provider.add_document(None, &doc).unwrap();
157+
provider.add_document(&doc).unwrap();
158158
159159
Builder::new()
160160
.with_metadata_field(SupportedField::Id(id))
@@ -179,7 +179,7 @@ use crate::{
179179
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
180180
.unwrap()
181181
.build();
182-
provider.add_document(None, &doc).unwrap();
182+
provider.add_document(&doc).unwrap();
183183
184184
let (c2_sk, c2_kid) = create_dummy_key_pair(RoleId::Role0);
185185
Builder::new()

rust/signed_doc/src/validator/rules/ownership/tests/ref_field_based.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
2424
.unwrap()
2525
.build();
26-
provider.add_document(None, &doc).unwrap();
26+
provider.add_document(&doc).unwrap();
2727
2828
let id = UuidV7::new();
2929
Builder::new()
@@ -50,7 +50,7 @@ use crate::{
5050
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
5151
.unwrap()
5252
.build();
53-
provider.add_document(None, &doc).unwrap();
53+
provider.add_document(&doc).unwrap();
5454
5555
let id = UuidV7::new();
5656
Builder::new()
@@ -98,7 +98,7 @@ use crate::{
9898
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
9999
.unwrap()
100100
.build();
101-
provider.add_document(None, &doc).unwrap();
101+
provider.add_document(&doc).unwrap();
102102
103103
let (a_sk, a_kid) = create_dummy_key_pair(RoleId::Role0);
104104
let id = UuidV7::new();

rust/signed_doc/src/validator/rules/ownership/tests/without_collaborators.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::{
3636
.add_signature(|m| sk.sign(&m).to_vec(), kid.clone())
3737
.unwrap()
3838
.build();
39-
provider.add_document(None, &doc).unwrap();
39+
provider.add_document(&doc).unwrap();
4040
4141
Builder::new()
4242
.with_metadata_field(SupportedField::Id(id))
@@ -83,7 +83,7 @@ use crate::{
8383
.add_signature(|m| sk.sign(&m).to_vec(), kid.clone())
8484
.unwrap()
8585
.build();
86-
provider.add_document(None, &doc).unwrap();
86+
provider.add_document(&doc).unwrap();
8787
8888
let (sk, kid) = create_dummy_key_pair(RoleId::Role0);
8989
Builder::new()
@@ -106,7 +106,7 @@ use crate::{
106106
.add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone())
107107
.unwrap()
108108
.build();
109-
provider.add_document(None, &doc).unwrap();
109+
provider.add_document(&doc).unwrap();
110110
111111
Builder::new()
112112
.with_metadata_field(SupportedField::Id(id))

0 commit comments

Comments
 (0)