Skip to content

Commit 938860e

Browse files
authored
Merge pull request #266 from okp4/fix/object-hash
Fix/object hash
2 parents 3d95467 + 98cef6c commit 938860e

File tree

3 files changed

+139
-50
lines changed

3 files changed

+139
-50
lines changed

contracts/okp4-cognitarium/src/contract.rs

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ mod tests {
248248
namespaces, triples, Namespace, Node, Object, StoreLimits, StoreStat, Subject, Triple,
249249
};
250250
use crate::{msg, state};
251-
use blake3::Hash;
252251
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
253252
use cosmwasm_std::{from_binary, Addr, Attribute, Order, Uint128};
254253
use std::collections::BTreeMap;
@@ -386,10 +385,11 @@ mod tests {
386385
.load(
387386
&deps.storage,
388387
(
389-
Hash::from_hex(
390-
"09653b5306fa80dc7bea8313d84ac6ed9ded591d42c7f4838c39d1d7a4f09d03"
391-
)
392-
.unwrap()
388+
Object::Named(Node {
389+
namespace: 4u128,
390+
value: "0x04d1f1b8f8a7a28f9a5a254c326a963a22f5a5b5d5f5e5d5c5b5a5958575655"
391+
.to_string()
392+
}).as_hash()
393393
.as_bytes(),
394394
Node {
395395
namespace: 3u128,
@@ -1178,18 +1178,7 @@ mod tests {
11781178
DescribeResponse {
11791179
format: DataFormat::Turtle,
11801180
data: Binary::from(
1181-
"<https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> , <https://ontology.okp4.space/metadata/dataset/GeneralMetadata> ;
1182-
\t<https://ontology.okp4.space/core/hasTag> \"test\" ;
1183-
\t<https://ontology.okp4.space/core/hasTitle> \"test Dataset\"@en , \"Dataset de test\"@fr ;
1184-
\t<https://ontology.okp4.space/core/hasTopic> <https://ontology.okp4.space/thesaurus/topic/Test> ;
1185-
\t<https://ontology.okp4.space/core/describes> <https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde> ;
1186-
\t<https://ontology.okp4.space/core/hasFormat> <https://ontology.okp4.space/thesaurus/media-type/application_vndms-excel> ;
1187-
\t<https://ontology.okp4.space/core/hasCreator> \"Me\" ;
1188-
\t<https://ontology.okp4.space/core/hasLicense> <https://ontology.okp4.space/thesaurus/license/LO-FR-1_0> ;
1189-
\t<https://ontology.okp4.space/core/hasPublisher> \"OKP4\" ;
1190-
\t<https://ontology.okp4.space/core/hasDescription> \"Un Dataset de test.\"@fr , \"A test Dataset.\"@en .
1191-
\
1192-
".to_string().as_bytes().to_vec()),
1181+
"<https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://ontology.okp4.space/metadata/dataset/GeneralMetadata> , <http://www.w3.org/2002/07/owl#NamedIndividual> ;\n\t<https://ontology.okp4.space/core/hasTag> \"test\" ;\n\t<https://ontology.okp4.space/core/hasTitle> \"test Dataset\"@en , \"Dataset de test\"@fr ;\n\t<https://ontology.okp4.space/core/hasTopic> <https://ontology.okp4.space/thesaurus/topic/Test> ;\n\t<https://ontology.okp4.space/core/describes> <https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde> ;\n\t<https://ontology.okp4.space/core/hasFormat> <https://ontology.okp4.space/thesaurus/media-type/application_vndms-excel> ;\n\t<https://ontology.okp4.space/core/hasCreator> \"Me\" ;\n\t<https://ontology.okp4.space/core/hasLicense> <https://ontology.okp4.space/thesaurus/license/LO-FR-1_0> ;\n\t<https://ontology.okp4.space/core/hasPublisher> \"OKP4\" ;\n\t<https://ontology.okp4.space/core/hasDescription> \"Un Dataset de test.\"@fr , \"A test Dataset.\"@en .\n".to_string().as_bytes().to_vec()),
11931182
}
11941183
),
11951184
];
@@ -1256,25 +1245,7 @@ mod tests {
12561245
DescribeResponse {
12571246
format: DataFormat::Turtle,
12581247
data: Binary::from(
1259-
"<https://ontology.okp4.space/dataverse/dataspace/metadata/dcf48417-01c5-4b43-9bc7-49e54c028473> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://ontology.okp4.space/metadata/dataspace/GeneralMetadata> , <http://www.w3.org/2002/07/owl#NamedIndividual> ;
1260-
\t<https://ontology.okp4.space/core/hasTag> \"Test\" , \"OKP4\" ;
1261-
\t<https://ontology.okp4.space/core/hasTitle> \"Data Space de test\"@fr , \"Test Data Space\"@en ;
1262-
\t<https://ontology.okp4.space/core/hasTopic> <https://ontology.okp4.space/thesaurus/topic/Test> ;
1263-
\t<https://ontology.okp4.space/core/describes> <https://ontology.okp4.space/dataverse/dataspace/97ff7e16-c08d-47be-8475-211016c82e33> ;
1264-
\t<https://ontology.okp4.space/core/hasPublisher> \"OKP4\" ;
1265-
\t<https://ontology.okp4.space/core/hasDescription> \"A test Data Space.\"@en , \"Un Data Space de test.\"@fr .
1266-
<https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> , <https://ontology.okp4.space/metadata/dataset/GeneralMetadata> ;
1267-
\t<https://ontology.okp4.space/core/hasTag> \"test\" ;
1268-
\t<https://ontology.okp4.space/core/hasTitle> \"test Dataset\"@en , \"Dataset de test\"@fr ;
1269-
\t<https://ontology.okp4.space/core/hasTopic> <https://ontology.okp4.space/thesaurus/topic/Test> ;
1270-
\t<https://ontology.okp4.space/core/describes> <https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde> ;
1271-
\t<https://ontology.okp4.space/core/hasFormat> <https://ontology.okp4.space/thesaurus/media-type/application_vndms-excel> ;
1272-
\t<https://ontology.okp4.space/core/hasCreator> \"Me\" ;
1273-
\t<https://ontology.okp4.space/core/hasLicense> <https://ontology.okp4.space/thesaurus/license/LO-FR-1_0> ;
1274-
\t<https://ontology.okp4.space/core/hasPublisher> \"OKP4\" ;
1275-
\t<https://ontology.okp4.space/core/hasDescription> \"Un Dataset de test.\"@fr , \"A test Dataset.\"@en .
1276-
\
1277-
".to_string().as_bytes().to_vec()),
1248+
"<https://ontology.okp4.space/dataverse/dataspace/metadata/dcf48417-01c5-4b43-9bc7-49e54c028473> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://ontology.okp4.space/metadata/dataspace/GeneralMetadata> , <http://www.w3.org/2002/07/owl#NamedIndividual> ;\n\t<https://ontology.okp4.space/core/hasTag> \"Test\" , \"OKP4\" ;\n\t<https://ontology.okp4.space/core/hasTitle> \"Data Space de test\"@fr , \"Test Data Space\"@en ;\n\t<https://ontology.okp4.space/core/hasTopic> <https://ontology.okp4.space/thesaurus/topic/Test> ;\n\t<https://ontology.okp4.space/core/describes> <https://ontology.okp4.space/dataverse/dataspace/97ff7e16-c08d-47be-8475-211016c82e33> ;\n\t<https://ontology.okp4.space/core/hasPublisher> \"OKP4\" ;\n\t<https://ontology.okp4.space/core/hasDescription> \"A test Data Space.\"@en , \"Un Data Space de test.\"@fr .\n<https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://ontology.okp4.space/metadata/dataset/GeneralMetadata> , <http://www.w3.org/2002/07/owl#NamedIndividual> ;\n\t<https://ontology.okp4.space/core/hasTag> \"test\" ;\n\t<https://ontology.okp4.space/core/hasTitle> \"test Dataset\"@en , \"Dataset de test\"@fr ;\n\t<https://ontology.okp4.space/core/hasTopic> <https://ontology.okp4.space/thesaurus/topic/Test> ;\n\t<https://ontology.okp4.space/core/describes> <https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde> ;\n\t<https://ontology.okp4.space/core/hasFormat> <https://ontology.okp4.space/thesaurus/media-type/application_vndms-excel> ;\n\t<https://ontology.okp4.space/core/hasCreator> \"Me\" ;\n\t<https://ontology.okp4.space/core/hasLicense> <https://ontology.okp4.space/thesaurus/license/LO-FR-1_0> ;\n\t<https://ontology.okp4.space/core/hasPublisher> \"OKP4\" ;\n\t<https://ontology.okp4.space/core/hasDescription> \"Un Dataset de test.\"@fr , \"A test Dataset.\"@en .\n".to_string().as_bytes().to_vec()),
12781249
}
12791250
),
12801251
];
@@ -1345,10 +1316,7 @@ mod tests {
13451316
DescribeResponse {
13461317
format: DataFormat::Turtle,
13471318
data: Binary::from(
1348-
"<riog00000001> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://ontology.okp4.space/core/Period> , <http://www.w3.org/2002/07/owl#NamedIndividual> ;
1349-
\t<https://ontology.okp4.space/core/hasStartDate> \"2022-01-01T00:00:00+00:00\"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
1350-
\
1351-
".to_string().as_bytes().to_vec()),
1319+
"<riog00000001> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual> , <https://ontology.okp4.space/core/Period> ;\n\t<https://ontology.okp4.space/core/hasStartDate> \"2022-01-01T00:00:00+00:00\"^^<http://www.w3.org/2001/XMLSchema#dateTime> .\n".to_string().as_bytes().to_vec()),
13521320
}
13531321
),
13541322
];

contracts/okp4-cognitarium/src/querier/engine.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -587,19 +587,19 @@ mod test {
587587
results: Results {
588588
bindings: vec![
589589
BTreeMap::from([
590-
("subject".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde".to_string())}),
591-
("predicate".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/core/hasIdentifier".to_string())}),
592-
("object".to_string(), Value::URI {value: IRI::Full("urn:uuid:0ea1fc7a-dd97-4adc-a10e-169c6597bcde".to_string())}),
590+
("subject".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e".to_string())}),
591+
("predicate".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/core/describes".to_string())}),
592+
("object".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde".to_string())}),
593593
]),
594594
BTreeMap::from([
595-
("subject".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/dataverse/dataspace/97ff7e16-c08d-47be-8475-211016c82e33".to_string())}),
596-
("predicate".to_string(), Value::URI {value: IRI::Full("http://www.w3.org/1999/02/22-rdf-syntax-ns#type".to_string())}),
597-
("object".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/core/DataSpace".to_string())}),
595+
("subject".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e".to_string())}),
596+
("predicate".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/core/hasDescription".to_string())}),
597+
("object".to_string(), Value::Literal {value: "Un Dataset de test.".to_string(), lang: Some("fr".to_string()), datatype: None }),
598598
]),
599599
BTreeMap::from([
600-
("subject".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/dataverse/dataset/0ea1fc7a-dd97-4adc-a10e-169c6597bcde".to_string())}),
601-
("predicate".to_string(), Value::URI {value: IRI::Full("http://www.w3.org/1999/02/22-rdf-syntax-ns#type".to_string())}),
602-
("object".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/core/Dataset".to_string())}),
600+
("subject".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/dataverse/dataset/metadata/d1615703-4ee1-4e2f-997e-15aecf1eea4e".to_string())}),
601+
("predicate".to_string(), Value::URI {value: IRI::Full("https://ontology.okp4.space/core/hasTitle".to_string())}),
602+
("object".to_string(), Value::Literal { value: "test Dataset".to_string(), lang: Some("en".to_string()), datatype: None }),
603603
]),
604604
],
605605
},

contracts/okp4-cognitarium/src/state/triples.rs

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Object {
8585
hasher
8686
.update(&[b'n'])
8787
.update(n.namespace.to_be_bytes().as_slice())
88-
.update(n.namespace.to_be_bytes().as_slice());
88+
.update(n.value.as_bytes());
8989
}
9090
Object::Blank(n) => {
9191
hasher.update(&[b'b']).update(n.as_bytes());
@@ -143,3 +143,124 @@ pub enum Literal {
143143
I18NString { value: String, language: String },
144144
Typed { value: String, datatype: Node },
145145
}
146+
147+
#[cfg(test)]
148+
mod test {
149+
use super::*;
150+
151+
#[test]
152+
fn object_hash() {
153+
let cases = vec![
154+
(
155+
Object::Named(Node {
156+
namespace: 0,
157+
value: "val1".to_string(),
158+
}),
159+
Object::Named(Node {
160+
namespace: 0,
161+
value: "val2".to_string(),
162+
}),
163+
),
164+
(
165+
Object::Named(Node {
166+
namespace: 1,
167+
value: "val".to_string(),
168+
}),
169+
Object::Named(Node {
170+
namespace: 2,
171+
value: "val".to_string(),
172+
}),
173+
),
174+
(
175+
Object::Blank("val1".to_string()),
176+
Object::Blank("val2".to_string()),
177+
),
178+
(
179+
Object::Literal(Literal::Simple {
180+
value: "val1".to_string(),
181+
}),
182+
Object::Literal(Literal::Simple {
183+
value: "val2".to_string(),
184+
}),
185+
),
186+
(
187+
Object::Literal(Literal::I18NString {
188+
language: "fr".to_string(),
189+
value: "val1".to_string(),
190+
}),
191+
Object::Literal(Literal::I18NString {
192+
language: "fr".to_string(),
193+
value: "val2".to_string(),
194+
}),
195+
),
196+
(
197+
Object::Literal(Literal::I18NString {
198+
language: "fr".to_string(),
199+
value: "val".to_string(),
200+
}),
201+
Object::Literal(Literal::I18NString {
202+
language: "en".to_string(),
203+
value: "val".to_string(),
204+
}),
205+
),
206+
(
207+
Object::Literal(Literal::Typed {
208+
datatype: Node {
209+
namespace: 0,
210+
value: "n".to_string(),
211+
},
212+
value: "val1".to_string(),
213+
}),
214+
Object::Literal(Literal::Typed {
215+
datatype: Node {
216+
namespace: 0,
217+
value: "n".to_string(),
218+
},
219+
value: "val2".to_string(),
220+
}),
221+
),
222+
(
223+
Object::Literal(Literal::Typed {
224+
datatype: Node {
225+
namespace: 0,
226+
value: "n1".to_string(),
227+
},
228+
value: "val".to_string(),
229+
}),
230+
Object::Literal(Literal::Typed {
231+
datatype: Node {
232+
namespace: 0,
233+
value: "n2".to_string(),
234+
},
235+
value: "val".to_string(),
236+
}),
237+
),
238+
(
239+
Object::Literal(Literal::Typed {
240+
datatype: Node {
241+
namespace: 1,
242+
value: "n".to_string(),
243+
},
244+
value: "val".to_string(),
245+
}),
246+
Object::Literal(Literal::Typed {
247+
datatype: Node {
248+
namespace: 2,
249+
value: "n".to_string(),
250+
},
251+
value: "val".to_string(),
252+
}),
253+
),
254+
(
255+
Object::Blank("val".to_string()),
256+
Object::Literal(Literal::Simple {
257+
value: "val".to_string(),
258+
}),
259+
),
260+
];
261+
262+
for case in cases {
263+
assert_ne!(case.0.as_hash(), case.1.as_hash())
264+
}
265+
}
266+
}

0 commit comments

Comments
 (0)