Skip to content

Commit

Permalink
tests - authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
codehans committed Mar 11, 2024
1 parent ba4da19 commit 4a89f36
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ mod tests {
use cosmwasm_std::{
from_json,
testing::{mock_dependencies, mock_env, mock_info},
Uint128,
};

#[test]
Expand All @@ -149,4 +150,84 @@ mod tests {
from_json(query(deps.as_ref(), mock_env(), QueryMsg::Actions {}).unwrap()).unwrap();
assert_eq!(actions.actions, vec![]);
}
#[test]
fn authorization() {
let mut deps = mock_dependencies();
let info = mock_info("owner", &vec![]);
let msg = InstantiateMsg {
owner: Addr::unchecked("owner"),
revenue_denom: Denom::from("ukuji"),
};
instantiate(deps.as_mut(), mock_env(), info.clone(), msg).unwrap();

execute(
deps.as_mut(),
mock_env(),
info.clone(),
ExecuteMsg::SetOwner(Addr::unchecked("owner-new")),
)
.unwrap();

execute(
deps.as_mut(),
mock_env(),
info.clone(),
ExecuteMsg::SetOwner(Addr::unchecked("owner-new")),
)
.unwrap_err();

let action = Action {
denom: Denom::from("uatom"),
contract: Addr::unchecked("fin"),
limit: Uint128::MAX,
msg: Binary::default(),
};

execute(
deps.as_mut(),
mock_env(),
info.clone(),
ExecuteMsg::SetAction(action.clone()),
)
.unwrap_err();

execute(
deps.as_mut(),
mock_env(),
mock_info("owner-new", &vec![]),
ExecuteMsg::SetAction(action.clone()),
)
.unwrap();

let actions: ActionsResponse =
from_json(query(deps.as_ref(), mock_env(), QueryMsg::Actions {}).unwrap()).unwrap();
assert_eq!(
actions.actions,
vec![ActionResponse {
denom: action.denom.clone(),
contract: action.contract,
limit: action.limit,
msg: action.msg
}]
);

execute(
deps.as_mut(),
mock_env(),
info,
ExecuteMsg::UnsetAction(action.denom.clone()),
)
.unwrap_err();
execute(
deps.as_mut(),
mock_env(),
mock_info("owner-new", &vec![]),
ExecuteMsg::UnsetAction(action.denom),
)
.unwrap();

let actions: ActionsResponse =
from_json(query(deps.as_ref(), mock_env(), QueryMsg::Actions {}).unwrap()).unwrap();
assert_eq!(actions.actions, vec![]);
}
}

0 comments on commit 4a89f36

Please sign in to comment.