Skip to content

Commit

Permalink
Build vault interface multitest properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed May 30, 2024
1 parent 4e724a4 commit a787515
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
1 change: 1 addition & 0 deletions contracts/provider/vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ serde = { workspace = true }
thiserror = { workspace = true }

cw-orch = { workspace = true}
anyhow = { workspace = true }

[dev-dependencies]
sylvia = { workspace = true, features = ["mt"] }
Expand Down
1 change: 1 addition & 0 deletions contracts/provider/vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct VaultContract<'a> {
}

#[cfg_attr(not(feature = "library"), sylvia::entry_points)]
// #[sylvia::entry_points]
#[contract]
#[sv::error(ContractError)]
#[sv::messages(vault_api as VaultApi)]
Expand Down
74 changes: 72 additions & 2 deletions contracts/provider/vault/src/orch.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
// This contains all code we needed to manually add to make it work well with cw-orch
// In the future, hopefully some of this can me auto-generated. But let's get it to work now.
use crate::contract::entry_points::{execute, instantiate, query};

// use crate::contract::entry_points::{execute, instantiate, query};
// use crate::contract::sv::mt;

use crate::contract::sv::{ContractExecMsg, ContractQueryMsg, ContractSudoMsg, InstantiateMsg};
use cw_orch::prelude::*;

// Maybe uploadable can be autogenerated?
// But this is fine to include in the client code

#[cfg(any(feature = "mt", test))]
impl<'a> MockContract<Empty> for crate::contract::VaultContract<'a> {
fn execute(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
info: cosmwasm_std::MessageInfo,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::execute(self, deps, env, info, msg)
}

fn instantiate(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
info: cosmwasm_std::MessageInfo,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::instantiate(self, deps, env, info, msg)
}

fn query(
&self,
deps: cosmwasm_std::Deps<Empty>,
env: cosmwasm_std::Env,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Binary> {
sylvia::cw_multi_test::Contract::query(self, deps, env, msg)
}

fn sudo(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::sudo(self, deps, env, msg)
}

fn reply(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
msg: cosmwasm_std::Reply,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::reply(self, deps, env, msg)
}

fn migrate(
&self,
deps: cosmwasm_std::DepsMut<Empty>,
env: cosmwasm_std::Env,
msg: Vec<u8>,
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
sylvia::cw_multi_test::Contract::migrate(self, deps, env, msg)
}
}

#[cw_orch::interface(InstantiateMsg, ContractExecMsg, ContractQueryMsg, Empty)]
pub struct MeshVault;

Expand All @@ -17,9 +79,17 @@ impl<Chain> Uploadable for MeshVault<Chain> {
.find_wasm_path("mesh_vault")
.unwrap()
}

/// Returns a CosmWasm contract wrapper
#[cfg(any(feature = "mt", test))]
fn wrapper() -> Box<dyn MockContract<Empty>> {
let c = crate::contract::VaultContract::new();
Box::new(c)
}

#[cfg(not(any(feature = "mt", test)))]
fn wrapper() -> Box<dyn MockContract<Empty>> {
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query))
panic!("Multitest only implemented in tests or with 'mt' feature");
}
}

Expand Down

0 comments on commit a787515

Please sign in to comment.