diff --git a/src/kernel_sdk/tezos_smart_rollup_mock/src/state/mod.rs b/src/kernel_sdk/tezos_smart_rollup_mock/src/state/mod.rs index 1c271af053d4c1f45495114567204b16e7c7be6c..d8fdabde1512c5a10a65afc59328237eade291af 100644 --- a/src/kernel_sdk/tezos_smart_rollup_mock/src/state/mod.rs +++ b/src/kernel_sdk/tezos_smart_rollup_mock/src/state/mod.rs @@ -237,6 +237,13 @@ impl HostState { .and_then(|n| n.inner.keys().nth(index as usize)) .ok_or(Error::StoreInvalidSubkeyIndex) .cloned() + .map(|n| { + if n == store::VALUE_NAME { + String::new() + } else { + n + } + }) } pub(crate) fn handle_store_move( @@ -496,6 +503,13 @@ mod tests { // Assert assert_eq!(10, result, "Expected 10 subkeys of prefix"); + + // Value is included in the count + state + .handle_store_write(prefix.as_bytes(), 0, &[1, 2, 3]) + .unwrap(); + let with_value = state.handle_store_list_size(prefix.as_bytes()).unwrap(); + assert_eq!(11, with_value, "Expected 10 subkeys of prefix, plus value"); } #[test] @@ -537,6 +551,25 @@ mod tests { assert_eq!(results, expected, "Expected stable store_list_get"); } + #[test] + fn store_list_get_value() { + // Arrange + let mut state = HostState::default(); + let prefix = "/hello".as_bytes(); + + state.handle_store_write(prefix, 0, &[]).unwrap(); + + // Act + let result = state.handle_store_list_get(prefix, 0).unwrap(); + + // Assert + assert_eq!( + result, + "".to_string(), + "Value should return empty string as subkey" + ); + } + #[test] fn store_move() { // Arrange diff --git a/src/kernel_sdk/tezos_smart_rollup_mock/src/state/store.rs b/src/kernel_sdk/tezos_smart_rollup_mock/src/state/store.rs index 0ca373be66953ca2c5eb2be48abcae151f97bfac..ae56aa9917372b3a75c55e784300f4725a976d8c 100644 --- a/src/kernel_sdk/tezos_smart_rollup_mock/src/state/store.rs +++ b/src/kernel_sdk/tezos_smart_rollup_mock/src/state/store.rs @@ -21,6 +21,8 @@ pub(crate) struct Node { pub(crate) inner: HashMap>, } +pub(crate) const VALUE_NAME: &str = "@"; + impl Node { fn print(&self, prefix: &str, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if let Some(v) = &self.value { @@ -135,11 +137,13 @@ impl Store { pub fn set_value(&mut self, path: &str, value: Vec) { if let Some(mut node) = self.node_from_path_mut(path) { node.value = Some(value); + node.inner.insert(VALUE_NAME.to_string(), Box::default()); } else { - let node = Node { + let mut node = Node { inner: HashMap::default(), value: Some(value), }; + node.inner.insert(VALUE_NAME.to_string(), Box::default()); self.node_insert(path, node); } }