abstract_testing/
abstract_mock_querier.rs

1use abstract_std::{
2    account::state::{ACCOUNT_ID, CALLING_TO_AS_ADMIN},
3    ans_host::state::{ASSET_ADDRESSES, CHANNELS, CONTRACT_ADDRESSES},
4    objects::{
5        gov_type::GovernanceDetails, ownership::Ownership,
6        storage_namespaces::OWNERSHIP_STORAGE_KEY, AccountId, AssetEntry, ChannelEntry,
7        ContractEntry,
8    },
9    registry::{state::ACCOUNT_ADDRESSES, Account},
10};
11use cosmwasm_std::Addr;
12use cw_asset::AssetInfo;
13use cw_storage_plus::Item;
14
15use crate::prelude::*;
16
17pub trait AbstractMockQuerier {
18    /// Mock the existence of an Account by setting the Account id for the account along with registering the account to registry.
19    fn account(self, account: &Account, account_id: AccountId) -> Self;
20
21    /// Add mock assets into ANS
22    fn assets(self, assets: Vec<(&AssetEntry, AssetInfo)>) -> Self;
23
24    fn set_account_admin_call_to(self, account: &Account) -> Self;
25
26    fn contracts(self, contracts: Vec<(&ContractEntry, Addr)>) -> Self;
27
28    fn channels(self, channels: Vec<(&ChannelEntry, String)>) -> Self;
29
30    fn addrs(&self) -> AbstractMockAddrs;
31}
32
33impl AbstractMockQuerier for MockQuerierBuilder {
34    /// Mock the existence of an Account by setting the Account id for the account along with registering the account to registry.
35    fn account(self, account: &Account, account_id: AccountId) -> Self {
36        let abstract_addrs = self.addrs();
37        self.with_contract_item(account.addr(), ACCOUNT_ID, &account_id)
38            // Setup the account owner as the test owner
39            .with_contract_item(
40                account.addr(),
41                Item::new(OWNERSHIP_STORAGE_KEY),
42                &Some(Ownership {
43                    owner: GovernanceDetails::Monarchy {
44                        monarch: abstract_addrs.owner.clone(),
45                    },
46                    pending_owner: None,
47                    pending_expiry: None,
48                }),
49            )
50            .with_contract_map_entry(
51                &abstract_addrs.registry,
52                ACCOUNT_ADDRESSES,
53                (&account_id, account.clone()),
54            )
55            .with_contract_map_entry(
56                account.addr(),
57                abstract_std::account::state::ACCOUNT_MODULES,
58                (TEST_MODULE_ID, abstract_addrs.module_address),
59            )
60    }
61
62    fn assets(self, assets: Vec<(&AssetEntry, AssetInfo)>) -> Self {
63        let abstract_addrs = self.addrs();
64        self.with_contract_map_entries(&abstract_addrs.ans_host, ASSET_ADDRESSES, assets)
65    }
66
67    fn contracts(self, contracts: Vec<(&ContractEntry, Addr)>) -> Self {
68        let abstract_addrs = self.addrs();
69
70        self.with_contract_map_entries(&abstract_addrs.ans_host, CONTRACT_ADDRESSES, contracts)
71    }
72
73    fn channels(self, channels: Vec<(&ChannelEntry, String)>) -> Self {
74        let abstract_addrs = self.addrs();
75
76        self.with_contract_map_entries(&abstract_addrs.ans_host, CHANNELS, channels)
77    }
78
79    fn addrs(&self) -> AbstractMockAddrs {
80        AbstractMockAddrs::new(self.api)
81    }
82
83    fn set_account_admin_call_to(self, account: &Account) -> Self {
84        let env = mock_env_validated(self.api);
85        self.with_contract_item(account.addr(), CALLING_TO_AS_ADMIN, &env.contract.address)
86    }
87}