diff --git a/rln/src/pm_tree_adapter.rs b/rln/src/pm_tree_adapter.rs index c42ce47..3007c7d 100644 --- a/rln/src/pm_tree_adapter.rs +++ b/rln/src/pm_tree_adapter.rs @@ -246,7 +246,8 @@ impl ZerokitMerkleTree for PmTree { let data = self.tree.db.get(METADATA_KEY)?; if data.is_none() { - return Err(Report::msg("metadata does not exist")); + // send empty Metadata + return Ok(Vec::new()); } Ok(data.unwrap()) } diff --git a/rln/src/public.rs b/rln/src/public.rs index 746ac0d..99a5b98 100644 --- a/rln/src/public.rs +++ b/rln/src/public.rs @@ -2108,4 +2108,19 @@ mod test { assert_eq!(arbitrary_metadata, received_metadata); } + + #[test] + fn test_empty_metadata() { + let tree_height = TEST_TREE_HEIGHT; + + let input_buffer = + Cursor::new(json!({ "resources_folder": TEST_RESOURCES_FOLDER }).to_string()); + let rln = RLN::new(tree_height, input_buffer).unwrap(); + + let mut buffer = Cursor::new(Vec::::new()); + rln.get_metadata(&mut buffer).unwrap(); + let received_metadata = buffer.into_inner(); + + assert_eq!(received_metadata.len(), 0); + } } diff --git a/rln/tests/ffi.rs b/rln/tests/ffi.rs index 8b72c2e..2b2c7a7 100644 --- a/rln/tests/ffi.rs +++ b/rln/tests/ffi.rs @@ -1209,7 +1209,7 @@ mod test { } #[test] - fn test_metadata() { + fn test_valid_metadata() { // We create a RLN instance let tree_height = TEST_TREE_HEIGHT; @@ -1235,4 +1235,25 @@ mod test { assert_eq!(result_data, seed_bytes.to_vec()); } + + #[test] + fn test_empty_metadata() { + // We create a RLN instance + let tree_height = TEST_TREE_HEIGHT; + + let mut rln_pointer = MaybeUninit::<*mut RLN>::uninit(); + let input_config = json!({ "resources_folder": TEST_RESOURCES_FOLDER }).to_string(); + let input_buffer = &Buffer::from(input_config.as_bytes()); + let success = new(tree_height, input_buffer, rln_pointer.as_mut_ptr()); + assert!(success, "RLN object creation failed"); + let rln_pointer = unsafe { &mut *rln_pointer.assume_init() }; + + let mut output_buffer = MaybeUninit::::uninit(); + let success = get_metadata(rln_pointer, output_buffer.as_mut_ptr()); + assert!(success, "get_metadata call failed"); + + let output_buffer = unsafe { output_buffer.assume_init() }; + + assert_eq!(output_buffer.len, 0); + } }