-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subdao-timelocks unit tests implemented
- Loading branch information
swelf
committed
Dec 29, 2022
1 parent
d6fffde
commit 17e41fc
Showing
7 changed files
with
580 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ pub mod proposal; | |
pub mod state; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
mod testing; | ||
|
||
pub use crate::error::ContractError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
contracts/subdaos/cwd-subdao-timelock-single/src/testing/mock_querier.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::marker::PhantomData; | ||
|
||
use cosmwasm_std::{ | ||
from_binary, from_slice, | ||
testing::{MockApi, MockQuerier, MockStorage}, | ||
to_binary, ContractResult, Empty, OwnedDeps, Querier, QuerierResult, QueryRequest, SystemError, | ||
SystemResult, WasmQuery, | ||
}; | ||
use cwd_pre_propose_base::msg::QueryMsg as PreProposeQuery; | ||
|
||
pub const MOCK_SUBDAO_CORE_ADDR: &str = "neutron1subdao_core_contract"; | ||
pub const MOCK_TIMELOCK_INITIALIZER: &str = "neutron1timelock_initializer"; | ||
|
||
pub fn mock_dependencies() -> OwnedDeps<MockStorage, MockApi, WasmMockQuerier> { | ||
let custom_querier = WasmMockQuerier::new(MockQuerier::new(&[])); | ||
|
||
OwnedDeps { | ||
storage: MockStorage::default(), | ||
api: MockApi::default(), | ||
querier: custom_querier, | ||
custom_query_type: PhantomData, | ||
} | ||
} | ||
|
||
pub struct WasmMockQuerier { | ||
base: MockQuerier, | ||
} | ||
|
||
impl Querier for WasmMockQuerier { | ||
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult { | ||
let request: QueryRequest<Empty> = match from_slice(bin_request) { | ||
Ok(v) => v, | ||
Err(e) => { | ||
return QuerierResult::Err(SystemError::InvalidRequest { | ||
error: format!("Parsing query request: {}", e), | ||
request: bin_request.into(), | ||
}); | ||
} | ||
}; | ||
self.handle_query(&request) | ||
} | ||
} | ||
|
||
impl WasmMockQuerier { | ||
pub fn handle_query(&self, request: &QueryRequest<Empty>) -> QuerierResult { | ||
match &request { | ||
QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => { | ||
if contract_addr == MOCK_TIMELOCK_INITIALIZER { | ||
let q: PreProposeQuery = from_binary(msg).unwrap(); | ||
let addr = match q { | ||
PreProposeQuery::ProposalModule {} => todo!(), | ||
PreProposeQuery::Dao {} => MOCK_SUBDAO_CORE_ADDR, | ||
PreProposeQuery::Config {} => todo!(), | ||
PreProposeQuery::DepositInfo { proposal_id: _ } => todo!(), | ||
}; | ||
return SystemResult::Ok(ContractResult::from(to_binary(addr))); | ||
} | ||
SystemResult::Err(SystemError::NoSuchContract { | ||
addr: contract_addr.to_string(), | ||
}) | ||
} | ||
_ => self.base.handle_query(request), | ||
} | ||
} | ||
} | ||
|
||
impl WasmMockQuerier { | ||
pub fn new(base: MockQuerier) -> Self { | ||
WasmMockQuerier { base } | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
contracts/subdaos/cwd-subdao-timelock-single/src/testing/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod mock_querier; | ||
mod tests; |
Oops, something went wrong.