Skip to content

Commit

Permalink
Cosmwasm std 2 update (#390)
Browse files Browse the repository at this point in the history
* Started cosmwasm-std2 change

* Nit

* Update

* Check all features work

* Update

* formatting

* Make bumps and compilable

* fix tests

* test fixes

* fix interchain tests and doctests

* move compatibility test

* clippy

* Cosmwasm2 accept addr (#467)

* accept addr instead of Into<String> where bech32 address expected

* doctests

---------

Co-authored-by: Buckram <[email protected]>
Co-authored-by: Mykhailo Donchenko <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2024
1 parent 4b28561 commit 388dc29
Show file tree
Hide file tree
Showing 82 changed files with 544 additions and 920 deletions.
50 changes: 26 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ members = [
"packages/cw-orch-core",
"packages/cw-orch-mock",
"packages/cw-orch-networks",
"packages/cw-orch-osmosis-test-tube",
# "packages/clone-testing",
# "packages/cw-orch-osmosis-test-tube",
"packages/cw-orch-traits",
"contracts/*",
"test_contracts/*",
"packages/macros/*",
"packages/interchain/*",
]
exclude = ["test_contracts/compatibility-test"]
resolver = "2"

[workspace.package]
Expand All @@ -21,44 +24,46 @@ license = "GPL-3.0-only"
repository = "https://github.com/AbstractSDK/cw-orchestrator"

[workspace.dependencies]
cw-utils = { version = "1.0.1" }
cosmwasm-std = { version = "1.1" }
cw-multi-test = { package = "abstract-cw-multi-test", version = "1.0.0", features = [
"cosmwasm_1_4",
cw-utils = { version = "2.0.0" }
cosmwasm-std = { version = "2.0" }
cw-storage-plus = { version = "2.0.0" }

cw-multi-test = { package = "abstract-cw-multi-test", version = "2.0.0", features = [
"cosmwasm_1_2",
] }
cw20 = { package = "abstract-cw20", version = "1.2.2" }
cw20-base = { package = "abstract-cw20-base", version = "1.2.2" }
cw20 = { package = "abstract-cw20", version = "3.0.0" }
cw20-base = { package = "abstract-cw20-base", version = "3.0.0" }

osmosis-test-tube = { version = "25.0.0" }

anyhow = "1.0"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
tokio = { version = "1.4", features = ["full"] }

cw-orch = { path = "./cw-orch", version = "0.24.1" }
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.24.3" }
cw-orch-core = { path = "packages/cw-orch-core", version = "1.2.2" }
cw-orch-traits = { path = "packages/cw-orch-traits", version = "0.23.3" }
cw-orch-mock = { path = "packages/cw-orch-mock", version = "0.23.1" }
cw-orch-networks = { path = "packages/cw-orch-networks", version = "0.23.3" }
cw-orch = { path = "./cw-orch", version = "0.25.0" }
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.25.0" }
cw-orch-core = { path = "packages/cw-orch-core", version = "2.0.0" }
cw-orch-traits = { path = "packages/cw-orch-traits", version = "0.24.0" }
cw-orch-mock = { path = "packages/cw-orch-mock", version = "0.24.0" }
cw-orch-networks = { path = "packages/cw-orch-networks", version = "0.24.0" }

# Macros
cw-orch-contract-derive = { path = "packages/macros/cw-orch-contract-derive", version = "0.21.0" }
cw-orch-fns-derive = { path = "packages/macros/cw-orch-fns-derive", version = "0.22.0" }

# Extensions
cw-orch-osmosis-test-tube = { version = "0.3.0", path = "packages/cw-orch-osmosis-test-tube" }
# cw-orch-osmosis-test-tube = { version = "0.3.0", path = "packages/cw-orch-osmosis-test-tube" }

# Interchain
cw-orch-interchain = { path = "cw-orch-interchain", version = "0.3.1" }
cw-orch-interchain-core = { path = "packages/interchain/interchain-core", version = "0.4.1" }
cw-orch-interchain-daemon = { path = "packages/interchain/interchain-daemon", version = "0.4.1" }
cw-orch-interchain-mock = { path = "packages/interchain/interchain-mock", version = "0.4.1" }
cw-orch-starship = { path = "packages/interchain/starship", version = "0.4.1" }
cw-orch-proto = { path = "packages/interchain/proto", version = "0.4.1" }
cw-orch-interchain = { path = "cw-orch-interchain", version = "0.4.0" }
cw-orch-interchain-core = { path = "packages/interchain/interchain-core", version = "0.5.0" }
cw-orch-interchain-daemon = { path = "packages/interchain/interchain-daemon", version = "0.5.0" }
cw-orch-interchain-mock = { path = "packages/interchain/interchain-mock", version = "0.5.0" }
cw-orch-starship = { path = "packages/interchain/starship", version = "0.5.0" }
cw-orch-proto = { path = "packages/interchain/proto", version = "0.5.0" }

#Clone Testing
cw-orch-clone-testing = { version = "0.6.1", path = "packages/clone-testing" }
# cw-orch-clone-testing = { version = "0.6.1", path = "packages/clone-testing" }

thiserror = { version = "1.0.21" }
sha2 = { version = "0.10.8" }
Expand All @@ -76,6 +81,3 @@ log = "0.4.14"
# Interchain
ibc-relayer-types = { version = "0.25.0" }
ibc-chain-registry = { version = "0.25.0" }

[patch.crates-io]
cw-orch-core = { path = "packages/cw-orch-core" }
12 changes: 3 additions & 9 deletions contracts/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export = []

[dependencies]
cosmwasm-std = { workspace = true }
cw-storage-plus = "1.0"
cw2 = "1.0"
cw-storage-plus = { workspace = true }
cw2 = "2.0"
cosmwasm-schema = "1.2"
schemars = "0.8.10"
thiserror = { version = "1.0.21" }
Expand All @@ -34,11 +34,5 @@ name = "deploy"
dotenv = { version = "0.15.0" }
pretty_env_logger = { version = "0.5.0" }
cw-orch = { path = "../../cw-orch", features = ["daemon"] }
cw-orch-osmosis-test-tube = { workspace = true }
# cw-orch-osmosis-test-tube = { workspace = true }
anyhow = { workspace = true }

# Clone Testing test
cw-orch-clone-testing = { workspace = true }
cw20 = { workspace = true }
cw20-base = { workspace = true }
log = { workspace = true }
15 changes: 8 additions & 7 deletions contracts/counter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ mod tests {
use super::*;
use cosmwasm_std::{
coins, from_json,
testing::{mock_dependencies, mock_env, mock_info},
testing::{message_info, mock_dependencies, mock_env},
Addr,
};

#[test]
fn proper_initialization() {
let mut deps = mock_dependencies();

let msg = InstantiateMsg { count: 17 };
let info = mock_info("creator", &coins(1000, "earth"));
let info = message_info(&Addr::unchecked("creator"), &coins(1000, "earth"));

// we can just call .unwrap() to assert this was a success
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
Expand All @@ -88,11 +89,11 @@ mod tests {
let mut deps = mock_dependencies();

let msg = InstantiateMsg { count: 17 };
let info = mock_info("creator", &coins(2, "token"));
let info = message_info(&Addr::unchecked("creator"), &coins(2, "token"));
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();

// beneficiary can release it
let info = mock_info("anyone", &coins(2, "token"));
let info = message_info(&Addr::unchecked("anyone"), &coins(2, "token"));
let msg = ExecuteMsg::Increment {};
let _res = execute(deps.as_mut(), mock_env(), info, msg).unwrap();

Expand All @@ -107,11 +108,11 @@ mod tests {
let mut deps = mock_dependencies();

let msg = InstantiateMsg { count: 17 };
let info = mock_info("creator", &coins(2, "token"));
let info = message_info(&Addr::unchecked("creator"), &coins(2, "token"));
let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();

// beneficiary can release it
let unauth_info = mock_info("anyone", &coins(2, "token"));
let unauth_info = message_info(&Addr::unchecked("anyone"), &coins(2, "token"));
let msg = ExecuteMsg::Reset { count: 5 };
let res = execute(deps.as_mut(), mock_env(), unauth_info, msg);
match res {
Expand All @@ -120,7 +121,7 @@ mod tests {
}

// only the original creator can reset the counter
let auth_info = mock_info("creator", &coins(2, "token"));
let auth_info = message_info(&Addr::unchecked("creator"), &coins(2, "token"));
let msg = ExecuteMsg::Reset { count: 5 };
let _res = execute(deps.as_mut(), mock_env(), auth_info, msg).unwrap();

Expand Down
5 changes: 2 additions & 3 deletions contracts/counter/tests/checksum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use counter_contract::CounterContract;
use cw_orch::{contract::interface_traits::Uploadable, mock::Mock};
use cw_orch_osmosis_test_tube::MOCK_CHAIN_INFO;
use cw_orch::{contract::interface_traits::Uploadable, daemon::networks::OSMOSIS_1, mock::Mock};

#[test]
fn checksum() {
Expand All @@ -17,7 +16,7 @@ fn checksum() {
if line.contains("counter_contract.wasm") {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() > 1 {
let calculated_hash = CounterContract::<Mock>::wasm(&MOCK_CHAIN_INFO.into())
let calculated_hash = CounterContract::<Mock>::wasm(&OSMOSIS_1.into())
.checksum()
.unwrap();
assert_eq!(parts[0], calculated_hash.to_string());
Expand Down
4 changes: 2 additions & 2 deletions contracts/mock_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ interface = []

[dependencies]
cosmwasm-std = { workspace = true }
cw2 = { version = "1.1.2" }
cw2 = { version = "2.0.0" }
serde = { workspace = true }
schemars = "0.8.10"
serde_json = "1.0.79"
thiserror = { version = "1.0.21" }
cosmwasm-schema = "1.2"
cw-orch = { path = "../../cw-orch" }
cw-storage-plus = { version = "1.2.0" }
cw-storage-plus = { workspace = true }
6 changes: 3 additions & 3 deletions contracts/mock_contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ mod test {
#[test]
fn compiles() -> Result<(), CwOrchError> {
// We need to check we can still call the execute msgs conveniently
let sender = Addr::unchecked("sender");
let mock = Mock::new(&sender);
let mock = Mock::new("sender");
let sender = mock.sender_addr();
mock.set_balance(&sender, coins(156 * 3, "ujuno"))?;
let contract = LocalMockContract::new("mock-contract", mock.clone());

Expand Down Expand Up @@ -253,7 +253,7 @@ mod test {

let cw2_info: cw2::ContractVersion = from_json(
mock.wasm_querier()
.raw_query(contract.address()?, b"contract_info".to_vec())?,
.raw_query(&contract.address()?, b"contract_info".to_vec())?,
)?;

assert_eq!(
Expand Down
6 changes: 3 additions & 3 deletions contracts/mock_contract_u64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ pub mod interface {
mod test {
use super::interface::MockContract as LocalMockContract;
use super::*;
use cosmwasm_std::{coins, Addr};
use cosmwasm_std::coins;
use cw_orch::prelude::*;
use mock_contract::{ExecuteMsgFns, QueryMsgFns};

#[test]
fn compiles() -> Result<(), CwOrchError> {
// We need to check we can still call the execute msgs conveniently
let sender = Addr::unchecked("sender");
let mock = Mock::new(&sender);
let mock = Mock::new("sender");
let sender = mock.sender_addr();
mock.set_balance(&sender, coins(156 * 2, "ujuno"))?;
let contract = LocalMockContract::new(mock.clone());

Expand Down
2 changes: 1 addition & 1 deletion cw-orch-daemon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-daemon"
version = "0.24.3"
version = "0.25.0"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
7 changes: 5 additions & 2 deletions cw-orch-daemon/examples/daemon-capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use cosmrs::{tx::Msg, AccountId, Coin, Denom};
use cosmwasm_std::coins;
use cosmwasm_std::{coins, Addr};
// ANCHOR: full_counter_example
use cw_orch_daemon::senders::tx::TxSender;
use cw_orch_daemon::DaemonBuilder;
Expand All @@ -22,7 +22,10 @@ pub fn main() -> anyhow::Result<()> {
let wallet = daemon.sender();

let rt = daemon.rt_handle.clone();
rt.block_on(wallet.bank_send("<address-of-my-sister>", coins(345, "ujunox")))?;
rt.block_on(wallet.bank_send(
&Addr::unchecked("<address-of-my-sister>"),
coins(345, "ujunox"),
))?;
// ANCHOR_END: send_tx

// ANCHOR: cosmrs_tx
Expand Down
4 changes: 3 additions & 1 deletion cw-orch-daemon/examples/querier-daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ pub fn main() -> anyhow::Result<()> {
// There is no need to register a mnemonic to use this daemon querier
let chain: QueryOnlyDaemon = QueryOnlyDaemon::builder(network).build_sender(())?;

let balances = chain.bank_querier().balance(LOCAL_JUNO_SENDER, None)?;
let balances = chain
.bank_querier()
.balance(&Addr::unchecked(LOCAL_JUNO_SENDER), None)?;
assert!(!balances.is_empty());

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions cw-orch-daemon/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ impl AsyncWasmQuerier for DaemonAsync {
/// Query a contract.
fn smart_query<Q: Serialize + Sync, T: DeserializeOwned>(
&self,
address: impl Into<String> + Send,
address: &Addr,
query_msg: &Q,
) -> impl std::future::Future<Output = Result<T, DaemonError>> + Send {
let query_data = serde_json::to_vec(&query_msg).unwrap();
let query_data = serde_json::to_vec(query_msg).unwrap();
async {
let mut client =
cosmos_modules::cosmwasm::query_client::QueryClient::new(self.channel());
Expand Down
2 changes: 2 additions & 0 deletions cw-orch-daemon/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub enum DaemonError {
QuerierNeedRuntime,
#[error(transparent)]
Instantiate2Error(#[from] Instantiate2AddressError),
#[error(transparent)]
CheckSum(#[from] cosmwasm_std::ChecksumError),
#[error("Error opening file {0},err: ({1})")]
OpenFile(String, String),
#[error("State file {0} already locked, use another state file, clone daemon which holds the lock, or use `state` method of Builder")]
Expand Down
53 changes: 29 additions & 24 deletions cw-orch-daemon/src/live_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ impl WasmMockQuerier {

let query_result: Result<Binary, _> = handle
.block_on(
querier._contract_state(contract_addr.to_string(), msg.to_vec()),
querier
._contract_state(&Addr::unchecked(contract_addr), msg.to_vec()),
)
.map(|query_result| query_result.into());
SystemResult::Ok(ContractResult::from(query_result))
}
WasmQuery::Raw { contract_addr, key } => {
// We forward the request to the cosmwasm querie
let query_result = querier
.raw_query(contract_addr.to_string(), key.to_vec())
.raw_query(&Addr::unchecked(contract_addr), key.to_vec())
.map(|query_result| query_result.into());

SystemResult::Ok(ContractResult::from(query_result))
Expand All @@ -114,19 +115,17 @@ impl WasmMockQuerier {
};
match x {
BankQuery::Balance { address, denom } => {
let query_result =
querier.balance(address, Some(denom.clone())).map(|result| {
to_json_binary(&BalanceResponse {
amount: result[0].clone(),
})
.unwrap()
let query_result = querier
.balance(&Addr::unchecked(address), Some(denom.clone()))
.map(|result| {
to_json_binary(&BalanceResponse::new(result[0].clone())).unwrap()
});
SystemResult::Ok(ContractResult::from(query_result))
}
BankQuery::AllBalances { address } => {
let query_result = querier
.balance(address, None)
.map(|result| AllBalanceResponse { amount: result })
.balance(&Addr::unchecked(address), None)
.map(AllBalanceResponse::new)
.map(|query_result| to_json_binary(&query_result))
.unwrap();
SystemResult::Ok(ContractResult::from(query_result))
Expand All @@ -143,8 +142,8 @@ impl WasmMockQuerier {
StakingQuery::BondedDenom {} => {
let query_result = handle
.block_on(querier._params())
.map(|result| BondedDenomResponse {
denom: result.params.unwrap().bond_denom,
.map(|result| {
BondedDenomResponse::new(result.params.unwrap().bond_denom)
})
.map(|query_result| to_json_binary(&query_result))
.unwrap();
Expand All @@ -154,19 +153,25 @@ impl WasmMockQuerier {
// TODO, do better here
StakingQuery::AllDelegations { delegator } => {
let query_result = handle
.block_on(querier._delegator_delegations(delegator, None))
.map(|result| AllDelegationsResponse {
delegations: result
.delegation_responses
.into_iter()
.filter_map(|delegation| {
delegation.delegation.map(|d| Delegation {
delegator: Addr::unchecked(d.delegator_address),
validator: d.validator_address,
amount: to_cosmwasm_coin(delegation.balance.unwrap()),
.block_on(
querier._delegator_delegations(&Addr::unchecked(delegator), None),
)
.map(|result| {
AllDelegationsResponse::new(
result
.delegation_responses
.into_iter()
.filter_map(|delegation| {
delegation.delegation.map(|d| {
Delegation::new(
Addr::unchecked(d.delegator_address),
d.validator_address,
to_cosmwasm_coin(delegation.balance.unwrap()),
)
})
})
})
.collect(),
.collect(),
)
})
.map(|query_result| to_json_binary(&query_result))
.unwrap();
Expand Down
Loading

0 comments on commit 388dc29

Please sign in to comment.