diff --git a/packages/sync/src/locks.rs b/packages/sync/src/locks.rs index 9d0e8591..139d4749 100644 --- a/packages/sync/src/locks.rs +++ b/packages/sync/src/locks.rs @@ -245,6 +245,7 @@ mod tests { mod tests_plus { use super::*; + use crate::locks::tests_plus::MaybeCollateral::{Collateral, Locked}; use cosmwasm_std::{testing::MockStorage, StdError, Uint128}; use cw_storage_plus::{Item, Map}; @@ -282,6 +283,12 @@ mod tests_plus { pub total_slashable: Uint128, } + #[cw_serde] + enum MaybeCollateral { + Collateral(Uint128), + Locked { user: String }, + } + #[test] fn modify_item_with_locks() { let mut store = MockStorage::new(); @@ -539,6 +546,21 @@ mod tests_plus { .unwrap(); assert_eq!(collaterals.len(), 2); + // Finally, we can also report the locked users + let maybe_collaterals: Vec<_> = USERS + .range(&store, None, None, cosmwasm_std::Order::Ascending) + .map(|item| { + item.map(|(user, user_lock)| { + user_lock + .read() + .map(|user| Ok(Collateral(user.collateral))) + .unwrap_or(Ok(Locked { user })) // Report locked collateral + })? // Surface errors + }) + .collect::>() + .unwrap(); + assert_eq!(maybe_collaterals.len(), 3); + // We can get count (kind of edge case bug, but I don't think we can change this or it matters) let num_users = USERS .range(&store, None, None, cosmwasm_std::Order::Ascending)