Skip to content

Commit

Permalink
update cosmwasm to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joldie777 committed Jun 7, 2024
1 parent 8c30912 commit bb89795
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 140 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ 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 }
Expand All @@ -30,5 +30,5 @@ thiserror = "1.0.49"
protobuf = { version = "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: 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
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))
}
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 }

13 changes: 2 additions & 11 deletions contracts/neutron_interchain_queries/src/testing/mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::marker::PhantomData;

use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage};
use cosmwasm_std::{
from_json, Binary, Coin, ContractResult, CustomQuery, FullDelegation, OwnedDeps, Querier,
QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, Validator,
from_json, Binary, Coin, ContractResult, CustomQuery, OwnedDeps, Querier, QuerierResult,
QueryRequest, SystemError, SystemResult, Uint128,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -83,15 +83,6 @@ impl WasmMockQuerier {
}
}

pub fn _update_staking(
&mut self,
denom: &str,
validators: &[Validator],
delegations: &[FullDelegation],
) {
self.base.update_staking(denom, validators, delegations);
}

pub fn add_query_response(&mut self, query_id: u64, response: Binary) {
self.query_responses.insert(query_id, response);
}
Expand Down
105 changes: 76 additions & 29 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 @@ -219,8 +219,8 @@ fn build_interchain_query_balance_response(addr: Addr, denom: String, amount: St

let s = StorageValue {
storage_prefix: "".to_string(),
key: Binary(balance_key),
value: Binary(amount.into_bytes()),
key: Binary::new(balance_key),
value: Binary::new(amount.into_bytes()),
};
Binary::from(
to_string(&QueryRegisteredQueryResultResponse {
Expand Down Expand Up @@ -263,7 +263,12 @@ fn test_query_balance() {
denom: "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 @@ -303,7 +308,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 @@ -354,7 +364,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 @@ -393,7 +408,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 @@ -503,7 +523,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 @@ -606,7 +631,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 @@ -675,7 +705,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 @@ -762,17 +797,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 @@ -795,7 +830,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 @@ -919,7 +960,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
3 changes: 0 additions & 3 deletions contracts/neutron_interchain_txs/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 @@ -29,4 +27,3 @@ cosmos-sdk-proto = { workspace = true }
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }
prost-types = { workspace = true }
cosmwasm-schema = { workspace = true }

4 changes: 2 additions & 2 deletions contracts/neutron_interchain_txs/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn save_reply_payload(store: &mut dyn Storage, payload: SudoPayload) -> StdR

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

pub fn add_error_to_queue(store: &mut dyn Storage, error_msg: String) -> Option<()> {
Expand All @@ -69,7 +69,7 @@ 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))
}

pub fn save_sudo_payload(
Expand Down
2 changes: 1 addition & 1 deletion packages/neutron-sdk/src/bindings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl KVKey {

Some(KVKey {
path: split[0].to_string(),
key: Binary(decode_hex(split[1])?),
key: Binary::new(decode_hex(split[1])?),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/neutron-sdk/src/interchain_queries/v045/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub fn create_gov_proposal_keys(proposals_ids: Vec<u64>) -> NeutronResult<Vec<KV
for id in proposals_ids {
let kv_key = KVKey {
path: GOV_STORE_KEY.to_string(),
key: Binary(create_gov_proposal_key(id)?),
key: Binary::new(create_gov_proposal_key(id)?),
};

kv_keys.push(kv_key)
Expand Down Expand Up @@ -264,7 +264,7 @@ pub fn create_gov_proposals_voters_votes_keys(
for proposal_id in proposals_ids.clone() {
let kv_key = KVKey {
path: GOV_STORE_KEY.to_string(),
key: Binary(create_gov_proposal_voter_votes_key(
key: Binary::new(create_gov_proposal_voter_votes_key(
proposal_id,
&voter_addr,
)?),
Expand Down
Loading

0 comments on commit bb89795

Please sign in to comment.