Skip to content

Commit f58d43d

Browse files
committed
ref: apply andr macros to rates and address list
1 parent 58a96c0 commit f58d43d

File tree

7 files changed

+36
-77
lines changed

7 files changed

+36
-77
lines changed

contracts/modules/andromeda-address-list/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ andromeda-std = { workspace = true, features = [] }
2525
andromeda-modules = { workspace = true }
2626

2727
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
28-
cw-multi-test = { workspace = true, optional = true }
2928
andromeda-testing = { workspace = true, optional = true }
29+
cw-multi-test = { workspace = true, optional = true }
3030
cw-orch = { workspace = true }
3131

3232
[dev-dependencies]

contracts/modules/andromeda-address-list/src/contract.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use andromeda_std::{
55
ado_base::{permissioning::LocalPermission, InstantiateMsg as BaseInstantiateMsg, MigrateMsg},
66
ado_contract::ADOContract,
77
amp::AndrAddr,
8+
andr_execute_fn,
89
common::{context::ExecuteContext, encode_binary},
910
error::ContractError,
1011
};
@@ -13,7 +14,6 @@ use cosmwasm_std::{
1314
attr, ensure, entry_point, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response,
1415
StdError,
1516
};
16-
use cw_utils::nonpayable;
1717

1818
use crate::state::{add_actors_permission, includes_actor, PERMISSIONS};
1919
// version info for migration info
@@ -62,25 +62,8 @@ pub fn instantiate(
6262
Ok(inst_resp)
6363
}
6464

