Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: debug for op value and flags #278

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions grovedb/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,27 +380,9 @@ impl fmt::Debug for GroveDbOp {
self.key.visualize(key_drawer).unwrap();

let op_dbg = match &self.op {
Op::Insert { element } => match element {
Element::Item(..) => "Insert Item".to_string(),
Element::Reference(..) => "Insert Ref".to_string(),
Element::Tree(..) => "Insert Tree".to_string(),
Element::SumTree(..) => "Insert Sum Tree".to_string(),
Element::SumItem(..) => "Insert Sum Item".to_string(),
},
Op::Replace { element } => match element {
Element::Item(..) => "Replace Item".to_string(),
Element::Reference(..) => "Replace Ref".to_string(),
Element::Tree(..) => "Replace Tree".to_string(),
Element::SumTree(..) => "Replace Sum Tree".to_string(),
Element::SumItem(..) => "Replace Sum Item".to_string(),
},
Op::Patch { element, .. } => match element {
Element::Item(..) => "Patch Item".to_string(),
Element::Reference(..) => "Patch Ref".to_string(),
Element::Tree(..) => "Patch Tree".to_string(),
Element::SumTree(..) => "Patch Sum Tree".to_string(),
Element::SumItem(..) => "Patch Sum Item".to_string(),
},
Op::Insert { element } => format!("Insert {:?}", element),
Op::Replace { element } => format!("Replace {:?}", element),
Op::Patch { element, .. } => format!("Patch {:?}", element),
Op::RefreshReference {
reference_path_type,
max_reference_hop,
Expand Down
5 changes: 2 additions & 3 deletions grovedb/src/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2663,13 +2663,12 @@ fn test_query_b_depends_on_query_a() {
fn test_prove_absent_path_with_intermediate_emtpy_tree() {
// root
// test_leaf (empty)
let mut grovedb = make_test_grovedb();
let grovedb = make_test_grovedb();

// prove the absence of key "book" in ["test_leaf", "invalid"]
let mut query = Query::new();
query.insert_key(b"book".to_vec());
let mut path_query =
PathQuery::new_unsized(vec![TEST_LEAF.to_vec(), b"invalid".to_vec()], query);
let path_query = PathQuery::new_unsized(vec![TEST_LEAF.to_vec(), b"invalid".to_vec()], query);

let proof = grovedb
.prove_query(&path_query)
Expand Down
33 changes: 29 additions & 4 deletions grovedb/src/visualize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ use crate::{
impl Visualize for Element {
fn visualize<W: Write>(&self, mut drawer: Drawer<W>) -> Result<Drawer<W>> {
match self {
Element::Item(value, _) => {
Element::Item(value, flags) => {
drawer.write(b"item: ")?;
drawer = value.visualize(drawer)?;

if let Some(f) = flags {
if !f.is_empty() {
drawer = f.visualize(drawer)?;
}
}
}
Element::SumItem(value, _) => {
Element::SumItem(value, flags) => {
drawer.write(format!("sum_item: {value}").as_bytes())?;

if let Some(f) = flags {
if !f.is_empty() {
drawer = f.visualize(drawer)?;
}
}
}
Element::Reference(_ref, ..) => {
drawer.write(b"ref")?;
Expand All @@ -64,13 +76,26 @@ impl Visualize for Element {
// }
// drawer.write(b"]")?;
}
Element::Tree(root_key, _) => {
Element::Tree(root_key, flags) => {
drawer.write(b"tree: ")?;
drawer = root_key.as_deref().visualize(drawer)?;

if let Some(f) = flags {
if !f.is_empty() {
drawer = f.visualize(drawer)?;
}
}
}
Element::SumTree(root_key, ..) => {
Element::SumTree(root_key, value, flags) => {
drawer.write(b"sum_tree: ")?;
drawer = root_key.as_deref().visualize(drawer)?;
drawer.write(format!(" {value}").as_bytes())?;

if let Some(f) = flags {
if !f.is_empty() {
drawer = f.visualize(drawer)?;
}
}
}
}
Ok(drawer)
Expand Down
Loading