Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valset: better unjail error message when jail lock didn't expire #38

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/tgrade-valset/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ fn execute_unjail(
Ok(Some(expiration)) if (expiration.is_expired(&env.block) || is_admin) => {
JAIL.remove(deps.storage, operator);
}
// Jail not expired and called by non-admin
_ => return Err(AdminError::NotAdmin {}.into()),
// Jail not expired
_ => return Err(ContractError::JailDidNotExpire {}),
}

let res = Response::new()
Expand Down
3 changes: 3 additions & 0 deletions contracts/tgrade-valset/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ pub enum ContractError {

#[error("Cannot unjail validator who's been jailed forever")]
UnjailFromJailForeverForbidden {},

#[error("Jail did not yet expire")]
JailDidNotExpire {},
}

impl From<Ed25519PubkeyConversionError> for ContractError {
Expand Down
10 changes: 2 additions & 8 deletions contracts/tgrade-valset/src/multitest/jailing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,11 @@ fn anyone_can_unjail_self_after_period() {

// I cannot unjail myself before expiration...
let err = suite.unjail(members[0], None).unwrap_err();
assert_eq!(
ContractError::AdminError(AdminError::NotAdmin {}),
err.downcast().unwrap(),
);
assert_eq!(ContractError::JailDidNotExpire {}, err.downcast().unwrap(),);

// ...even directly pointing myself
let err = suite.unjail(members[0], members[0]).unwrap_err();
assert_eq!(
ContractError::AdminError(AdminError::NotAdmin {}),
err.downcast().unwrap(),
);
assert_eq!(ContractError::JailDidNotExpire {}, err.downcast().unwrap(),);

// And I cannot unjail anyone else
let err = suite.unjail(members[0], members[1]).unwrap_err();
Expand Down