sei_integration_tests/
helper.rs

1use cosmwasm_std::{
2    from_json,
3    testing::{MockApi, MockQuerier, MockStorage},
4    Api, BalanceResponse, BankQuery, BlockInfo, Empty, GovMsg, IbcMsg, IbcQuery, MemoryStorage,
5    Storage, Timestamp,
6};
7use cw_multi_test::{
8    App, AppBuilder, BankKeeper, DistributionKeeper, FailingModule, Module, Router, StakeKeeper,
9    WasmKeeper,
10};
11use sei_cosmwasm::{DenomOracleExchangeRatePair, SeiMsg, SeiQueryWrapper};
12
13use crate::module::SeiModule;
14
15// Get balance
16pub fn get_balance(
17    app: &App<BankKeeper, MockApi, MemoryStorage, SeiModule, WasmKeeper<SeiMsg, SeiQueryWrapper>>,
18    addr: String,
19    denom: String,
20) -> BalanceResponse {
21    let arr = app.read_module(|router, api, storage| {
22        router.bank.query(
23            api,
24            storage,
25            &MockQuerier::default(),
26            &BlockInfo {
27                height: 0,
28                time: Timestamp::from_seconds(0u64),
29                chain_id: "test".to_string(),
30            },
31            BankQuery::Balance {
32                address: addr,
33                denom: denom,
34            },
35        )
36    });
37    from_json(&arr.unwrap()).unwrap()
38}
39
40// Mock app
41pub fn mock_app<F>(
42    init_fn: F,
43    rates: Vec<DenomOracleExchangeRatePair>,
44) -> App<
45    BankKeeper,
46    MockApi,
47    MockStorage,
48    SeiModule,
49    WasmKeeper<SeiMsg, SeiQueryWrapper>,
50    StakeKeeper,
51    DistributionKeeper,
52    FailingModule<IbcMsg, IbcQuery, Empty>,
53    FailingModule<GovMsg, Empty, Empty>,
54>
55where
56    F: FnOnce(
57        &mut Router<
58            BankKeeper,
59            SeiModule,
60            WasmKeeper<SeiMsg, SeiQueryWrapper>,
61            StakeKeeper,
62            DistributionKeeper,
63            FailingModule<IbcMsg, IbcQuery, Empty>,
64            FailingModule<GovMsg, Empty, Empty>,
65        >,
66        &dyn Api,
67        &mut dyn Storage,
68    ),
69{
70    let appbuilder: AppBuilder<
71        BankKeeper,
72        MockApi,
73        MockStorage,
74        SeiModule,
75        WasmKeeper<SeiMsg, SeiQueryWrapper>,
76        StakeKeeper,
77        DistributionKeeper,
78        FailingModule<IbcMsg, IbcQuery, Empty>,
79        FailingModule<GovMsg, Empty, Empty>,
80    > = AppBuilder::new()
81        .with_custom(SeiModule::new_with_oracle_exchange_rates(rates))
82        .with_wasm::<SeiModule, WasmKeeper<SeiMsg, SeiQueryWrapper>>(WasmKeeper::new())
83        .with_staking(StakeKeeper::new())
84        .with_distribution(DistributionKeeper::new());
85
86    appbuilder.build(init_fn)
87}