Skip to content

Commit a787515

Browse files
committed
Build vault interface multitest properly
1 parent 4e724a4 commit a787515

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

contracts/provider/vault/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ serde = { workspace = true }
3434
thiserror = { workspace = true }
3535

3636
cw-orch = { workspace = true}
37+
anyhow = { workspace = true }
3738

3839
[dev-dependencies]
3940
sylvia = { workspace = true, features = ["mt"] }

contracts/provider/vault/src/contract.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct VaultContract<'a> {
6363
}
6464

6565
#[cfg_attr(not(feature = "library"), sylvia::entry_points)]
66+
// #[sylvia::entry_points]
6667
#[contract]
6768
#[sv::error(ContractError)]
6869
#[sv::messages(vault_api as VaultApi)]

contracts/provider/vault/src/orch.rs

+72-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,74 @@
11
// This contains all code we needed to manually add to make it work well with cw-orch
22
// In the future, hopefully some of this can me auto-generated. But let's get it to work now.
3-
use crate::contract::entry_points::{execute, instantiate, query};
3+
4+
// use crate::contract::entry_points::{execute, instantiate, query};
5+
// use crate::contract::sv::mt;
6+
47
use crate::contract::sv::{ContractExecMsg, ContractQueryMsg, ContractSudoMsg, InstantiateMsg};
58
use cw_orch::prelude::*;
69

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

13+
#[cfg(any(feature = "mt", test))]
14+
impl<'a> MockContract<Empty> for crate::contract::VaultContract<'a> {
15+
fn execute(
16+
&self,
17+
deps: cosmwasm_std::DepsMut<Empty>,
18+
env: cosmwasm_std::Env,
19+
info: cosmwasm_std::MessageInfo,
20+
msg: Vec<u8>,
21+
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
22+
sylvia::cw_multi_test::Contract::execute(self, deps, env, info, msg)
23+
}
24+
25+
fn instantiate(
26+
&self,
27+
deps: cosmwasm_std::DepsMut<Empty>,
28+
env: cosmwasm_std::Env,
29+
info: cosmwasm_std::MessageInfo,
30+
msg: Vec<u8>,
31+
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
32+
sylvia::cw_multi_test::Contract::instantiate(self, deps, env, info, msg)
33+
}
34+
35+
fn query(
36+
&self,
37+
deps: cosmwasm_std::Deps<Empty>,
38+
env: cosmwasm_std::Env,
39+
msg: Vec<u8>,
40+
) -> anyhow::Result<cosmwasm_std::Binary> {
41+
sylvia::cw_multi_test::Contract::query(self, deps, env, msg)
42+
}
43+
44+
fn sudo(
45+
&self,
46+
deps: cosmwasm_std::DepsMut<Empty>,
47+
env: cosmwasm_std::Env,
48+
msg: Vec<u8>,
49+
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
50+
sylvia::cw_multi_test::Contract::sudo(self, deps, env, msg)
51+
}
52+
53+
fn reply(
54+
&self,
55+
deps: cosmwasm_std::DepsMut<Empty>,
56+
env: cosmwasm_std::Env,
57+
msg: cosmwasm_std::Reply,
58+
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
59+
sylvia::cw_multi_test::Contract::reply(self, deps, env, msg)
60+
}
61+
62+
fn migrate(
63+
&self,
64+
deps: cosmwasm_std::DepsMut<Empty>,
65+
env: cosmwasm_std::Env,
66+
msg: Vec<u8>,
67+
) -> anyhow::Result<cosmwasm_std::Response<Empty>> {
68+
sylvia::cw_multi_test::Contract::migrate(self, deps, env, msg)
69+
}
70+
}
71+
1072
#[cw_orch::interface(InstantiateMsg, ContractExecMsg, ContractQueryMsg, Empty)]
1173
pub struct MeshVault;
1274

@@ -17,9 +79,17 @@ impl<Chain> Uploadable for MeshVault<Chain> {
1779
.find_wasm_path("mesh_vault")
1880
.unwrap()
1981
}
82+
2083
/// Returns a CosmWasm contract wrapper
84+
#[cfg(any(feature = "mt", test))]
85+
fn wrapper() -> Box<dyn MockContract<Empty>> {
86+
let c = crate::contract::VaultContract::new();
87+
Box::new(c)
88+
}
89+
90+
#[cfg(not(any(feature = "mt", test)))]
2191
fn wrapper() -> Box<dyn MockContract<Empty>> {
22-
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query))
92+
panic!("Multitest only implemented in tests or with 'mt' feature");
2393
}
2494
}
2595

0 commit comments

Comments
 (0)