diff --git a/pallets/stableswap/src/lib.rs b/pallets/stableswap/src/lib.rs index 40d4066f1..588b9b2b2 100644 --- a/pallets/stableswap/src/lib.rs +++ b/pallets/stableswap/src/lib.rs @@ -938,7 +938,7 @@ pub mod pallet { // Special case when withdrawing all remaining pool shares, so we can directly send all the remaining assets to the user. let amount = if share_amount == share_issuance { - // no need to ensure the min amounts in this case + ensure!(reserve >= min_amount, Error::::SlippageLimit); reserve } else { let amount = diff --git a/pallets/stableswap/src/tests/mock.rs b/pallets/stableswap/src/tests/mock.rs index f6a447582..8e71647c7 100644 --- a/pallets/stableswap/src/tests/mock.rs +++ b/pallets/stableswap/src/tests/mock.rs @@ -441,3 +441,7 @@ pub(crate) fn last_liquidity_changed_hook_state() -> Option<(AssetId, PoolState< pub(crate) fn last_trade_hook_state() -> Option<(AssetId, AssetId, AssetId, PoolState)> { LAST_TRADE_HOOK.with(|v| v.borrow().clone()) } + +pub(crate) fn expect_events(e: Vec) { + e.into_iter().for_each(frame_system::Pallet::::assert_has_event); +} diff --git a/pallets/stableswap/src/tests/remove_liquidity.rs b/pallets/stableswap/src/tests/remove_liquidity.rs index d60a1fc0a..1f1d5e568 100644 --- a/pallets/stableswap/src/tests/remove_liquidity.rs +++ b/pallets/stableswap/src/tests/remove_liquidity.rs @@ -1,6 +1,6 @@ use crate::tests::mock::*; use crate::types::{AssetAmount, PoolInfo}; -use crate::{assert_balance, Error, Pools}; +use crate::{assert_balance, Error, Event, Pools}; use frame_support::traits::Contains; use frame_support::{assert_noop, assert_ok, BoundedVec}; use sp_runtime::Permill; @@ -1118,6 +1118,9 @@ fn remove_multi_asset_liquidity_should_work_when_withdrawing_all_remaining_share ) .build() .execute_with(|| { + + System::set_block_number(1); + let pool_id = get_pool_id_at(0); let amount_added = 200 * ONE; @@ -1183,9 +1186,35 @@ fn remove_multi_asset_liquidity_should_work_when_withdrawing_all_remaining_share assert_balance!(ALICE, asset_b, pool_b_balance); assert_balance!(ALICE, asset_c, pool_c_balance); - // Ensure that has been removed + // Ensure that pool has been removed // Ensure that pool account has been removed from dust list assert!(Pools::::get(pool_id).is_none()); assert!(!Whitelist::contains(&pool_account)); + + // Ensure events are emitted + expect_events(vec![ + Event::PoolDestroyed { pool_id }.into(), + Event::LiquidityRemoved { + pool_id, + who: ALICE, + shares, + amounts: vec![ + AssetAmount { + asset_id: asset_a, + amount: pool_a_balance, + }, + AssetAmount { + asset_id: asset_b, + amount: pool_b_balance, + }, + AssetAmount { + asset_id: asset_c, + amount: pool_c_balance, + }, + ], + fee: 0u128, + } + .into(), + ]); }); }