Skip to content

Commit

Permalink
fix(minor-coordinator)!: use String instead of Addr in messages (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 authored Sep 17, 2024
1 parent 4d1fc52 commit f575623
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 256 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.

1 change: 1 addition & 0 deletions contracts/coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
error-stack = { workspace = true }
itertools = { workspace = true }
msgs-derive = { workspace = true }
multisig = { workspace = true, features = ["library"] }
report = { workspace = true }
Expand Down
28 changes: 15 additions & 13 deletions contracts/coordinator/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
use std::collections::HashSet;

use cosmwasm_std::{Addr, CosmosMsg};
use cosmwasm_std::CosmosMsg;
use error_stack::{Result, ResultExt};
use router_api::ChainName;

use crate::msg::{ExecuteMsg, QueryMsg};

#[derive(thiserror::Error, Debug, PartialEq)]
pub enum Error {
#[error("failed to execute ReadyToUnbond query at coordinator contract. worker_address: {0}")]
ReadyToUnbond(Addr),
#[error(
"failed to execute ReadyToUnbond query at coordinator contract. verifier_address: {0}"
)]
ReadyToUnbond(String),
}

impl From<QueryMsg> for Error {
fn from(value: QueryMsg) -> Self {
match value {
QueryMsg::ReadyToUnbond { worker_address } => Error::ReadyToUnbond(worker_address),
QueryMsg::ReadyToUnbond { verifier_address } => Error::ReadyToUnbond(verifier_address),
}
}
}
Expand All @@ -34,21 +36,21 @@ impl<'a> Client<'a> {
pub fn register_prover_contract(
&self,
chain_name: ChainName,
new_prover_addr: Addr,
new_prover_addr: String,
) -> CosmosMsg {
self.client.execute(&ExecuteMsg::RegisterProverContract {
chain_name,
new_prover_addr,
})
}

pub fn set_active_verifiers(&self, verifiers: HashSet<Addr>) -> CosmosMsg {
pub fn set_active_verifiers(&self, verifiers: HashSet<String>) -> CosmosMsg {
self.client
.execute(&ExecuteMsg::SetActiveVerifiers { verifiers })
}

pub fn ready_to_unbond(&self, worker_address: Addr) -> Result<bool, Error> {
let msg = QueryMsg::ReadyToUnbond { worker_address };
pub fn ready_to_unbond(&self, verifier_address: String) -> Result<bool, Error> {
let msg = QueryMsg::ReadyToUnbond { verifier_address };
self.client.query(&msg).change_context_lazy(|| msg.into())
}
}
Expand All @@ -67,7 +69,7 @@ mod test {
let (querier, addr) = setup_queries_to_fail();
let client: Client =
client::ContractClient::new(QuerierWrapper::new(&querier), &addr).into();
let res = client.ready_to_unbond(Addr::unchecked("worker"));
let res = client.ready_to_unbond(Addr::unchecked("verifier").to_string());

assert!(res.is_err());
goldie::assert!(res.unwrap_err().to_string());
Expand All @@ -78,7 +80,7 @@ mod test {
let (querier, addr) = setup_queries_to_succeed();
let client: Client =
client::ContractClient::new(QuerierWrapper::new(&querier), &addr).into();
let res = client.ready_to_unbond(Addr::unchecked("worker"));
let res = client.ready_to_unbond(Addr::unchecked("verifier").to_string());

assert!(res.is_ok());
goldie::assert_json!(res.unwrap());
Expand Down Expand Up @@ -109,9 +111,9 @@ mod test {
WasmQuery::Smart { contract_addr, msg } if contract_addr == addr => {
let msg = from_json::<QueryMsg>(msg).unwrap();
match msg {
QueryMsg::ReadyToUnbond { worker_address: _ } => {
Ok(to_json_binary(&true).into()).into()
}
QueryMsg::ReadyToUnbond {
verifier_address: _,
} => Ok(to_json_binary(&true).into()).into(),
}
}
_ => panic!("unexpected query: {:?}", msg),
Expand Down
42 changes: 29 additions & 13 deletions contracts/coordinator/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ mod execute;
mod migrations;
mod query;

use axelar_wasm_std::address::validate_cosmwasm_address;
use axelar_wasm_std::{address, permission_control, FnExt};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, Storage,
};
use error_stack::report;
use itertools::Itertools;

use crate::contract::migrations::v0_2_0;
use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::is_prover_registered;
Expand All @@ -24,8 +25,6 @@ pub fn migrate(
_env: Env,
_msg: Empty,
) -> Result<Response, axelar_wasm_std::error::ContractError> {
v0_2_0::migrate(deps.storage)?;

// this needs to be the last thing to do during migration,
// because previous migration steps should check the old version
cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Expand Down Expand Up @@ -63,8 +62,15 @@ pub fn execute(
ExecuteMsg::RegisterProverContract {
chain_name,
new_prover_addr,
} => execute::register_prover(deps, chain_name, new_prover_addr),
} => {
let new_prover_addr = validate_cosmwasm_address(deps.api, &new_prover_addr)?;
execute::register_prover(deps, chain_name, new_prover_addr)
}
ExecuteMsg::SetActiveVerifiers { verifiers } => {
let verifiers = verifiers
.iter()
.map(|v| validate_cosmwasm_address(deps.api, v))
.try_collect()?;
execute::set_active_verifier_set(deps, info, verifiers)
}
}?
Expand All @@ -84,11 +90,21 @@ fn find_prover_address(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
pub fn query(
deps: Deps,
_env: Env,
msg: QueryMsg,
) -> Result<Binary, axelar_wasm_std::error::ContractError> {
match msg {
QueryMsg::ReadyToUnbond { worker_address } => to_json_binary(
&query::check_verifier_ready_to_unbond(deps, worker_address)?,
)?,
QueryMsg::ReadyToUnbond {
verifier_address: worker_address,
} => {
let worker_address = validate_cosmwasm_address(deps.api, &worker_address)?;
to_json_binary(&query::check_verifier_ready_to_unbond(
deps,
worker_address,
)?)?
}
}
.then(Ok)
}
Expand Down Expand Up @@ -150,7 +166,7 @@ mod tests {
mock_info("not_governance", &[]),
ExecuteMsg::RegisterProverContract {
chain_name: test_setup.chain_name.clone(),
new_prover_addr: test_setup.prover.clone(),
new_prover_addr: test_setup.prover.to_string(),
}
)
.is_err());
Expand All @@ -161,7 +177,7 @@ mod tests {
mock_info(governance, &[]),
ExecuteMsg::RegisterProverContract {
chain_name: test_setup.chain_name.clone(),
new_prover_addr: test_setup.prover.clone(),
new_prover_addr: test_setup.prover.to_string(),
}
)
.is_ok());
Expand All @@ -178,7 +194,7 @@ mod tests {
mock_info(governance, &[]),
ExecuteMsg::RegisterProverContract {
chain_name: test_setup.chain_name.clone(),
new_prover_addr: test_setup.prover.clone(),
new_prover_addr: test_setup.prover.to_string(),
},
)
.unwrap();
Expand All @@ -202,7 +218,7 @@ mod tests {
mock_info("random_address", &[]),
ExecuteMsg::RegisterProverContract {
chain_name: test_setup.chain_name.clone(),
new_prover_addr: test_setup.prover.clone(),
new_prover_addr: test_setup.prover.to_string(),
},
);
assert_eq!(
Expand All @@ -228,7 +244,7 @@ mod tests {
mock_info(governance, &[]),
ExecuteMsg::RegisterProverContract {
chain_name: test_setup.chain_name.clone(),
new_prover_addr: test_setup.prover.clone(),
new_prover_addr: test_setup.prover.to_string(),
},
)
.unwrap();
Expand Down
3 changes: 1 addition & 2 deletions contracts/coordinator/src/contract/migrations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#[allow(deprecated)]
pub mod v0_2_0;

Loading

0 comments on commit f575623

Please sign in to comment.