Skip to content

Commit

Permalink
cosmwasm: update to_binary calls as per the linter
Browse files Browse the repository at this point in the history
  • Loading branch information
kakucodes committed Dec 19, 2024
1 parent 522c39f commit e1ee5d2
Show file tree
Hide file tree
Showing 27 changed files with 186 additions and 185 deletions.
12 changes: 6 additions & 6 deletions cosmwasm/contracts/cw20-wrapped/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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"))]
Expand Down Expand Up @@ -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<Binary> {
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)?)
}
}
}
Expand Down
51 changes: 22 additions & 29 deletions cosmwasm/contracts/cw20-wrapped/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,7 +21,7 @@ static SENDER: &str = "addr3333";
fn get_wrapped_asset_info<S: Storage>(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<MockStorage, MockApi, MockQuerier> {
Expand Down Expand Up @@ -108,7 +106,7 @@ fn check_balance(
fn check_token_details(deps: &OwnedDeps<MockStorage, MockApi, MockQuerier>, supply: Uint128) {
let query_response = query(deps.as_ref(), mock_env(), QueryMsg::TokenInfo {}).unwrap();
assert_eq!(
from_slice::<TokenInfoResponse>(query_response.as_slice()).unwrap(),
from_json::<TokenInfoResponse>(query_response.as_slice()).unwrap(),
TokenInfoResponse {
name: "Integers (Wormhole)".into(),
symbol: "INT".into(),
Expand All @@ -130,7 +128,7 @@ fn query_works() {

let query_response = query(deps.as_ref(), mock_env(), QueryMsg::WrappedAssetInfo {}).unwrap();
assert_eq!(
from_slice::<WrappedAssetInfoResponse>(query_response.as_slice()).unwrap(),
from_json::<WrappedAssetInfoResponse>(query_response.as_slice()).unwrap(),
WrappedAssetInfoResponse {
asset_chain: 1,
asset_address: vec![1; 32].into(),
Expand Down Expand Up @@ -180,15 +178,15 @@ fn transfer_works() {
check_balance(&deps, &recipient, &Uint128::new(123_123_000));
}

struct Cw20App {
pub(crate) struct Cw20App {
app: App,
admin: Addr,
user: Addr,
cw20_wrapped_contract: Addr,
cw20_code_id: u64,
}

pub fn create_cw20_wrapped_app(instantiate_msg: Option<InstantiateMsg>) -> Cw20App {
pub(crate) fn create_cw20_wrapped_app(instantiate_msg: Option<InstantiateMsg>) -> Cw20App {
let instantiate_msg = instantiate_msg.unwrap_or(InstantiateMsg {
name: "Integers".into(),
symbol: "INT".into(),
Expand Down Expand Up @@ -228,7 +226,7 @@ pub fn create_cw20_wrapped_app(instantiate_msg: Option<InstantiateMsg>) -> Cw20A
}
}

struct Cw20AndCounterApp {
pub(crate) struct Cw20AndCounterApp {
app: App,
admin: Addr,
user: Addr,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
}),
};
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -719,7 +717,6 @@ fn burn_functionality() -> Result<(), anyhow::Error> {
cw20_wrapped_contract,
mut app,
admin,
user,
..
} = create_cw20_wrapped_app(None);

Expand Down Expand Up @@ -858,7 +855,6 @@ fn burn_from_functionality() -> Result<(), anyhow::Error> {
cw20_wrapped_contract,
mut app,
admin,
user,
..
} = create_cw20_wrapped_app(None);

Expand Down Expand Up @@ -996,7 +992,6 @@ fn allowance_management() -> Result<(), anyhow::Error> {
cw20_wrapped_contract,
mut app,
admin,
user,
..
} = create_cw20_wrapped_app(None);

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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 {})?,
},
&[],
);
Expand Down Expand Up @@ -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 {})?,
},
&[],
);
Expand All @@ -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 {})?,
},
&[],
)?;
Expand Down Expand Up @@ -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 {})?,
},
&[],
);
Expand All @@ -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(
Expand Down Expand Up @@ -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 {})?,
},
&[],
)?;
Expand Down Expand Up @@ -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 {})?,
},
&[],
)?;
Expand Down Expand Up @@ -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 {})?,
},
&[],
)?;
Expand Down Expand Up @@ -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 {})?,
},
&[],
);
Expand Down
32 changes: 16 additions & 16 deletions cosmwasm/contracts/global-accountant/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +110,7 @@ fn submit_observations(
.context("failed to calculate quorum")?;

let observations: Vec<Observation> =
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());
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -497,43 +497,43 @@ fn handle_tokenbridge_vaa(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<WormholeQuery>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
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| {
e.downcast().unwrap_or_else(|e| StdError::GenericErr {
msg: format!("{e:#}"),
})
})
.and_then(|()| to_binary(&Empty {})),
.and_then(|()| to_json_binary(&Empty {})),
QueryMsg::ChainRegistration { chain } => {
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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod helpers;

use cosmwasm_std::{to_binary, Event};
use cosmwasm_std::{to_json_binary, Event};
use global_accountant::msg::ChainRegistrationResponse;
use helpers::*;
use wormhole_sdk::{
Expand Down Expand Up @@ -214,7 +214,7 @@ fn bad_serialization() {
let (v, _) = sign_vaa_body(&wh, create_vaa_body());

// Rather than using the wormhole wire format use cosmwasm json.
let data = to_binary(&v).unwrap();
let data = to_json_binary(&v).unwrap();

let err = contract
.submit_vaas(vec![data])
Expand Down
Loading

0 comments on commit e1ee5d2

Please sign in to comment.