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

Tokenfactory cw-multi-test update #533

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ cosmwasm-std = { version = "2.1" }
cw-storage-plus = { version = "2.0.0" }
cw-utils = { version = "2.0.0" }

cw-multi-test = { package = "abstract-cw-multi-test", version = "2.0.2", features = ["cosmwasm_1_2"] }
# cw-multi-test = { package = "abstract-cw-multi-test", version = "2.0.2", features = ["cosmwasm_1_2"] }
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"] }
cw20 = { version = "2.0.0" }
cw20-base = { version = "2.0.0" }

Expand Down
6 changes: 4 additions & 2 deletions packages/clone-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition.workspace = true
license.workspace = true
name = "cw-orch-clone-testing"
repository.workspace = true
version = "0.9.2"
version = "0.10.0"

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

Expand All @@ -16,7 +16,9 @@ cw-orch-core = { workspace = true }
cw-orch-daemon = { workspace = true }
cw-orch-mock = { workspace = true }

clone-cw-multi-test = { version = "0.6.1" }
# clone-cw-multi-test = { version = "0.7.0" }
# clone-cw-multi-test = { path = "../../../cw-multi-test-fork", features = ["cosmwasm_1_2", "tokenfactory", "staking"] }
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"] }

anyhow = { workspace = true }
cw-utils = { workspace = true }
Expand Down
56 changes: 42 additions & 14 deletions packages/clone-testing/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use std::{cell::RefCell, fmt::Debug, io::Read, rc::Rc};

use clone_cw_multi_test::tokenfactory::TokenFactoryStargate;
use clone_cw_multi_test::wasm_emulation::query::ContainsRemote;
use clone_cw_multi_test::{
addons::{MockAddressGenerator, MockApiBech32},
wasm_emulation::{channel::RemoteChannel, storage::analyzer::StorageAnalyzer},
App, AppBuilder, BankKeeper, Contract, Executor, WasmKeeper,
};
use clone_cw_multi_test::{
DistributionKeeper, FailingModule, GovFailingModule, IbcFailingModule, MockApiBech32,
StakeKeeper,
};
use cosmwasm_std::testing::MockStorage;
use cosmwasm_std::{
to_json_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, Empty, Event, StdError, StdResult,
Uint128, WasmMsg,
Expand All @@ -26,7 +32,18 @@ use crate::{contract::CloneTestingContract, queriers::bank::CloneBankQuerier};

use super::state::MockState;

pub type CloneTestingApp = App<BankKeeper, MockApiBech32>;
pub type CloneTestingApp = App<
BankKeeper,
MockApiBech32,
MockStorage,
FailingModule<Empty, Empty, Empty>,
WasmKeeper<Empty, Empty>,
StakeKeeper,
DistributionKeeper,
IbcFailingModule,
GovFailingModule,
TokenFactoryStargate,
>;

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

impl CloneTesting {
/// Ceates a new valid account
pub fn init_account(&self) -> Addr {
self.app.borrow_mut().next_address()
/// Creates a new valid account
pub fn addr_make(&self, account_name: impl Into<String>) -> Addr {
self.app.borrow().api().addr_make(&account_name.into())
}

pub fn addr_make_with_balance(
&self,
account_name: impl Into<String>,
balance: Vec<Coin>,
) -> Result<Addr, CwEnvError> {
let addr = self.app.borrow().api().addr_make(&account_name.into());
self.set_balance(&addr, balance)?;

Ok(addr)
}

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

contract.set_code_id(code_id);
println!("{code_id}");

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

let wasm = WasmKeeper::<Empty, Empty>::new()
.with_remote(remote_channel.clone())
.with_address_generator(MockAddressGenerator);
let wasm = WasmKeeper::<Empty, Empty>::new().with_remote(remote_channel.clone());

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

Expand All @@ -247,10 +274,11 @@ impl<S: StateInterface> CloneTesting<S> {
.with_bank(bank)
.with_api(MockApiBech32::new(&pub_address_prefix))
.with_block(block_info)
.with_remote(remote_channel.clone());
.with_remote(remote_channel.clone())
.with_stargate(TokenFactoryStargate);

let app = Rc::new(RefCell::new(app.build(|_, _, _| {})?));
let sender = app.borrow_mut().next_address();
let app = Rc::new(RefCell::new(app.build(|_, _, _| {})));
let sender = app.borrow().api().addr_make("sender");

Ok(Self {
chain,
Expand Down Expand Up @@ -573,7 +601,7 @@ mod test {
let chain = CloneTesting::new(chain_info)?;

let sender = chain.sender_addr();
let recipient = &chain.init_account();
let recipient = &chain.addr_make("recipient");

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

let chain: CloneTesting = CloneTesting::<_>::new_custom(&rt, chain, mock_state)?;
let recipient = chain.init_account();
let recipient = chain.addr_make("recipient");

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

let chain = CloneTesting::new(chain_info)?;
let recipient = &chain.init_account();
let recipient = &chain.addr_make("recipient");

chain
.add_balance(recipient, vec![Coin::new(amount, denom_1)])
Expand Down
4 changes: 3 additions & 1 deletion packages/clone-testing/tests/wasm-upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use counter_contract::CounterContract;
use cw_orch::prelude::*;
use cw_orch_clone_testing::CloneTesting;
use cw_orch_daemon::networks::JUNO_1;
use networks::OSMOSIS_1;

#[test]
fn multiple_upload() -> anyhow::Result<()> {
let mut chain = OSMOSIS_1;
// ANCHOR: clone_testing_setup
let chain = CloneTesting::new(JUNO_1)?;
let chain = CloneTesting::new(chain)?;
// ANCHOR_END: clone_testing_setup
// ANCHOR: counter_contract_setup
let contract = CounterContract::new(chain.clone());
Expand Down
3 changes: 2 additions & 1 deletion packages/cw-orch-mock/src/bech32.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{cell::RefCell, rc::Rc};

use cosmwasm_std::{testing::MockApi, Addr, Coin, Uint128};
use cw_multi_test::{AppBuilder, MockApiBech32};
use cw_multi_test::{AppBuilder, MockApiBech32, TokenFactoryStargate};
use cw_orch_core::{
environment::{BankQuerier, BankSetter, DefaultQueriers, StateInterface, TxHandler},
CwEnvError,
Expand Down Expand Up @@ -74,6 +74,7 @@ impl<S: StateInterface> MockBase<MockApiBech32, S> {
let app = Rc::new(RefCell::new(
AppBuilder::new_custom()
.with_api(MockApiBech32::new(prefix))
.with_stargate(TokenFactoryStargate)
.build(|_, _, _| {}),
));

Expand Down
4 changes: 2 additions & 2 deletions packages/cw-orch-mock/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmwasm_std::{
};
use cw_multi_test::{
ibc::IbcSimpleModule, App, AppResponse, BankKeeper, Contract, DistributionKeeper, Executor,
FailingModule, GovFailingModule, MockApiBech32, StakeKeeper, StargateFailing, WasmKeeper,
FailingModule, GovFailingModule, MockApiBech32, StakeKeeper, TokenFactoryStargate, WasmKeeper,
};
use serde::Serialize;

Expand All @@ -27,7 +27,7 @@ pub type MockApp<A = MockApi> = App<
DistributionKeeper,
IbcSimpleModule,
GovFailingModule,
StargateFailing,
TokenFactoryStargate,
>;

/// Wrapper around a cw-multi-test [`App`](cw_multi_test::App) backend.
Expand Down
6 changes: 4 additions & 2 deletions packages/cw-orch-mock/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::rc::Rc;

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