Skip to content

Commit 570aea3

Browse files
committed
Fix cw-orch-mock and clone-testing
1 parent 3e7c3b8 commit 570aea3

File tree

7 files changed

+59
-23
lines changed

7 files changed

+59
-23
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ cosmwasm-std = { version = "2.1" }
3232
cw-storage-plus = { version = "2.0.0" }
3333
cw-utils = { version = "2.0.0" }
3434

35-
cw-multi-test = { package = "abstract-cw-multi-test", version = "2.0.2", features = ["cosmwasm_1_2"] }
35+
# cw-multi-test = { package = "abstract-cw-multi-test", version = "2.0.2", features = ["cosmwasm_1_2"] }
36+
cw-multi-test = { package = "abstract-cw-multi-test", git = "https://github.com/abstractsdk/cw-multi-test-fork", branch = "token-factory-integration", version = "2.0.2", features = ["cosmwasm_1_2", "tokenfactory"] }
3637
cw20 = { version = "2.0.0" }
3738
cw20-base = { version = "2.0.0" }
3839

packages/clone-testing/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition.workspace = true
55
license.workspace = true
66
name = "cw-orch-clone-testing"
77
repository.workspace = true
8-
version = "0.9.2"
8+
version = "0.10.0"
99

1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

@@ -16,7 +16,9 @@ cw-orch-core = { workspace = true }
1616
cw-orch-daemon = { workspace = true }
1717
cw-orch-mock = { workspace = true }
1818

19-
clone-cw-multi-test = { version = "0.6.1" }
19+
# clone-cw-multi-test = { version = "0.7.0" }
20+
# clone-cw-multi-test = { path = "../../../cw-multi-test-fork", features = ["cosmwasm_1_2", "tokenfactory", "staking"] }
21+
clone-cw-multi-test = { git = "https://github.com/abstractsdk/cw-multi-test-fork", branch = "adapt_for_local_execution", features = ["cosmwasm_1_2", "stargate", "tokenfactory", "staking"] }
2022

2123
anyhow = { workspace = true }
2224
cw-utils = { workspace = true }

packages/clone-testing/src/core.rs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
use std::{cell::RefCell, fmt::Debug, io::Read, rc::Rc};
22

