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

Adding cw-orchestrator to beaker #127

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
5 changes: 5 additions & 0 deletions templates/project/contracts/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ overflow-checks = true
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []
# use interface feature to expose structure for contract orchestration
interface = ["dep:cw-orch"]

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
Expand All @@ -49,5 +51,8 @@ schemars = "0.8.8"
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }

cw-orch = { version = "0.18.1", optional = true }

[dev-dependencies]
cw-multi-test = "0.13.2"
counter = {path = ".", features=["interface"]}
45 changes: 45 additions & 0 deletions templates/project/contracts/counter/src/interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use cosmwasm_std::Empty;
use cw_orch::{interface, prelude::*};

#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, Empty)]
pub struct Counter;

impl<Chain: CwEnv> Uploadable for Counter<Chain> {
/// Return the path to the wasm file corresponding to the contract
fn wasm(&self) -> WasmPath {
artifacts_dir_from_workspace!()
.find_wasm_path("{{crate_name}}")
.unwrap()
}
/// Returns a CosmWasm contract wrapper
fn wrapper(&self) -> Box<dyn MockContract<Empty>> {
Box::new(ContractWrapper::new_with_empty(
crate::contract::execute,
crate::contract::instantiate,
crate::contract::query,
))
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::msg::{ExecuteMsgFns, QueryMsgFns};
use cw_orch::anyhow;

#[test]
fn contract_logic() -> anyhow::Result<()> {
let mock = Mock::new(&Addr::unchecked("sender"));
let contract = Counter::new("project-name", mock);
contract.upload()?;

contract.instantiate(&InstantiateMsg { count: 7 }, None, None)?;
assert_eq!(contract.get_count()?.count, 7);

contract.increment()?;
assert_eq!(contract.get_count()?.count, 8);

Ok(())
}
}
3 changes: 3 additions & 0 deletions templates/project/contracts/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pub mod msg;
pub mod state;

pub use crate::error::ContractError;

#[cfg(feature = "interface")]
pub mod interface;
2 changes: 2 additions & 0 deletions templates/project/contracts/counter/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ pub struct InstantiateMsg {
}

#[cw_serde]
#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
pub enum ExecuteMsg {
Increment {},
Reset { count: i32 },
}

#[cw_serde]
#[derive(QueryResponses)]
#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
pub enum QueryMsg {
// GetCount returns the current count as a json-encoded number
#[returns(GetCountResponse)]
Expand Down