From 4ba3f36372d2d3fdeb776c9c6646c6c32e4316a6 Mon Sep 17 00:00:00 2001 From: Obie Kaku Date: Thu, 19 Dec 2024 10:37:41 -0600 Subject: [PATCH] cosmwasm: update to_binary calls as per the linter --- .../contracts/cw20-wrapped/src/contract.rs | 12 ++-- .../cw20-wrapped/tests/integration.rs | 51 +++++++-------- .../global-accountant/src/contract.rs | 32 +++++----- .../contracts/ibc-translator/src/contract.rs | 4 +- .../contracts/ibc-translator/src/execute.rs | 19 +++--- .../contracts/ibc-translator/src/reply.rs | 8 +-- .../ibc-translator/tests/contract_test.rs | 6 +- .../ibc-translator/tests/execute_test.rs | 8 +-- .../ibc-translator/tests/reply_test.rs | 10 +-- .../ibc-translator/tests/test_setup/mod.rs | 4 +- .../contracts/mock-counter/src/contract.rs | 6 +- .../ntt-global-accountant/src/contract.rs | 38 +++++------ .../contracts/token-bridge/src/contract.rs | 64 ++++++++++--------- .../wormchain-ibc-receiver/src/contract.rs | 6 +- .../wormchain-ibc-receiver/src/ibc.rs | 8 +-- .../contracts/wormhole-ibc/src/contract.rs | 4 +- cosmwasm/contracts/wormhole/src/contract.rs | 14 ++-- .../wormhole/src/testing/integration.rs | 4 +- .../packages/wormhole-bindings/src/fake.rs | 10 +-- 19 files changed, 155 insertions(+), 153 deletions(-) diff --git a/cosmwasm/contracts/cw20-wrapped/src/contract.rs b/cosmwasm/contracts/cw20-wrapped/src/contract.rs index 4b4d127259..46ebfaa74a 100644 --- a/cosmwasm/contracts/cw20-wrapped/src/contract.rs +++ b/cosmwasm/contracts/cw20-wrapped/src/contract.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ - to_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, - Uint128, WasmMsg, + to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, + StdResult, Uint128, WasmMsg, }; #[cfg(not(feature = "library"))] @@ -167,12 +167,12 @@ fn execute_update_metadata( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::WrappedAssetInfo {} => to_binary(&query_wrapped_asset_info(deps)?), + QueryMsg::WrappedAssetInfo {} => to_json_binary(&query_wrapped_asset_info(deps)?), // inherited from cw20-base - QueryMsg::TokenInfo {} => to_binary(&query_token_info(deps)?), - QueryMsg::Balance { address } => to_binary(&query_balance(deps, address)?), + QueryMsg::TokenInfo {} => to_json_binary(&query_token_info(deps)?), + QueryMsg::Balance { address } => to_json_binary(&query_balance(deps, address)?), QueryMsg::Allowance { owner, spender } => { - to_binary(&query_allowance(deps, owner, spender)?) + to_json_binary(&query_allowance(deps, owner, spender)?) } } } diff --git a/cosmwasm/contracts/cw20-wrapped/tests/integration.rs b/cosmwasm/contracts/cw20-wrapped/tests/integration.rs index 5d32002a53..0931625884 100644 --- a/cosmwasm/contracts/cw20-wrapped/tests/integration.rs +++ b/cosmwasm/contracts/cw20-wrapped/tests/integration.rs @@ -1,9 +1,7 @@ -use std::convert::TryInto; - use cosmwasm_std::{ - from_slice, + from_json, testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage}, - to_binary, Addr, Api, Binary, OwnedDeps, Response, StdError, StdResult, Storage, Uint128, + to_json_binary, Addr, Api, OwnedDeps, Response, Storage, Uint128, }; use cosmwasm_storage::to_length_prefixed; use counter::msg as counter_msgs; @@ -23,7 +21,7 @@ static SENDER: &str = "addr3333"; fn get_wrapped_asset_info(storage: &S) -> WrappedAssetInfo { let key = to_length_prefixed(KEY_WRAPPED_ASSET); let data = storage.get(&key).expect("data should exist"); - from_slice(&data).expect("invalid data") + from_json(&data).expect("invalid data") } fn do_init() -> OwnedDeps { @@ -108,7 +106,7 @@ fn check_balance( fn check_token_details(deps: &OwnedDeps, supply: Uint128) { let query_response = query(deps.as_ref(), mock_env(), QueryMsg::TokenInfo {}).unwrap(); assert_eq!( - from_slice::(query_response.as_slice()).unwrap(), + from_json::(query_response.as_slice()).unwrap(), TokenInfoResponse { name: "Integers (Wormhole)".into(), symbol: "INT".into(), @@ -130,7 +128,7 @@ fn query_works() { let query_response = query(deps.as_ref(), mock_env(), QueryMsg::WrappedAssetInfo {}).unwrap(); assert_eq!( - from_slice::(query_response.as_slice()).unwrap(), + from_json::(query_response.as_slice()).unwrap(), WrappedAssetInfoResponse { asset_chain: 1, asset_address: vec![1; 32].into(), @@ -180,7 +178,7 @@ fn transfer_works() { check_balance(&deps, &recipient, &Uint128::new(123_123_000)); } -struct Cw20App { +pub(crate) struct Cw20App { app: App, admin: Addr, user: Addr, @@ -188,7 +186,7 @@ struct Cw20App { cw20_code_id: u64, } -pub fn create_cw20_wrapped_app(instantiate_msg: Option) -> Cw20App { +pub(crate) fn create_cw20_wrapped_app(instantiate_msg: Option) -> Cw20App { let instantiate_msg = instantiate_msg.unwrap_or(InstantiateMsg { name: "Integers".into(), symbol: "INT".into(), @@ -228,7 +226,7 @@ pub fn create_cw20_wrapped_app(instantiate_msg: Option) -> Cw20A } } -struct Cw20AndCounterApp { +pub(crate) struct Cw20AndCounterApp { app: App, admin: Addr, user: Addr, @@ -237,7 +235,7 @@ struct Cw20AndCounterApp { counter_address: Addr, } -pub fn create_cw20_and_counter() -> Cw20AndCounterApp { +pub(crate) fn create_cw20_and_counter() -> Cw20AndCounterApp { let Cw20App { mut app, admin, @@ -412,7 +410,7 @@ fn instantiate_with_inithook() -> Result<(), anyhow::Error> { decimals: 6, mint: None, init_hook: Some(InitHook { - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, contract_addr: counter_address.to_string(), }), }; @@ -563,7 +561,7 @@ fn send_tokens_functionality() -> Result<(), anyhow::Error> { let send_to_counter_app = ExecuteMsg::Send { contract: counter_address.to_string(), amount: Uint128::from(1_000_000u128), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }; let failing_send = app.execute_contract( @@ -719,7 +717,6 @@ fn burn_functionality() -> Result<(), anyhow::Error> { cw20_wrapped_contract, mut app, admin, - user, .. } = create_cw20_wrapped_app(None); @@ -858,7 +855,6 @@ fn burn_from_functionality() -> Result<(), anyhow::Error> { cw20_wrapped_contract, mut app, admin, - user, .. } = create_cw20_wrapped_app(None); @@ -996,7 +992,6 @@ fn allowance_management() -> Result<(), anyhow::Error> { cw20_wrapped_contract, mut app, admin, - user, .. } = create_cw20_wrapped_app(None); @@ -1113,7 +1108,7 @@ fn allowance_management() -> Result<(), anyhow::Error> { assert_eq!(decreased_allowance.allowance, Uint128::from(400_000u128)); // Decreasing allowance bellow zero results in a zero allowance - let excessive_decrease = app.execute_contract( + let _ = app.execute_contract( token_owner.clone(), cw20_wrapped_contract.clone(), &ExecuteMsg::DecreaseAllowance { @@ -1174,14 +1169,13 @@ fn send_from_functionality() -> Result<(), anyhow::Error> { let Cw20AndCounterApp { mut app, admin, - user, + user: spender, counter_address, cw20_wrapped_contract: cw20_address, .. } = create_cw20_and_counter(); let token_owner = Addr::unchecked("token_owner"); - let spender = Addr::unchecked("spender"); // Mint tokens to the token owner app.execute_contract( @@ -1202,7 +1196,7 @@ fn send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 500_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], ); @@ -1231,7 +1225,7 @@ fn send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 600_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], ); @@ -1248,7 +1242,7 @@ fn send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 300_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], )?; @@ -1305,7 +1299,7 @@ fn send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 50_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], ); @@ -1332,14 +1326,13 @@ fn multiple_send_from_functionality() -> Result<(), anyhow::Error> { let Cw20AndCounterApp { mut app, admin, - user, + user: spender, counter_address, cw20_wrapped_contract: cw20_address, .. } = create_cw20_and_counter(); let token_owner = Addr::unchecked("token_owner"); - let spender = Addr::unchecked("spender"); // Mint tokens to the token owner app.execute_contract( @@ -1372,7 +1365,7 @@ fn multiple_send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 250_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], )?; @@ -1408,7 +1401,7 @@ fn multiple_send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 200_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], )?; @@ -1444,7 +1437,7 @@ fn multiple_send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 300_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], )?; @@ -1492,7 +1485,7 @@ fn multiple_send_from_functionality() -> Result<(), anyhow::Error> { owner: token_owner.to_string(), contract: counter_address.to_string(), amount: 100_000u128.into(), - msg: to_binary(&counter_msgs::ExecuteMsg::Increment {})?, + msg: to_json_binary(&counter_msgs::ExecuteMsg::Increment {})?, }, &[], ); diff --git a/cosmwasm/contracts/global-accountant/src/contract.rs b/cosmwasm/contracts/global-accountant/src/contract.rs index 63b35352b3..19303d0982 100644 --- a/cosmwasm/contracts/global-accountant/src/contract.rs +++ b/cosmwasm/contracts/global-accountant/src/contract.rs @@ -9,7 +9,7 @@ use anyhow::{ensure, Context}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - from_binary, to_binary, Binary, ConversionOverflowError, Deps, DepsMut, Empty, Env, Event, + from_json, to_json_binary, Binary, ConversionOverflowError, Deps, DepsMut, Empty, Env, Event, MessageInfo, Order, Response, StdError, StdResult, Uint256, }; use cw2::set_contract_version; @@ -110,7 +110,7 @@ fn submit_observations( .context("failed to calculate quorum")?; let observations: Vec = - from_binary(&observations).context("failed to parse `Observations`")?; + from_json(&observations).context("failed to parse `Observations`")?; let mut responses = Vec::with_capacity(observations.len()); let mut events = Vec::with_capacity(observations.len()); @@ -139,7 +139,7 @@ fn submit_observations( } } - let data = to_binary(&responses).context("failed to serialize transfer details")?; + let data = to_json_binary(&responses).context("failed to serialize transfer details")?; Ok(Response::new() .add_attribute("action", "submit_observations") @@ -497,21 +497,22 @@ fn handle_tokenbridge_vaa( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Balance(key) => query_balance(deps, key).and_then(|resp| to_binary(&resp)), + QueryMsg::Balance(key) => query_balance(deps, key).and_then(|resp| to_json_binary(&resp)), QueryMsg::AllAccounts { start_after, limit } => { - query_all_accounts(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_accounts(deps, start_after, limit).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllTransfers { start_after, limit } => { - query_all_transfers(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_transfers(deps, start_after, limit).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllPendingTransfers { start_after, limit } => { - query_all_pending_transfers(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_pending_transfers(deps, start_after, limit) + .and_then(|resp| to_json_binary(&resp)) } QueryMsg::Modification { sequence } => { - query_modification(deps, sequence).and_then(|resp| to_binary(&resp)) + query_modification(deps, sequence).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllModifications { start_after, limit } => { - query_all_modifications(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_modifications(deps, start_after, limit).and_then(|resp| to_json_binary(&resp)) } QueryMsg::ValidateTransfer { transfer } => validate_transfer(deps, &transfer) .map_err(|e| { @@ -519,21 +520,20 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - query_chain_registration(deps, chain).and_then(|resp| to_binary(&resp)) + query_chain_registration(deps, chain).and_then(|resp| to_json_binary(&resp)) } QueryMsg::MissingObservations { guardian_set, index, - } => { - query_missing_observations(deps, guardian_set, index).and_then(|resp| to_binary(&resp)) - } + } => query_missing_observations(deps, guardian_set, index) + .and_then(|resp| to_json_binary(&resp)), QueryMsg::TransferStatus(key) => { - query_transfer_status(deps, &key).and_then(|resp| to_binary(&resp)) + query_transfer_status(deps, &key).and_then(|resp| to_json_binary(&resp)) } QueryMsg::BatchTransferStatus(keys) => { - query_batch_transfer_status(deps, keys).and_then(|resp| to_binary(&resp)) + query_batch_transfer_status(deps, keys).and_then(|resp| to_json_binary(&resp)) } } } diff --git a/cosmwasm/contracts/ibc-translator/src/contract.rs b/cosmwasm/contracts/ibc-translator/src/contract.rs index c2e1a79271..70d57c0b96 100644 --- a/cosmwasm/contracts/ibc-translator/src/contract.rs +++ b/cosmwasm/contracts/ibc-translator/src/contract.rs @@ -3,7 +3,7 @@ use cosmwasm_std::entry_point; use anyhow::{bail, Context}; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult, + to_json_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdResult, }; use wormhole_bindings::{tokenfactory::TokenFactoryMsg, WormholeQuery}; @@ -102,6 +102,6 @@ pub fn reply( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::IbcChannel { chain_id } => to_binary(&query_ibc_channel(deps, chain_id)?), + QueryMsg::IbcChannel { chain_id } => to_json_binary(&query_ibc_channel(deps, chain_id)?), } } diff --git a/cosmwasm/contracts/ibc-translator/src/execute.rs b/cosmwasm/contracts/ibc-translator/src/execute.rs index a746948af7..69c2405db8 100644 --- a/cosmwasm/contracts/ibc-translator/src/execute.rs +++ b/cosmwasm/contracts/ibc-translator/src/execute.rs @@ -1,6 +1,6 @@ use anyhow::{bail, ensure, Context}; use cosmwasm_std::{ - to_binary, Binary, Coin, CosmosMsg, Deps, DepsMut, Empty, Env, Event, MessageInfo, + to_json_binary, Binary, Coin, CosmosMsg, Deps, DepsMut, Empty, Env, Event, MessageInfo, QueryRequest, Response, SubMsg, Uint128, WasmMsg, WasmQuery, }; use cw_token_bridge::msg::{ @@ -48,11 +48,12 @@ pub fn complete_transfer_and_convert( // craft the token bridge execute message // this will be added as a submessage to the response - let token_bridge_execute_msg = to_binary(&TokenBridgeExecuteMsg::CompleteTransferWithPayload { - data: vaa.clone(), - relayer: info.sender.to_string(), - }) - .context("could not serialize token bridge execute msg")?; + let token_bridge_execute_msg = + to_json_binary(&TokenBridgeExecuteMsg::CompleteTransferWithPayload { + data: vaa.clone(), + relayer: info.sender.to_string(), + }) + .context("could not serialize token bridge execute msg")?; let sub_msg = SubMsg::reply_on_success( CosmosMsg::Wasm(WasmMsg::Execute { @@ -64,7 +65,7 @@ pub fn complete_transfer_and_convert( ); // craft the token bridge query message to parse the payload3 vaa - let token_bridge_query_msg = to_binary(&TokenBridgeQueryMsg::TransferInfo { vaa }) + let token_bridge_query_msg = to_json_binary(&TokenBridgeQueryMsg::TransferInfo { vaa }) .context("could not serialize token bridge transfer_info query msg")?; let transfer_info: TransferInfoResponse = deps @@ -132,7 +133,7 @@ pub fn convert_and_transfer( }); // 2. cw20::increaseAllowance to the contract address for the token bridge to spend the amount of tokens - let increase_allowance_msg = to_binary(&Cw20WrappedExecuteMsg::IncreaseAllowance { + let increase_allowance_msg = to_json_binary(&Cw20WrappedExecuteMsg::IncreaseAllowance { spender: token_bridge_contract.clone(), amount: bridging_coin.amount, expires: None, @@ -174,7 +175,7 @@ pub fn convert_and_transfer( } } }; - let initiate_transfer_msg = to_binary(&token_bridge_transfer) + let initiate_transfer_msg = to_json_binary(&token_bridge_transfer) .context("could not serialize token bridge initiate_transfer msg")?; response = response.add_message(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: token_bridge_contract, diff --git a/cosmwasm/contracts/ibc-translator/src/reply.rs b/cosmwasm/contracts/ibc-translator/src/reply.rs index 64dbb21587..e79c7fd13b 100644 --- a/cosmwasm/contracts/ibc-translator/src/reply.rs +++ b/cosmwasm/contracts/ibc-translator/src/reply.rs @@ -5,8 +5,8 @@ use crate::{ use anybuf::Anybuf; use anyhow::{ensure, Context}; use cosmwasm_std::{ - from_binary, to_binary, Binary, CosmosMsg::Stargate, Deps, DepsMut, Env, QueryRequest, Reply, - Response, SubMsg, WasmQuery, + from_json, to_json_binary, Binary, CosmosMsg::Stargate, Deps, DepsMut, Env, QueryRequest, + Reply, Response, SubMsg, WasmQuery, }; use cw20::TokenInfoResponse; use cw20_base::msg::QueryMsg as TokenQuery; @@ -29,7 +29,7 @@ pub fn handle_complete_transfer_reply( .data .context("no data in the response, we should never get here")?; let res_data: CompleteTransferResponse = - from_binary(&res_data_raw).context("failed to deserialize response data")?; + from_json(&res_data_raw).context("failed to deserialize response data")?; let contract_addr = res_data .contract .context("no contract in response, we should never get here")?; @@ -114,7 +114,7 @@ pub fn convert_cw20_to_bank_and_send( // call into the cw20 contract to get the token's metadata let request = QueryRequest::Wasm(WasmQuery::Smart { contract_addr: cw20_contract_addr.clone(), - msg: to_binary(&TokenQuery::TokenInfo {})?, + msg: to_json_binary(&TokenQuery::TokenInfo {})?, }); let token_info: TokenInfoResponse = deps.querier.query(&request)?; diff --git a/cosmwasm/contracts/ibc-translator/tests/contract_test.rs b/cosmwasm/contracts/ibc-translator/tests/contract_test.rs index ef3a2e3fdf..6fcab252d5 100644 --- a/cosmwasm/contracts/ibc-translator/tests/contract_test.rs +++ b/cosmwasm/contracts/ibc-translator/tests/contract_test.rs @@ -1,7 +1,7 @@ use cosmwasm_std::{ coin, testing::{mock_dependencies, mock_env, mock_info}, - to_binary, Binary, ContractResult, CosmosMsg, Empty, Event, Reply, ReplyOn, Response, + to_json_binary, Binary, ContractResult, CosmosMsg, Empty, Event, Reply, ReplyOn, Response, SubMsgResponse, SystemError, SystemResult, Uint128, WasmMsg, WasmQuery, }; use cw_token_bridge::msg::TransferInfoResponse; @@ -98,7 +98,7 @@ fn execute_complete_transfer_and_convert() { contract_addr: _, msg: _, } => SystemResult::Ok(ContractResult::Ok( - to_binary(&transfer_info_response_copy).unwrap(), + to_json_binary(&transfer_info_response_copy).unwrap(), )), _ => SystemResult::Err(SystemError::UnsupportedRequest { kind: "wasm".to_string(), @@ -363,7 +363,7 @@ fn query_query_ibc_channel_happy_path() { .save(deps.as_mut().storage, 0, &channel) .unwrap(); - let expected_response = to_binary(&ChannelResponse { channel }).unwrap(); + let expected_response = to_json_binary(&ChannelResponse { channel }).unwrap(); let response = query(deps.as_ref(), env, msg).unwrap(); assert_eq!(expected_response, response); diff --git a/cosmwasm/contracts/ibc-translator/tests/execute_test.rs b/cosmwasm/contracts/ibc-translator/tests/execute_test.rs index ac7ee79e2f..ff2fa682ff 100644 --- a/cosmwasm/contracts/ibc-translator/tests/execute_test.rs +++ b/cosmwasm/contracts/ibc-translator/tests/execute_test.rs @@ -1,7 +1,7 @@ use cosmwasm_std::{ coin, testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}, - to_binary, Binary, Coin, ContractResult, CosmosMsg, Event, ReplyOn, Response, SystemError, + to_json_binary, Binary, Coin, ContractResult, CosmosMsg, Event, ReplyOn, Response, SystemError, SystemResult, Uint128, WasmMsg, WasmQuery, }; use cw_token_bridge::msg::TransferInfoResponse; @@ -78,7 +78,7 @@ fn complete_transfer_and_convert_happy_path() { contract_addr: _, msg: _, } => SystemResult::Ok(ContractResult::Ok( - to_binary(&transfer_info_response_copy).unwrap(), + to_json_binary(&transfer_info_response_copy).unwrap(), )), _ => SystemResult::Err(SystemError::UnsupportedRequest { kind: "wasm".to_string(), @@ -176,7 +176,7 @@ fn complete_transfer_and_convert_failure_humanize_recipient() { let mut deps = execute_custom_mock_deps(); let env = mock_env(); - let transfer_info_response = to_binary(&cw_token_bridge::msg::TransferInfoResponse { + let transfer_info_response = to_json_binary(&cw_token_bridge::msg::TransferInfoResponse { amount: 1000000u32.into(), token_address: hex::decode("0000000000000000000000009c3c9283d3e44854697cd22d3faa240cfb032889").unwrap().try_into().unwrap(), token_chain: 5, @@ -214,7 +214,7 @@ fn complete_transfer_and_convert_nomatch_recipient_contract() { let mut deps = execute_custom_mock_deps(); let env = mock_env(); - let transfer_info_response = to_binary(&cw_token_bridge::msg::TransferInfoResponse { + let transfer_info_response = to_json_binary(&cw_token_bridge::msg::TransferInfoResponse { amount: 1000000u32.into(), token_address: hex::decode("0000000000000000000000009c3c9283d3e44854697cd22d3faa240cfb032889").unwrap().try_into().unwrap(), token_chain: 5, diff --git a/cosmwasm/contracts/ibc-translator/tests/reply_test.rs b/cosmwasm/contracts/ibc-translator/tests/reply_test.rs index f5b97ca5ae..fa43267ca1 100644 --- a/cosmwasm/contracts/ibc-translator/tests/reply_test.rs +++ b/cosmwasm/contracts/ibc-translator/tests/reply_test.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ testing::{mock_dependencies, mock_env}, - to_binary, to_vec, Binary, ContractResult, + to_json_binary, to_json_vec, Binary, ContractResult, CosmosMsg::Stargate, Reply, Response, SubMsgResponse, SystemError, SystemResult, Uint128, WasmQuery, }; @@ -206,7 +206,7 @@ fn handle_complete_transfer_reply_invalid_response_data_type() { // encode a payload as protobuf // the payload is NOT a CompleteTransferResponse let execute_reply = MsgExecuteContractResponse { - data: to_vec(&AssetInfo::NativeToken { + data: to_json_vec(&AssetInfo::NativeToken { denom: "denomA".to_string(), }) .unwrap(), @@ -235,7 +235,7 @@ fn handle_complete_transfer_reply_no_response_contract() { // encode a payload as protobuf // the payload is a CompleteTransferResponse let execute_reply = MsgExecuteContractResponse { - data: to_vec(&CompleteTransferResponse { + data: to_json_vec(&CompleteTransferResponse { contract: None, denom: None, recipient: "fake".to_string(), @@ -472,7 +472,7 @@ fn convert_cw20_to_bank_happy_path_create_denom() { contract_addr: _, msg: _, } => SystemResult::Ok(ContractResult::Ok( - to_binary(&token_info_response_copy).unwrap(), + to_json_binary(&token_info_response_copy).unwrap(), )), _ => SystemResult::Err(SystemError::UnsupportedRequest { kind: "wasm".to_string(), @@ -578,7 +578,7 @@ fn convert_cw20_to_bank_happy_path_create_denom_empty_symbol() { contract_addr: _, msg: _, } => SystemResult::Ok(ContractResult::Ok( - to_binary(&token_info_response_copy).unwrap(), + to_json_binary(&token_info_response_copy).unwrap(), )), _ => SystemResult::Err(SystemError::UnsupportedRequest { kind: "wasm".to_string(), diff --git a/cosmwasm/contracts/ibc-translator/tests/test_setup/mod.rs b/cosmwasm/contracts/ibc-translator/tests/test_setup/mod.rs index 8cf7c0886d..5be33eb206 100644 --- a/cosmwasm/contracts/ibc-translator/tests/test_setup/mod.rs +++ b/cosmwasm/contracts/ibc-translator/tests/test_setup/mod.rs @@ -2,7 +2,7 @@ use serde::de::DeserializeOwned; use std::marker::PhantomData; use cosmwasm_std::{ - from_slice, + from_json, testing::{mock_env, BankQuerier, MockQuerierCustomHandlerResult, MockStorage}, Addr, Api, Binary, CanonicalAddr, Coin, ContractResult, CustomQuery, Empty, Env, OwnedDeps, Querier, QuerierResult, QueryRequest, RecoverPubkeyError, StdError, StdResult, SystemError, @@ -263,7 +263,7 @@ impl Default for MockQuerier { impl Querier for MockQuerier { fn raw_query(&self, bin_request: &[u8]) -> QuerierResult { - let request: QueryRequest = match from_slice(bin_request) { + let request: QueryRequest = match from_json(bin_request) { Ok(v) => v, Err(e) => { return SystemResult::Err(SystemError::InvalidRequest { diff --git a/cosmwasm/contracts/mock-counter/src/contract.rs b/cosmwasm/contracts/mock-counter/src/contract.rs index b6f0bd1f32..d76bc8ea2b 100644 --- a/cosmwasm/contracts/mock-counter/src/contract.rs +++ b/cosmwasm/contracts/mock-counter/src/contract.rs @@ -1,7 +1,7 @@ use crate::{msg::ReceiveMsg, CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg}; use cosmwasm_std::{ - entry_point, from_binary, from_json, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, - Response, StdResult, + entry_point, from_json, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, + StdResult, }; use cw_storage_plus::Item; @@ -58,7 +58,7 @@ pub fn reset(deps: DepsMut) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::GetCount {} => to_binary(&query_count(deps)?), + QueryMsg::GetCount {} => to_json_binary(&query_count(deps)?), } } diff --git a/cosmwasm/contracts/ntt-global-accountant/src/contract.rs b/cosmwasm/contracts/ntt-global-accountant/src/contract.rs index f2a086434a..fc2a9c1417 100644 --- a/cosmwasm/contracts/ntt-global-accountant/src/contract.rs +++ b/cosmwasm/contracts/ntt-global-accountant/src/contract.rs @@ -9,7 +9,7 @@ use anyhow::{ensure, Context}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - from_binary, to_binary, Binary, ConversionOverflowError, Deps, DepsMut, Empty, Env, Event, + from_json, to_json_binary, Binary, ConversionOverflowError, Deps, DepsMut, Empty, Env, Event, MessageInfo, Order, Response, StdError, StdResult, Uint256, }; use cw2::set_contract_version; @@ -124,7 +124,7 @@ fn submit_observations( .context("failed to calculate quorum")?; let observations: Vec = - from_binary(&observations).context("failed to parse `Observations`")?; + from_json(&observations).context("failed to parse `Observations`")?; let mut responses = Vec::with_capacity(observations.len()); let mut events = Vec::with_capacity(observations.len()); @@ -154,7 +154,7 @@ fn submit_observations( } } - let data = to_binary(&responses).context("failed to serialize transfer details")?; + let data = to_json_binary(&responses).context("failed to serialize transfer details")?; Ok(Response::new() .add_attribute("action", "submit_observations") @@ -635,21 +635,22 @@ fn handle_ntt_vaa( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Balance(key) => query_balance(deps, key).and_then(|resp| to_binary(&resp)), + QueryMsg::Balance(key) => query_balance(deps, key).and_then(|resp| to_json_binary(&resp)), QueryMsg::AllAccounts { start_after, limit } => { - query_all_accounts(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_accounts(deps, start_after, limit).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllTransfers { start_after, limit } => { - query_all_transfers(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_transfers(deps, start_after, limit).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllPendingTransfers { start_after, limit } => { - query_all_pending_transfers(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_pending_transfers(deps, start_after, limit) + .and_then(|resp| to_json_binary(&resp)) } QueryMsg::Modification { sequence } => { - query_modification(deps, sequence).and_then(|resp| to_binary(&resp)) + query_modification(deps, sequence).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllModifications { start_after, limit } => { - query_all_modifications(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_modifications(deps, start_after, limit).and_then(|resp| to_json_binary(&resp)) } QueryMsg::ValidateTransfer { transfer } => validate_transfer(deps, &transfer) .map_err(|e| { @@ -657,27 +658,28 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - query_relayer_chain_registration(deps, chain).and_then(|resp| to_binary(&resp)) + query_relayer_chain_registration(deps, chain).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllTransceiverHubs { start_after, limit } => { - query_all_transceiver_hubs(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_transceiver_hubs(deps, start_after, limit) + .and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllTransceiverPeers { start_after, limit } => { - query_all_transceiver_peers(deps, start_after, limit).and_then(|resp| to_binary(&resp)) + query_all_transceiver_peers(deps, start_after, limit) + .and_then(|resp| to_json_binary(&resp)) } QueryMsg::MissingObservations { guardian_set, index, - } => { - query_missing_observations(deps, guardian_set, index).and_then(|resp| to_binary(&resp)) - } + } => query_missing_observations(deps, guardian_set, index) + .and_then(|resp| to_json_binary(&resp)), QueryMsg::TransferStatus(key) => { - query_transfer_status(deps, &key).and_then(|resp| to_binary(&resp)) + query_transfer_status(deps, &key).and_then(|resp| to_json_binary(&resp)) } QueryMsg::BatchTransferStatus(keys) => { - query_batch_transfer_status(deps, keys).and_then(|resp| to_binary(&resp)) + query_batch_transfer_status(deps, keys).and_then(|resp| to_json_binary(&resp)) } } } diff --git a/cosmwasm/contracts/token-bridge/src/contract.rs b/cosmwasm/contracts/token-bridge/src/contract.rs index 090210c28e..cddfe74450 100644 --- a/cosmwasm/contracts/token-bridge/src/contract.rs +++ b/cosmwasm/contracts/token-bridge/src/contract.rs @@ -23,7 +23,7 @@ use cw_wormhole::{ use cosmwasm_std::entry_point; use cosmwasm_std::{ - coin, to_binary, BankMsg, Binary, CanonicalAddr, CosmosMsg, Deps, DepsMut, Empty, Env, + coin, to_json_binary, BankMsg, Binary, CanonicalAddr, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, QueryRequest, Reply, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg, WasmQuery, }; @@ -169,7 +169,7 @@ pub fn reply(deps: DepsMut, env: Env, _msg: Reply) -> StdResult { let new_balance: BalanceResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: state.token_address.to_string(), - msg: to_binary(&TokenQuery::Balance { + msg: to_json_binary(&TokenQuery::Balance { address: env.contract.address.to_string(), })?, }))?; @@ -212,7 +212,7 @@ pub fn reply(deps: DepsMut, env: Env, _msg: Reply) -> StdResult { let message = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: cfg.wormhole_contract, funds: vec![], - msg: to_binary(&WormholeExecuteMsg::PostMessage { + msg: to_json_binary(&WormholeExecuteMsg::PostMessage { message: Binary::from(token_bridge_message.serialize()), nonce: state.nonce, })?, @@ -229,7 +229,7 @@ fn parse_vaa(deps: Deps, block_time: u64, data: &Binary) -> StdResult let cfg = config_read(deps.storage).load()?; let vaa: ParsedVAA = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: cfg.wormhole_contract, - msg: to_binary(&WormholeQueryMsg::VerifyVAA { + msg: to_json_binary(&WormholeQueryMsg::VerifyVAA { vaa: data.clone(), block_time, })?, @@ -454,7 +454,7 @@ fn handle_attest_meta( } CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract.into_string(), - msg: to_binary(&WrappedMsg::UpdateMetadata { + msg: to_json_binary(&WrappedMsg::UpdateMetadata { name: get_string_from_32(&meta.name), symbol: get_string_from_32(&meta.symbol), })?, @@ -464,7 +464,7 @@ fn handle_attest_meta( CosmosMsg::Wasm(WasmMsg::Instantiate { admin: Some(env.contract.address.clone().into_string()), code_id: cfg.wrapped_asset_code_id, - msg: to_binary(&WrappedInit { + msg: to_json_binary(&WrappedInit { name: get_string_from_32(&meta.name), symbol: get_string_from_32(&meta.symbol), asset_chain: meta.token_chain, @@ -473,7 +473,7 @@ fn handle_attest_meta( mint: None, init_hook: Some(InitHook { contract_addr: env.contract.address.to_string(), - msg: to_binary(&ExecuteMsg::RegisterAssetHook { + msg: to_json_binary(&ExecuteMsg::RegisterAssetHook { chain: meta.token_chain, token_address: meta.token_address.clone(), })?, @@ -515,7 +515,7 @@ fn handle_create_asset_meta_token( let request = QueryRequest::Wasm(WasmQuery::Smart { contract_addr: asset_address.clone(), - msg: to_binary(&TokenQuery::TokenInfo {})?, + msg: to_json_binary(&TokenQuery::TokenInfo {})?, }); let asset_human = deps.api.addr_validate(&asset_address)?; @@ -541,7 +541,7 @@ fn handle_create_asset_meta_token( Ok(Response::new() .add_message(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: cfg.wormhole_contract, - msg: to_binary(&WormholeExecuteMsg::PostMessage { + msg: to_json_binary(&WormholeExecuteMsg::PostMessage { message: Binary::from(token_bridge_message.serialize()), nonce, })?, @@ -584,7 +584,7 @@ fn handle_create_asset_meta_native_token( Ok(Response::new() .add_message(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: cfg.wormhole_contract, - msg: to_binary(&WormholeExecuteMsg::PostMessage { + msg: to_json_binary(&WormholeExecuteMsg::PostMessage { message: Binary::from(token_bridge_message.serialize()), nonce, })?, @@ -729,7 +729,7 @@ fn handle_upgrade_contract(_deps: DepsMut, env: Env, data: &Vec) -> StdResul .add_message(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: env.contract.address.to_string(), new_code_id: new_contract, - msg: to_binary(&MigrateMsg {})?, + msg: to_json_binary(&MigrateMsg {})?, })) .add_attribute("action", "contract_upgrade")) } @@ -870,7 +870,7 @@ fn handle_complete_transfer_token( // Asset already deployed, just mint let mut messages = vec![CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract_addr.clone(), - msg: to_binary(&WrappedMsg::Mint { + msg: to_json_binary(&WrappedMsg::Mint { recipient: recipient.to_string(), amount: Uint128::from(amount), })?, @@ -879,7 +879,7 @@ fn handle_complete_transfer_token( if fee != 0 { messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract_addr.clone(), - msg: to_binary(&WrappedMsg::Mint { + msg: to_json_binary(&WrappedMsg::Mint { recipient: relayer_address.to_string(), amount: Uint128::from(fee), })?, @@ -888,7 +888,7 @@ fn handle_complete_transfer_token( } // serialize response data that will be returned to the caller - let response_data = to_binary(&CompleteTransferResponse { + let response_data = to_json_binary(&CompleteTransferResponse { contract: Some(contract_addr.clone()), denom: None, recipient: recipient.clone().into_string(), @@ -916,7 +916,7 @@ fn handle_complete_transfer_token( let token_info: TokenInfoResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: contract_address.to_string(), - msg: to_binary(&TokenQuery::TokenInfo {})?, + msg: to_json_binary(&TokenQuery::TokenInfo {})?, }))?; let decimals = token_info.decimals; @@ -926,7 +926,7 @@ fn handle_complete_transfer_token( let mut messages = vec![CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract_address.to_string(), - msg: to_binary(&TokenMsg::Transfer { + msg: to_json_binary(&TokenMsg::Transfer { recipient: recipient.to_string(), amount: Uint128::from(amount), })?, @@ -936,7 +936,7 @@ fn handle_complete_transfer_token( if fee != 0 { messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract_address.to_string(), - msg: to_binary(&TokenMsg::Transfer { + msg: to_json_binary(&TokenMsg::Transfer { recipient: relayer_address.to_string(), amount: Uint128::from(fee), })?, @@ -945,7 +945,7 @@ fn handle_complete_transfer_token( } // serialize response data that will be returned to the caller - let response_data = to_binary(&CompleteTransferResponse { + let response_data = to_json_binary(&CompleteTransferResponse { contract: Some(contract_address.to_string()), denom: None, recipient: recipient.clone().into_string(), @@ -1046,7 +1046,7 @@ fn handle_complete_transfer_token_native( } // serialize response data that will be returned to the caller - let response_data = to_binary(&CompleteTransferResponse { + let response_data = to_json_binary(&CompleteTransferResponse { contract: None, denom: Some(denom.clone()), recipient: recipient.clone().into_string(), @@ -1150,7 +1150,7 @@ fn handle_initiate_transfer_token( // This is a deployed wrapped asset, burn it messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: asset.clone(), - msg: to_binary(&WrappedMsg::Burn { + msg: to_json_binary(&WrappedMsg::Burn { account: info.sender.to_string(), amount, })?, @@ -1158,7 +1158,7 @@ fn handle_initiate_transfer_token( })); let request = QueryRequest::::Wasm(WasmQuery::Smart { contract_addr: asset, - msg: to_binary(&WrappedQuery::WrappedAssetInfo {})?, + msg: to_json_binary(&WrappedQuery::WrappedAssetInfo {})?, }); let wrapped_token_info: WrappedAssetInfoResponse = deps.querier.query(&request)?; asset_chain = wrapped_token_info.asset_chain; @@ -1201,7 +1201,7 @@ fn handle_initiate_transfer_token( messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: cfg.wormhole_contract, - msg: to_binary(&WormholeExecuteMsg::PostMessage { + msg: to_json_binary(&WormholeExecuteMsg::PostMessage { message: Binary::from(token_bridge_message.serialize()), nonce, })?, @@ -1216,7 +1216,7 @@ fn handle_initiate_transfer_token( let token_info: TokenInfoResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: asset.clone(), - msg: to_binary(&TokenQuery::TokenInfo {})?, + msg: to_json_binary(&TokenQuery::TokenInfo {})?, }))?; let decimals = token_info.decimals; @@ -1241,7 +1241,7 @@ fn handle_initiate_transfer_token( submessages.push(SubMsg::reply_on_success( CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: asset.clone(), - msg: to_binary(&TokenMsg::TransferFrom { + msg: to_json_binary(&TokenMsg::TransferFrom { owner: info.sender.to_string(), recipient: env.contract.address.to_string(), amount, @@ -1267,7 +1267,7 @@ fn handle_initiate_transfer_token( let balance: BalanceResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: asset.to_string(), - msg: to_binary(&TokenQuery::Balance { + msg: to_json_binary(&TokenQuery::Balance { address: env.contract.address.to_string(), })?, }))?; @@ -1449,7 +1449,7 @@ fn handle_initiate_transfer_native_token( let sender = deps.api.addr_canonicalize(info.sender.as_str())?; messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: cfg.wormhole_contract, - msg: to_binary(&WormholeExecuteMsg::PostMessage { + msg: to_json_binary(&WormholeExecuteMsg::PostMessage { message: Binary::from(token_bridge_message.serialize()), nonce, })?, @@ -1475,13 +1475,15 @@ fn handle_initiate_transfer_native_token( pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::WrappedRegistry { chain, address } => { - to_binary(&query_wrapped_registry(deps, chain, address.as_slice())?) + to_json_binary(&query_wrapped_registry(deps, chain, address.as_slice())?) } - QueryMsg::TransferInfo { vaa } => to_binary(&query_transfer_info(deps, env, &vaa)?), - QueryMsg::ExternalId { external_id } => to_binary(&query_external_id(deps, external_id)?), - QueryMsg::IsVaaRedeemed { vaa } => to_binary(&query_is_vaa_redeemed(deps, env, &vaa)?), + QueryMsg::TransferInfo { vaa } => to_json_binary(&query_transfer_info(deps, env, &vaa)?), + QueryMsg::ExternalId { external_id } => { + to_json_binary(&query_external_id(deps, external_id)?) + } + QueryMsg::IsVaaRedeemed { vaa } => to_json_binary(&query_is_vaa_redeemed(deps, env, &vaa)?), QueryMsg::ChainRegistration { chain } => { - query_chain_registration(deps, chain).and_then(|r| to_binary(&r)) + query_chain_registration(deps, chain).and_then(|r| to_json_binary(&r)) } } } diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs index 16613f483d..b4a50b9987 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/contract.rs @@ -2,7 +2,7 @@ use crate::error::ContractError; use crate::msg::{AllChannelChainsResponse, ChannelChainResponse, ExecuteMsg, QueryMsg}; use crate::state::{CHANNEL_CHAIN, VAA_ARCHIVE}; use anyhow::{bail, ensure, Context}; -use cosmwasm_std::{entry_point, to_binary, Binary, Deps, Empty, Event, StdResult}; +use cosmwasm_std::{entry_point, to_json_binary, Binary, Deps, Empty, Event, StdResult}; use cosmwasm_std::{DepsMut, Env, MessageInfo, Order, Response}; use serde_wormhole::RawMessage; use std::str; @@ -132,10 +132,10 @@ fn handle_vaa(deps: DepsMut, vaa: Binary) -> anyhow::Result StdResult { match msg { QueryMsg::ChannelChain { channel_id } => { - query_channel_chain(deps, channel_id).and_then(|resp| to_binary(&resp)) + query_channel_chain(deps, channel_id).and_then(|resp| to_json_binary(&resp)) } QueryMsg::AllChannelChains {} => { - query_all_channel_chains(deps).and_then(|resp| to_binary(&resp)) + query_all_channel_chains(deps).and_then(|resp| to_json_binary(&resp)) } } } diff --git a/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs b/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs index 8b24b75968..d3111fdf30 100644 --- a/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs +++ b/cosmwasm/contracts/wormchain-ibc-receiver/src/ibc.rs @@ -1,6 +1,6 @@ use anyhow::{bail, ensure}; use cosmwasm_std::{ - entry_point, from_slice, to_binary, Attribute, Binary, ContractResult, DepsMut, Env, + entry_point, from_json, to_json_binary, Attribute, Binary, ContractResult, DepsMut, Env, Ibc3ChannelOpenResponse, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, StdError, StdResult, @@ -91,7 +91,7 @@ fn handle_packet_receive(msg: IbcPacketReceiveMsg) -> Result { receive_publish(channel_id, publish_attrs) @@ -135,7 +135,7 @@ fn receive_publish( } // send the ack and emit the message with the attributes from the wormhole message - let acknowledgement = to_binary(&ContractResult::<()>::Ok(()))?; + let acknowledgement = to_json_binary(&ContractResult::<()>::Ok(()))?; Ok(IbcReceiveResponse::new() .set_ack(acknowledgement) .add_attribute("action", "receive_publish") @@ -146,7 +146,7 @@ fn receive_publish( // this encode an error or error message into a proper acknowledgement to the recevier fn encode_ibc_error(msg: impl Into) -> Binary { // this cannot error, unwrap to keep the interface simple - to_binary(&ContractResult::<()>::Err(msg.into())).unwrap() + to_json_binary(&ContractResult::<()>::Err(msg.into())).unwrap() } /// 5. Acknowledging a packet. Called when the other chain successfully receives a packet from us. diff --git a/cosmwasm/contracts/wormhole-ibc/src/contract.rs b/cosmwasm/contracts/wormhole-ibc/src/contract.rs index 68384d2758..de5b48eaef 100644 --- a/cosmwasm/contracts/wormhole-ibc/src/contract.rs +++ b/cosmwasm/contracts/wormhole-ibc/src/contract.rs @@ -19,7 +19,7 @@ use crate::{ }; use anyhow::{bail, ensure, Context}; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, Event, IbcMsg, MessageInfo, Response, StdResult, + to_json_binary, Binary, Deps, DepsMut, Env, Event, IbcMsg, MessageInfo, Response, StdResult, }; use cw_wormhole::msg::{ExecuteMsg as WormholeExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; @@ -157,7 +157,7 @@ fn post_message_ibc( }; let ibc_msg = IbcMsg::SendPacket { channel_id, - data: to_binary(&packet)?, + data: to_json_binary(&packet)?, timeout: packet_timeout, }; diff --git a/cosmwasm/contracts/wormhole/src/contract.rs b/cosmwasm/contracts/wormhole/src/contract.rs index 99dd40c100..9d107f48be 100644 --- a/cosmwasm/contracts/wormhole/src/contract.rs +++ b/cosmwasm/contracts/wormhole/src/contract.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - has_coins, to_binary, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, + has_coins, to_json_binary, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Storage, WasmMsg, }; @@ -272,7 +272,7 @@ fn vaa_update_contract(_deps: DepsMut, env: Env, data: &[u8]) -> StdResult StdResult { match msg { - QueryMsg::GuardianSetInfo {} => to_binary(&query_guardian_set_info(deps)?), - QueryMsg::VerifyVAA { vaa, block_time } => to_binary(&query_parse_and_verify_vaa( + QueryMsg::GuardianSetInfo {} => to_json_binary(&query_guardian_set_info(deps)?), + QueryMsg::VerifyVAA { vaa, block_time } => to_json_binary(&query_parse_and_verify_vaa( deps, vaa.as_slice(), block_time, )?), - QueryMsg::GetState {} => to_binary(&query_state(deps)?), - QueryMsg::QueryAddressHex { address } => to_binary(&query_address_hex(deps, &address)?), + QueryMsg::GetState {} => to_json_binary(&query_state(deps)?), + QueryMsg::QueryAddressHex { address } => { + to_json_binary(&query_address_hex(deps, &address)?) + } } } diff --git a/cosmwasm/contracts/wormhole/src/testing/integration.rs b/cosmwasm/contracts/wormhole/src/testing/integration.rs index 0e5e2f5800..e97dcf57b9 100644 --- a/cosmwasm/contracts/wormhole/src/testing/integration.rs +++ b/cosmwasm/contracts/wormhole/src/testing/integration.rs @@ -9,7 +9,7 @@ use crate::{ state::{ConfigInfo, GuardianAddress, ParsedVAA, CONFIG_KEY}, }; use cosmwasm_std::{ - from_slice, + from_json, testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage}, Coin, OwnedDeps, Response, StdResult, Storage, }; @@ -29,7 +29,7 @@ static INITIALIZER: &str = "initializer"; fn get_config_info(storage: &S) -> ConfigInfo { let key = to_length_prefixed(CONFIG_KEY); let data = storage.get(&key).expect("data should exist"); - from_slice(&data).expect("invalid data") + from_json(&data).expect("invalid data") } fn do_init(guardians: &[GuardianAddress]) -> OwnedDeps { diff --git a/cosmwasm/packages/wormhole-bindings/src/fake.rs b/cosmwasm/packages/wormhole-bindings/src/fake.rs index eb47a990ca..9bc65a3f72 100644 --- a/cosmwasm/packages/wormhole-bindings/src/fake.rs +++ b/cosmwasm/packages/wormhole-bindings/src/fake.rs @@ -1,7 +1,9 @@ use std::{cell::RefCell, collections::BTreeSet, fmt::Debug, rc::Rc}; use anyhow::{anyhow, bail, ensure, Context}; -use cosmwasm_std::{to_binary, Addr, Api, Binary, BlockInfo, CustomQuery, Empty, Querier, Storage}; +use cosmwasm_std::{ + to_json_binary, Addr, Api, Binary, BlockInfo, CustomQuery, Empty, Querier, Storage, +}; use cw_multi_test::{AppResponse, CosmosRouter, Module}; use k256::ecdsa::{recoverable, signature::Signer, SigningKey}; use schemars::JsonSchema; @@ -178,7 +180,7 @@ impl WormholeKeeper { match request { WormholeQuery::VerifyVaa { vaa } => self .verify_vaa(&vaa, block.height) - .and_then(|e| to_binary(&e).map_err(From::from)), + .and_then(|e| to_json_binary(&e).map_err(From::from)), WormholeQuery::VerifyMessageSignature { prefix, data, @@ -186,10 +188,10 @@ impl WormholeKeeper { signature, } => self .verify_signature(&prefix, &data, guardian_set_index, &signature, block.height) - .and_then(|e| to_binary(&e).map_err(From::from)), + .and_then(|e| to_json_binary(&e).map_err(From::from)), WormholeQuery::CalculateQuorum { guardian_set_index } => self .calculate_quorum(guardian_set_index, block.height) - .and_then(|q| to_binary(&q).map_err(From::from)), + .and_then(|q| to_json_binary(&q).map_err(From::from)), } }