Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Cosmwasm-std 2.1 for Clone Testing #480

Merged
merged 14 commits into from
Sep 11, 2024
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ members = [
"packages/cw-orch-core",
"packages/cw-orch-mock",
"packages/cw-orch-networks",
# TODO: clone-cw-multi-test depends on cw-orch, so needs to be bumped first
# "packages/clone-testing",
"packages/clone-testing",
# TODO: release those after *-std reaches to prost 0.13
# "packages/cw-orch-osmosis-test-tube",
# "packages/cw-orch-neutron-test-tube",
Expand Down
14 changes: 9 additions & 5 deletions packages/clone-testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-orch-clone-testing"
version = "0.6.4"
version = "0.7.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand All @@ -11,10 +11,13 @@ description = "Adapter for interacting with cw-multi-test via the cw-orchestrato

[dependencies]
cosmwasm-std = { workspace = true }
cw-orch-daemon = { workspace = true }

cw-orch-core = { workspace = true }
cw-orch-mock = { workspace = true }
clone-cw-multi-test = { version = "0.5", features = ["cosmwasm_1_2"] }
cw-orch-daemon = { workspace = true }

clone-cw-multi-test = { version = "0.6.0" }

cw-utils = { workspace = true }
serde = { workspace = true }
log = { workspace = true }
Expand All @@ -27,8 +30,9 @@ tonic = { workspace = true }
[dev-dependencies]
cosmwasm-schema = "2.0.0"
speculoos = { workspace = true }
cw20 = { workspace = true }
cw20-base = { workspace = true }

cw20 = { version = "2.0.0" }
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
cw20-base = { version = "2.0.0" }

env_logger = "0.10.0"
counter-contract = { path = "../../contracts-ws/contracts/counter" }
Expand Down
31 changes: 16 additions & 15 deletions packages/clone-testing/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use std::{cell::RefCell, fmt::Debug, io::Read, rc::Rc};

use clone_cw_multi_test::{
addons::{MockAddressGenerator, MockApiBech32},
wasm_emulation::{
channel::RemoteChannel,
contract::{LocalWasmContract, WasmContract},
storage::analyzer::StorageAnalyzer,
},
wasm_emulation::{channel::RemoteChannel, storage::analyzer::StorageAnalyzer},
App, AppBuilder, BankKeeper, Contract, Executor, WasmKeeper,
};
use cosmwasm_std::{to_json_binary, WasmMsg};
Expand Down Expand Up @@ -155,10 +151,7 @@ impl CloneTesting {
let mut file = std::fs::File::open(T::wasm(&self.chain).path())?;
let mut wasm = Vec::<u8>::new();
file.read_to_end(&mut wasm)?;
let code_id = self
.app
.borrow_mut()
.store_wasm_code(WasmContract::Local(LocalWasmContract { code: wasm }));
let code_id = self.app.borrow_mut().store_wasm_code(wasm);

contract.set_code_id(code_id);

Expand Down Expand Up @@ -224,8 +217,17 @@ impl<S: StateInterface> CloneTesting<S> {
let state = Rc::new(RefCell::new(custom_state));

let pub_address_prefix = chain.network_info.pub_address_prefix.clone();
let remote_channel =
RemoteChannel::new(rt, chain.clone(), pub_address_prefix.clone()).unwrap();
let remote_channel = RemoteChannel::new(
rt,
&chain
.grpc_urls
.iter()
.map(|s| s.as_str())
.collect::<Vec<_>>(),
&chain.chain_id,
&chain.network_info.pub_address_prefix,
)
.unwrap();

let wasm = WasmKeeper::<Empty, Empty>::new()
.with_remote(remote_channel.clone())
Expand Down Expand Up @@ -278,8 +280,8 @@ impl<S: StateInterface> TxHandler for CloneTesting<S> {
type ContractSource = Box<dyn Contract<Empty, Empty>>;
type Sender = Addr;

fn sender(&self) -> Addr {
self.sender_addr()
fn sender(&self) -> &cosmwasm_std::Addr {
&self.sender
}

fn sender_addr(&self) -> Addr {
Expand Down Expand Up @@ -602,8 +604,7 @@ mod test {
.that(&query_res.balance)
.is_equal_to(Uint128::from(100u128));

let migration_res =
chain.migrate(&cw20_base::msg::MigrateMsg {}, code_id, &contract_address);
let migration_res = chain.migrate(&Empty {}, code_id, &contract_address);
asserting("that migration passed on correctly")
.that(&migration_res)
.is_ok();
Expand Down
2 changes: 1 addition & 1 deletion packages/clone-testing/src/queriers/bank.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cell::RefCell, rc::Rc};

use cosmwasm_std::Coin;
use cosmwasm_std::{Addr, Coin};
use cw_orch_core::{
environment::{BankQuerier, Querier, QuerierGetter, StateInterface},
CwEnvError,
Expand Down
10 changes: 7 additions & 3 deletions packages/clone-testing/src/queriers/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{cell::RefCell, rc::Rc};
use crate::{core::CloneTestingApp, CloneTesting};
use clone_cw_multi_test::AddressGenerator;
use clone_cw_multi_test::CosmosRouter;
use cosmwasm_std::{instantiate2_address, Api, Checksum, ContractInfoResponse};
use cosmwasm_std::{instantiate2_address, Addr, Api, Checksum, ContractInfoResponse};
use cw_orch_core::{
contract::interface_traits::{ContractInstance, Uploadable},
environment::{Querier, QuerierGetter, StateInterface, WasmQuerier},
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<S: StateInterface> WasmQuerier for CloneWasmQuerier<S> {
.app
.borrow()
.wrap()
.query_wasm_smart(address.into(), query_data)?)
.query_wasm_smart(address, query_data)?)
}

fn code(&self, code_id: u64) -> Result<cosmwasm_std::CodeInfoResponse, Self::Error> {
Expand All @@ -109,7 +109,11 @@ impl<S: StateInterface> WasmQuerier for CloneWasmQuerier<S> {
) -> Result<String, Self::Error> {
// Clone Testing needs mock
let checksum = self.code_id_hash(code_id)?;
let canon_creator = self.app.borrow().api().addr_canonicalize(&creator.into())?;
let canon_creator = self
.app
.borrow()
.api()
.addr_canonicalize(creator.as_str())?;
let canonical_addr = instantiate2_address(checksum.as_slice(), &canon_creator, &salt)?;
Ok(self
.app
Expand Down
4 changes: 2 additions & 2 deletions packages/clone-testing/tests/clone-testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn cavern_integration_test() -> cw_orch::anyhow::Result<()> {

// 0. We start by saving some useful information for later (admin for migration (1.) + code id for remigration (3.))

let contract_info = app.wasm_querier().contract_info(market_addr.to_string())?;
let contract_info = app.wasm_querier().contract_info(&market_addr)?;

let money_market_admin = Addr::unchecked(contract_info.admin.unwrap());
let money_market_code_id = contract_info.code_id;
Expand Down Expand Up @@ -183,6 +183,6 @@ fn query_contract_info() -> cw_orch::anyhow::Result<()> {
let market_addr = Addr::unchecked(MARKET_ADDR);
market.set_address(&market_addr);

app.wasm_querier().contract_info(market.address()?)?;
app.wasm_querier().contract_info(&market.address()?)?;
Ok(())
}
4 changes: 2 additions & 2 deletions packages/clone-testing/tests/wasm-upload.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use counter_contract::CounterContract;
use cw_orch::prelude::*;
use cw_orch_clone_testing::CloneTesting;
use cw_orch_daemon::networks::ARCHWAY_1;
use cw_orch_daemon::networks::JUNO_1;

#[test]
fn multiple_upload() -> anyhow::Result<()> {
// ANCHOR: clone_testing_setup
let chain = CloneTesting::new(ARCHWAY_1)?;
let chain = CloneTesting::new(JUNO_1)?;
// ANCHOR_END: clone_testing_setup
// ANCHOR: counter_contract_setup
let contract = CounterContract::new(chain.clone());
Expand Down
Loading