1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::error::BootError;
use crate::state::StateInterface;
use cosmwasm_std::Addr;
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct MockState {
pub code_ids: HashMap<String, u64>,
pub addresses: HashMap<String, Addr>,
}
impl MockState {
pub fn new() -> Self {
Self {
addresses: HashMap::new(),
code_ids: HashMap::new(),
}
}
}
impl Default for MockState {
fn default() -> Self {
Self::new()
}
}
impl StateInterface for MockState {
fn get_address(&self, contract_id: &str) -> Result<Addr, BootError> {
self.addresses
.get(contract_id)
.ok_or_else(|| BootError::AddrNotInStore(contract_id.to_owned()))
.map(|val| val.to_owned())
}
fn set_address(&mut self, contract_id: &str, address: &Addr) {
self.addresses
.insert(contract_id.to_string(), address.to_owned());
}
fn get_code_id(&self, contract_id: &str) -> Result<u64, BootError> {
self.code_ids
.get(contract_id)
.ok_or_else(|| BootError::CodeIdNotInStore(contract_id.to_owned()))
.map(|val| val.to_owned())
}
fn set_code_id(&mut self, contract_id: &str, code_id: u64) {
self.code_ids.insert(contract_id.to_string(), code_id);
}
fn get_all_addresses(&self) -> Result<HashMap<String, Addr>, BootError> {
Ok(self.addresses.clone())
}
fn get_all_code_ids(&self) -> Result<HashMap<String, u64>, BootError> {
Ok(self.code_ids.clone())
}
}