From 275757542fadf0e28944381b0c06e875e0e60501 Mon Sep 17 00:00:00 2001 From: Joe Monem Date: Fri, 10 Jan 2025 16:44:47 +0200 Subject: [PATCH] fix: stop returning error if there's no fee attached to action --- .../src/testing/tests.rs | 45 +++++++++---------- packages/std/src/common/actions.rs | 33 ++++++-------- packages/std/src/os/aos_querier.rs | 1 - 3 files changed, 34 insertions(+), 45 deletions(-) diff --git a/contracts/modules/andromeda-address-list/src/testing/tests.rs b/contracts/modules/andromeda-address-list/src/testing/tests.rs index e53abb909..82ed7a55e 100644 --- a/contracts/modules/andromeda-address-list/src/testing/tests.rs +++ b/contracts/modules/andromeda-address-list/src/testing/tests.rs @@ -1,20 +1,19 @@ -use crate::contract::{execute, instantiate, query}; -use crate::state::PERMISSIONS; -use crate::testing::mock_querier::{mock_dependencies_custom, MOCK_KERNEL_CONTRACT}; +use crate::{ + contract::{execute, instantiate, query}, + state::PERMISSIONS, + testing::mock_querier::{mock_dependencies_custom, MOCK_KERNEL_CONTRACT}, +}; use andromeda_modules::address_list::{ ActorPermission, ActorPermissionResponse, ExecuteMsg, IncludesActorResponse, InstantiateMsg, QueryMsg, }; -use andromeda_std::ado_base::permissioning::LocalPermission; - -use andromeda_std::amp::AndrAddr; -use andromeda_std::error::ContractError; - -use andromeda_testing::economics_msg::generate_economics_message; -use cosmwasm_std::{attr, from_json, Addr, DepsMut, MessageInfo}; +use andromeda_std::{ + ado_base::permissioning::LocalPermission, amp::AndrAddr, error::ContractError, +}; use cosmwasm_std::{ + attr, from_json, testing::{mock_env, mock_info}, - Response, + Addr, DepsMut, MessageInfo, Response, }; fn init(deps: DepsMut, info: MessageInfo) { @@ -88,13 +87,11 @@ fn test_add_remove_actor() { }; let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); - let expected = Response::default() - .add_attributes(vec![ - attr("action", "add_actor_permission"), - attr("actor", actor.clone()), - attr("permission", permission.to_string()), - ]) - .add_submessage(generate_economics_message("creator", "PermissionActors")); + let expected = Response::default().add_attributes(vec![ + attr("action", "add_actor_permission"), + attr("actor", actor.clone()), + attr("permission", permission.to_string()), + ]); assert_eq!(expected, res); // Check that the actor and permission have been saved. @@ -164,13 +161,11 @@ fn test_add_remove_multiple_actors() { }; let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap(); - let expected = Response::default() - .add_attributes(vec![ - attr("action", "add_actor_permission"), - attr("actor", "actor1, actor2"), - attr("permission", permission.to_string()), - ]) - .add_submessage(generate_economics_message("creator", "PermissionActors")); + let expected = Response::default().add_attributes(vec![ + attr("action", "add_actor_permission"), + attr("actor", "actor1, actor2"), + attr("permission", permission.to_string()), + ]); assert_eq!(expected, res); // Check that the actor and permission have been saved. diff --git a/packages/std/src/common/actions.rs b/packages/std/src/common/actions.rs index 46334722a..74814532e 100644 --- a/packages/std/src/common/actions.rs +++ b/packages/std/src/common/actions.rs @@ -25,25 +25,20 @@ pub fn call_action( }; let adodb_addr = ADOContract::default().get_adodb_address(deps.storage, &deps.querier)?; - let contract_info = deps + let code_id = deps .querier - .query_wasm_contract_info(env.contract.address.clone())?; - let code_id = contract_info.code_id; - // If ADO type is not found, return default response - let ado_type = AOSQuerier::ado_type_getter(&deps.querier, &adodb_addr, code_id)?; - if let Some(ado_type) = ado_type { - if AOSQuerier::action_fee_getter(&deps.querier, &adodb_addr, &ado_type, action)?.is_some() { - let fee_msg = ADOContract::default().pay_fee( - deps.storage, - &deps.querier, - action.to_owned(), - payee, - )?; - Ok(Response::default().add_submessage(fee_msg)) - } else { - Ok(Response::default()) - } - } else { - Ok(Response::default()) + .query_wasm_contract_info(env.contract.address.clone())? + .code_id; + + // Check ADO type and fees in one chain + match AOSQuerier::ado_type_getter(&deps.querier, &adodb_addr, code_id)? + .and_then(|ado_type| { + AOSQuerier::action_fee_getter(&deps.querier, &adodb_addr, &ado_type, action).ok() + }) + .map(|_| { + ADOContract::default().pay_fee(deps.storage, &deps.querier, action.to_owned(), payee) + }) { + Some(fee_msg) => Ok(Response::default().add_submessage(fee_msg?)), + None => Ok(Response::default()), } } diff --git a/packages/std/src/os/aos_querier.rs b/packages/std/src/os/aos_querier.rs index f4fbd8a77..e80ef2558 100644 --- a/packages/std/src/os/aos_querier.rs +++ b/packages/std/src/os/aos_querier.rs @@ -182,7 +182,6 @@ impl AOSQuerier { &[ado_type.as_bytes(), action.as_bytes()], )?; let fee: Option = AOSQuerier::query_storage(querier, adodb_addr, &key)?; - Ok(fee) }