Skip to content
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

feat: emit additional event on reset_team #874

Open
wants to merge 3 commits into
base: bonded-coins-audit-fixes
Choose a base branch
from
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
15 changes: 12 additions & 3 deletions pallets/pallet-bonded-coins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ pub mod pallet {
id: T::PoolId,
manager: Option<T::AccountId>,
},
/// The asset managing team of a pool has been reset.
TeamChanged {
id: T::PoolId,
team: PoolManagingTeam<T::AccountId>,
},
}

#[pallet::error]
Expand Down Expand Up @@ -501,9 +506,9 @@ pub mod pallet {
ensure!(pool_details.is_manager(&who), Error::<T>::NoPermission);
ensure!(pool_details.state.is_live(), Error::<T>::PoolNotLive);

let pool_id_account = pool_id.into();
let pool_id_account = pool_id.clone().into();

let PoolManagingTeam { freezer, admin } = team;
let PoolManagingTeam { ref freezer, ref admin } = team;

pool_details.bonded_currencies.into_iter().try_for_each(|asset_id| {
T::Fungibles::reset_team(
Expand All @@ -513,7 +518,11 @@ pub mod pallet {
pool_id_account.clone(),
freezer.clone(),
)
})
})?;

Self::deposit_event(Event::TeamChanged { id: pool_id, team });

Ok(())
}

/// Resets the manager of a pool. The new manager will be set to the
Expand Down
38 changes: 37 additions & 1 deletion pallets/pallet-bonded-coins/src/tests/transactions/reset_team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
mock::{runtime::*, *},
traits::ResetTeam,
types::{PoolManagingTeam, PoolStatus},
AccountIdOf, Error as BondingPalletErrors,
AccountIdOf, Error as BondingPalletErrors, Event,
};

#[test]
Expand Down Expand Up @@ -55,6 +55,18 @@ fn resets_team() {
1
));

// Ensure the event is emitted
System::assert_has_event(
Event::TeamChanged {
id: pool_id.clone(),
team: PoolManagingTeam {
admin: ACCOUNT_00,
freezer: ACCOUNT_01,
},
}
.into(),
);

assert_eq!(Assets::admin(DEFAULT_BONDED_CURRENCY_ID), Some(ACCOUNT_00));
assert_eq!(Assets::freezer(DEFAULT_BONDED_CURRENCY_ID), Some(ACCOUNT_01));
assert_eq!(Assets::owner(DEFAULT_BONDED_CURRENCY_ID), Some(pool_id.clone()));
Expand Down Expand Up @@ -106,6 +118,18 @@ fn resets_owner_if_changed() {
1
));

// Ensure the event is emitted
System::assert_has_event(
Event::TeamChanged {
id: pool_id.clone(),
team: PoolManagingTeam {
admin: pool_id.clone(),
freezer: pool_id.clone(),
},
}
.into(),
);

assert_eq!(Assets::admin(DEFAULT_BONDED_CURRENCY_ID), Some(pool_id.clone()));
assert_eq!(Assets::freezer(DEFAULT_BONDED_CURRENCY_ID), Some(pool_id.clone()));
assert_eq!(Assets::owner(DEFAULT_BONDED_CURRENCY_ID), Some(pool_id.clone()));
Expand Down Expand Up @@ -145,6 +169,18 @@ fn resets_team_for_all() {
2
));

// Ensure the event is emitted
System::assert_has_event(
Event::TeamChanged {
id: pool_id.clone(),
team: PoolManagingTeam {
admin: ACCOUNT_00,
freezer: ACCOUNT_01,
},
}
.into(),
);

assert_eq!(Assets::admin(currencies[0]), Some(ACCOUNT_00));
assert_eq!(Assets::freezer(currencies[0]), Some(ACCOUNT_01));
assert_eq!(Assets::owner(currencies[0]), Some(pool_id.clone()));
Expand Down
Loading