From 319e8ba7d11194dab6c97756ade0acbdbd897223 Mon Sep 17 00:00:00 2001 From: Jake Hartnell Date: Sat, 19 Aug 2023 14:55:47 -0700 Subject: [PATCH] More test coverage --- .../dao-voting-native-staked/src/tests.rs | 27 ++++++++++++++++++- packages/cw-hooks/src/lib.rs | 10 ++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/contracts/voting/dao-voting-native-staked/src/tests.rs b/contracts/voting/dao-voting-native-staked/src/tests.rs index 885a158a3..9a8fef950 100644 --- a/contracts/voting/dao-voting-native-staked/src/tests.rs +++ b/contracts/voting/dao-voting-native-staked/src/tests.rs @@ -1306,7 +1306,7 @@ fn test_update_active_threshold() { let resp: ActiveThresholdResponse = app .wrap() - .query_wasm_smart(addr, &QueryMsg::ActiveThreshold {}) + .query_wasm_smart(addr.clone(), &QueryMsg::ActiveThreshold {}) .unwrap(); assert_eq!( resp.active_threshold, @@ -1314,6 +1314,31 @@ fn test_update_active_threshold() { count: Uint128::new(100) }) ); + + // Can't set threshold to invalid value + let msg = ExecuteMsg::UpdateActiveThreshold { + new_threshold: Some(ActiveThreshold::Percentage { + percent: Decimal::percent(120), + }), + }; + let err: ContractError = app + .execute_contract(Addr::unchecked(DAO_ADDR), addr.clone(), &msg, &[]) + .unwrap_err() + .downcast() + .unwrap(); + assert_eq!(err, ContractError::InvalidActivePercentage {}); + + // Remove threshold + let msg = ExecuteMsg::UpdateActiveThreshold { + new_threshold: None, + }; + app.execute_contract(Addr::unchecked(DAO_ADDR), addr.clone(), &msg, &[]) + .unwrap(); + let resp: ActiveThresholdResponse = app + .wrap() + .query_wasm_smart(addr, &QueryMsg::ActiveThreshold {}) + .unwrap(); + assert_eq!(resp.active_threshold, None); } #[test] diff --git a/packages/cw-hooks/src/lib.rs b/packages/cw-hooks/src/lib.rs index 59560154d..fdbf43577 100644 --- a/packages/cw-hooks/src/lib.rs +++ b/packages/cw-hooks/src/lib.rs @@ -189,8 +189,16 @@ mod tests { )] ); + // Query hooks returns all hooks added let HooksResponse { hooks: the_hooks } = hooks.query_hooks(deps.as_ref()).unwrap(); - assert_eq!(the_hooks, vec![addr!("meow")]); + + // Remove last hook + hooks.remove_hook(&mut deps.storage, addr!("meow")).unwrap(); + + // Query hooks returns empty vector if no hooks added + let HooksResponse { hooks: the_hooks } = hooks.query_hooks(deps.as_ref()).unwrap(); + let no_hooks: Vec = vec![]; + assert_eq!(the_hooks, no_hooks); } }