1use cosmwasm_std::{Addr, BlockInfo, ContractInfo, Env, Timestamp};
2
3pub fn create_env() -> Env {
5 create_ownable_env(String::new(), None)
6}
7
8pub fn create_ownable_env(chain_id: impl Into<String>, time: Option<Timestamp>) -> Env {
10 Env {
11 block: BlockInfo {
12 height: 0,
13 time: time.unwrap_or_else(|| Timestamp::from_seconds(0)),
14 chain_id: chain_id.into(),
15 },
16 contract: ContractInfo {
17 address: Addr::unchecked(""),
18 },
19 transaction: None,
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn create_env_produces_default_env() {
29 let env = create_env();
30 assert_eq!(env.block.height, 0);
31 assert_eq!(env.block.chain_id, "");
32 }
33
34 #[test]
35 fn create_ownable_env_sets_chain_id() {
36 let env = create_ownable_env("my-chain", None);
37 assert_eq!(env.block.chain_id, "my-chain");
38 }
39
40 #[test]
41 fn create_ownable_env_sets_timestamp() {
42 let ts = Timestamp::from_seconds(12345);
43 let env = create_ownable_env("", Some(ts));
44 assert_eq!(env.block.time, ts);
45 }
46}