Skip to content

Commit

Permalink
Revert "Remove Staking::Withdraw support / tests"
Browse files Browse the repository at this point in the history
This reverts commit dba6152.
  • Loading branch information
maurolacy committed Apr 21, 2021
1 parent bf7f8c6 commit 9daea73
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions contracts/cw1-subkeys/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ pub fn check_staking_permissions(
return Err(ContractError::ReDelegatePerm {});
}
}
StakingMsg::Withdraw { .. } => {
if !permissions.withdraw {
return Err(ContractError::WithdrawPerm {});
}
}
s => panic!("Unsupported staking message: {:?}", s),
}
Ok(true)
Expand Down Expand Up @@ -1257,11 +1262,17 @@ mod tests {
amount: coin1,
}
.into()];
let msg_withdraw = vec![StakingMsg::Withdraw {
validator: "validator1".into(),
recipient: None,
}
.into()];

let msgs = vec![
msg_delegate.clone(),
msg_redelegate.clone(),
msg_undelegate.clone(),
msg_withdraw.clone(),
];

// spender1 can execute
Expand Down Expand Up @@ -1327,6 +1338,13 @@ mod tests {
},
);
assert!(res.is_ok());
let res = execute(
deps.as_mut(),
mock_env(),
info,
ExecuteMsg::Execute { msgs: msg_withdraw },
);
assert!(res.is_err())
}

// tests permissions and allowances are independent features and does not affect each other
Expand Down Expand Up @@ -1444,6 +1462,10 @@ mod tests {
validator: anyone.to_string(),
amount: coin(70000, "ureef"),
});
let staking_withdraw_msg = CosmosMsg::Staking(StakingMsg::Withdraw {
validator: anyone.to_string(),
recipient: None,
});

// owner can send big or small
let res = query_can_execute(deps.as_ref(), owner.to_string(), send_msg.clone()).unwrap();
Expand Down Expand Up @@ -1475,6 +1497,13 @@ mod tests {
)
.unwrap();
assert_eq!(res.can_execute, true);
let res = query_can_execute(
deps.as_ref(),
spender.to_string(),
staking_withdraw_msg.clone(),
)
.unwrap();
assert_eq!(res.can_execute, false);

// random person cannot do anything
let res = query_can_execute(deps.as_ref(), anyone.to_string(), send_msg).unwrap();
Expand All @@ -1484,5 +1513,8 @@ mod tests {
let res =
query_can_execute(deps.as_ref(), anyone.to_string(), staking_delegate_msg).unwrap();
assert_eq!(res.can_execute, false);
let res =
query_can_execute(deps.as_ref(), anyone.to_string(), staking_withdraw_msg).unwrap();
assert_eq!(res.can_execute, false);
}
}

0 comments on commit 9daea73

Please sign in to comment.