65-
#[cfg_attr(not(feature = "library"), entry_point)]
66-
pub fn execute(
67-
deps: DepsMut,
68-
env: Env,
69-
info: MessageInfo,
70-
msg: ExecuteMsg,
71-
) -> Result<Response, ContractError> {
72-
let _contract = ADOContract::default();
73-
let ctx = ExecuteContext::new(deps, info, env);
74-
75-
match msg {
76-
ExecuteMsg::AMPReceive(pkt) => {
77-
ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute)
78-
}
79-
_ => handle_execute(ctx, msg),
80-
}
81-
}
82-
83-
pub fn handle_execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, ContractError> {
65+
#[andr_execute_fn]
66+
pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, ContractError> {
8467
match msg {
8568
ExecuteMsg::PermissionActors { actors, permission } => {
8669
execute_permission_actors(ctx, actors, permission)
@@ -95,12 +78,7 @@ fn execute_permission_actors(
9578
actors: Vec<AndrAddr>,
9679
permission: LocalPermission,
9780
) -> Result<Response, ContractError> {
98-
let ExecuteContext { deps, info, .. } = ctx;
99-
nonpayable(&info)?;
100-
ensure!(
101-
ADOContract::default().is_owner_or_operator(deps.storage, info.sender.as_str())?,
102-
ContractError::Unauthorized {}
103-
);
81+
let ExecuteContext { deps, .. } = ctx;
10482
if let LocalPermission::Limited { .. } = permission {
10583
return Err(ContractError::InvalidPermission {
10684
msg: "Limited permission is not supported in address list contract".to_string(),
@@ -127,12 +105,7 @@ fn execute_remove_permissions(
127105
ctx: ExecuteContext,
128106
actors: Vec<AndrAddr>,
129107
) -> Result<Response, ContractError> {
130-
let ExecuteContext { deps, info, .. } = ctx;
131-
nonpayable(&info)?;
132-
ensure!(
133-
ADOContract::default().is_owner_or_operator(deps.storage, info.sender.as_str())?,
134-
ContractError::Unauthorized {}
135-
);
108+
let ExecuteContext { deps, .. } = ctx;
136109
ensure!(!actors.is_empty(), ContractError::NoActorsProvided {});
137110

138111
for actor in actors.clone() {

contracts/modules/andromeda-address-list/src/testing/tests.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use andromeda_std::ado_base::permissioning::LocalPermission;
1010
use andromeda_std::amp::AndrAddr;
1111
use andromeda_std::error::ContractError;
1212

13+
use andromeda_testing::economics_msg::generate_economics_message;
1314
use cosmwasm_std::{attr, from_json, Addr, DepsMut, MessageInfo};
1415
use cosmwasm_std::{
1516
testing::{mock_env, mock_info},
@@ -87,11 +88,13 @@ fn test_add_remove_actor() {
8788
};
8889

8990
let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap();
90-
let expected = Response::default().add_attributes(vec![
91-
attr("action", "add_actor_permission"),
92-
attr("actor", actor.clone()),
93-
attr("permission", permission.to_string()),
94-
]);
91+
let expected = Response::default()
92+
.add_attributes(vec![
93+
attr("action", "add_actor_permission"),
94+
attr("actor", actor.clone()),
95+
attr("permission", permission.to_string()),
96+
])
97+
.add_submessage(generate_economics_message("creator", "PermissionActors"));
9598
assert_eq!(expected, res);
9699

97100
// Check that the actor and permission have been saved.
@@ -161,11 +164,13 @@ fn test_add_remove_multiple_actors() {
161164
};
162165

163166
let res = execute(deps.as_mut(), env.clone(), info.clone(), msg.clone()).unwrap();
164-
let expected = Response::default().add_attributes(vec![
165-
attr("action", "add_actor_permission"),
166-
attr("actor", "actor1, actor2"),
167-
attr("permission", permission.to_string()),
168-
]);
167+
let expected = Response::default()
168+
.add_attributes(vec![
169+
attr("action", "add_actor_permission"),
170+
attr("actor", "actor1, actor2"),
171+
attr("permission", permission.to_string()),
172+
])
173+
.add_submessage(generate_economics_message("creator", "PermissionActors"));
169174
assert_eq!(expected, res);
170175

171176
// Check that the actor and permission have been saved.

contracts/modules/andromeda-rates/src/contract.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ use andromeda_std::{
77
InstantiateMsg as BaseInstantiateMsg, MigrateMsg,
88
},
99
ado_contract::ADOContract,
10+
andr_execute_fn,
1011
common::{context::ExecuteContext, deduct_funds, encode_binary, Funds},
1112
error::ContractError,
1213
};
1314

1415
use cosmwasm_std::{
15-
attr, coin, ensure, Binary, Coin, Deps, DepsMut, Env, Event, MessageInfo, Reply, Response,
16-
StdError, SubMsg,
16+
attr, coin, Binary, Coin, Deps, DepsMut, Env, Event, MessageInfo, Reply, Response, StdError,
17+
SubMsg,
1718
};
1819
use cosmwasm_std::{entry_point, from_json};
1920
use cw20::Cw20Coin;
20-
use cw_utils::nonpayable;
2121
// version info for migration info
2222
const CONTRACT_NAME: &str = "crates.io:andromeda-rates";
2323
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -52,24 +52,8 @@ pub fn instantiate(
5252
Ok(inst_resp)
5353
}
5454

55-
#[cfg_attr(not(feature = "library"), entry_point)]
56-
pub fn execute(
57-
deps: DepsMut,
58-
env: Env,
59-
info: MessageInfo,
60-
msg: ExecuteMsg,
61-
) -> Result<Response, ContractError> {
62-
let ctx = ExecuteContext::new(deps, info, env);
63-
64-
match msg {
65-
ExecuteMsg::AMPReceive(pkt) => {
66-
ADOContract::default().execute_amp_receive(ctx, pkt, handle_execute)
67-
}
68-
_ => handle_execute(ctx, msg),
69-
}
70-
}
71-
72-
pub fn handle_execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, ContractError> {
55+
#[andr_execute_fn]
56+
pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, ContractError> {
7357
match msg {
7458
ExecuteMsg::SetRate { action, rate } => execute_set_rate(ctx, action, rate),
7559
ExecuteMsg::RemoveRate { action } => execute_remove_rate(ctx, action),
@@ -82,13 +66,8 @@ fn execute_set_rate(
8266
action: String,
8367
rate: LocalRate,
8468
) -> Result<Response, ContractError> {
85-
let ExecuteContext { deps, info, .. } = ctx;
86-
nonpayable(&info)?;
69+
let ExecuteContext { deps, .. } = ctx;
8770

88-
ensure!(
89-
ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?,
90-
ContractError::Unauthorized {}
91-
);
9271
rate.validate(deps.as_ref())?;
9372

9473
RATES.save(deps.storage, &action, &rate)?;
@@ -97,13 +76,8 @@ fn execute_set_rate(
9776
}
9877

9978
fn execute_remove_rate(ctx: ExecuteContext, action: String) -> Result<Response, ContractError> {
100-
let ExecuteContext { deps, info, .. } = ctx;
101-
nonpayable(&info)?;
79+
let ExecuteContext { deps, .. } = ctx;
10280

103-
ensure!(
104-
ADOContract::default().is_contract_owner(deps.storage, info.sender.as_str())?,
105-
ContractError::Unauthorized {}
106-
);
10781
if RATES.has(deps.storage, &action) {
10882
RATES.remove(deps.storage, &action);
10983
Ok(Response::new().add_attributes(vec![attr("action", "remove_rates")]))

contracts/modules/andromeda-rates/src/testing/tests.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use andromeda_std::common::Funds;
1010
use andromeda_std::testing::mock_querier::{MOCK_CW20_CONTRACT, MOCK_UANDR};
1111
use andromeda_std::{amp::recipient::Recipient, common::encode_binary};
1212

13+
use andromeda_testing::economics_msg::generate_economics_message;
1314
use cosmwasm_std::{attr, Event};
1415
use cosmwasm_std::{
1516
coin, coins,
@@ -83,7 +84,9 @@ fn test_andr_receive() {
8384

8485
let res = execute(deps.as_mut(), env, info, msg).unwrap();
8586
assert_eq!(
86-
Response::new().add_attributes(vec![attr("action", "set_rate")]),
87+
Response::new()
88+
.add_attributes(vec![attr("action", "set_rate")])
89+
.add_submessage(generate_economics_message("owner", "SetRate")),
8790
res
8891
);
8992
}

packages/andromeda-modules/src/address_list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ pub struct ActorPermission {
2121
#[cw_serde]
2222
pub enum ExecuteMsg {
2323
/// Adds an actor key and a permission value
24+
#[attrs(restricted, nonpayable)]
2425
PermissionActors {
2526
actors: Vec<AndrAddr>,
2627
permission: LocalPermission,
2728
},
2829
/// Removes actor alongisde his permission
30+
#[attrs(restricted, nonpayable)]
2931
RemovePermissions { actors: Vec<AndrAddr> },
3032
}
3133

packages/andromeda-modules/src/rates.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ pub struct InstantiateMsg {
1111
#[andr_exec]
1212
#[cw_serde]
1313
pub enum ExecuteMsg {
14+
#[attrs(restricted, nonpayable)]
1415
SetRate { action: String, rate: LocalRate },
16+
#[attrs(restricted, nonpayable)]
1517
RemoveRate { action: String },
1618
}
1719

0 commit comments

Comments
 (0)