Skip to content

Commit d7b4ca1

Browse files
authored
refactor: replace deprecated to_binary and from_binary calls (#303)
1 parent 15c4344 commit d7b4ca1

File tree

30 files changed

+142
-127
lines changed

30 files changed

+142
-127
lines changed

contracts/aggregate-verifier/src/client.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use axelar_wasm_std::utils::TryMapExt;
22
use axelar_wasm_std::{FnExt, VerificationStatus};
33
use connection_router_api::{CrossChainId, Message};
4-
use cosmwasm_std::{to_binary, Addr, QuerierWrapper, QueryRequest, WasmMsg, WasmQuery};
4+
use cosmwasm_std::{to_json_binary, Addr, QuerierWrapper, QueryRequest, WasmMsg, WasmQuery};
55
use error_stack::{Result, ResultExt};
66
use serde::de::DeserializeOwned;
77
use std::collections::HashMap;
@@ -15,7 +15,7 @@ impl Verifier<'_> {
1515
fn execute(&self, msg: &crate::msg::ExecuteMsg) -> WasmMsg {
1616
WasmMsg::Execute {
1717
contract_addr: self.address.to_string(),
18-
msg: to_binary(msg).expect("msg should always be serializable"),
18+
msg: to_json_binary(msg).expect("msg should always be serializable"),
1919
funds: vec![],
2020
}
2121
}
@@ -24,7 +24,7 @@ impl Verifier<'_> {
2424
self.querier
2525
.query(&QueryRequest::Wasm(WasmQuery::Smart {
2626
contract_addr: self.address.to_string(),
27-
msg: to_binary(&msg).expect("msg should always be serializable"),
27+
msg: to_json_binary(&msg).expect("msg should always be serializable"),
2828
}))
2929
.change_context(Error::QueryVerifier)
3030
}
@@ -120,7 +120,7 @@ mod tests {
120120
fn verifier_returns_error_on_return_type_mismatch() {
121121
let mut querier = MockQuerier::default();
122122
querier.update_wasm(|_| {
123-
Ok(to_binary(&CrossChainId::from_str("eth:0x1234").unwrap()).into()).into()
123+
Ok(to_json_binary(&CrossChainId::from_str("eth:0x1234").unwrap()).into()).into()
124124
});
125125

126126
let verifier = Verifier {

contracts/aggregate-verifier/src/contract.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use connection_router_api::CrossChainId;
33
#[cfg(not(feature = "library"))]
44
use cosmwasm_std::entry_point;
55
use cosmwasm_std::{
6-
from_binary, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, QueryRequest, Reply, Response,
7-
StdResult, WasmQuery,
6+
from_json, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, QueryRequest, Reply,
7+
Response, StdResult, WasmQuery,
88
};
99
use cw_utils::{parse_reply_execute_data, MsgExecuteContractResponse};
1010

@@ -45,7 +45,7 @@ pub fn execute(
4545
}
4646

4747
pub mod execute {
48-
use cosmwasm_std::{to_binary, SubMsg, WasmMsg};
48+
use cosmwasm_std::{to_json_binary, SubMsg, WasmMsg};
4949

5050
use connection_router_api::Message;
5151

@@ -59,7 +59,7 @@ pub mod execute {
5959
Ok(Response::new().add_submessage(SubMsg::reply_on_success(
6060
WasmMsg::Execute {
6161
contract_addr: verifier.to_string(),
62-
msg: to_binary(&voting_msg::ExecuteMsg::VerifyMessages { messages: msgs })?,
62+
msg: to_json_binary(&voting_msg::ExecuteMsg::VerifyMessages { messages: msgs })?,
6363
funds: vec![],
6464
},
6565
VERIFY_REPLY,
@@ -79,7 +79,7 @@ pub fn reply(
7979
match parse_reply_execute_data(reply) {
8080
Ok(MsgExecuteContractResponse { data: Some(data) }) => {
8181
// check format of data
82-
let _: Vec<(CrossChainId, VerificationStatus)> = from_binary(&data)?;
82+
let _: Vec<(CrossChainId, VerificationStatus)> = from_json(&data)?;
8383

8484
// only one verifier, so just return the response as is
8585
Ok(Response::new().set_data(data))
@@ -102,7 +102,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
102102
let verifier = CONFIG.load(deps.storage)?.verifier;
103103
deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
104104
contract_addr: verifier.to_string(),
105-
msg: to_binary(&voting_msg::QueryMsg::GetMessagesStatus { messages })?,
105+
msg: to_json_binary(&voting_msg::QueryMsg::GetMessagesStatus { messages })?,
106106
}))
107107
}
108108
}

contracts/aggregate-verifier/tests/mock.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use aggregate_verifier::error::ContractError;
22
use axelar_wasm_std::VerificationStatus;
33
use connection_router_api::{CrossChainId, Message};
44
use cosmwasm_schema::cw_serde;
5-
use cosmwasm_std::{to_binary, Addr, DepsMut, Env, MessageInfo, Response};
5+
use cosmwasm_std::{to_json_binary, Addr, DepsMut, Env, MessageInfo, Response};
66
use cw_multi_test::{App, ContractWrapper, Executor};
77
use cw_storage_plus::Map;
88

@@ -33,7 +33,7 @@ pub fn mock_verifier_execute(
3333
None => res.push((m.cc_id, VerificationStatus::None)),
3434
}
3535
}
36-
Ok(Response::new().set_data(to_binary(&res)?))
36+
Ok(Response::new().set_data(to_json_binary(&res)?))
3737
}
3838
MockVotingVerifierExecuteMsg::MessagesVerified { messages } => {
3939
for m in messages {
@@ -64,7 +64,7 @@ pub fn make_mock_voting_verifier(app: &mut App) -> Addr {
6464
|_, _, _, _: MockVotingVerifierInstantiateMsg| {
6565
Ok::<Response, ContractError>(Response::new())
6666
},
67-
|_, _, _: aggregate_verifier::msg::QueryMsg| to_binary(&()),
67+
|_, _, _: aggregate_verifier::msg::QueryMsg| to_json_binary(&()),
6868
);
6969
let code_id = app.store_code(Box::new(code));
7070

contracts/aggregate-verifier/tests/test.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use aggregate_verifier::msg::ExecuteMsg;
22
use axelar_wasm_std::VerificationStatus;
33
use connection_router_api::{CrossChainId, Message, ID_SEPARATOR};
4-
use cosmwasm_std::from_binary;
4+
use cosmwasm_std::from_json;
55
use cosmwasm_std::Addr;
66
use cw_multi_test::{App, Executor};
77
use integration_tests::contract::Contract;
@@ -46,7 +46,7 @@ fn verify_messages_empty() {
4646
&ExecuteMsg::VerifyMessages { messages: vec![] },
4747
)
4848
.unwrap();
49-
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
49+
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(&res.data.unwrap()).unwrap();
5050
assert_eq!(ret, vec![]);
5151
}
5252

@@ -70,7 +70,7 @@ fn verify_messages_not_verified() {
7070
},
7171
)
7272
.unwrap();
73-
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
73+
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(&res.data.unwrap()).unwrap();
7474
assert_eq!(
7575
ret,
7676
messages
@@ -102,7 +102,7 @@ fn verify_messages_verified() {
102102
},
103103
)
104104
.unwrap();
105-
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
105+
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(&res.data.unwrap()).unwrap();
106106
assert_eq!(
107107
ret,
108108
messages
@@ -135,7 +135,7 @@ fn verify_messages_mixed_status() {
135135
},
136136
)
137137
.unwrap();
138-
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
138+
let ret: Vec<(CrossChainId, VerificationStatus)> = from_json(&res.data.unwrap()).unwrap();
139139
assert_eq!(
140140
ret,
141141
messages

contracts/connection-router/src/contract.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use connection_router_api::msg::{ExecuteMsg, QueryMsg};
21
#[cfg(not(feature = "library"))]
32
use cosmwasm_std::entry_point;
4-
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response};
3+
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response};
4+
5+
use connection_router_api::msg::{ExecuteMsg, QueryMsg};
56

67
use crate::events::RouterInstantiated;
78
use crate::msg::InstantiateMsg;
@@ -107,7 +108,7 @@ pub fn query(
107108
msg: QueryMsg,
108109
) -> Result<Binary, axelar_wasm_std::ContractError> {
109110
match msg {
110-
QueryMsg::GetChainInfo(chain) => to_binary(&query::get_chain_info(deps, chain)?),
111+
QueryMsg::GetChainInfo(chain) => to_json_binary(&query::get_chain_info(deps, chain)?),
111112
}
112113
.map_err(axelar_wasm_std::ContractError::from)
113114
}

contracts/connection-router/src/contract/execute.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::vec;
22

3+
use cosmwasm_std::{to_json_binary, Addr, DepsMut, MessageInfo, Response, StdResult, WasmMsg};
4+
use error_stack::report;
5+
use itertools::Itertools;
6+
37
use axelar_wasm_std::flagset::FlagSet;
48
use connection_router_api::error::Error;
59
use connection_router_api::{ChainEndpoint, ChainName, Gateway, GatewayDirection, Message};
6-
use cosmwasm_std::{to_binary, Addr, DepsMut, MessageInfo, Response, StdResult, WasmMsg};
7-
use error_stack::report;
8-
use itertools::Itertools;
910

1011
use crate::events::{ChainFrozen, ChainRegistered, GatewayInfo, GatewayUpgraded, MessageRouted};
1112
use crate::state::{chain_endpoints, Store, CONFIG};
@@ -174,7 +175,7 @@ where
174175

175176
Ok(WasmMsg::Execute {
176177
contract_addr: gateway.to_string(),
177-
msg: to_binary(&gateway_api::msg::ExecuteMsg::RouteMessages(
178+
msg: to_json_binary(&gateway_api::msg::ExecuteMsg::RouteMessages(
178179
msgs.cloned().collect(),
179180
))
180181
.expect("must serialize message"),
@@ -191,14 +192,15 @@ where
191192

192193
#[cfg(test)]
193194
mod test {
195+
use cosmwasm_std::Addr;
196+
use mockall::predicate;
197+
use rand::{Rng, RngCore};
198+
194199
use axelar_wasm_std::flagset::FlagSet;
195200
use connection_router_api::error::Error;
196201
use connection_router_api::{
197202
ChainEndpoint, ChainName, CrossChainId, Gateway, GatewayDirection, Message,
198203
};
199-
use cosmwasm_std::Addr;
200-
use mockall::predicate;
201-
use rand::{Rng, RngCore};
202204

203205
use crate::{
204206
contract::Contract,

contracts/connection-router/tests/mock.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use connection_router_api::error::Error;
22
use connection_router_api::{CrossChainId, Message};
33
use cosmwasm_schema::cw_serde;
4-
use cosmwasm_std::{to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
4+
use cosmwasm_std::{
5+
to_json_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
6+
};
57
use cw_multi_test::{App, ContractWrapper, Executor};
68
use cw_storage_plus::Map;
79

@@ -45,7 +47,7 @@ pub fn mock_gateway_query(deps: Deps, _env: Env, msg: MockGatewayQueryMsg) -> St
4547
}
4648
}
4749
}
48-
to_binary(&msgs)
50+
to_json_binary(&msgs)
4951
}
5052

5153
pub fn get_gateway_messages(

contracts/gateway/src/contract.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub enum Error {
5757
mod internal {
5858
use aggregate_verifier::client::Verifier;
5959
use connection_router_api::client::Router;
60-
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response};
60+
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response};
6161
use error_stack::{Result, ResultExt};
6262
use gateway_api::msg::{ExecuteMsg, QueryMsg};
6363

@@ -122,7 +122,7 @@ mod internal {
122122
match msg {
123123
QueryMsg::GetOutgoingMessages { message_ids } => {
124124
let msgs = contract::query::get_outgoing_messages(deps.storage, message_ids)?;
125-
to_binary(&msgs).change_context(Error::SerializeResponse)
125+
to_json_binary(&msgs).change_context(Error::SerializeResponse)
126126
}
127127
}
128128
}

contracts/gateway/tests/contract.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use axelar_wasm_std::{ContractError, VerificationStatus};
77
use connection_router_api::{CrossChainId, Message, ID_SEPARATOR};
88
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info, MockQuerier};
99
use cosmwasm_std::{
10-
from_binary, to_binary, Addr, ContractResult, DepsMut, QuerierResult, WasmQuery,
10+
from_json, to_json_binary, Addr, ContractResult, DepsMut, QuerierResult, WasmQuery,
1111
};
1212
use gateway::contract::*;
1313
use gateway::msg::InstantiateMsg;
@@ -145,7 +145,10 @@ fn successful_route_outgoing() {
145145
iter::repeat(query(deps.as_ref(), mock_env(), query_msg.clone()).unwrap())
146146
.take(2)
147147
.for_each(|response| {
148-
assert_eq!(response, to_binary::<Vec<CrossChainId>>(&vec![]).unwrap())
148+
assert_eq!(
149+
response,
150+
to_json_binary::<Vec<CrossChainId>>(&vec![]).unwrap()
151+
)
149152
});
150153

151154
// check routing of outgoing messages is idempotent
@@ -169,7 +172,7 @@ fn successful_route_outgoing() {
169172
// check all outgoing messages are stored because the router (sender) is implicitly trusted
170173
iter::repeat(query(deps.as_ref(), mock_env().clone(), query_msg).unwrap())
171174
.take(2)
172-
.for_each(|response| assert_eq!(response, to_binary(&msgs).unwrap()));
175+
.for_each(|response| assert_eq!(response, to_json_binary(&msgs).unwrap()));
173176
}
174177

175178
let golden_file = "tests/test_route_outgoing.json";
@@ -426,8 +429,8 @@ fn update_query_handler<U: Serialize>(
426429
) {
427430
let handler = move |msg: &WasmQuery| match msg {
428431
WasmQuery::Smart { msg, .. } => {
429-
let result = handler(from_binary(msg).expect("should not fail to deserialize"))
430-
.map(|response| to_binary(&response).expect("should not fail to serialize"));
432+
let result = handler(from_json(msg).expect("should not fail to deserialize"))
433+
.map(|response| to_json_binary(&response).expect("should not fail to serialize"));
431434

432435
QuerierResult::Ok(ContractResult::from(result))
433436
}

contracts/multisig-prover/src/contract.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(not(feature = "library"))]
22
use cosmwasm_std::entry_point;
33
use cosmwasm_std::{
4-
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult,
4+
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult,
55
};
66

77
use crate::{
@@ -84,24 +84,25 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
8484
match msg {
8585
QueryMsg::GetProof {
8686
multisig_session_id,
87-
} => to_binary(&query::get_proof(deps, multisig_session_id)?),
88-
QueryMsg::GetWorkerSet {} => to_binary(&query::get_worker_set(deps)?),
87+
} => to_json_binary(&query::get_proof(deps, multisig_session_id)?),
88+
QueryMsg::GetWorkerSet {} => to_json_binary(&query::get_worker_set(deps)?),
8989
}
9090
}
9191

9292
#[cfg(test)]
9393
mod tests {
94-
9594
use anyhow::Error;
96-
use axelar_wasm_std::Threshold;
97-
use connection_router_api::CrossChainId;
9895
use cosmwasm_std::{
9996
testing::{mock_dependencies, mock_env, mock_info},
10097
Addr, Fraction, Uint256, Uint64,
10198
};
10299
use cw_multi_test::{AppResponse, Executor};
100+
101+
use axelar_wasm_std::Threshold;
102+
use connection_router_api::CrossChainId;
103103
use multisig::{msg::Signer, worker_set::WorkerSet};
104104

105+
use crate::contract::execute::should_update_worker_set;
105106
use crate::{
106107
encoding::Encoder,
107108
msg::{GetProofResponse, ProofStatus},
@@ -112,8 +113,6 @@ mod tests {
112113
},
113114
};
114115

115-
use crate::contract::execute::should_update_worker_set;
116-
117116
use super::*;
118117

119118
const RELAYER: &str = "relayer";

contracts/multisig-prover/src/execute.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cosmwasm_std::{
2-
to_binary, wasm_execute, Addr, DepsMut, Env, QuerierWrapper, QueryRequest, Response, Storage,
3-
SubMsg, WasmQuery,
2+
to_json_binary, wasm_execute, Addr, DepsMut, Env, QuerierWrapper, QueryRequest, Response,
3+
Storage, SubMsg, WasmQuery,
44
};
55

66
use multisig::{key::PublicKey, msg::Signer, worker_set::WorkerSet};
@@ -79,7 +79,7 @@ fn get_messages(
7979
let query = gateway_api::msg::QueryMsg::GetOutgoingMessages { message_ids };
8080
let messages: Vec<Message> = querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
8181
contract_addr: gateway.into(),
82-
msg: to_binary(&query)?,
82+
msg: to_json_binary(&query)?,
8383
}))?;
8484

8585
assert!(
@@ -106,7 +106,7 @@ fn get_workers_info(deps: &DepsMut, config: &Config) -> Result<WorkersInfo, Cont
106106
let weighted_workers: Vec<WeightedWorker> =
107107
deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
108108
contract_addr: config.service_registry.to_string(),
109-
msg: to_binary(&active_workers_query)?,
109+
msg: to_json_binary(&active_workers_query)?,
110110
}))?;
111111

112112
let workers: Vec<Worker> = weighted_workers
@@ -131,7 +131,7 @@ fn get_workers_info(deps: &DepsMut, config: &Config) -> Result<WorkersInfo, Cont
131131
};
132132
let pub_key: PublicKey = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
133133
contract_addr: config.multisig.to_string(),
134-
msg: to_binary(&pub_key_query)?,
134+
msg: to_json_binary(&pub_key_query)?,
135135
}))?;
136136
pub_keys.push(pub_key);
137137
}
@@ -245,7 +245,7 @@ pub fn confirm_worker_set(deps: DepsMut) -> Result<Response, ContractError> {
245245

246246
let status: VerificationStatus = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
247247
contract_addr: config.voting_verifier.to_string(),
248-
msg: to_binary(&query)?,
248+
msg: to_json_binary(&query)?,
249249
}))?;
250250

251251
if status != VerificationStatus::SucceededOnChain {

0 commit comments

Comments
 (0)