Skip to content

Commit

Permalink
Merge pull request #147 from neutron-org/feat/bump_cosmwasm_deps
Browse files Browse the repository at this point in the history
feat: update cosmwasm to 2.0 #NTRN-302
  • Loading branch information
pr0n00gler authored Jul 3, 2024
2 parents f45c35d + 867d722 commit 9aac376
Show file tree
Hide file tree
Showing 26 changed files with 371 additions and 151 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ incremental = false
overflow-checks = true

[workspace.dependencies]
cosmwasm-std = "1.4.0"
cw2 = "1.1.1"
cosmwasm-std = "2.0.4"
cw2 = "2.0.0"
schemars = "0.8.15"
serde = { version = "1.0.188", default-features = false }
serde-json-wasm = "1.0.0"
cw-storage-plus = "1.1.0"
cosmwasm-schema = { version = "1.4.0", default-features = false }
base64 = "0.21.4"
cw-storage-plus = "2.0.0"
cosmwasm-schema = { version = "2.0.4", default-features = false }
base64 = "0.21.7"
prost = "0.12.3"
prost-types = "0.12.1"
cosmos-sdk-proto = { version = "0.20.0", default-features = false }
bech32 = "0.9.1"
thiserror = "1.0.49"
protobuf = { version = "3.3.0" }
protobuf = "~3.3.0"
hex = "0.4.3"
serde_json = { version = "1.0.87" }
tendermint-proto = "0.34"
tendermint-proto = "0.34.1"
speedate = "0.13.0"
2 changes: 1 addition & 1 deletion contracts/ibc_transfer/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
unit-test = "test --lib"
integration-test = "test --test integration"
schema = "run --bin ibc_transfer_schema"
2 changes: 0 additions & 2 deletions contracts/ibc_transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ crate-type = ["cdylib", "rlib"]

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
Expand Down
18 changes: 11 additions & 7 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use cosmwasm_std::{
coin, entry_point, from_json, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply,
Response, StdError, StdResult, SubMsg,
coin, entry_point, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, Response,
StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_sdk::interchain_txs::helpers::decode_message_response;
use neutron_sdk::proto_types::neutron::transfer::MsgTransferResponse;
use neutron_sdk::{
bindings::{
msg::{IbcFee, MsgIbcTransferResponse, NeutronMsg},
msg::{IbcFee, NeutronMsg},
query::NeutronQuery,
},
query::min_ibc_fee::query_min_ibc_fee,
Expand Down Expand Up @@ -112,12 +114,14 @@ fn msg_with_sudo_callback<C: Into<CosmosMsg<T>>, T>(
// and process this payload when an acknowledgement for the SubmitTx message is received in Sudo handler
fn prepare_sudo_payload(mut deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> {
let payload = read_reply_payload(deps.storage, msg.id)?;
let resp: MsgIbcTransferResponse = from_json(
msg.result
let resp: MsgTransferResponse = decode_message_response(
&msg.result
.into_result()
.map_err(StdError::generic_err)?
.data
.ok_or_else(|| StdError::generic_err("no result"))?,
.msg_responses[0] // msg_responses must have exactly one Msg response: https://github.com/neutron-org/neutron/blob/28b1d2ce968aaf1866e92d5286487f079eba3370/wasmbinding/message_plugin.go#L307
.clone()
.value
.to_vec(),
)
.map_err(|e| StdError::generic_err(format!("failed to parse response: {:?}", e)))?;
let seq_id = resp.sequence_id;
Expand Down
4 changes: 2 additions & 2 deletions contracts/ibc_transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn save_reply_payload(store: &mut dyn Storage, payload: SudoPayload) -> StdR

pub fn read_reply_payload(store: &dyn Storage, id: u64) -> StdResult<SudoPayload> {
let data = REPLY_QUEUE_ID.load(store, id)?;
from_json(Binary(data))
from_json(Binary::new(data))
}

/// SUDO_PAYLOAD - tmp storage for sudo handler payloads
Expand All @@ -59,5 +59,5 @@ pub fn read_sudo_payload(
seq_id: u64,
) -> StdResult<SudoPayload> {
let data = SUDO_PAYLOAD.load(store, (channel_id, seq_id))?;
from_json(Binary(data))
from_json(Binary::new(data))
}
2 changes: 1 addition & 1 deletion contracts/neutron_interchain_queries/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
unit-test = "test --lib"
integration-test = "test --test integration"
schema = "run --bin neutron_interchain_queries_schema"
3 changes: 0 additions & 3 deletions contracts/neutron_interchain_queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ exclude = [
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
Expand All @@ -32,4 +30,3 @@ cosmwasm-schema = { workspace = true }

[dev-dependencies]
base64 = { workspace = true }

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl WasmMockQuerier {
validators: &[Validator],
delegations: &[FullDelegation],
) {
self.base.update_staking(denom, validators, delegations);
self.base.staking.update(denom, validators, delegations);
}

pub fn add_query_response(&mut self, query_id: u64, response: Binary) {
Expand Down
112 changes: 82 additions & 30 deletions contracts/neutron_interchain_queries/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use cosmos_sdk_proto::cosmos::slashing::v1beta1::ValidatorSigningInfo as CosmosV
use cosmos_sdk_proto::cosmos::staking::v1beta1::Validator as CosmosValidator;
use cosmos_sdk_proto::traits::Message;
use cosmos_sdk_proto::Any;
use cosmwasm_std::testing::{mock_env, mock_info, MockApi, MockStorage};
use cosmwasm_std::testing::{message_info, mock_env, MockApi, MockStorage};
use cosmwasm_std::{
from_json, to_json_binary, Addr, Binary, Coin, Decimal, Delegation, Env, MessageInfo,
OwnedDeps, StdError, Uint128,
from_json, to_json_binary, Addr, Binary, Coin, Decimal, Env, MessageInfo, OwnedDeps, StdError,
Uint128,
};
use neutron_sdk::bindings::query::{
NeutronQuery, QueryRegisteredQueryResponse, QueryRegisteredQueryResultResponse,
Expand All @@ -35,8 +35,8 @@ use neutron_sdk::interchain_queries::v047::helpers::{
create_total_denom_key, create_validator_key,
};
use neutron_sdk::interchain_queries::v047::types::{
Balances, FeePool, GovernmentProposal, Proposal, SigningInfo, StakingValidator, TallyResult,
TotalSupply, Validator, ValidatorSigningInfo, RECIPIENT_FIELD, STAKING_PARAMS_KEY,
Balances, FeePool, GovernmentProposal, Proposal, SigningInfo, StakingValidator, StdDelegation,
TallyResult, TotalSupply, Validator, ValidatorSigningInfo, RECIPIENT_FIELD, STAKING_PARAMS_KEY,
};

use neutron_sdk::interchain_queries::v047::queries::{
Expand Down Expand Up @@ -96,8 +96,8 @@ fn build_interchain_query_bank_total_denom_value(denom: String, amount: String)

StorageValue {
storage_prefix: "".to_string(),
key: Binary(bank_total_key),
value: Binary(amount),
key: Binary::new(bank_total_key),
value: Binary::new(amount),
}
}

Expand All @@ -112,8 +112,8 @@ fn build_interchain_query_distribution_fee_pool_response(denom: String, amount:

let s = StorageValue {
storage_prefix: "".to_string(),
key: Binary(fee_pool_key),
value: Binary(fee_pool.encode_to_vec()),
key: Binary::new(fee_pool_key),
value: Binary::new(fee_pool.encode_to_vec()),
};
Binary::from(
to_string(&QueryRegisteredQueryResultResponse {
Expand Down Expand Up @@ -151,8 +151,8 @@ fn build_interchain_query_staking_validator_value(validator: String) -> StorageV

StorageValue {
storage_prefix: "".to_string(),
key: Binary(validator_key),
value: Binary(validator.encode_to_vec()),
key: Binary::new(validator_key),
value: Binary::new(validator.encode_to_vec()),
}
}

Expand All @@ -174,8 +174,8 @@ fn build_interchain_query_validator_signing_info_value(

StorageValue {
storage_prefix: "".to_string(),
key: Binary(validator_key),
value: Binary(validator.encode_to_vec()),
key: Binary::new(validator_key),
value: Binary::new(validator.encode_to_vec()),
}
}

Expand Down Expand Up @@ -207,8 +207,8 @@ fn build_interchain_query_gov_proposal_value(proposal_id: u64) -> StorageValue {

StorageValue {
storage_prefix: "".to_string(),
key: Binary(proposal_key),
value: Binary(proposal.encode_to_vec()),
key: Binary::new(proposal_key),
value: Binary::new(proposal.encode_to_vec()),
}
}

Expand All @@ -223,8 +223,8 @@ fn build_interchain_query_balances_response(addr: Addr, balances: Vec<Coin>) ->
.unwrap();
StorageValue {
storage_prefix: "".to_string(),
key: Binary(balance_key),
value: Binary(c.amount.to_string().into_bytes()),
key: Binary::new(balance_key),
value: Binary::new(c.amount.to_string().into_bytes()),
}
})
.collect();
Expand Down Expand Up @@ -270,7 +270,12 @@ fn test_query_balance() {
denoms: vec!["uosmo".to_string()],
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);
Expand Down Expand Up @@ -308,7 +313,12 @@ fn test_query_balances() {
denoms: vec!["uosmo".to_string(), "uatom".to_string()],
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);
Expand Down Expand Up @@ -353,7 +363,12 @@ fn test_bank_total_supply_query() {
denoms: denoms.clone(),
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);
Expand Down Expand Up @@ -404,7 +419,12 @@ fn test_distribution_fee_pool_query() {
update_period: 10,
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);
Expand Down Expand Up @@ -443,7 +463,12 @@ fn test_gov_proposals_query() {
update_period: 10,
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);
Expand Down Expand Up @@ -553,7 +578,12 @@ fn test_staking_validators_query() {
validators: validators.clone(),
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);
Expand Down Expand Up @@ -656,7 +686,12 @@ fn test_validators_signing_infos_query() {
validators: validators.clone().into_iter().map(|(v, _)| v).collect(),
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys.0), QueryType::KV, 987);
Expand Down Expand Up @@ -725,7 +760,12 @@ fn test_query_delegator_delegations() {
],
};

let keys = register_query(&mut deps, mock_env(), mock_info("", &[]), msg);
let keys = register_query(
&mut deps,
mock_env(),
message_info(&Addr::unchecked(""), &[]),
msg,
);

let delegations_response = QueryRegisteredQueryResultResponse {
result: InterchainQueryResult {
Expand Down Expand Up @@ -812,17 +852,17 @@ fn test_query_delegator_delegations() {
DelegatorDelegationsResponse {
last_submitted_local_height: 987,
delegations: vec![
Delegation {
StdDelegation {
delegator: Addr::unchecked("osmo1yz54ncxj9csp7un3xled03q6thrrhy9cztkfzs"),
validator: "osmovaloper1r2u5q6t6w0wssrk6l66n3t2q3dw2uqny4gj2e3".to_string(),
amount: Coin::new(5177628u128, "uatom".to_string()),
},
Delegation {
StdDelegation {
delegator: Addr::unchecked("osmo1yz54ncxj9csp7un3xled03q6thrrhy9cztkfzs"),
validator: "osmovaloper1ej2es5fjztqjcd4pwa0zyvaevtjd2y5w37wr9t".to_string(),
amount: Coin::new(29620221u128, "uatom".to_string()),
},
Delegation {
StdDelegation {
delegator: Addr::unchecked("osmo1yz54ncxj9csp7un3xled03q6thrrhy9cztkfzs"),
validator: "osmovaloper1lzhlnpahvznwfv4jmay2tgaha5kmz5qxwmj9we".to_string(),
amount: Coin::new(219920u128, "uatom".to_string()),
Expand All @@ -845,7 +885,13 @@ fn test_sudo_tx_query_result_callback() {
recipient: watched_addr.clone(),
min_height: None,
};
execute(deps.as_mut(), env.clone(), mock_info("", &[]), msg).unwrap();
execute(
deps.as_mut(),
env.clone(),
message_info(&Addr::unchecked(""), &[]),
msg,
)
.unwrap();
let registered_query = build_registered_query_response(
1,
QueryParam::TransactionsFilter(
Expand Down Expand Up @@ -969,7 +1015,13 @@ fn test_sudo_tx_query_result_min_height_callback() {
recipient: watched_addr.clone(),
min_height: Some(100000),
};
execute(deps.as_mut(), env.clone(), mock_info("", &[]), msg).unwrap();
execute(
deps.as_mut(),
env.clone(),
message_info(&Addr::unchecked(""), &[]),
msg,
)
.unwrap();
let registered_query = build_registered_query_response(
1,
QueryParam::TransactionsFilter(
Expand Down
2 changes: 1 addition & 1 deletion contracts/neutron_interchain_txs/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
unit-test = "test --lib"
integration-test = "test --test integration"
schema = "run --bin neutron_interchain_txs_schema"
Loading

0 comments on commit 9aac376

Please sign in to comment.