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

Allow cw-orch wasm compilation without features #342

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cw-orchestrator Changelog

## Unreleased

- Allow cw-orch wasm compilation without features

## 0.21.0

- Updated cw-multi-test to allow for IBC packet timeout
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn example_test() {

The `ExecuteFns` macro can be added to the `ExecuteMsg` definition of your contract. It will generate a trait that allows you to call the variants of the message directly without the need to construct the struct yourself.

The `ExecuteFns` macro should only run on the Msg when the "interface" trait is enable. This is ensured by the `interface` feature in the following example:
The `ExecuteFns` macro would only run on the Msg when compiled for non-wasm target. Optionally you can ensure it by the `interface` feature, like in the following example:

```rust,ignore
use cw_orch::prelude::*;
Expand Down Expand Up @@ -163,8 +163,8 @@ pub enum GenericExecuteMsg<T> {

// A type that will fill the generic.
#[cosmwasm_schema::cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
#[cfg_attr(feature = "interface", impl_into(ExecuteMsg))]
#[derive(cw_orch::ExecuteFns)]
#[impl_into(ExecuteMsg)]
pub enum Foo {
Bar { a: String },
}
Expand Down
9 changes: 3 additions & 6 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
ec347443a5ed4442b2cc166bce53ebab18d8a881543acc11fbca68a9bb092362 counter_contract-aarch64.wasm
9bf5a2cb8f98b122cca06ac0a604c2a3150be32430551f4b0af43d79e34dd3a6 counter_contract.wasm
ed55bd2c18c7fbd20e9b15f56ff619a986a47a363c66358382c4c2fcf16e6389 mock_contract-aarch64.wasm
8155b5e91d05d6db9e3e50d0bd660d7668f6b8414b05b64d0858b5045ea55ba7 mock_contract.wasm
48856f5a5c169089cf289d31c14fd41d35bb298530577ff3c77ce08725f96496 mock_contract_u64-aarch64.wasm
4b828f1f6b21ef87718342987b8171e32e018d4959558e174d9eb3ba07d255d5 mock_contract_u64.wasm
cb8d415822e00facae900ea8155369c527a52a17f3b032d70d49ecea661cf5fa counter_contract.wasm
a10b9eef9e09166b6a5b33db76a93e53bf75f492532f25f28c34170998013970 mock_contract.wasm
8c28381f7ce56a4e662b921ad1b3133e07f1265a53a93f7fc1d9627f888ec5fc mock_contract_u64.wasm
Binary file modified artifacts/counter_contract.wasm
Binary file not shown.
Binary file modified artifacts/mock_contract.wasm
Binary file not shown.
Binary file modified artifacts/mock_contract_u64.wasm
Binary file not shown.
7 changes: 4 additions & 3 deletions contracts/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ crate-type = ["cdylib", "rlib"]
[features]
default = ["export"]
export = []
interface = ["dep:cw-orch"]

[dependencies]
cosmwasm-std = { workspace = true }
Expand All @@ -23,10 +22,12 @@ schemars = "0.8.10"
thiserror = { version = "1.0.21" }
serde = { workspace = true }
serde_json = "1.0.79"
cw-orch = { path = "../../cw-orch", optional = true, features = ["daemon"] }
cw-orch = { path = "../../cw-orch", features = ["daemon"] }

[[example]]
name = "deploy"

[dev-dependencies]
counter-contract = { path = ".", features = ["interface"] }
# Deps for deployment
dotenv = { version = "0.15.0" }
pretty_env_logger = { version = "0.5.0" }
Expand Down
12 changes: 6 additions & 6 deletions contracts/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ pub(crate) mod query;
pub mod state;

pub use crate::error::ContractError;
// ANCHOR: interface_reexport
#[cfg(feature = "interface")]
pub use crate::interface::CounterContract;
// ANCHOR_END: interface_reexport
// ANCHOR: fn_re_export
#[cfg(feature = "interface")]
pub use crate::msg::{ExecuteMsgFns as CounterExecuteMsgFns, QueryMsgFns as CounterQueryMsgFns};
// ANCHOR_END: fn_re_export

// ANCHOR: custom_interface
#[cfg(feature = "interface")]
#[cfg(not(target_arch = "wasm32"))]
mod interface;
// ANCHOR_END: custom_interface

// ANCHOR: interface_reexport
#[cfg(not(target_arch = "wasm32"))]
pub use crate::interface::CounterContract;
// ANCHOR_END: interface_reexport
4 changes: 2 additions & 2 deletions contracts/counter/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct InstantiateMsg {

// ANCHOR: exec_msg
#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))] // Function generation
#[derive(cw_orch::ExecuteFns)] // Function generation
/// Execute methods for counter
pub enum ExecuteMsg {
/// Increment count by one
Expand All @@ -27,7 +27,7 @@ pub enum ExecuteMsg {

// ANCHOR: query_msg
#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))] // Function generation
#[derive(cw_orch::QueryFns)] // Function generation
#[derive(QueryResponses)]
/// Query methods for counter
pub enum QueryMsg {
Expand Down
7 changes: 2 additions & 5 deletions contracts/mock_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib", "rlib"]
[features]
default = ["export"]
export = []
interface = ["dep:cw-orch"]
interface = []

[dependencies]
cosmwasm-std = { workspace = true }
Expand All @@ -22,7 +22,4 @@ schemars = "0.8.10"
serde_json = "1.0.79"
thiserror = { version = "1.0.21" }
cosmwasm-schema = "1.2"
cw-orch = { path = "../../cw-orch", optional = true }

[dev-dependencies]
mock-contract = { path = ".", features = ["interface"] }
cw-orch = { path = "../../cw-orch" }
6 changes: 2 additions & 4 deletions contracts/mock_contract/src/custom_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
pub struct InstantiateMsg {}

#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
#[derive(cw_orch::ExecuteFns)]

Check warning on line 18 in contracts/mock_contract/src/custom_resp.rs

View check run for this annotation

Codecov / codecov/patch

contracts/mock_contract/src/custom_resp.rs#L18

Added line #L18 was not covered by tests
pub enum ExecuteMsg {
FirstMessage {},
}

#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
#[derive(QueryResponses)]
#[derive(cw_orch::QueryFns, QueryResponses)]

Check warning on line 24 in contracts/mock_contract/src/custom_resp.rs

View check run for this annotation

Codecov / codecov/patch

contracts/mock_contract/src/custom_resp.rs#L24

Added line #L24 was not covered by tests
pub enum QueryMsg {
#[returns(String)]
FirstQuery {},
Expand Down Expand Up @@ -74,6 +73,5 @@
}
}

#[cfg(feature = "interface")]
#[cw_orch::interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg)]
struct MockContract;
49 changes: 25 additions & 24 deletions contracts/mock_contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
mod custom_resp;

#[cfg(feature = "interface")]
mod msg_tests;

use cosmwasm_schema::{cw_serde, QueryResponses};
Expand All @@ -13,13 +11,13 @@ use serde::Serialize;
pub struct InstantiateMsg {}

#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
#[derive(cw_orch::ExecuteFns)]
pub enum ExecuteMsg<T = String>
where
T: Serialize,
{
FirstMessage {},
#[cfg_attr(feature = "interface", payable)]
#[payable]
SecondMessage {
/// test doc-comment
t: T,
Expand All @@ -30,16 +28,15 @@ where
t: T,
},
FourthMessage,
#[cfg_attr(feature = "interface", payable)]
#[payable]
FifthMessage,
SixthMessage(u64, String),
#[cfg_attr(feature = "interface", payable)]
#[payable]
SeventhMessage(Uint128, String),
}

#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
#[derive(QueryResponses)]
#[derive(cw_orch::QueryFns, QueryResponses)]
pub enum QueryMsg<T = String>
where
T: Serialize,
Expand Down Expand Up @@ -134,26 +131,30 @@ pub fn migrate(_deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult<Response
}
}

#[cfg(feature = "interface")]
#[cw_orch::interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg)]
pub struct MockContract;

#[cfg(feature = "interface")]
impl<Chain: cw_orch::prelude::CwEnv> cw_orch::prelude::Uploadable for MockContract<Chain> {
fn wrapper(
&self,
) -> Box<dyn cw_orch::prelude::MockContract<cosmwasm_std::Empty, cosmwasm_std::Empty>> {
Box::new(
cw_orch::prelude::ContractWrapper::new(execute, instantiate, query)
.with_migrate(migrate),
)
}
#[cfg(not(target_arch = "wasm32"))]
pub mod interface {
use super::*;

fn wasm(&self) -> cw_orch::prelude::WasmPath {
use cw_orch::prelude::*;
artifacts_dir_from_workspace!()
.find_wasm_path("mock_contract")
.unwrap()
impl<Chain: cw_orch::prelude::CwEnv> cw_orch::prelude::Uploadable for MockContract<Chain> {
fn wrapper(
&self,
) -> Box<dyn cw_orch::prelude::MockContract<cosmwasm_std::Empty, cosmwasm_std::Empty>>
{
Box::new(
cw_orch::prelude::ContractWrapper::new(execute, instantiate, query)
.with_migrate(migrate),
)
}

fn wasm(&self) -> cw_orch::prelude::WasmPath {
use cw_orch::prelude::*;
artifacts_dir_from_workspace!()
.find_wasm_path("mock_contract")
.unwrap()
}
}
}

Expand Down
29 changes: 17 additions & 12 deletions contracts/mock_contract/src/msg_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult};
use cw_orch::prelude::*;

// ANCHOR: unordered_msg_def
#[cw_serde]
Expand Down Expand Up @@ -58,26 +57,32 @@ pub fn execute_ordered(
pub fn query(_deps: Deps, _env: Env, _msg: Empty) -> StdResult<Binary> {
Ok(vec![].into())
}
#[cfg(not(target_arch = "wasm32"))]
mod interface {
use super::*;
use cw_orch::prelude::*;

impl<Chain: CwEnv> Uploadable for TestContract<Chain> {
fn wrapper(&self) -> <Mock as TxHandler>::ContractSource {
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query))
impl<Chain: CwEnv> Uploadable for TestContract<Chain> {
fn wrapper(&self) -> <Mock as TxHandler>::ContractSource {
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query))
}
}
}

impl<Chain: CwEnv> Uploadable for OrderedTestContract<Chain> {
fn wrapper(&self) -> <Mock as TxHandler>::ContractSource {
Box::new(ContractWrapper::new_with_empty(
execute_ordered,
instantiate,
query,
))
impl<Chain: CwEnv> Uploadable for OrderedTestContract<Chain> {
fn wrapper(&self) -> <Mock as TxHandler>::ContractSource {
Box::new(ContractWrapper::new_with_empty(
execute_ordered,
instantiate,
query,
))
}
}
}

#[cfg(test)]
mod test {
use super::*;
use cw_orch::prelude::*;
#[test]
pub fn test() -> Result<(), CwOrchError> {
let chain = Mock::new("sender");
Expand Down
10 changes: 2 additions & 8 deletions contracts/mock_contract_u64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ crate-type = ["cdylib", "rlib"]
[features]
default = ["export"]
export = []
interface = ["dep:cw-orch"]

[dependencies]
cosmwasm-std = { workspace = true }
Expand All @@ -22,11 +21,6 @@ schemars = "0.8.10"
serde_json = "1.0.79"
thiserror = { version = "1.0.21" }
cosmwasm-schema = "1.2"
cw-orch = { path = "../../cw-orch", features = ["daemon"], optional = true }
cw-orch = { path = "../../cw-orch" }

mock-contract = { path = "../mock_contract", default-features = false }
[dev-dependencies]
mock-contract = { path = "../mock_contract", default-features = false, features = [
"interface",
] }
mock-contract-u64 = { path = ".", features = ["interface"] }
mock-contract = { path = "../mock_contract" }
46 changes: 25 additions & 21 deletions contracts/mock_contract_u64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,38 @@
}
}

#[cfg(feature = "interface")]
#[cw_orch::interface(InstantiateMsg, ExecuteMsg<T>, QueryMsg<Q>, MigrateMsg, id = "mock-contract")]
pub struct MockContract<Chain, T, Q>;
#[cfg(not(target_arch = "wasm32"))]
pub mod interface {
use super::*;

#[cfg(feature = "interface")]
impl<Chain: cw_orch::prelude::CwEnv> cw_orch::prelude::Uploadable
for MockContract<Chain, u64, u64>
{
fn wrapper(
&self,
) -> Box<dyn cw_orch::prelude::MockContract<cosmwasm_std::Empty, cosmwasm_std::Empty>> {
Box::new(
cw_orch::prelude::ContractWrapper::new(execute, instantiate, query)
.with_migrate(migrate),
)
}
#[cw_orch::interface(InstantiateMsg, ExecuteMsg<T>, QueryMsg<Q>, MigrateMsg, id = "mock-contract")]
pub struct MockContract<Chain, T, Q>;

fn wasm(&self) -> cw_orch::prelude::WasmPath {
use cw_orch::prelude::*;
artifacts_dir_from_workspace!()
.find_wasm_path("mock_contract")
.unwrap()
impl<Chain: cw_orch::prelude::CwEnv> cw_orch::prelude::Uploadable
for MockContract<Chain, u64, u64>
{
fn wrapper(
&self,
) -> Box<dyn cw_orch::prelude::MockContract<cosmwasm_std::Empty, cosmwasm_std::Empty>>
{
Box::new(
cw_orch::prelude::ContractWrapper::new(execute, instantiate, query)
.with_migrate(migrate),
)
}

fn wasm(&self) -> cw_orch::prelude::WasmPath {
use cw_orch::prelude::*;
artifacts_dir_from_workspace!()
.find_wasm_path("mock_contract")
.unwrap()
}

Check warning on line 101 in contracts/mock_contract_u64/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

contracts/mock_contract_u64/src/lib.rs#L96-L101

Added lines #L96 - L101 were not covered by tests
}
}

#[cfg(test)]
mod test {
use super::MockContract as LocalMockContract;
use super::interface::MockContract as LocalMockContract;
use super::*;
use cosmwasm_std::{coins, Addr};
use cw_orch::prelude::*;
Expand Down
Loading
Loading