Skip to content

Commit

Permalink
feat(nexus-gateway): add permission control to nexus-gateway (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgorenflo authored Jul 23, 2024
1 parent 7a7f9bf commit 8ee688f
Show file tree
Hide file tree
Showing 27 changed files with 434 additions and 501 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions contracts/coordinator/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn migrate(
deps: DepsMut,
_env: Env,
_msg: Empty,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
v0_2_0::migrate(deps.storage)?;

// this needs to be the last thing to do during migration,
Expand All @@ -39,7 +39,7 @@ pub fn instantiate(
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let governance = deps.api.addr_validate(&msg.governance_address)?;
Expand All @@ -54,7 +54,7 @@ pub fn execute(
_env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
match msg.ensure_permissions(
deps.storage,
&info.sender,
Expand Down Expand Up @@ -208,10 +208,12 @@ mod tests {
);
assert_eq!(
res.unwrap_err().to_string(),
axelar_wasm_std::ContractError::from(permission_control::Error::PermissionDenied {
expected: Permission::Governance.into(),
actual: Permission::NoPrivilege.into()
})
axelar_wasm_std::error::ContractError::from(
permission_control::Error::PermissionDenied {
expected: Permission::Governance.into(),
actual: Permission::NoPrivilege.into()
}
)
.to_string()
);
}
Expand Down Expand Up @@ -257,9 +259,11 @@ mod tests {
},
);
assert!(res.unwrap_err().to_string().contains(
&axelar_wasm_std::ContractError::from(permission_control::Error::WhitelistNotFound {
sender: test_setup.prover
})
&axelar_wasm_std::error::ContractError::from(
permission_control::Error::WhitelistNotFound {
sender: test_setup.prover
}
)
.to_string()
));
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/coordinator/src/contract/migrations/v0_2_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {

fn instantiate_0_2_0_contract(
deps: DepsMut,
) -> Result<InstantiateMsg, axelar_wasm_std::ContractError> {
) -> Result<InstantiateMsg, axelar_wasm_std::error::ContractError> {
let governance = "governance";

let msg = InstantiateMsg {
Expand Down
8 changes: 4 additions & 4 deletions contracts/gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn migrate(
deps: DepsMut,
_env: Env,
_msg: Empty,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
// any version checks should be done before here

cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Expand All @@ -33,7 +33,7 @@ pub fn instantiate(
env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Ok(internal::instantiate(deps, env, info, msg)?)
Expand All @@ -45,7 +45,7 @@ pub fn execute(
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
let msg = msg.ensure_permissions(deps.storage, &info.sender)?;
Ok(internal::execute(deps, env, info, msg)?)
}
Expand All @@ -55,7 +55,7 @@ pub fn query(
deps: Deps,
env: Env,
msg: QueryMsg,
) -> Result<Binary, axelar_wasm_std::ContractError> {
) -> Result<Binary, axelar_wasm_std::error::ContractError> {
Ok(internal::query(deps, env, msg)?)
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/gateway/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::fmt::Debug;
use std::fs::File;
use std::iter;

use axelar_wasm_std::{ContractError, VerificationStatus};
use axelar_wasm_std::error::ContractError;
use axelar_wasm_std::VerificationStatus;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info, MockQuerier};
#[cfg(not(feature = "generate_golden_files"))]
use cosmwasm_std::Response;
Expand Down
51 changes: 28 additions & 23 deletions contracts/multisig-prover/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn instantiate(
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let config = Config {
Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn execute(
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
match msg.ensure_permissions(deps.storage, &info.sender)? {
ExecuteMsg::ConstructProof { message_ids } => {
Ok(execute::construct_proof(deps, message_ids)?)
Expand All @@ -83,20 +83,20 @@ pub fn reply(
deps: DepsMut,
_env: Env,
reply: Reply,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
match reply.id {
START_MULTISIG_REPLY_ID => reply::start_multisig_reply(deps, reply),
_ => unreachable!("unknown reply ID"),
}
.map_err(axelar_wasm_std::ContractError::from)
.map_err(axelar_wasm_std::error::ContractError::from)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(
deps: Deps,
_env: Env,
msg: QueryMsg,
) -> Result<Binary, axelar_wasm_std::ContractError> {
) -> Result<Binary, axelar_wasm_std::error::ContractError> {
match msg {
QueryMsg::GetProof {
multisig_session_id,
Expand All @@ -105,15 +105,15 @@ pub fn query(
QueryMsg::NextVerifierSet {} => to_json_binary(&query::next_verifier_set(deps)?),
}
.change_context(ContractError::SerializeResponse)
.map_err(axelar_wasm_std::ContractError::from)
.map_err(axelar_wasm_std::error::ContractError::from)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(
deps: DepsMut,
_env: Env,
_msg: Empty,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
migrations::v0_6_0::migrate(deps.storage)?;

cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Expand Down Expand Up @@ -185,15 +185,15 @@ mod tests {

fn execute_update_verifier_set(
deps: DepsMut,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
let msg = ExecuteMsg::UpdateVerifierSet {};
execute(deps, mock_env(), mock_info(ADMIN, &[]), msg)
}

fn confirm_verifier_set(
deps: DepsMut,
sender: Addr,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
let msg = ExecuteMsg::ConfirmVerifierSet {};
execute(deps, mock_env(), mock_info(sender.as_str(), &[]), msg)
}
Expand All @@ -202,7 +202,7 @@ mod tests {
deps: DepsMut,
sender: Addr,
new_signing_threshold: MajorityThreshold,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
let msg = ExecuteMsg::UpdateSigningThreshold {
new_signing_threshold,
};
Expand All @@ -213,15 +213,15 @@ mod tests {
deps: DepsMut,
sender: &str,
new_admin_address: String,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
let msg = ExecuteMsg::UpdateAdmin { new_admin_address };
execute(deps, mock_env(), mock_info(sender, &[]), msg)
}

fn execute_construct_proof(
deps: DepsMut,
message_ids: Option<Vec<CrossChainId>>,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
let message_ids = message_ids.unwrap_or_else(|| {
test_data::messages()
.into_iter()
Expand All @@ -233,7 +233,9 @@ mod tests {
execute(deps, mock_env(), mock_info(RELAYER, &[]), msg)
}

fn reply_construct_proof(deps: DepsMut) -> Result<Response, axelar_wasm_std::ContractError> {
fn reply_construct_proof(
deps: DepsMut,
) -> Result<Response, axelar_wasm_std::error::ContractError> {
let session_id = to_json_binary(&MULTISIG_SESSION_ID).unwrap();

let response = SubMsgResponse {
Expand All @@ -259,7 +261,7 @@ mod tests {
fn query_get_proof(
deps: Deps,
multisig_session_id: Option<Uint64>,
) -> Result<GetProofResponse, axelar_wasm_std::ContractError> {
) -> Result<GetProofResponse, axelar_wasm_std::error::ContractError> {
let multisig_session_id = match multisig_session_id {
Some(id) => id,
None => MULTISIG_SESSION_ID,
Expand All @@ -277,7 +279,7 @@ mod tests {

fn query_get_verifier_set(
deps: Deps,
) -> Result<Option<VerifierSetResponse>, axelar_wasm_std::ContractError> {
) -> Result<Option<VerifierSetResponse>, axelar_wasm_std::error::ContractError> {
query(deps, mock_env(), QueryMsg::CurrentVerifierSet {}).map(|res| from_json(res).unwrap())
}

Expand Down Expand Up @@ -415,10 +417,12 @@ mod tests {
assert!(res.is_err());
assert_eq!(
res.unwrap_err().to_string(),
axelar_wasm_std::ContractError::from(permission_control::Error::PermissionDenied {
expected: Permission::Elevated.into(),
actual: Permission::NoPrivilege.into()
})
axelar_wasm_std::error::ContractError::from(
permission_control::Error::PermissionDenied {
expected: Permission::Elevated.into(),
actual: Permission::NoPrivilege.into()
}
)
.to_string()
);
}
Expand Down Expand Up @@ -557,7 +561,8 @@ mod tests {
assert!(res.is_err());
assert_eq!(
res.unwrap_err().to_string(),
axelar_wasm_std::ContractError::from(ContractError::VerifierSetUnchanged).to_string()
axelar_wasm_std::error::ContractError::from(ContractError::VerifierSetUnchanged)
.to_string()
);
}

Expand All @@ -582,7 +587,7 @@ mod tests {
assert!(res.is_err());
assert_eq!(
res.unwrap_err().to_string(),
axelar_wasm_std::ContractError::from(ContractError::VerifierSetNotConfirmed)
axelar_wasm_std::error::ContractError::from(ContractError::VerifierSetNotConfirmed)
.to_string()
);
}
Expand Down Expand Up @@ -612,7 +617,7 @@ mod tests {
assert!(res.is_err());
assert_eq!(
res.unwrap_err().to_string(),
axelar_wasm_std::ContractError::from(ContractError::VerifierSetNotConfirmed)
axelar_wasm_std::error::ContractError::from(ContractError::VerifierSetNotConfirmed)
.to_string()
);
}
Expand Down Expand Up @@ -669,7 +674,7 @@ mod tests {
assert!(res.is_err());
assert_eq!(
res.unwrap_err().to_string(),
axelar_wasm_std::ContractError::from(ContractError::NoVerifierSet).to_string()
axelar_wasm_std::error::ContractError::from(ContractError::NoVerifierSet).to_string()
);
}

Expand Down
7 changes: 4 additions & 3 deletions contracts/multisig-prover/src/contract/migrations/v0_6_0.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![allow(deprecated)]

use axelar_wasm_std::error::ContractError;
use axelar_wasm_std::hash::Hash;
use axelar_wasm_std::{permission_control, ContractError, MajorityThreshold};
use axelar_wasm_std::{permission_control, MajorityThreshold};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Storage};
use cw_storage_plus::Item;
Expand Down Expand Up @@ -174,7 +175,7 @@ mod tests {
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, axelar_wasm_std::ContractError> {
) -> Result<Response, axelar_wasm_std::error::ContractError> {
cw2::set_contract_version(deps.storage, CONTRACT_NAME, v0_6_0::BASE_VERSION)?;

let config = make_config(&deps, msg)?;
Expand All @@ -186,7 +187,7 @@ mod tests {
fn make_config(
deps: &DepsMut,
msg: InstantiateMsg,
) -> Result<v0_6_0::Config, axelar_wasm_std::ContractError> {
) -> Result<v0_6_0::Config, axelar_wasm_std::error::ContractError> {
let admin = deps.api.addr_validate(&msg.admin_address)?;
let governance = deps.api.addr_validate(&msg.governance_address)?;
let gateway = deps.api.addr_validate(&msg.gateway_address)?;
Expand Down
Loading

0 comments on commit 8ee688f

Please sign in to comment.