bvs_guardrail/
testing.rs

1#![cfg(not(target_arch = "wasm32"))]
2
3use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
4use bvs_library::testing::TestingContract;
5use cosmwasm_std::{Addr, Decimal, Empty, Env};
6use cw_multi_test::{App, Contract, ContractWrapper};
7use cw_utils::Threshold;
8use serde::{Deserialize, Serialize};
9
10#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
11pub struct GuardrailContract {
12    pub addr: Addr,
13    pub init: InstantiateMsg,
14}
15
16impl TestingContract<InstantiateMsg, ExecuteMsg, QueryMsg, Empty> for GuardrailContract {
17    fn wrapper() -> Box<dyn Contract<Empty>> {
18        Box::new(ContractWrapper::new(
19            crate::contract::execute,
20            crate::contract::instantiate,
21            crate::contract::query,
22        ))
23    }
24
25    fn default_init(app: &mut App, _env: &Env) -> InstantiateMsg {
26        let owner = app.api().addr_make("owner");
27        InstantiateMsg {
28            owner: owner.to_string(),
29            members: vec![cw4::Member {
30                addr: owner.to_string(),
31                weight: 1,
32            }],
33            threshold: Threshold::AbsolutePercentage {
34                percentage: Decimal::percent(0), // auto pass proposal
35            },
36            default_expiration: 100,
37        }
38    }
39
40    fn new(app: &mut App, env: &Env, msg: Option<InstantiateMsg>) -> Self {
41        let init = msg.unwrap_or(Self::default_init(app, env));
42        let code_id = Self::store_code(app);
43        let addr = Self::instantiate(app, code_id, "guardrail", &init);
44        Self { addr, init }
45    }
46
47    fn addr(&self) -> &Addr {
48        &self.addr
49    }
50}