From a7875156fcc1d0847626d4cc084321eda5b36828 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 30 May 2024 13:33:00 +0200 Subject: [PATCH] Build vault interface multitest properly --- contracts/provider/vault/Cargo.toml | 1 + contracts/provider/vault/src/contract.rs | 1 + contracts/provider/vault/src/orch.rs | 74 +++++++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/contracts/provider/vault/Cargo.toml b/contracts/provider/vault/Cargo.toml index 810cae6b..b51e6a46 100644 --- a/contracts/provider/vault/Cargo.toml +++ b/contracts/provider/vault/Cargo.toml @@ -34,6 +34,7 @@ serde = { workspace = true } thiserror = { workspace = true } cw-orch = { workspace = true} +anyhow = { workspace = true } [dev-dependencies] sylvia = { workspace = true, features = ["mt"] } diff --git a/contracts/provider/vault/src/contract.rs b/contracts/provider/vault/src/contract.rs index 04a0d0e6..cd7517fa 100644 --- a/contracts/provider/vault/src/contract.rs +++ b/contracts/provider/vault/src/contract.rs @@ -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)] diff --git a/contracts/provider/vault/src/orch.rs b/contracts/provider/vault/src/orch.rs index b0f1faec..12635dc5 100644 --- a/contracts/provider/vault/src/orch.rs +++ b/contracts/provider/vault/src/orch.rs @@ -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 for crate::contract::VaultContract<'a> { + fn execute( + &self, + deps: cosmwasm_std::DepsMut, + env: cosmwasm_std::Env, + info: cosmwasm_std::MessageInfo, + msg: Vec, + ) -> anyhow::Result> { + sylvia::cw_multi_test::Contract::execute(self, deps, env, info, msg) + } + + fn instantiate( + &self, + deps: cosmwasm_std::DepsMut, + env: cosmwasm_std::Env, + info: cosmwasm_std::MessageInfo, + msg: Vec, + ) -> anyhow::Result> { + sylvia::cw_multi_test::Contract::instantiate(self, deps, env, info, msg) + } + + fn query( + &self, + deps: cosmwasm_std::Deps, + env: cosmwasm_std::Env, + msg: Vec, + ) -> anyhow::Result { + sylvia::cw_multi_test::Contract::query(self, deps, env, msg) + } + + fn sudo( + &self, + deps: cosmwasm_std::DepsMut, + env: cosmwasm_std::Env, + msg: Vec, + ) -> anyhow::Result> { + sylvia::cw_multi_test::Contract::sudo(self, deps, env, msg) + } + + fn reply( + &self, + deps: cosmwasm_std::DepsMut, + env: cosmwasm_std::Env, + msg: cosmwasm_std::Reply, + ) -> anyhow::Result> { + sylvia::cw_multi_test::Contract::reply(self, deps, env, msg) + } + + fn migrate( + &self, + deps: cosmwasm_std::DepsMut, + env: cosmwasm_std::Env, + msg: Vec, + ) -> anyhow::Result> { + sylvia::cw_multi_test::Contract::migrate(self, deps, env, msg) + } +} + #[cw_orch::interface(InstantiateMsg, ContractExecMsg, ContractQueryMsg, Empty)] pub struct MeshVault; @@ -17,9 +79,17 @@ impl Uploadable for MeshVault { .find_wasm_path("mesh_vault") .unwrap() } + /// Returns a CosmWasm contract wrapper + #[cfg(any(feature = "mt", test))] + fn wrapper() -> Box> { + let c = crate::contract::VaultContract::new(); + Box::new(c) + } + + #[cfg(not(any(feature = "mt", test)))] fn wrapper() -> Box> { - Box::new(ContractWrapper::new_with_empty(execute, instantiate, query)) + panic!("Multitest only implemented in tests or with 'mt' feature"); } }