Skip to content

Commit

Permalink
More test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell committed Aug 20, 2023
1 parent cb37559 commit 319e8ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
27 changes: 26 additions & 1 deletion contracts/voting/dao-voting-native-staked/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,14 +1306,39 @@ 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,
Some(ActiveThreshold::AbsoluteCount {
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]
Expand Down
10 changes: 9 additions & 1 deletion packages/cw-hooks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = vec![];
assert_eq!(the_hooks, no_hooks);
}
}

0 comments on commit 319e8ba

Please sign in to comment.