-
Notifications
You must be signed in to change notification settings - Fork 47
test: reset manager and team #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1695dca
test: reset manager
rflechtner 53a2024
test: reset_team
rflechtner 55afeb2
chore: use DEFAULT_BONDED_CURRENCY_ID
rflechtner ecebdf4
Merge remote-tracking branch 'origin/pallet_bonded_coins' into rf-tes…
rflechtner 625079e
chore: use bounded_vec! macro in tests
rflechtner 86b1735
refactor: use assertions on fungibles instead of foreign events
rflechtner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| mod burn_into; | ||
| mod create_pool; | ||
| mod mint_into; | ||
| mod reset_manager; | ||
| mod reset_team; | ||
| mod set_lock; | ||
| mod swap_into; | ||
|
|
||
| mod unlock; |
95 changes: 95 additions & 0 deletions
95
pallets/pallet-bonded-coins/src/tests/transactions/reset_manager.rs
This file contains hidden or 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,95 @@ | ||
| use frame_support::{assert_err, assert_ok}; | ||
| use frame_system::RawOrigin; | ||
|
|
||
| use crate::{ | ||
| mock::{runtime::*, *}, | ||
| types::PoolStatus, | ||
| Error as BondingPalletErrors, Event as BondingPalletEvents, Pools, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn changes_manager() { | ||
| let curve = get_linear_bonding_curve(); | ||
|
|
||
| let pool_details = generate_pool_details( | ||
| vec![0], | ||
| curve, | ||
| false, | ||
| Some(PoolStatus::Active), | ||
| Some(ACCOUNT_00), | ||
| None, | ||
| None, | ||
| ); | ||
| let pool_id = calculate_pool_id(&[0]); | ||
| ExtBuilder::default() | ||
| .with_pools(vec![(pool_id.clone(), pool_details.clone())]) | ||
| .build() | ||
| .execute_with(|| { | ||
| let origin = RawOrigin::Signed(ACCOUNT_00).into(); | ||
| assert_ok!(BondingPallet::reset_manager(origin, pool_id.clone(), Some(ACCOUNT_01))); | ||
|
|
||
| System::assert_has_event( | ||
| BondingPalletEvents::ManagerUpdated { | ||
| id: pool_id.clone(), | ||
| manager: Some(ACCOUNT_01), | ||
| } | ||
| .into(), | ||
| ); | ||
|
|
||
| let new_details = Pools::<Test>::get(&pool_id).unwrap(); | ||
| assert_eq!(new_details.manager, Some(ACCOUNT_01)); | ||
| assert_eq!(new_details.owner, pool_details.owner) | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn only_manager_can_change_manager() { | ||
| let curve = get_linear_bonding_curve(); | ||
|
|
||
| let manager = AccountId::new([10u8; 32]); | ||
| let pool_details = generate_pool_details( | ||
| vec![0], | ||
| curve, | ||
| false, | ||
| Some(PoolStatus::Active), | ||
| Some(manager.clone()), | ||
| None, | ||
| Some(ACCOUNT_00), | ||
| ); | ||
| let pool_id = calculate_pool_id(&[0]); | ||
| ExtBuilder::default() | ||
| .with_pools(vec![(pool_id.clone(), pool_details.clone())]) | ||
| .build() | ||
| .execute_with(|| { | ||
| let owner_origin = RawOrigin::Signed(ACCOUNT_00).into(); | ||
| let other_origin = RawOrigin::Signed(ACCOUNT_01).into(); | ||
|
|
||
| assert_err!( | ||
| BondingPallet::reset_manager(owner_origin, pool_id.clone(), Some(ACCOUNT_00)), | ||
| BondingPalletErrors::<Test>::NoPermission | ||
| ); | ||
|
|
||
| assert_err!( | ||
| BondingPallet::reset_manager(other_origin, pool_id.clone(), Some(ACCOUNT_00)), | ||
| BondingPalletErrors::<Test>::NoPermission | ||
| ); | ||
|
|
||
| let new_details = Pools::<Test>::get(&pool_id).unwrap(); | ||
| assert_eq!(new_details.manager, Some(manager)); | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn cant_change_manager_if_pool_nonexistent() { | ||
| let pool_id = calculate_pool_id(&[0]); | ||
| ExtBuilder::default().build().execute_with(|| { | ||
| let origin = RawOrigin::Signed(ACCOUNT_00).into(); | ||
|
|
||
| assert!(Pools::<Test>::get(&pool_id).is_none()); | ||
|
|
||
| assert_err!( | ||
| BondingPallet::reset_manager(origin, pool_id.clone(), Some(ACCOUNT_00)), | ||
| BondingPalletErrors::<Test>::PoolUnknown | ||
| ); | ||
| }) | ||
| } | ||
171 changes: 171 additions & 0 deletions
171
pallets/pallet-bonded-coins/src/tests/transactions/reset_team.rs
This file contains hidden or 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,171 @@ | ||
| use frame_support::{assert_err, assert_ok}; | ||
| use frame_system::RawOrigin; | ||
| use pallet_assets::Event as AssetsPalletEvents; | ||
|
|
||
| use crate::{ | ||
| mock::{runtime::*, *}, | ||
| types::{PoolManagingTeam, PoolStatus}, | ||
| Error as BondingPalletErrors, Pools, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn resets_team() { | ||
| let pool_details = generate_pool_details( | ||
| vec![0], | ||
| get_linear_bonding_curve(), | ||
| false, | ||
| Some(PoolStatus::Active), | ||
| Some(ACCOUNT_00), | ||
| None, | ||
| None, | ||
| ); | ||
| let pool_id = calculate_pool_id(&[0]); | ||
|
|
||
| ExtBuilder::default() | ||
| .with_pools(vec![(pool_id.clone(), pool_details.clone())]) | ||
| .build() | ||
| .execute_with(|| { | ||
| let manager_origin = RawOrigin::Signed(ACCOUNT_00).into(); | ||
|
|
||
| assert_ok!(BondingPallet::reset_team( | ||
| manager_origin, | ||
| pool_id.clone(), | ||
| PoolManagingTeam { | ||
| admin: ACCOUNT_00, | ||
| freezer: ACCOUNT_01, | ||
| }, | ||
| 0 | ||
| )); | ||
|
|
||
| System::assert_has_event( | ||
| AssetsPalletEvents::<Test>::TeamChanged { | ||
| asset_id: 0, | ||
| issuer: pool_id, | ||
| admin: ACCOUNT_00, | ||
| freezer: ACCOUNT_01, | ||
| } | ||
| .into(), | ||
| ); | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn does_not_change_team_when_not_live() { | ||
| let pool_details = generate_pool_details( | ||
| vec![0], | ||
| get_linear_bonding_curve(), | ||
| false, | ||
| Some(PoolStatus::Refunding), | ||
| Some(ACCOUNT_00), | ||
| None, | ||
| None, | ||
| ); | ||
| let pool_id = calculate_pool_id(&[0]); | ||
|
|
||
| ExtBuilder::default() | ||
| .with_pools(vec![(pool_id.clone(), pool_details.clone())]) | ||
| .build() | ||
| .execute_with(|| { | ||
| let manager_origin = RawOrigin::Signed(ACCOUNT_00).into(); | ||
|
|
||
| assert_err!( | ||
| BondingPallet::reset_team( | ||
| manager_origin, | ||
| pool_id.clone(), | ||
| PoolManagingTeam { | ||
| admin: ACCOUNT_00, | ||
| freezer: ACCOUNT_00, | ||
| }, | ||
| 0 | ||
| ), | ||
| BondingPalletErrors::<Test>::PoolNotLive | ||
| ); | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn only_manager_can_change_team() { | ||
| let curve = get_linear_bonding_curve(); | ||
|
|
||
| let manager = AccountId::new([10u8; 32]); | ||
| let pool_details = generate_pool_details( | ||
| vec![0], | ||
| curve, | ||
| false, | ||
| Some(PoolStatus::Active), | ||
| Some(manager.clone()), | ||
| None, | ||
| Some(ACCOUNT_00), | ||
| ); | ||
| let pool_id = calculate_pool_id(&[0]); | ||
| ExtBuilder::default() | ||
| .with_pools(vec![(pool_id.clone(), pool_details.clone())]) | ||
| .build() | ||
| .execute_with(|| { | ||
| let owner_origin = RawOrigin::Signed(ACCOUNT_00).into(); | ||
| let other_origin = RawOrigin::Signed(ACCOUNT_01).into(); | ||
|
|
||
| assert_err!( | ||
| BondingPallet::reset_team( | ||
| owner_origin, | ||
| pool_id.clone(), | ||
| PoolManagingTeam { | ||
| admin: ACCOUNT_00, | ||
| freezer: ACCOUNT_00, | ||
| }, | ||
| 0 | ||
| ), | ||
| BondingPalletErrors::<Test>::NoPermission | ||
| ); | ||
|
|
||
| assert_err!( | ||
| BondingPallet::reset_team( | ||
| other_origin, | ||
| pool_id.clone(), | ||
| PoolManagingTeam { | ||
| admin: ACCOUNT_00, | ||
| freezer: ACCOUNT_00, | ||
| }, | ||
| 0 | ||
| ), | ||
| BondingPalletErrors::<Test>::NoPermission | ||
| ); | ||
|
|
||
| let new_details = Pools::<Test>::get(&pool_id).unwrap(); | ||
| assert_eq!(new_details.manager, Some(manager)); | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn handles_currency_idx_out_of_bounds() { | ||
| let pool_details = generate_pool_details( | ||
| vec![0], | ||
| get_linear_bonding_curve(), | ||
| false, | ||
| Some(PoolStatus::Active), | ||
| Some(ACCOUNT_00), | ||
| None, | ||
| None, | ||
| ); | ||
| let pool_id = calculate_pool_id(&[0]); | ||
|
|
||
| ExtBuilder::default() | ||
| .with_pools(vec![(pool_id.clone(), pool_details.clone())]) | ||
| .build() | ||
| .execute_with(|| { | ||
| let manager_origin = RawOrigin::Signed(ACCOUNT_00).into(); | ||
|
|
||
| assert_err!( | ||
| BondingPallet::reset_team( | ||
| manager_origin, | ||
| pool_id.clone(), | ||
| PoolManagingTeam { | ||
| admin: ACCOUNT_00, | ||
| freezer: ACCOUNT_00, | ||
| }, | ||
| 2 | ||
| ), | ||
| BondingPalletErrors::<Test>::IndexOutOfBounds | ||
| ); | ||
| }) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.