Skip to content

Commit

Permalink
Merge pull request #61 from osmosis-labs/extra-lockable-tests-2
Browse files Browse the repository at this point in the history
Add extra test of Lockable
  • Loading branch information
maurolacy committed Jun 20, 2023
2 parents 470f726 + 5d454a7 commit 82d449d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/sync/src/locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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::<Result<_, TestsError>>()
.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)
Expand Down

0 comments on commit 82d449d

Please sign in to comment.