-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests currently failing (fix TBD in another PR): - [ ] Team cannot be reset when pool is not live (fixed by #786)
- Loading branch information
1 parent
b2c71b2
commit c9da03a
Showing
5 changed files
with
292 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +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 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![DEFAULT_BONDED_CURRENCY_ID], | ||
curve, | ||
false, | ||
Some(PoolStatus::Active), | ||
Some(ACCOUNT_00), | ||
None, | ||
None, | ||
); | ||
let pool_id = calculate_pool_id(&[DEFAULT_BONDED_CURRENCY_ID]); | ||
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![DEFAULT_BONDED_CURRENCY_ID], | ||
curve, | ||
false, | ||
Some(PoolStatus::Active), | ||
Some(manager.clone()), | ||
None, | ||
Some(ACCOUNT_00), | ||
); | ||
let pool_id = calculate_pool_id(&[DEFAULT_BONDED_CURRENCY_ID]); | ||
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(&[DEFAULT_BONDED_CURRENCY_ID]); | ||
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 | ||
); | ||
}) | ||
} |
184 changes: 184 additions & 0 deletions
184
pallets/pallet-bonded-coins/src/tests/transactions/reset_team.rs
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,184 @@ | ||
use frame_support::{assert_err, assert_ok, traits::fungibles::roles::Inspect}; | ||
use frame_system::RawOrigin; | ||
|
||
use crate::{ | ||
mock::{runtime::*, *}, | ||
types::{PoolManagingTeam, PoolStatus}, | ||
Error as BondingPalletErrors, | ||
}; | ||
|
||
#[test] | ||
fn resets_team() { | ||
let pool_details = generate_pool_details( | ||
vec![DEFAULT_BONDED_CURRENCY_ID], | ||
get_linear_bonding_curve(), | ||
false, | ||
Some(PoolStatus::Active), | ||
Some(ACCOUNT_00), | ||
None, | ||
None, | ||
); | ||
let pool_id = calculate_pool_id(&[DEFAULT_BONDED_CURRENCY_ID]); | ||
|
||
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 | ||
)); | ||
|
||
assert_eq!( | ||
<Test as crate::Config>::Fungibles::admin(DEFAULT_BONDED_CURRENCY_ID), | ||
Some(ACCOUNT_00) | ||
); | ||
assert_eq!( | ||
<Test as crate::Config>::Fungibles::freezer(DEFAULT_BONDED_CURRENCY_ID), | ||
Some(ACCOUNT_01) | ||
); | ||
assert_eq!( | ||
<Test as crate::Config>::Fungibles::owner(DEFAULT_BONDED_CURRENCY_ID), | ||
Some(pool_id.clone()) | ||
); | ||
assert_eq!( | ||
<Test as crate::Config>::Fungibles::issuer(DEFAULT_BONDED_CURRENCY_ID), | ||
Some(pool_id) | ||
); | ||
}) | ||
} | ||
|
||
#[test] | ||
fn does_not_change_team_when_not_live() { | ||
let pool_details = generate_pool_details( | ||
vec![DEFAULT_BONDED_CURRENCY_ID], | ||
get_linear_bonding_curve(), | ||
false, | ||
Some(PoolStatus::Refunding), | ||
Some(ACCOUNT_00), | ||
None, | ||
None, | ||
); | ||
let pool_id = calculate_pool_id(&[DEFAULT_BONDED_CURRENCY_ID]); | ||
|
||
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 | ||
); | ||
|
||
assert_eq!( | ||
<Test as crate::Config>::Fungibles::admin(DEFAULT_BONDED_CURRENCY_ID), | ||
Some(pool_id) | ||
); | ||
}) | ||
} | ||
|
||
#[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![DEFAULT_BONDED_CURRENCY_ID], | ||
curve, | ||
false, | ||
Some(PoolStatus::Active), | ||
Some(manager.clone()), | ||
None, | ||
Some(ACCOUNT_00), | ||
); | ||
let pool_id = calculate_pool_id(&[DEFAULT_BONDED_CURRENCY_ID]); | ||
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 | ||
); | ||
|
||
assert_eq!( | ||
<Test as crate::Config>::Fungibles::admin(DEFAULT_BONDED_CURRENCY_ID), | ||
Some(pool_id) | ||
); | ||
}) | ||
} | ||
|
||
#[test] | ||
fn handles_currency_idx_out_of_bounds() { | ||
let pool_details = generate_pool_details( | ||
vec![DEFAULT_BONDED_CURRENCY_ID], | ||
get_linear_bonding_curve(), | ||
false, | ||
Some(PoolStatus::Active), | ||
Some(ACCOUNT_00), | ||
None, | ||
None, | ||
); | ||
let pool_id = calculate_pool_id(&[DEFAULT_BONDED_CURRENCY_ID]); | ||
|
||
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 | ||
); | ||
}) | ||
} |