From fab605f9893144c381b73e9697a21d1815ed4e12 Mon Sep 17 00:00:00 2001 From: Sergey Ratiashvili <serg.s.r@gmail.com> Date: Fri, 29 Nov 2024 14:23:17 +0100 Subject: [PATCH] fix: simplify cache --- contracts/auto-withdrawer/src/tests.rs | 8 +- contracts/core/src/tests.rs | 91 +++++++------------ contracts/factory/src/contract.rs | 11 --- contracts/factory/src/tests.rs | 24 ----- .../lsm-share-bond-provider/src/tests.rs | 57 +++++------- contracts/native-bond-provider/src/tests.rs | 14 ++- contracts/strategy/src/tests.rs | 3 +- contracts/token/src/tests.rs | 20 ++-- packages/base/src/msg/factory.rs | 2 - packages/helpers/src/phonebook.rs | 38 ++------ packages/helpers/src/testing.rs | 65 ++++++++++--- ts-client/lib/contractLib/dropFactory.d.ts | 31 +------ ts-client/lib/contractLib/dropFactory.js | 3 - ts-client/src/contractLib/dropFactory.ts | 35 +------ 14 files changed, 144 insertions(+), 258 deletions(-) diff --git a/contracts/auto-withdrawer/src/tests.rs b/contracts/auto-withdrawer/src/tests.rs index e614ef39..2631eec7 100644 --- a/contracts/auto-withdrawer/src/tests.rs +++ b/contracts/auto-withdrawer/src/tests.rs @@ -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() { @@ -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, @@ -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, diff --git a/contracts/core/src/tests.rs b/contracts/core/src/tests.rs index 027b6b42..d69c144b 100644 --- a/contracts/core/src/tests.rs +++ b/contracts/core/src/tests.rs @@ -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::{ @@ -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(); @@ -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), @@ -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 @@ -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(); @@ -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 @@ -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 { @@ -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 { @@ -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(); @@ -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 { @@ -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 { @@ -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 { @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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 @@ -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 @@ -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 @@ -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", |_| { @@ -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", |_| { @@ -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", |_| { @@ -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", |_| { @@ -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", |_| { @@ -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", |_| { @@ -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", |_| { @@ -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; @@ -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 @@ -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 @@ -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() diff --git a/contracts/factory/src/contract.rs b/contracts/factory/src/contract.rs index 15ff4f1a..ac7971c2 100644 --- a/contracts/factory/src/contract.rs +++ b/contracts/factory/src/contract.rs @@ -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), } } @@ -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)?; diff --git a/contracts/factory/src/tests.rs b/contracts/factory/src/tests.rs index f88af6e3..bc5add41 100644 --- a/contracts/factory/src/tests.rs +++ b/contracts/factory/src/tests.rs @@ -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(&[]); diff --git a/contracts/lsm-share-bond-provider/src/tests.rs b/contracts/lsm-share-bond-provider/src/tests.rs index 71d8974e..445b25ec 100644 --- a/contracts/lsm-share-bond-provider/src/tests.rs +++ b/contracts/lsm-share-bond-provider/src/tests.rs @@ -11,7 +11,7 @@ use cw_ownable::{Action, Ownership}; use cw_utils::PaymentError; use drop_helpers::{ ica::IcaState, - testing::{mock_dependencies, mock_locator_query, WasmMockQuerier}, + testing::{mock_dependencies, mock_state_query, WasmMockQuerier}, }; use drop_staking_base::{ error::lsm_share_bond_provider::ContractError, @@ -347,7 +347,7 @@ fn test_update_ownership() { #[test] fn process_on_idle_not_core_contract() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); CONFIG .save(deps.as_mut().storage, &get_default_config(100u64, 200u64)) @@ -370,7 +370,7 @@ fn process_on_idle_not_core_contract() { #[test] fn test_process_on_idle_lsm_share_not_ready() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); let deps_mut = deps.as_mut(); CONFIG @@ -400,8 +400,7 @@ fn test_process_on_idle_lsm_share_not_ready() { #[test] fn test_process_on_idle_supported() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_custom_query_response(|_| { to_json_binary(&MinIbcFeeResponse { min_fee: IbcFee { @@ -486,8 +485,7 @@ fn test_process_on_idle_supported() { #[test] fn test_execute_bond() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); lsm_denom_query_config(deps.borrow_mut(), false); let deps_mut = deps.as_mut(); @@ -562,8 +560,7 @@ fn test_execute_bond() { #[test] fn test_execute_bond_wrong_denom() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); lsm_denom_query_config(deps.borrow_mut(), false); drop_staking_base::state::lsm_share_bond_provider::CONFIG @@ -587,7 +584,7 @@ fn test_execute_bond_wrong_denom() { #[test] fn test_execute_bond_no_funds() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); drop_staking_base::state::lsm_share_bond_provider::CONFIG .save(deps.as_mut().storage, &get_default_config(100u64, 200u64)) @@ -612,8 +609,7 @@ fn test_execute_bond_no_funds() { #[test] fn test_bond_lsm_share_wrong_validator() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); lsm_denom_query_config(deps.borrow_mut(), true); drop_staking_base::state::lsm_share_bond_provider::CONFIG @@ -634,7 +630,7 @@ fn test_bond_lsm_share_wrong_validator() { #[test] fn test_execute_bond_multiple_denoms() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); drop_staking_base::state::lsm_share_bond_provider::CONFIG .save( @@ -700,8 +696,7 @@ mod query { #[test] fn test_token_amount_wrong_denom() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); lsm_denom_query_config(deps.borrow_mut(), false); drop_staking_base::state::lsm_share_bond_provider::CONFIG @@ -741,7 +736,7 @@ mod query { #[test] fn test_can_process_idle_with_enough_interval() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); let deps_mut = deps.as_mut(); let env = mock_env(); @@ -784,7 +779,7 @@ mod query { #[test] fn test_can_process_false_below_threshold() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); let deps_mut = deps.as_mut(); let env = mock_env(); @@ -1113,8 +1108,7 @@ mod query { #[test] fn test_token_amount_half() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); lsm_denom_query_config(deps.borrow_mut(), false); CONFIG @@ -1140,8 +1134,7 @@ mod query { #[test] fn test_token_amount_above_one() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); lsm_denom_query_config(deps.borrow_mut(), false); CONFIG @@ -1176,7 +1169,7 @@ mod check_denom { #[test] fn test_invalid_port() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_stargate_query_response( "/ibc.applications.transfer.v1.Query/DenomTrace", |_| { @@ -1201,7 +1194,7 @@ mod check_denom { #[test] fn test_invalid_channel() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_stargate_query_response( "/ibc.applications.transfer.v1.Query/DenomTrace", |_| { @@ -1226,7 +1219,7 @@ mod check_denom { #[test] fn test_invalid_port_and_channel() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_stargate_query_response( "/ibc.applications.transfer.v1.Query/DenomTrace", |_| { @@ -1251,7 +1244,7 @@ mod check_denom { #[test] fn test_not_an_lsm_share() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_stargate_query_response( "/ibc.applications.transfer.v1.Query/DenomTrace", |_| { @@ -1276,7 +1269,7 @@ mod check_denom { #[test] fn test_unknown_validator() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_stargate_query_response( "/ibc.applications.transfer.v1.Query/DenomTrace", |_| { @@ -1322,7 +1315,7 @@ mod check_denom { #[test] fn test_invalid_validator_index() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_stargate_query_response( "/ibc.applications.transfer.v1.Query/DenomTrace", |_| { @@ -1347,7 +1340,7 @@ mod check_denom { #[test] fn test_known_validator() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); deps.querier.add_stargate_query_response( "/ibc.applications.transfer.v1.Query/DenomTrace", |_| { @@ -1421,7 +1414,7 @@ mod pending_redeem_shares { #[test] fn no_pending_lsm_shares() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); let config = &get_default_config(100u64, 200u64); @@ -1436,7 +1429,7 @@ mod pending_redeem_shares { #[test] fn lsm_shares_below_threshold() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); let config = &get_default_config(100u64, 200u64); @@ -1467,7 +1460,7 @@ mod pending_redeem_shares { #[test] fn lsm_shares_pass_threshold() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); let lsm_redeem_maximum_interval = 100; @@ -1523,7 +1516,7 @@ mod pending_redeem_shares { #[test] fn lsm_shares_limit_redeem() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); let config = &get_default_config(2u64, 200u64); diff --git a/contracts/native-bond-provider/src/tests.rs b/contracts/native-bond-provider/src/tests.rs index 130866e7..6029bca1 100644 --- a/contracts/native-bond-provider/src/tests.rs +++ b/contracts/native-bond-provider/src/tests.rs @@ -8,7 +8,7 @@ use cw_ownable::{Action, Ownership}; use cw_utils::PaymentError; use drop_helpers::{ ica::IcaState, - testing::{mock_dependencies, mock_locator_query}, + testing::{mock_dependencies, mock_state_query}, }; use drop_staking_base::state::native_bond_provider::{ Config, ConfigOptional, ReplyMsg, TxState, CONFIG, NON_STAKED_BALANCE, TX_STATE, @@ -569,7 +569,7 @@ fn update_ownership() { #[test] fn process_on_idle_not_in_idle_state() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); CONFIG .save(deps.as_mut().storage, &get_default_config()) @@ -610,7 +610,7 @@ fn process_on_idle_not_in_idle_state() { #[test] fn process_on_idle_not_core_contract() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); CONFIG .save(deps.as_mut().storage, &get_default_config()) @@ -633,8 +633,7 @@ fn process_on_idle_not_core_contract() { #[test] fn process_on_idle_delegation() { 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()) @@ -690,8 +689,7 @@ fn process_on_idle_delegation() { #[test] fn process_on_idle_ibc_transfer() { 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()) @@ -777,7 +775,7 @@ fn process_on_idle_ibc_transfer() { #[test] fn process_on_idle_not_allowed_if_no_funds() { let mut deps = mock_dependencies(&[]); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); CONFIG .save(deps.as_mut().storage, &get_default_config()) diff --git a/contracts/strategy/src/tests.rs b/contracts/strategy/src/tests.rs index 72a487d2..a9397484 100644 --- a/contracts/strategy/src/tests.rs +++ b/contracts/strategy/src/tests.rs @@ -141,8 +141,7 @@ fn instantiate_puppeteer_contract(app: &mut App) -> Addr { fn factory_query(_deps: Deps, _env: Env, msg: FactoryQueryMsg) -> StdResult<Binary> { match msg { - FactoryQueryMsg::State {} => todo!(), - FactoryQueryMsg::Locate { contracts: _ } => { + FactoryQueryMsg::State {} => { let out = HashMap::from([ ( VALIDATOR_SET_CONTRACT_ADDR.to_string(), diff --git a/contracts/token/src/tests.rs b/contracts/token/src/tests.rs index 9324ae65..698c1e38 100644 --- a/contracts/token/src/tests.rs +++ b/contracts/token/src/tests.rs @@ -12,7 +12,7 @@ use cosmwasm_std::{ to_json_binary, Addr, Binary, CosmosMsg, Event, QueryRequest, Reply, ReplyOn, SubMsgResult, Uint128, }; -use drop_helpers::testing::{mock_dependencies, mock_locator_query}; +use drop_helpers::testing::{mock_dependencies, mock_state_query}; use drop_staking_base::{ msg::token::{ConfigResponse, DenomMetadata, ExecuteMsg, InstantiateMsg, QueryMsg}, state::token::{DENOM, FACTORY_CONTRACT, TOKEN_METADATA}, @@ -189,7 +189,7 @@ fn mint_zero() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -213,7 +213,7 @@ fn mint() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -252,7 +252,7 @@ fn mint_stranger() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -277,7 +277,7 @@ fn burn_zero() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -301,7 +301,7 @@ fn burn_multiple_coins() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -325,7 +325,7 @@ fn burn_invalid_coin() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -349,7 +349,7 @@ fn burn() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -384,7 +384,7 @@ fn burn_stranger() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); @@ -406,7 +406,7 @@ fn query_config() { FACTORY_CONTRACT .save(deps.as_mut().storage, &Addr::unchecked("factory_contract")) .unwrap(); - mock_locator_query(&mut deps); + mock_state_query(&mut deps); DENOM .save(deps.as_mut().storage, &String::from("denom")) .unwrap(); diff --git a/packages/base/src/msg/factory.rs b/packages/base/src/msg/factory.rs index cb28449c..ad4f7cb1 100644 --- a/packages/base/src/msg/factory.rs +++ b/packages/base/src/msg/factory.rs @@ -87,7 +87,5 @@ pub enum QueryMsg { #[returns(std::collections::HashMap<String, String>)] State {}, #[returns(std::collections::HashMap<String, String>)] - Locate { contracts: Vec<String> }, - #[returns(crate::state::factory::PauseInfoResponse)] PauseInfo {}, } diff --git a/packages/helpers/src/phonebook.rs b/packages/helpers/src/phonebook.rs index b641f56d..c6c8c099 100644 --- a/packages/helpers/src/phonebook.rs +++ b/packages/helpers/src/phonebook.rs @@ -1,6 +1,6 @@ pub static CONTRACTS_CACHE: once_cell::sync::Lazy< - std::sync::RwLock<std::collections::HashMap<String, String>>, -> = once_cell::sync::Lazy::new(|| std::sync::RwLock::new(std::collections::HashMap::new())); + std::sync::RwLock<Option<std::collections::HashMap<String, String>>>, +> = once_cell::sync::Lazy::new(|| std::sync::RwLock::new(None)); #[macro_export] macro_rules! get_contracts { @@ -13,44 +13,24 @@ macro_rules! get_contracts { )* } use drop_helpers::phonebook::CONTRACTS_CACHE; - - // Collect all requested contract names - let requested_contracts = vec![$(stringify!($field_name).to_string()),*]; - // List for contracts that need to be queried - let mut not_cached_contracts = vec![]; - { - let cache = CONTRACTS_CACHE.read().unwrap(); - for contract_name in &requested_contracts { - if !cache.contains_key(contract_name) { - not_cached_contracts.push(contract_name.clone()); - } - } - } - - // Query for the missing contracts if needed - if !not_cached_contracts.is_empty() { - let queried_results:std::collections::HashMap<String, String> = $deps + let mut cache = CONTRACTS_CACHE.write().unwrap(); + if cache.is_none() { + let queried_results:std::collections::HashMap<String, String> = $deps .querier .query(&cosmwasm_std::QueryRequest::Wasm(cosmwasm_std::WasmQuery::Smart { contract_addr: $factory_contract.to_string(), - msg: to_json_binary(&drop_staking_base::msg::factory::QueryMsg::Locate { - contracts: not_cached_contracts.clone(), - })?, + msg: to_json_binary(&drop_staking_base::msg::factory::QueryMsg::State {})?, }))?; - - // Update the cache with newly queried results - let mut cache = CONTRACTS_CACHE.write().unwrap(); - for (key, value) in queried_results.iter() { - cache.insert(key.clone(), value.clone()); + *cache = Some(queried_results); } } - - // Build the Phonebook struct using the updated cache let cache = CONTRACTS_CACHE.read().unwrap(); Phonebook { $( $field_name: cache + .as_ref() + .unwrap() .get(stringify!($field_name)) .expect(&format!("{} contract not found in cache", stringify!($field_name))) .to_string(), diff --git a/packages/helpers/src/testing.rs b/packages/helpers/src/testing.rs index c3ddad39..c0a6cc88 100644 --- a/packages/helpers/src/testing.rs +++ b/packages/helpers/src/testing.rs @@ -331,22 +331,57 @@ impl WasmMockQuerier { } } -#[cw_serde] -enum FactoryQueryMsg { - Locate { contracts: Vec<String> }, -} -pub fn mock_locator_query( - deps: &mut OwnedDeps<MockStorage, MockApi, WasmMockQuerier, NeutronQuery>, -) { +pub fn mock_state_query(deps: &mut OwnedDeps<MockStorage, MockApi, WasmMockQuerier, NeutronQuery>) { deps.querier - .add_wasm_query_response("factory_contract", |req| { - let q: FactoryQueryMsg = cosmwasm_std::from_json(req).unwrap(); - let contracts = match q { - FactoryQueryMsg::Locate { contracts } => contracts - .iter() - .map(|c| (c.to_string(), c.to_string())) - .collect::<HashMap<_, _>>(), - }; + .add_wasm_query_response("factory_contract", |_| { + let contracts = HashMap::from([ + ("core_contract".to_string(), "core_contract".to_string()), + ("token_contract".to_string(), "token_contract".to_string()), + ( + "withdrawal_voucher_contract".to_string(), + "withdrawal_voucher_contract".to_string(), + ), + ( + "withdrawal_manager_contract".to_string(), + "withdrawal_manager_contract".to_string(), + ), + ( + "strategy_contract".to_string(), + "strategy_contract".to_string(), + ), + ( + "validators_set_contract".to_string(), + "validators_set_contract".to_string(), + ), + ( + "distribution_contract".to_string(), + "distribution_contract".to_string(), + ), + ( + "puppeteer_contract".to_string(), + "puppeteer_contract".to_string(), + ), + ( + "rewards_manager_contract".to_string(), + "rewards_manager_contract".to_string(), + ), + ( + "rewards_pump_contract".to_string(), + "rewards_pump_contract".to_string(), + ), + ( + "splitter_contract".to_string(), + "splitter_contract".to_string(), + ), + ( + "lsm_share_bond_provider_contract".to_string(), + "lsm_share_bond_provider_contract".to_string(), + ), + ( + "native_bond_provider_contract".to_string(), + "native_bond_provider_contract".to_string(), + ), + ]); to_json_binary(&contracts).unwrap() }); } diff --git a/ts-client/lib/contractLib/dropFactory.d.ts b/ts-client/lib/contractLib/dropFactory.d.ts index 258cc4da..bdbb6f7d 100644 --- a/ts-client/lib/contractLib/dropFactory.d.ts +++ b/ts-client/lib/contractLib/dropFactory.d.ts @@ -34,14 +34,6 @@ export type Timestamp = Uint64; * let b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ``` */ export type Uint64 = string; -/** - * Information about if the contract is currently paused. - */ -export type PauseInfoResponse1 = { - paused: {}; -} | { - unpaused: {}; -}; export type UpdateConfigArgs = { core: ConfigOptional; } | { @@ -669,15 +661,11 @@ export type UpdateOwnershipArgs = { }; } | "accept_ownership" | "renounce_ownership"; export interface DropFactorySchema { - responses: MapOfString | OwnershipForString | PauseInfoResponse | MapOfString1; - query: LocateArgs; + responses: OwnershipForString | MapOfString | MapOfString1; execute: UpdateConfigArgs | ProxyArgs | AdminExecuteArgs | UpdateOwnershipArgs; instantiate?: InstantiateMsg; [k: string]: unknown; } -export interface MapOfString { - [k: string]: string; -} /** * The contract's ownership info */ @@ -695,22 +683,12 @@ export interface OwnershipForString { */ pending_owner?: string | null; } -export interface PauseInfoResponse { - core: Pause; - rewards_manager: PauseInfoResponse1; - withdrawal_manager: PauseInfoResponse1; -} -export interface Pause { - bond: boolean; - tick: boolean; - unbond: boolean; +export interface MapOfString { + [k: string]: string; } export interface MapOfString1 { [k: string]: string; } -export interface LocateArgs { - contracts: string[]; -} export interface ConfigOptional { base_denom?: string | null; bond_limit?: Uint128 | null; @@ -1202,8 +1180,7 @@ export declare class Client { static instantiate(client: SigningCosmWasmClient, sender: string, codeId: number, initMsg: InstantiateMsg, label: string, fees: StdFee | 'auto' | number, initCoins?: readonly Coin[]): Promise<InstantiateResult>; static instantiate2(client: SigningCosmWasmClient, sender: string, codeId: number, salt: number, initMsg: InstantiateMsg, label: string, fees: StdFee | 'auto' | number, initCoins?: readonly Coin[]): Promise<InstantiateResult>; queryState: () => Promise<MapOfString>; - queryLocate: (args: LocateArgs) => Promise<MapOfString>; - queryPauseInfo: () => Promise<PauseInfoResponse>; + queryPauseInfo: () => Promise<MapOfString>; queryOwnership: () => Promise<OwnershipForString>; updateConfig: (sender: string, args: UpdateConfigArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise<ExecuteResult>; proxy: (sender: string, args: ProxyArgs, fee?: number | StdFee | "auto", memo?: string, funds?: Coin[]) => Promise<ExecuteResult>; diff --git a/ts-client/lib/contractLib/dropFactory.js b/ts-client/lib/contractLib/dropFactory.js index 428b8a42..c8444be2 100644 --- a/ts-client/lib/contractLib/dropFactory.js +++ b/ts-client/lib/contractLib/dropFactory.js @@ -29,9 +29,6 @@ class Client { queryState = async () => { return this.client.queryContractSmart(this.contractAddress, { state: {} }); }; - queryLocate = async (args) => { - return this.client.queryContractSmart(this.contractAddress, { locate: args }); - }; queryPauseInfo = async () => { return this.client.queryContractSmart(this.contractAddress, { pause_info: {} }); }; diff --git a/ts-client/src/contractLib/dropFactory.ts b/ts-client/src/contractLib/dropFactory.ts index aaa2b12b..a291c009 100644 --- a/ts-client/src/contractLib/dropFactory.ts +++ b/ts-client/src/contractLib/dropFactory.ts @@ -37,16 +37,6 @@ export type Timestamp = Uint64; * let b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ``` */ export type Uint64 = string; -/** - * Information about if the contract is currently paused. - */ -export type PauseInfoResponse1 = - | { - paused: {}; - } - | { - unpaused: {}; - }; export type UpdateConfigArgs = | { core: ConfigOptional; @@ -739,15 +729,11 @@ export type UpdateOwnershipArgs = | "renounce_ownership"; export interface DropFactorySchema { - responses: MapOfString | OwnershipForString | PauseInfoResponse | MapOfString1; - query: LocateArgs; + responses: OwnershipForString | MapOfString | MapOfString1; execute: UpdateConfigArgs | ProxyArgs | AdminExecuteArgs | UpdateOwnershipArgs; instantiate?: InstantiateMsg; [k: string]: unknown; } -export interface MapOfString { - [k: string]: string; -} /** * The contract's ownership info */ @@ -765,22 +751,12 @@ export interface OwnershipForString { */ pending_owner?: string | null; } -export interface PauseInfoResponse { - core: Pause; - rewards_manager: PauseInfoResponse1; - withdrawal_manager: PauseInfoResponse1; -} -export interface Pause { - bond: boolean; - tick: boolean; - unbond: boolean; +export interface MapOfString { + [k: string]: string; } export interface MapOfString1 { [k: string]: string; } -export interface LocateArgs { - contracts: string[]; -} export interface ConfigOptional { base_denom?: string | null; bond_limit?: Uint128 | null; @@ -1314,10 +1290,7 @@ export class Client { queryState = async(): Promise<MapOfString> => { return this.client.queryContractSmart(this.contractAddress, { state: {} }); } - queryLocate = async(args: LocateArgs): Promise<MapOfString> => { - return this.client.queryContractSmart(this.contractAddress, { locate: args }); - } - queryPauseInfo = async(): Promise<PauseInfoResponse> => { + queryPauseInfo = async(): Promise<MapOfString> => { return this.client.queryContractSmart(this.contractAddress, { pause_info: {} }); } queryOwnership = async(): Promise<OwnershipForString> => {