Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Feb 22, 2023
1 parent 2d72a62 commit e6a8e3b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions core/src/ledger/storage_api/collections/lazy_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,11 @@ where
let iter = storage_api::iter_prefix(storage, &self.get_data_prefix())?;
Ok(iter.map(|key_val_res| {
let (key, val) = key_val_res?;
dbg!(&key, &val);
let sub_key = LazyCollection::is_valid_sub_key(self, &key)?
.ok_or(ReadError::UnexpectedlyEmptyStorageKey)
.into_storage_result()?;
dbg!(&sub_key);
Ok((sub_key, val))
}))
}
Expand Down Expand Up @@ -523,6 +525,7 @@ where
mod test {
use super::*;
use crate::ledger::storage::testing::TestWlStorage;
use crate::ledger::storage_api::collections::LazyVec;

#[test]
fn test_lazy_map_basics() -> storage_api::Result<()> {
Expand Down Expand Up @@ -583,4 +586,30 @@ mod test {

Ok(())
}

#[test]
fn test_nested_map() {
let mut storage = TestWlStorage::default();

let key = storage::Key::parse("testing").unwrap();
let nested_map =
NestedMap::<u32, NestedMap<String, LazyVec<u32>>>::open(
key.clone(),
);
nested_map
.at(&0_u32)
.at(&"string1".to_string())
.push(&mut storage, 100_u32)
.unwrap();

storage_api::iter_prefix_bytes(&storage, &key)
.unwrap()
.for_each(|a| {
dbg!(a);
});

nested_map.iter(&storage).unwrap().for_each(|a| {
dbg!(a);
});
}
}
2 changes: 1 addition & 1 deletion core/src/ledger/storage_api/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait LazyCollection {
type SubKeyWithData: Debug;

/// A type of a value in the inner-most collection
type Value: BorshDeserialize;
type Value: BorshDeserialize + Debug;

/// Create or use an existing vector with the given storage `key`.
fn open(key: storage::Key) -> Self;
Expand Down
1 change: 1 addition & 0 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,7 @@ where

validator_slashes_handle(validator).push(storage, slash.clone())?;
slashes_handle()
.get_data_handler()
.at(&processing_epoch)
.at(validator)
.push(storage, slash)?;
Expand Down

0 comments on commit e6a8e3b

Please sign in to comment.