3+
use clone_cw_multi_test::tokenfactory::TokenFactoryStargate;
4+
use clone_cw_multi_test::wasm_emulation::query::ContainsRemote;
35
use clone_cw_multi_test::{
4-
addons::{MockAddressGenerator, MockApiBech32},
56
wasm_emulation::{channel::RemoteChannel, storage::analyzer::StorageAnalyzer},
67
App, AppBuilder, BankKeeper, Contract, Executor, WasmKeeper,
78
};
9+
use clone_cw_multi_test::{
10+
DistributionKeeper, FailingModule, GovFailingModule, IbcFailingModule, MockApiBech32,
11+
StakeKeeper,
12+
};
13+
use cosmwasm_std::testing::MockStorage;
814
use cosmwasm_std::{
915
to_json_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Empty, Event, StdError, StdResult,
1016
Uint128, WasmMsg,
@@ -26,7 +32,18 @@ use crate::{contract::CloneTestingContract, queriers::bank::CloneBankQuerier};
2632

2733
use super::state::MockState;
2834

29-
pub type CloneTestingApp = App<BankKeeper, MockApiBech32>;
35+
pub type CloneTestingApp = App<
36+
BankKeeper,
37+
MockApiBech32,
38+
MockStorage,
39+
FailingModule<Empty, Empty, Empty>,
40+
WasmKeeper<Empty, Empty>,
41+
StakeKeeper,
42+
DistributionKeeper,
43+
IbcFailingModule,
44+
GovFailingModule,
45+
TokenFactoryStargate,
46+
>;
3047

3148
/// Wrapper around a cw-multi-test [`App`](cw_multi_test::App) backend.
3249
///
@@ -77,9 +94,20 @@ pub struct CloneTesting<S: StateInterface = MockState> {
7794
}
7895

7996
impl CloneTesting {
80-
/// Ceates a new valid account
81-
pub fn init_account(&self) -> Addr {
82-
self.app.borrow_mut().next_address()
97+
/// Creates a new valid account
98+
pub fn addr_make(&self, account_name: impl Into<String>) -> Addr {
99+
self.app.borrow().api().addr_make(&account_name.into())
100+
}
101+
102+
pub fn addr_make_with_balance(
103+
&self,
104+
account_name: impl Into<String>,
105+
balance: Vec<Coin>,
106+
) -> Result<Addr, CwEnvError> {
107+
let addr = self.app.borrow().api().addr_make(&account_name.into());
108+
self.set_balance(&addr, balance)?;
109+
110+
Ok(addr)
83111
}
84112

85113
/// Set the bank balance of an address.
@@ -154,6 +182,7 @@ impl CloneTesting {
154182
let code_id = self.app.borrow_mut().store_wasm_code(wasm);
155183

156184
contract.set_code_id(code_id);
185+
println!("{code_id}");
157186

158187
// add contract code_id to events manually
159188
let mut event = Event::new("store_code");
@@ -229,9 +258,7 @@ impl<S: StateInterface> CloneTesting<S> {
229258
)
230259
.unwrap();
231260

232-
let wasm = WasmKeeper::<Empty, Empty>::new()
233-
.with_remote(remote_channel.clone())
234-
.with_address_generator(MockAddressGenerator);
261+
let wasm = WasmKeeper::<Empty, Empty>::new().with_remote(remote_channel.clone());
235262

236263
let bank = BankKeeper::new().with_remote(remote_channel.clone());
237264

@@ -247,10 +274,11 @@ impl<S: StateInterface> CloneTesting<S> {
247274
.with_bank(bank)
248275
.with_api(MockApiBech32::new(&pub_address_prefix))
249276
.with_block(block_info)
250-
.with_remote(remote_channel.clone());
277+
.with_remote(remote_channel.clone())
278+
.with_stargate(TokenFactoryStargate);
251279

252-
let app = Rc::new(RefCell::new(app.build(|_, _, _| {})?));
253-
let sender = app.borrow_mut().next_address();
280+
let app = Rc::new(RefCell::new(app.build(|_, _, _| {})));
281+
let sender = app.borrow().api().addr_make("sender");
254282

255283
Ok(Self {
256284
chain,
@@ -573,7 +601,7 @@ mod test {
573601
let chain = CloneTesting::new(chain_info)?;
574602

575603
let sender = chain.sender_addr();
576-
let recipient = &chain.init_account();
604+
let recipient = &chain.addr_make("recipient");
577605

578606
chain
579607
.set_balance(recipient, vec![Coin::new(amount, denom)])
@@ -657,7 +685,7 @@ mod test {
657685
let mock_state = MockState::new(JUNO_1.into(), "default_id");
658686

659687
let chain: CloneTesting = CloneTesting::<_>::new_custom(&rt, chain, mock_state)?;
660-
let recipient = chain.init_account();
688+
let recipient = chain.addr_make("recipient");
661689

662690
chain
663691
.set_balances(&[(&recipient, &[Coin::new(amount, denom)])])
@@ -705,7 +733,7 @@ mod test {
705733
let chain_info = JUNO_1;
706734

707735
let chain = CloneTesting::new(chain_info)?;
708-
let recipient = &chain.init_account();
736+
let recipient = &chain.addr_make("recipient");
709737

710738
chain
711739
.add_balance(recipient, vec![Coin::new(amount, denom_1)])

packages/clone-testing/tests/wasm-upload.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ use counter_contract::CounterContract;
22
use cw_orch::prelude::*;
33
use cw_orch_clone_testing::CloneTesting;
44
use cw_orch_daemon::networks::JUNO_1;
5+
use networks::OSMOSIS_1;
56

67
#[test]
78
fn multiple_upload() -> anyhow::Result<()> {
9+
let mut chain = OSMOSIS_1;
810
// ANCHOR: clone_testing_setup
9-
let chain = CloneTesting::new(JUNO_1)?;
11+
let chain = CloneTesting::new(chain)?;
1012
// ANCHOR_END: clone_testing_setup
1113
// ANCHOR: counter_contract_setup
1214
let contract = CounterContract::new(chain.clone());

packages/cw-orch-mock/src/bech32.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{cell::RefCell, rc::Rc};
22

33
use cosmwasm_std::{testing::MockApi, Addr, Coin, Uint128};
4-
use cw_multi_test::{AppBuilder, MockApiBech32};
4+
use cw_multi_test::{AppBuilder, MockApiBech32, TokenFactoryStargate};
55
use cw_orch_core::{
66
environment::{BankQuerier, BankSetter, DefaultQueriers, StateInterface, TxHandler},
77
CwEnvError,
@@ -74,6 +74,7 @@ impl<S: StateInterface> MockBase<MockApiBech32, S> {
7474
let app = Rc::new(RefCell::new(
7575
AppBuilder::new_custom()
7676
.with_api(MockApiBech32::new(prefix))
77+
.with_stargate(TokenFactoryStargate)
7778
.build(|_, _, _| {}),
7879
));
7980

packages/cw-orch-mock/src/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cosmwasm_std::{
66
};
77
use cw_multi_test::{
88
ibc::IbcSimpleModule, App, AppResponse, BankKeeper, Contract, DistributionKeeper, Executor,
9-
FailingModule, GovFailingModule, MockApiBech32, StakeKeeper, StargateFailing, WasmKeeper,
9+
FailingModule, GovFailingModule, MockApiBech32, StakeKeeper, TokenFactoryStargate, WasmKeeper,
1010
};
1111
use serde::Serialize;
1212

@@ -27,7 +27,7 @@ pub type MockApp<A = MockApi> = App<
2727
DistributionKeeper,
2828
IbcSimpleModule,
2929
GovFailingModule,
30-
StargateFailing,
30+
TokenFactoryStargate,
3131
>;
3232

3333
/// Wrapper around a cw-multi-test [`App`](cw_multi_test::App) backend.

packages/cw-orch-mock/src/simple.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::rc::Rc;
33

44
use cosmwasm_std::testing::MockApi;
55
use cosmwasm_std::{Addr, Coin, Uint128};
6-
use cw_multi_test::AppBuilder;
6+
use cw_multi_test::{AppBuilder, TokenFactoryStargate};
77
use cw_orch_core::environment::{BankQuerier, BankSetter, TxHandler};
88
use cw_orch_core::{
99
environment::{DefaultQueriers, StateInterface},
@@ -105,7 +105,9 @@ impl<S: StateInterface> Mock<S> {
105105
/// The state is customizable by implementing the `StateInterface` trait on a custom struct and providing it on the custom constructor.
106106
pub fn new_custom(sender: impl Into<String>, custom_state: S) -> Self {
107107
let state = Rc::new(RefCell::new(custom_state));
108-
let app = AppBuilder::new_custom().build(|_, _, _| {});
108+
let app = AppBuilder::new_custom()
109+
.with_stargate(TokenFactoryStargate)
110+
.build(|_, _, _| {});
109111
let sender: String = sender.into();
110112
let sender = app.api().addr_make(&sender);
111113
let app = Rc::new(RefCell::new(app));

0 commit comments

Comments
 (0)