mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-06 15:23:10 +00:00
Merge pull request #54 from vacp2p/bug-fix-sc-storage
SC public stage storage testing
This commit is contained in:
commit
a893cce2f7
@ -49,7 +49,7 @@ pub fn produce_blob_list_from_sc_public_state<S: Serialize>(
|
|||||||
let ser_data = serde_json::to_vec(state)?;
|
let ser_data = serde_json::to_vec(state)?;
|
||||||
|
|
||||||
//`ToDo` Replace with `next_chunk` usage, when feature stabilizes in Rust
|
//`ToDo` Replace with `next_chunk` usage, when feature stabilizes in Rust
|
||||||
for i in 0..(ser_data.len() / SC_DATA_BLOB_SIZE) {
|
for i in 0..=(ser_data.len() / SC_DATA_BLOB_SIZE) {
|
||||||
let next_chunk: Vec<u8>;
|
let next_chunk: Vec<u8>;
|
||||||
|
|
||||||
if (i + 1) * SC_DATA_BLOB_SIZE < ser_data.len() {
|
if (i + 1) * SC_DATA_BLOB_SIZE < ser_data.len() {
|
||||||
@ -116,3 +116,69 @@ pub fn compare_blob_lists(
|
|||||||
|
|
||||||
changed_ids
|
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;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_produce_blob_from_fit_vec() {
|
||||||
|
let data = (0..0 + 255).collect();
|
||||||
|
let blob = produce_blob_from_fit_vec(data);
|
||||||
|
assert_eq!(blob[..4], [0, 1, 2, 3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn test_produce_blob_from_fit_vec_panic() {
|
||||||
|
let data = vec![0; SC_DATA_BLOB_SIZE + 1];
|
||||||
|
let _ = produce_blob_from_fit_vec(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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<DataBlob> = vec![];
|
||||||
|
let new_list: Vec<DataBlob> = vec![[1; SC_DATA_BLOB_SIZE]];
|
||||||
|
|
||||||
|
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<DataBlob> = vec![[1; SC_DATA_BLOB_SIZE]];
|
||||||
|
let new_list: Vec<DataBlob> = 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<DataBlob> = vec![[1; SC_DATA_BLOB_SIZE]];
|
||||||
|
let new_list: Vec<DataBlob> = vec![[2; SC_DATA_BLOB_SIZE]];
|
||||||
|
|
||||||
|
let changes = compare_blob_lists(&old_list, &new_list);
|
||||||
|
assert_eq!(changes.len(), 1);
|
||||||
|
assert!(matches!(changes[0], DataBlobChangeVariant::Modified { .. }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user