Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- feat: Batch send NFTs [(#816)](https://github.com/andromedaprotocol/andromeda-core/pull/816)
- feat: Added Permissionless attribute to relevant messages [(#825)](https://github.com/andromedaprotocol/andromeda-core/pull/825)
- feat: Apply Serde default to previous_hops [(#829)](https://github.com/andromedaprotocol/andromeda-core/pull/829)
- feat: Frequency in Permissioning [(#855)](https://github.com/andromedaprotocol/andromeda-core/pull/855)

### Changed

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/data-storage/andromeda-boolean/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn instantiate(
None => info.sender,
Some(owner) => Addr::unchecked(owner),
},
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/data-storage/andromeda-form/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn instantiate(
deps.storage,
SUBMIT_FORM_ACTION,
addr,
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn test_transfer() {
assert_eq!(err, ContractError::Unauthorized {});

// Now whitelist the sender, that should allow him to call the function successfully
let permission = Permission::Local(LocalPermission::whitelisted(None, None));
let permission = Permission::Local(LocalPermission::whitelisted(None, None, None, None, None));
let actors = vec![AndrAddr::from_string("sender")];
let action = "Transfer";
let ctx = ExecuteContext::new(deps.as_mut(), mock_info("owner", &[]), mock_env());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn instantiate(
deps.storage,
SEND_CW20_ACTION,
addr,
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/math/andromeda-curve/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ pub fn instantiate(
deps.storage,
UPDATE_CURVE_CONFIG_ACTION,
addr.clone(),
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
ADOContract::set_permission(
deps.storage,
RESET_ACTION,
addr.clone(),
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/math/andromeda-matrix/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ pub fn instantiate(
deps.storage,
STORE_MATRIX_ACTION,
addr.clone(),
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
ADOContract::set_permission(
deps.storage,
DELETE_MATRIX_ACTION,
addr.clone(),
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/modules/andromeda-address-list/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-address-list"
version = "2.1.0"
version = "2.1.1-b.1"
edition = "2021"
rust-version = "1.75.0"

Expand Down
53 changes: 39 additions & 14 deletions contracts/modules/andromeda-address-list/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use andromeda_modules::address_list::{ActorPermissionResponse, IncludesActorResponse};
use andromeda_modules::address_list::{
ActorPermissionResponse, IncludesActorResponse, PERMISSION_ACTORS_ACTION,
};
#[cfg(not(feature = "library"))]
use andromeda_modules::address_list::{ExecuteMsg, InstantiateMsg, QueryMsg};
use andromeda_std::{
ado_base::{permissioning::LocalPermission, InstantiateMsg as BaseInstantiateMsg, MigrateMsg},
ado_base::{
permissioning::{LocalPermission, Permission},
InstantiateMsg as BaseInstantiateMsg, MigrateMsg,
},
ado_contract::ADOContract,
amp::AndrAddr,
andr_execute_fn,
Expand All @@ -28,23 +33,47 @@ pub fn instantiate(
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
// If the user provided an actor and permission, save them.
if let Some(actor_permission) = msg.actor_permission {
// Permissions of type Limited local permissions aren't allowed in the address list contract
if let LocalPermission::Limited { .. } = actor_permission.permission {
return Err(ContractError::InvalidPermission {
msg: "Limited permission is not supported in address list contract".to_string(),
});
}
if let Some(mut actor_permission) = msg.actor_permission {
ensure!(
!actor_permission.actors.is_empty(),
ContractError::NoActorsProvided {}
);
actor_permission.permission.validate_times(&env)?;

// If the permission is a whitelist, make sure to set last used time as none
actor_permission.permission = if let LocalPermission::Whitelisted {
start,
expiration,
uses,
frequency,
..
} = actor_permission.permission
{
LocalPermission::Whitelisted {
start,
expiration,
uses,
frequency,
last_used: None,
}
} else {
actor_permission.permission
};

for actor in actor_permission.actors {
let verified_actor = actor.get_raw_address(&deps.as_ref())?;
add_actors_permission(deps.storage, verified_actor, &actor_permission.permission)?;
}
}

ADOContract::default().permission_action(deps.storage, PERMISSION_ACTORS_ACTION)?;
ADOContract::set_permission(
deps.storage,
PERMISSION_ACTORS_ACTION.to_string(),
info.sender.clone(),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;

let inst_resp = ADOContract::default().instantiate(
deps.storage,
env,
Expand Down Expand Up @@ -79,11 +108,7 @@ fn execute_permission_actors(
permission: LocalPermission,
) -> Result<Response, ContractError> {
let ExecuteContext { deps, env, .. } = ctx;
if let LocalPermission::Limited { .. } = permission {
return Err(ContractError::InvalidPermission {
msg: "Limited permission is not supported in address list contract".to_string(),
});
}

ensure!(!actors.is_empty(), ContractError::NoActorsProvided {});
permission.validate_times(&env)?;
for actor in actors.clone() {
Expand Down
41 changes: 40 additions & 1 deletion contracts/modules/andromeda-address-list/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

use crate::contract::{execute, instantiate, query};
use andromeda_modules::address_list::{ActorPermission, ExecuteMsg, InstantiateMsg, QueryMsg};
use andromeda_std::{ado_base::permissioning::LocalPermission, amp::AndrAddr};
use andromeda_std::{
ado_base::permissioning::{LocalPermission, Permission, PermissioningMessage},
amp::AndrAddr,
};
use andromeda_testing::{
mock::MockApp, mock_ado, mock_contract::ExecuteResult, MockADO, MockContract,
};
Expand Down Expand Up @@ -49,6 +52,22 @@ impl MockAddressList {
&[],
)
}

pub fn execute_set_permission_actor(
&self,
app: &mut MockApp,
sender: Addr,
actors: Vec<AndrAddr>,
action: String,
permission: Permission,
) -> ExecuteResult {
self.execute(
app,
&mock_set_permission_actor_msg(actors, action, permission),
sender,
&[],
)
}
}

pub fn mock_andromeda_address_list() -> Box<dyn Contract<Empty>> {
Expand All @@ -68,9 +87,29 @@ pub fn mock_address_list_instantiate_msg(
}
}

pub fn mock_permission_action_msg(action: String) -> ExecuteMsg {
ExecuteMsg::Permissioning(PermissioningMessage::PermissionAction { action })
}

pub fn mock_add_actor_permission_msg(
actors: Vec<AndrAddr>,
permission: LocalPermission,
) -> ExecuteMsg {
ExecuteMsg::PermissionActors { actors, permission }
}

pub fn mock_set_permission_actor_msg(
actors: Vec<AndrAddr>,
action: String,
permission: Permission,
) -> ExecuteMsg {
ExecuteMsg::Permissioning(PermissioningMessage::SetPermission {
actors,
action,
permission,
})
}

pub fn mock_query_permission_msg(actor: Addr) -> QueryMsg {
QueryMsg::ActorPermission { actor }
}
57 changes: 1 addition & 56 deletions contracts/modules/andromeda-address-list/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn init(deps: DepsMut, info: MessageInfo) {
owner: None,
actor_permission: Some(ActorPermission {
actors: vec![AndrAddr::from_string("actor")],
permission: LocalPermission::whitelisted(None, None),
permission: LocalPermission::whitelisted(None, None, None, None, None),
}),
},
)
Expand All @@ -41,33 +41,6 @@ fn test_instantiate() {
init(deps.as_mut(), info);
}

// #[test]
// fn test_instantiate_contract_permission() {
// let mut deps = mock_dependencies_custom(&[]);
// let info = mock_info("creator", &[]);

// let err = instantiate(
// deps.as_mut(),
// mock_env(),
// info,
// InstantiateMsg {
// kernel_address: MOCK_KERNEL_CONTRACT.to_string(),
// owner: None,
// actor_permission: Some(ActorPermission {
// actor: Addr::unchecked(MOCK_KERNEL_CONTRACT),
// permission: Permission::Whitelisted(None),
// }),
// },
// )
// .unwrap_err();
// assert_eq!(
// err,
// ContractError::InvalidPermission {
// msg: "Contract permissions aren't allowed in the address list contract".to_string()
// }
// )
// }

#[test]
fn test_add_remove_actor() {
let mut deps = mock_dependencies_custom(&[]);
Expand Down Expand Up @@ -103,20 +76,6 @@ fn test_add_remove_actor() {
let res = execute(deps.as_mut(), env.clone(), unauth_info, msg).unwrap_err();
assert_eq!(ContractError::Unauthorized {}, res);

// // Contract permissions aren't allowed to be saved in the address list contract
// let contract_permission = Permission::Whitelisted(None);
// let msg = ExecuteMsg::PermissionActors {
// actor: Addr::unchecked(MOCK_KERNEL_CONTRACT),
// permission: contract_permission,
// };
// let err = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap_err();
// assert_eq!(
// err,
// ContractError::InvalidPermission {
// msg: "Contract permissions aren't allowed in the address list contract".to_string()
// }
// );

// Test remove actor
let msg = ExecuteMsg::RemovePermissions {
actors: vec![AndrAddr::from_string(actor.clone())],
Expand Down Expand Up @@ -189,20 +148,6 @@ fn test_add_remove_multiple_actors() {
let res = execute(deps.as_mut(), env.clone(), unauth_info, msg).unwrap_err();
assert_eq!(ContractError::Unauthorized {}, res);

// // Contract permissions aren't allowed to be saved in the address list contract
// let contract_permission = Permission::Whitelisted(None);
// let msg = ExecuteMsg::PermissionActors {
// actor: Addr::unchecked(MOCK_KERNEL_CONTRACT),
// permission: contract_permission,
// };
// let err = execute(deps.as_mut(), env.clone(), info.clone(), msg).unwrap_err();
// assert_eq!(
// err,
// ContractError::InvalidPermission {
// msg: "Contract permissions aren't allowed in the address list contract".to_string()
// }
// );

// Test remove actor
let msg = ExecuteMsg::RemovePermissions {
actors: actors.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ fn execute_start_auction(
deps.storage,
auction_id.to_string(),
whitelisted_address,
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}
};
Expand Down Expand Up @@ -406,7 +406,7 @@ fn execute_update_auction(
deps.storage,
token_auction_state.auction_id.to_string(),
whitelisted_address,
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn instantiate(
deps.storage,
SEND_CW20_ACTION,
addr,
Permission::Local(LocalPermission::whitelisted(None, None)),
Permission::Local(LocalPermission::whitelisted(None, None, None, None, None)),
)?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ macro_rules! ensure_can_mint {
&$ctx.env,
&$ctx.amp_ctx,
MINT_ACTION,
)?;
)?
.0;

ensure!(has_mint_permission, ContractError::Unauthorized {});
};
Expand Down
Loading
Loading