Skip to content

Commit

Permalink
ensure events are emitted correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
enthusiastmartin committed Nov 4, 2024
1 parent 7f0b42f commit b5638d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pallets/stableswap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::SlippageLimit);
reserve
} else {
let amount =
Expand Down
4 changes: 4 additions & 0 deletions pallets/stableswap/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssetId>)> {
LAST_TRADE_HOOK.with(|v| v.borrow().clone())
}

pub(crate) fn expect_events(e: Vec<RuntimeEvent>) {
e.into_iter().for_each(frame_system::Pallet::<Test>::assert_has_event);
}
33 changes: 31 additions & 2 deletions pallets/stableswap/src/tests/remove_liquidity.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Test>::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(),
]);
});
}

0 comments on commit b5638d9

Please sign in to comment.