Skip to content

Commit

Permalink
fix: simplify cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik committed Nov 29, 2024
1 parent c03a400 commit fab605f
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 258 deletions.
8 changes: 4 additions & 4 deletions contracts/auto-withdrawer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cosmwasm_std::{
testing::{mock_env, mock_info},
Event,
};
use drop_helpers::testing::{mock_dependencies, mock_locator_query};
use drop_helpers::testing::{mock_dependencies, mock_state_query};

#[test]
fn instantiate() {
Expand Down Expand Up @@ -45,7 +45,7 @@ fn instantiate() {
#[test]
fn bond_missing_ld_assets() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
FACTORY_CONTRACT
.save(
deps.as_mut().storage,
Expand All @@ -67,14 +67,14 @@ fn bond_missing_ld_assets() {
}

mod bond_missing_deposit {
use drop_helpers::testing::{mock_dependencies, mock_locator_query};
use drop_helpers::testing::{mock_dependencies, mock_state_query};

use super::*;

#[test]
fn with_ld_assets() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
FACTORY_CONTRACT
.save(
deps.as_mut().storage,
Expand Down
91 changes: 31 additions & 60 deletions contracts/core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{
};
use drop_helpers::{
pause::PauseError,
testing::{mock_dependencies, mock_locator_query, WasmMockQuerier},
testing::{mock_dependencies, mock_state_query, WasmMockQuerier},
};
use drop_puppeteer_base::msg::TransferReadyBatchesMsg;
use drop_staking_base::{
Expand Down Expand Up @@ -89,7 +89,7 @@ fn test_update_config() {
})
.unwrap()
});
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
let env = mock_env();
let info = mock_info("admin", &[]);
let mut deps_mut = deps.as_mut();
Expand Down Expand Up @@ -192,8 +192,7 @@ fn test_update_withdrawn_amount() {
CONFIG
.save(deps.as_mut().storage, &get_default_config(1000, 10, 6000))
.unwrap();
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
let withdrawn_batch = &UnbondBatch {
total_dasset_amount_to_withdraw: Uint128::from(1001u128),
expected_native_asset_amount: Uint128::from(1001u128),
Expand Down Expand Up @@ -259,8 +258,7 @@ fn test_update_withdrawn_amount() {
#[test]
fn test_execute_reset_bonded_amount() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
let deps_mut = deps.as_mut();
cw_ownable::initialize_owner(deps_mut.storage, deps_mut.api, Some("admin")).unwrap();
BONDED_AMOUNT
Expand All @@ -286,8 +284,7 @@ fn test_execute_reset_bonded_amount() {
#[test]
fn test_add_remove_bond_provider() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
let deps_mut = deps.as_mut();
cw_ownable::initialize_owner(deps_mut.storage, deps_mut.api, Some("admin")).unwrap();

Expand Down Expand Up @@ -351,9 +348,7 @@ fn test_add_remove_bond_provider() {
#[test]
fn test_execute_tick_idle_process_bondig_provider() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
BOND_PROVIDERS.init(deps.as_mut().storage).unwrap();

deps.querier
Expand Down Expand Up @@ -449,9 +444,7 @@ fn test_execute_tick_idle_process_bondig_provider() {
#[test]
fn test_tick_idle_claim_wo_unbond() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier
.add_wasm_query_response("puppeteer_contract", |_| {
to_json_binary(&BalancesResponse {
Expand Down Expand Up @@ -612,9 +605,7 @@ fn test_tick_idle_claim_wo_unbond() {
#[test]
fn test_tick_idle_claim_with_unbond_transfer() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier
.add_wasm_query_response("puppeteer_contract", |_| {
to_json_binary(&BalancesResponse {
Expand Down Expand Up @@ -771,8 +762,7 @@ fn test_tick_idle_claim_with_unbond_transfer() {
#[test]
fn test_tick_no_puppeteer_response() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
CONFIG
.save(deps.as_mut().storage, &get_default_config(1000, 100, 600))
.unwrap();
Expand Down Expand Up @@ -822,8 +812,7 @@ fn test_tick_no_puppeteer_response() {
fn test_tick_claiming_error_wo_transfer() {
// no unbonded batch, no pending transfer for stake, some balance in ICA to stake
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier
.add_wasm_query_response("puppeteer_contract", |_| {
to_json_binary(&BalancesResponse {
Expand Down Expand Up @@ -934,8 +923,7 @@ fn test_tick_claiming_error_wo_transfer() {
fn test_tick_claiming_error_with_transfer() {
// no unbonded batch, no pending transfer for stake, some balance in ICA to stake
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier
.add_wasm_query_response("puppeteer_contract", |_| {
to_json_binary(&BalancesResponse {
Expand Down Expand Up @@ -1078,9 +1066,7 @@ fn test_tick_claiming_error_with_transfer() {
fn test_tick_claiming_wo_transfer_unbonding() {
// no unbonded batch, no pending transfer for stake, no balance on ICA, but we have unbond batch to switch
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier
.add_wasm_query_response("puppeteer_contract", |_| {
to_json_binary(&BalancesResponse {
Expand Down Expand Up @@ -1265,8 +1251,7 @@ fn test_tick_claiming_wo_idle() {
// no unbonded batch, no pending transfer for stake, no balance on ICA,
// and no unbond batch to switch, so we go to idle
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
LAST_ICA_CHANGE_HEIGHT
.save(deps.as_mut().storage, &0)
.unwrap();
Expand Down Expand Up @@ -1417,7 +1402,7 @@ fn test_tick_claiming_wo_idle() {
#[test]
fn test_execute_tick_guard_balance_outdated() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
CONFIG
.save(deps.as_mut().storage, &get_default_config(1000, 100, 600))
.unwrap();
Expand Down Expand Up @@ -1458,7 +1443,7 @@ fn test_execute_tick_guard_balance_outdated() {
#[test]
fn test_execute_tick_guard_delegations_outdated() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
CONFIG
.save(deps.as_mut().storage, &get_default_config(1000, 100, 600))
.unwrap();
Expand Down Expand Up @@ -1511,7 +1496,7 @@ fn test_execute_tick_guard_delegations_outdated() {
#[test]
fn test_execute_tick_staking_no_puppeteer_response() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
CONFIG
.save(deps.as_mut().storage, &get_default_config(1000, 100, 600))
.unwrap();
Expand Down Expand Up @@ -1558,7 +1543,7 @@ fn test_execute_tick_staking_no_puppeteer_response() {
#[test]
fn test_execute_tick_unbonding_no_puppeteer_response() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
CONFIG
.save(deps.as_mut().storage, &get_default_config(1000, 100, 600))
.unwrap();
Expand Down Expand Up @@ -1606,8 +1591,7 @@ fn test_execute_tick_unbonding_no_puppeteer_response() {
#[test]
fn test_bond_wo_receiver() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
BOND_PROVIDERS.init(deps.as_mut().storage).unwrap();

deps.querier
Expand Down Expand Up @@ -1692,8 +1676,7 @@ fn test_bond_wo_receiver() {
#[test]
fn test_bond_with_receiver() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
BOND_PROVIDERS.init(deps.as_mut().storage).unwrap();

deps.querier
Expand Down Expand Up @@ -1817,8 +1800,7 @@ fn test_bond_lsm_share_increase_exchange_rate() {
denom: "ld_denom".to_string(),
amount: Uint128::new(1001),
}]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
BOND_PROVIDERS.init(deps.as_mut().storage).unwrap();

deps.querier
Expand Down Expand Up @@ -2263,9 +2245,7 @@ mod check_denom {
#[test]
fn invalid_port() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier.add_stargate_query_response(
"/ibc.applications.transfer.v1.Query/DenomTrace",
|_| {
Expand All @@ -2290,8 +2270,7 @@ mod check_denom {
#[test]
fn invalid_channel() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier.add_stargate_query_response(
"/ibc.applications.transfer.v1.Query/DenomTrace",
|_| {
Expand All @@ -2316,8 +2295,7 @@ mod check_denom {
#[test]
fn invalid_port_and_channel() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier.add_stargate_query_response(
"/ibc.applications.transfer.v1.Query/DenomTrace",
|_| {
Expand All @@ -2342,8 +2320,7 @@ mod check_denom {
#[test]
fn not_an_lsm_share() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier.add_stargate_query_response(
"/ibc.applications.transfer.v1.Query/DenomTrace",
|_| {
Expand All @@ -2368,8 +2345,7 @@ mod check_denom {
#[test]
fn unknown_validator() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier.add_stargate_query_response(
"/ibc.applications.transfer.v1.Query/DenomTrace",
|_| {
Expand Down Expand Up @@ -2414,8 +2390,7 @@ mod check_denom {
#[test]
fn invalid_validator_index() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier.add_stargate_query_response(
"/ibc.applications.transfer.v1.Query/DenomTrace",
|_| {
Expand All @@ -2440,8 +2415,7 @@ mod check_denom {
#[test]
fn known_validator() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier.add_stargate_query_response(
"/ibc.applications.transfer.v1.Query/DenomTrace",
|_| {
Expand Down Expand Up @@ -2500,7 +2474,7 @@ mod check_denom {
mod bond_hooks {
use super::*;
use cosmwasm_std::ReplyOn;
use drop_helpers::testing::mock_locator_query;
use drop_helpers::testing::mock_state_query;
use drop_staking_base::msg::core::{BondCallback, BondHook};
use neutron_sdk::bindings::msg::NeutronMsg;

Expand Down Expand Up @@ -2651,8 +2625,7 @@ mod bond_hooks {
#[test]
fn execute_bond_with_active_bond_hook_no_ref() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
BOND_PROVIDERS.init(deps.as_mut().storage).unwrap();

deps.querier
Expand Down Expand Up @@ -2727,8 +2700,7 @@ mod bond_hooks {
#[test]
fn execute_bond_with_active_bond_hook() {
let mut deps = mock_dependencies(&[]);
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
BOND_PROVIDERS.init(deps.as_mut().storage).unwrap();

deps.querier
Expand Down Expand Up @@ -2810,8 +2782,7 @@ mod bond_hooks {
.add_wasm_query_response("native_provider_address", |_| {
to_json_binary(&true).unwrap()
});
mock_locator_query(&mut deps);
mock_locator_query(&mut deps);
mock_state_query(&mut deps);
deps.querier
.add_wasm_query_response("native_provider_address", |_| {
to_json_binary(&Uint128::from(1000u128)).unwrap()
Expand Down
11 changes: 0 additions & 11 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ pub fn query(deps: Deps<NeutronQuery>, _env: Env, msg: QueryMsg) -> ContractResu
let ownership = cw_ownable::get_ownership(deps.storage)?;
Ok(to_json_binary(&ownership)?)
}
QueryMsg::Locate { contracts } => query_locate(deps, contracts),
}
}

Expand All @@ -482,16 +481,6 @@ fn query_state(deps: Deps<NeutronQuery>) -> ContractResult<Binary> {
Ok(to_json_binary(&out)?)
}

fn query_locate(deps: Deps<NeutronQuery>, items: Vec<String>) -> ContractResult<Binary> {
let mut contracts: HashMap<String, String> = HashMap::new();

for item in items {
let addr = STATE.load(deps.storage, &item)?;
contracts.insert(item, addr.into_string());
}
Ok(to_json_binary(&contracts)?)
}

fn query_pause_info(deps: Deps<NeutronQuery>) -> ContractResult<Binary> {
let core_contract = STATE.load(deps.storage, CORE_CONTRACT)?;
let withdrawal_manager_contract = STATE.load(deps.storage, WITHDRAWAL_MANAGER_CONTRACT)?;
Expand Down
24 changes: 0 additions & 24 deletions contracts/factory/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,30 +1206,6 @@ fn test_query_state() {
);
}

#[test]
fn test_query_locate() {
let mut deps = mock_dependencies(&[]);
set_default_factory_state(deps.as_mut());
let query_res: HashMap<String, String> = from_json(
query(
deps.as_ref(),
mock_env(),
QueryMsg::Locate {
contracts: vec!["core_contract".to_string(), "token_contract".to_string()],
},
)
.unwrap(),
)
.unwrap();
assert_eq!(
query_res,
HashMap::from([
("core_contract".to_string(), "core_contract".to_string()),
("token_contract".to_string(), "token_contract".to_string()),
])
);
}

#[test]
fn test_query_pause_info() {
let mut deps = mock_dependencies(&[]);
Expand Down
Loading

0 comments on commit fab605f

Please sign in to comment.