Skip to content

Commit

Permalink
fix: stop returning error if there's no fee attached to action
Browse files Browse the repository at this point in the history
  • Loading branch information
joemonem committed Jan 10, 2025
1 parent 84cbb3f commit 2757575
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
45 changes: 20 additions & 25 deletions contracts/modules/andromeda-address-list/src/testing/tests.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
33 changes: 14 additions & 19 deletions packages/std/src/common/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
1 change: 0 additions & 1 deletion packages/std/src/os/aos_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ impl AOSQuerier {
&[ado_type.as_bytes(), action.as_bytes()],
)?;
let fee: Option<ActionFee> = AOSQuerier::query_storage(querier, adodb_addr, &key)?;

Ok(fee)
}

Expand Down

0 comments on commit 2757575

Please sign in to comment.