-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
603 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use pallet_governance::AgentApplications; | ||
use pallet_governance::GlobalGovernanceConfig; | ||
use test_utils::*; | ||
|
||
#[test] | ||
fn whitelist_executes_application_correctly() { | ||
new_test_ext().execute_with(|| { | ||
zero_min_burn(); | ||
|
||
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); | ||
// first submit an application | ||
let balance_before = get_balance(key); | ||
|
||
assert_ok!(pallet_governance::Pallet::<Test>::submit_application( | ||
get_origin(key), | ||
adding_key, | ||
data.clone(), | ||
)); | ||
|
||
let balance_after = get_balance(key); | ||
assert_eq!(balance_after, balance_before - proposal_cost); | ||
|
||
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; | ||
} | ||
|
||
assert_ok!(pallet_governance::Pallet::<Test>::accept_application( | ||
get_origin(key), | ||
application_id | ||
)); | ||
|
||
let balance_after_accept = get_balance(key); | ||
|
||
assert_eq!(balance_after_accept, balance_before); | ||
|
||
assert!(pallet_governance::whitelist::is_whitelisted::<Test>( | ||
&adding_key | ||
)); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn application_denied_doesnt_add_to_whitelist() { | ||
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); | ||
let balance_before = get_balance(key); | ||
|
||
assert_ok!(pallet_governance::Pallet::<Test>::submit_application( | ||
get_origin(key), | ||
adding_key, | ||
data.clone(), | ||
)); | ||
|
||
let balance_after = get_balance(key); | ||
assert_eq!(balance_after, balance_before - proposal_cost); | ||
|
||
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; | ||
} | ||
|
||
assert_ok!(pallet_governance::Pallet::<Test>::deny_application( | ||
get_origin(key), | ||
application_id | ||
)); | ||
|
||
let balance_after_accept = get_balance(key); | ||
|
||
assert_eq!(balance_after_accept, balance_after); | ||
|
||
assert!(!pallet_governance::whitelist::is_whitelisted::<Test>( | ||
&adding_key | ||
)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::pallet_governance::Error; | ||
use pallet_governance::Curators; | ||
use polkadot_sdk::frame_support::assert_err; | ||
use test_utils::*; | ||
|
||
#[test] | ||
fn user_is_added_to_whitelist() { | ||
new_test_ext().execute_with(|| { | ||
let curator_key = 0; | ||
let module_key = 1; | ||
Curators::<Test>::insert(curator_key, ()); | ||
|
||
assert_ok!(pallet_governance::Pallet::<Test>::add_to_whitelist( | ||
get_origin(curator_key), | ||
module_key | ||
)); | ||
|
||
assert!(pallet_governance::whitelist::is_whitelisted::<Test>( | ||
&module_key | ||
)) | ||
}); | ||
} | ||
|
||
#[test] | ||
fn only_curators_can_whitelist() { | ||
new_test_ext().execute_with(|| { | ||
let not_curator_key = 0; | ||
let module_key = 1; | ||
|
||
assert_err!( | ||
pallet_governance::Pallet::<Test>::add_to_whitelist( | ||
get_origin(not_curator_key), | ||
module_key | ||
), | ||
Error::<Test>::NotCurator | ||
); | ||
}); | ||
} |
Oops, something went wrong.