Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devwckd committed Jan 2, 2025
1 parent 52803d4 commit e33ec22
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pallets/governance/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,9 @@ pub(crate) fn resolver_expired_applications<T: crate::Config>(current_block: Blo
crate::Pallet::<T>::deposit_event(crate::Event::<T>::ApplicationExpired(application.id));
}
}

pub(crate) fn exists_for_agent_key<T: crate::Config>(key: &AccountIdOf<T>) -> bool {
crate::AgentApplications::<T>::iter().any(|(_, application)| {
application.agent_key == *key && application.status == ApplicationStatus::Open
})
}
50 changes: 50 additions & 0 deletions pallets/governance/tests/application.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pallet_governance::application::ApplicationStatus;
use pallet_governance::AgentApplications;
use pallet_governance::GlobalGovernanceConfig;
use test_utils::*;
Expand Down Expand Up @@ -46,6 +47,13 @@ fn whitelist_executes_application_correctly() {
assert!(pallet_governance::whitelist::is_whitelisted::<Test>(
&adding_key
));

let application =
pallet_governance::AgentApplications::<Test>::get(application_id).unwrap();
assert_eq!(
application.status,
ApplicationStatus::Resolved { accepted: true }
);
});
}

Expand Down Expand Up @@ -90,5 +98,47 @@ fn application_denied_doesnt_add_to_whitelist() {
assert!(!pallet_governance::whitelist::is_whitelisted::<Test>(
&adding_key
));

let application =
pallet_governance::AgentApplications::<Test>::get(application_id).unwrap();
assert_eq!(
application.status,
ApplicationStatus::Resolved { accepted: false }
);
});
}

#[test]
fn application_expires() {
new_test_ext().execute_with(|| {
let key = 0;
let adding_key = 1;
pallet_governance::Curators::<Test>::insert(key, ());

let proposal_cost = GlobalGovernanceConfig::<Test>::get().agent_application_cost;
let data = "test".as_bytes().to_vec();

add_balance(key, proposal_cost + 1);

assert_ok!(pallet_governance::Pallet::<Test>::submit_application(
get_origin(key),
adding_key,
data.clone(),
));

let mut application_id: u32 = u32::MAX;
for (_, value) in AgentApplications::<Test>::iter() {
assert_eq!(value.agent_key, adding_key);
assert_eq!(value.data, data);
application_id = value.id;
}

step_block(
pallet_governance::GlobalGovernanceConfig::<Test>::get().agent_application_expiration,
);

let application =
pallet_governance::AgentApplications::<Test>::get(application_id).unwrap();
assert_eq!(application.status, ApplicationStatus::Expired);
});
}

0 comments on commit e33ec22

Please sign in to comment.