-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding state for Loan Pool Collateral and other changes.
- Loading branch information
1 parent
a601f9b
commit 7c5c55c
Showing
9 changed files
with
173 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
crates/contract/src/execute/settlement/whitelist_loanpool_contributors.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use cosmwasm_std::{Addr, Order, Storage}; | ||
use cw_storage_plus::Map; | ||
use crate::core::collateral::LoanPoolMarkerCollateral; | ||
use crate::core::constants::LOAN_POOL_COLLATERAL; | ||
use crate::core::error::ContractError; | ||
|
||
pub const COLLATERAL: Map<Addr, LoanPoolMarkerCollateral> = Map::new(LOAN_POOL_COLLATERAL); | ||
|
||
pub fn get(storage: &dyn Storage, marker_address: Addr) -> Result<LoanPoolMarkerCollateral, ContractError> { | ||
Ok(COLLATERAL.load(storage, marker_address)?) | ||
} | ||
|
||
pub fn set(storage: &mut dyn Storage, collateral: &LoanPoolMarkerCollateral) -> Result<(), ContractError> { | ||
Ok(COLLATERAL.save(storage, collateral.marker_address.clone(), collateral)?) | ||
} | ||
|
||
pub fn remove(storage: &mut dyn Storage, commitment_lp: Addr) { | ||
COLLATERAL.remove(storage, commitment_lp); | ||
} | ||
|
||
pub fn exists(storage: &dyn Storage, lp: Addr) -> bool { | ||
COLLATERAL.has(storage, lp) | ||
} | ||
|
||
pub fn get_with_state(storage: &dyn Storage, state: LoanPoolMarkerCollateral) -> Vec<LoanPoolMarkerCollateral> { | ||
let collateral: Vec<LoanPoolMarkerCollateral> = COLLATERAL | ||
.range(storage, None, None, Order::Ascending) | ||
.filter(|item| item.is_ok() && item.as_ref().unwrap().1.marker_denom == state.marker_denom) | ||
.map(|item| item.unwrap().1) | ||
.collect(); | ||
collateral | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use provwasm_mocks::mock_dependencies; | ||
use super::*; | ||
|
||
#[test] | ||
fn test_get_and_set() { | ||
let mut deps = mock_dependencies(&[]); | ||
let marker_address = Addr::unchecked("addr1"); | ||
let collateral = LoanPoolMarkerCollateral::new( | ||
marker_address.clone(), | ||
"denom".to_string(), | ||
100, | ||
Vec::new() | ||
); | ||
|
||
// Test setting collateral | ||
set(&mut deps.storage, &collateral).unwrap(); | ||
let result = get(&deps.storage, marker_address.clone()).unwrap(); | ||
assert_eq!(result, collateral); | ||
|
||
// Test removing collateral | ||
remove(&mut deps.storage, marker_address.clone()); | ||
let result = get(&deps.storage, marker_address.clone()); | ||
assert!(result.is_err()); // Expect an error because the collateral has been removed | ||
} | ||
|
||
#[test] | ||
fn test_exists() { | ||
let mut deps = mock_dependencies(&[]); | ||
let marker_address = Addr::unchecked("addr1"); | ||
let collateral = LoanPoolMarkerCollateral::new( | ||
marker_address.clone(), | ||
"denom".to_string(), | ||
100, | ||
Vec::new() | ||
); | ||
|
||
// Test existence after setting | ||
set(&mut deps.storage, &collateral).unwrap(); | ||
assert!(exists(&deps.storage, marker_address.clone())); | ||
|
||
// Test existence after removing | ||
remove(&mut deps.storage, marker_address.clone()); | ||
assert!(!exists(&deps.storage, marker_address.clone())); | ||
} | ||
|
||
// Add more tests as needed for other functions and edge cases | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters