diff --git a/sc_core/src/blob_utils.rs b/sc_core/src/blob_utils.rs index 5da5625..3f9a950 100644 --- a/sc_core/src/blob_utils.rs +++ b/sc_core/src/blob_utils.rs @@ -80,3 +80,54 @@ pub fn compare_blob_lists( changed_ids } +#[cfg(test)] +mod tests { + use super::*; + use serde::Serialize; + + const TEST_BLOB_SIZE: usize = 256; // Define a test blob size for simplicity + static SC_DATA_BLOB_SIZE: usize = TEST_BLOB_SIZE; + + #[derive(Serialize)] + struct TestState { + a: u32, + b: u32, + } + + #[test] + fn test_produce_blob_list_from_sc_public_state() { + let state = TestState { a: 42, b: 99 }; + let result = produce_blob_list_from_sc_public_state(&state).unwrap(); + assert!(!result.is_empty()); + } + + #[test] + fn test_compare_blob_lists_created() { + let old_list: Vec = vec![]; + let new_list: Vec = vec![[1; SC_DATA_BLOB_SIZE].into()]; + + let changes = compare_blob_lists(&old_list, &new_list); + assert_eq!(changes.len(), 1); + assert!(matches!(changes[0], DataBlobChangeVariant::Created { .. })); + } + + #[test] + fn test_compare_blob_lists_deleted() { + let old_list: Vec = vec![[1; SC_DATA_BLOB_SIZE].into()]; + let new_list: Vec = vec![]; + + let changes = compare_blob_lists(&old_list, &new_list); + assert_eq!(changes.len(), 1); + assert!(matches!(changes[0], DataBlobChangeVariant::Deleted { .. })); + } + + #[test] + fn test_compare_blob_lists_modified() { + let old_list: Vec = vec![[1; SC_DATA_BLOB_SIZE].into()]; + let new_list: Vec = vec![[2; SC_DATA_BLOB_SIZE].into()]; + + let changes = compare_blob_lists(&old_list, &new_list); + assert_eq!(changes.len(), 1); + assert!(matches!(changes[0], DataBlobChangeVariant::Modified { .. })); + } +}