From 1a28e7536ac725e2f8d0f55198b44fb204b5bed9 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 9 Jul 2024 08:57:48 +0700 Subject: [PATCH] reactivated test --- grovedb/src/tests/query_tests.rs | 113 +++++++++++++++++-------------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/grovedb/src/tests/query_tests.rs b/grovedb/src/tests/query_tests.rs index 2427abd3..e7325a6a 100644 --- a/grovedb/src/tests/query_tests.rs +++ b/grovedb/src/tests/query_tests.rs @@ -1663,14 +1663,14 @@ mod tests { let proof = db.prove_query(&path_query, None).unwrap().unwrap(); let (hash, result_set) = GroveDb::verify_query_raw(&proof, &path_query).unwrap(); assert_eq!(hash, db.root_hash(None).unwrap().unwrap()); - println!( - "{}", - result_set - .iter() - .map(|a| a.to_string()) - .collect::>() - .join(" | ") - ); + // println!( + // "{}", + // result_set + // .iter() + // .map(|a| a.to_string()) + // .collect::>() + // .join(" | ") + // ); assert_eq!(result_set.len(), 5); compare_result_sets(&elements, &result_set); @@ -1850,14 +1850,14 @@ mod tests { let (hash, result_set) = GroveDb::verify_query_raw(&proof, &path_query).unwrap(); assert_eq!(hash, db.root_hash(None).unwrap().unwrap()); - println!( - "{}", - result_set - .iter() - .map(|a| a.to_string()) - .collect::>() - .join(", ") - ); + // println!( + // "{}", + // result_set + // .iter() + // .map(|a| a.to_string()) + // .collect::>() + // .join(", ") + // ); assert_eq!(result_set.len(), 5); // TODO: verify that the result set is exactly the same @@ -2014,39 +2014,54 @@ mod tests { .expect("successful subtree insert"); // // if you don't have an item at the subquery path translation, you shouldn't // be // added to the result set. - // let mut query = Query::new(); - // query.insert_all(); - // query.set_subquery_path(vec![b"d".to_vec()]); - // - // let path = vec![TEST_LEAF.to_vec()]; - // - // let path_query = PathQuery::new_unsized(path, query.clone()); - // - // let (elements, _) = db - // .query_raw( - // &path_query, - // false, - // true, - // false, - // QueryResultType::QueryPathKeyElementTrioResultType, - // None, - // ) - // .unwrap() - // .expect("expected successful get_path_query"); - // - // assert_eq!(elements, - // QueryResultElements::from_elements(vec![PathKeyElementTrioResultItem((vec![b" - // test_leaf".to_vec(), b"a".to_vec()], b"d".to_vec(), - // Element::Tree(Some(b"d".to_vec()), None) )), - // PathKeyElementTrioResultItem((vec![b"test_leaf".to_vec(), b"b".to_vec()], - // b"d".to_vec(), Element::Tree(Some(b"j".to_vec()), None) ))])); - // - // let proof = db.prove_query(&path_query, None).unwrap().unwrap(); - // let (hash, result_set) = GroveDb::verify_query_raw(&proof, - // &path_query).unwrap(); assert_eq!(hash, - // db.root_hash(None).unwrap().unwrap()); println!("{}", - // result_set.iter().map(|a| a.to_string()).collect::>().join("| ")); - // assert_eq!(result_set.len(), 2); + let mut query = Query::new(); + query.insert_all(); + query.set_subquery_path(vec![b"d".to_vec()]); + + let path = vec![TEST_LEAF.to_vec()]; + + let path_query = PathQuery::new_unsized(path, query.clone()); + + let (elements, _) = db + .query_raw( + &path_query, + false, + true, + false, + QueryResultType::QueryPathKeyElementTrioResultType, + None, + ) + .unwrap() + .expect("expected successful get_path_query"); + + assert_eq!( + elements, + QueryResultElements::from_elements(vec![ + PathKeyElementTrioResultItem(( + vec![b"test_leaf".to_vec(), b"a".to_vec()], + b"d".to_vec(), + Element::Tree(Some(b"d".to_vec()), None) + )), + PathKeyElementTrioResultItem(( + vec![b"test_leaf".to_vec(), b"b".to_vec()], + b"d".to_vec(), + Element::Tree(Some(b"j".to_vec()), None) + )) + ]) + ); + + let proof = db.prove_query(&path_query, None).unwrap().unwrap(); + let (hash, result_set) = GroveDb::verify_query_raw(&proof, &path_query).unwrap(); + assert_eq!(hash, db.root_hash(None).unwrap().unwrap()); + // println!( + // "{}", + // result_set + // .iter() + // .map(|a| a.to_string()) + // .collect::>() + // .join("| ") + // ); + assert_eq!(result_set.len(), 2); // apply path translation then query let mut query = Query::new();