Skip to content

Commit

Permalink
Added cw-plus contracts and Uploadable from distant sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Sep 17, 2024
1 parent dafd9b6 commit 21531dc
Show file tree
Hide file tree
Showing 36 changed files with 1,869 additions and 266 deletions.
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"test_contracts/*",
"packages/macros/*",
"packages/interchain/*",
"packages/integrations/*",
]
exclude = [
"test_contracts/compatibility-test", # TODO: add new after cw-orch-core 2.0.0 as it's breaking, it shouldn't be compatible
Expand All @@ -30,6 +31,8 @@ repository = "https://github.com/AbstractSDK/cw-orchestrator"
[workspace.dependencies]
cw-utils = { version = "2.0.0" }
cosmwasm-std = { version = "2.1" }
cosmwasm-schema = { version = "2.1" }

cw-storage-plus = { version = "2.0.0" }
cosmos-sdk-proto = { version = "0.24.0", default-features = false }

Expand Down Expand Up @@ -68,8 +71,11 @@ cw-orch-interchain-mock = { path = "packages/interchain/interchain-mock", versio
cw-orch-starship = { path = "packages/interchain/starship", version = "0.5.0" }
# cw-orch-proto = { path = "packages/interchain/proto", version = "0.5.0" } # prost, tonic, cosmrs bump locked by osmosis (we use it for tokenfactory)

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

# Integrations
cw-plus-orch = { path = "packages/integrations/cw-plus" }

thiserror = { version = "1.0.63" }
sha2 = { version = "0.10.8" }
Expand Down
1 change: 1 addition & 0 deletions contracts-ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"

[workspace.dependencies]
cosmwasm-std = "2.0.0"
cosmwasm-schema = "2.0.0"
cw20 = { package = "abstract-cw20", version = "2.0.0" }
cw20-base = { package = "abstract-cw20-base", version = "2.0.0" }
cw-storage-plus = { version = "2.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion contracts-ws/contracts/mock_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ serde = { workspace = true }
schemars = "0.8.21"
serde_json = "1.0.125"
thiserror = { version = "1.0.63" }
cosmwasm-schema = "2.1"
cosmwasm-schema = { workspace = true }
cw-orch = { workspace = true }
cw-storage-plus = { workspace = true }
2 changes: 1 addition & 1 deletion contracts-ws/contracts/mock_contract_u64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde = { workspace = true }
schemars = "0.8.21"
serde_json = "1.0.125"
thiserror = { version = "1.0.63" }
cosmwasm-schema = "2.1"
cosmwasm-schema = { workspace = true }
cw-orch = { workspace = true }

mock-contract = { path = "../mock_contract" }
2 changes: 1 addition & 1 deletion cw-orch-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ cw-orch = { path = "../cw-orch", features = ["daemon"] }
env_logger = "0.11.5"
cw20 = { version = "2" }
cw20-base = { version = "2" }
cosmwasm-schema = "2.1"
cosmwasm-schema = { workspace = true }
speculoos = "0.11.0"
ctor = "0.2.8"
duct = "0.13"
Expand Down
2 changes: 1 addition & 1 deletion cw-orch-daemon/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub async fn upload_wasm<T: TxSender>(
wasm_path: WasmPath,
access: Option<AccessConfig>,
) -> Result<CosmTxResponse, DaemonError> {
let file_contents = std::fs::read(wasm_path.path())?;
let file_contents = wasm_path.wasm().await?;
let mut e = write::GzEncoder::new(Vec::new(), Compression::default());
e.write_all(&file_contents)?;
let wasm_byte_code = e.finish()?;
Expand Down
4 changes: 3 additions & 1 deletion cw-orch-daemon/src/queriers/cosmwasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ impl<Sender: QuerySender> WasmQuerier for CosmWasmBase<Sender> {
&self,
contract: &T,
) -> Result<Checksum, cw_orch_core::CwEnvError> {
<T as Uploadable>::wasm(contract.environment().daemon.chain_info()).checksum()
self.rt_handle.as_ref().unwrap().block_on(
<T as Uploadable>::wasm(contract.environment().daemon.chain_info()).checksum(),
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cw-orch-daemon/tests/daemon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ fn reuse_same_state_multichain() {
let daemon_res = DaemonBuilder::new(NEUTRON_1)
.state(daemon.state())
.mnemonic(DUMMY_MNEMONIC)
.build();
.build()
.unwrap();

assert!(daemon_res.is_ok());
std::env::remove_var(STATE_FILE_ENV_NAME);
}

Expand Down
5 changes: 4 additions & 1 deletion cw-orch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cw-orch-mock = { workspace = true }
[dev-dependencies]
cw-orch = { features = ["daemon", "snapshot-testing"], path = "." }
env_logger = "0.11.5"
cosmwasm-schema = "2.1"
cosmwasm-schema = { workspace = true }
counter-contract = { path = "../contracts-ws/contracts/counter" }
mock-contract = { path = "../contracts-ws/contracts/mock_contract" }
mock-contract-u64 = { path = "../contracts-ws/contracts/mock_contract_u64" }
Expand All @@ -103,3 +103,6 @@ dotenv = "0.15.0"
osmosis-std = "0.25.0"
prost = { workspace = true }
prost-types = { workspace = true }
cw-plus-orch = { workspace = true }
cw20 = { version = "2.0.0" }
cw20-base = { version = "2.0.0" }
86 changes: 86 additions & 0 deletions cw-orch/examples/cw-plus-wasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use cosmwasm_std::Uint128;
use cw20::{Cw20Coin, Cw20ExecuteMsg};
use cw_orch::contract::{GithubWasmPath, GithubWasmPathLocation};
use cw_orch::prelude::*;
use cw_plus_orch::cw20_base::{Cw20Base, InstantiateMsg};
use cw_plus_orch::cw20_base::{QueryMsg, QueryMsgInterfaceFns};
use networks::LOCAL_JUNO;

pub const INITIAL_AMOUNT: u128 = 567;

pub fn main() -> anyhow::Result<()> {
dotenv::dotenv()?;
env_logger::init();

let daemon = Daemon::builder(LOCAL_JUNO).build()?;

let release_cw20 = Cw20Base::new("cw20-test-release", daemon.clone());
execution(release_cw20, &daemon.sender_addr())?;

let file_cw20 = FileCw20Base::new("cw20-test-file", daemon.clone());
execution(file_cw20, &daemon.sender_addr())?;

Ok(())
}

fn execution<T>(cw20: T, sender: &Addr) -> anyhow::Result<()>
where
T: Uploadable
+ CwOrchUpload<Daemon>
+ ContractInstance<Daemon>
+ CwOrchInstantiate<Daemon>
+ CwOrchExecute<Daemon>
+ InstantiableContract<InstantiateMsg = InstantiateMsg>
+ ExecutableContract<ExecuteMsg = Cw20ExecuteMsg>
+ QueryMsgInterfaceFns<Daemon, QueryMsg>,
{
cw20.upload()?;
cw20.instantiate(
&InstantiateMsg {
name: "cw20".to_string(),
symbol: "CWTEST".to_string(),
decimals: 6,
initial_balances: vec![Cw20Coin {
address: sender.to_string(),
amount: Uint128::from(INITIAL_AMOUNT),
}],
mint: None,
marketing: None,
},
None,
&[],
)?;

let balance = cw20.balance(sender)?;

assert_eq!(balance.balance.u128(), INITIAL_AMOUNT);
Ok(())
}

#[cw_orch::interface(InstantiateMsg, Cw20ExecuteMsg, QueryMsg, cosmwasm_std::Empty)]
pub struct FileCw20Base;

impl<Chain: CwEnv> Uploadable for FileCw20Base<Chain> {
// Return the path to the wasm file
fn wasm(_chain: &ChainInfoOwned) -> WasmPath {
WasmPath::Github(GithubWasmPath {
owner: "Abstractsdk".to_string(),
repo_name: "cw-plus".to_string(),
location: GithubWasmPathLocation::File {
reference: "abstract_versions".to_string(),
file_path: "artifacts/abstract_cw20_base.wasm".to_string(),
},
})
}
// Return a CosmWasm contract wrapper
fn wrapper() -> Box<dyn MockContract<Empty>> {
Box::new(
ContractWrapper::new_with_empty(
cw20_base::contract::execute,
cw20_base::contract::instantiate,
cw20_base::contract::query,
)
.with_migrate(cw20_base::contract::migrate),
)
}
}
2 changes: 1 addition & 1 deletion packages/clone-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sha2 = "0.10.8"
tonic = { workspace = true }

[dev-dependencies]
cosmwasm-schema = "2.0.0"
cosmwasm-schema = { workspace = true }
speculoos = { workspace = true }

cw20 = { version = "2.0.0" }
Expand Down
11 changes: 6 additions & 5 deletions packages/clone-testing/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::RefCell, fmt::Debug, io::Read, rc::Rc};
use std::{cell::RefCell, fmt::Debug, rc::Rc};

use clone_cw_multi_test::{
addons::{MockAddressGenerator, MockApiBech32},
Expand All @@ -20,7 +20,7 @@ use cw_orch_core::{
use cw_orch_daemon::{queriers::Node, read_network_config, DEFAULT_DEPLOYMENT, RUNTIME};
use cw_utils::NativeBalance;
use serde::Serialize;
use tokio::runtime::Runtime;
use tokio::runtime::{Handle, Runtime};

use crate::{contract::CloneTestingContract, queriers::bank::CloneBankQuerier};

Expand Down Expand Up @@ -74,6 +74,8 @@ pub struct CloneTesting<S: StateInterface = MockState> {
pub state: Rc<RefCell<S>>,
/// Inner mutable cw-multi-test app backend
pub app: Rc<RefCell<CloneTestingApp>>,

pub rt_handle: Handle,
}

impl CloneTesting {
Expand Down Expand Up @@ -148,9 +150,7 @@ impl CloneTesting {
&self,
contract: &T,
) -> Result<<Self as TxHandler>::Response, CwEnvError> {
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 wasm = self.rt_handle.block_on(T::wasm(&self.chain).wasm())?;
let code_id = self.app.borrow_mut().store_wasm_code(wasm);

contract.set_code_id(code_id);
Expand Down Expand Up @@ -257,6 +257,7 @@ impl<S: StateInterface> CloneTesting<S> {
sender: sender.clone(),
state,
app,
rt_handle: rt.handle().clone(),
})
}

Expand Down
4 changes: 4 additions & 0 deletions packages/cw-orch-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ dirs = "5.0.1"
cw-utils = { workspace = true }
cosmos-sdk-proto = { workspace = true, features = ["cosmwasm"] }
cw-storage-plus = { workspace = true }
octocrab = "0.39.0"
reqwest = "0.12.7"
http = "1.1.0"
http-body-util = "0.1.2"

[dev-dependencies]
speculoos = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-core/src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub use contract_instance::Contract;
pub use deploy::Deploy;

pub use paths::from_workspace as artifacts_dir_from_workspace;
pub use paths::{ArtifactsDir, WasmPath};
pub use paths::{ArtifactsDir, GithubWasmPath, GithubWasmPathLocation, WasmPath};
Loading

0 comments on commit 21531dc

Please sign in to comment.