Skip to content

Commit

Permalink
change(pallet-assets-freezer): handle assert_debugs when calling `d…
Browse files Browse the repository at this point in the history
…ied`
  • Loading branch information
pandres95 committed Nov 3, 2024
1 parent 6ce2b83 commit 189d8d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions substrate/frame/assets-freezer/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ impl<T: Config<I>, I: 'static> FrozenBalance<T::AssetId, T::AccountId, T::Balanc
}

fn died(asset: T::AssetId, who: &T::AccountId) {
defensive_assert!(
Freezes::<T, I>::get(asset.clone(), who).is_empty(),
"The list of Freezes should be empty before allowing an account to die"
);
defensive_assert!(
FrozenBalances::<T, I>::get(asset.clone(), who).is_none(),
"There should not be a frozen balance before allowing to die"
);

FrozenBalances::<T, I>::remove(asset.clone(), who);
Freezes::<T, I>::remove(asset, who);
}
Expand Down
11 changes: 11 additions & 0 deletions substrate/frame/assets-freezer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ mod impl_frozen_balance {
});
}

#[test]
#[should_panic = "The list of Freezes should be empty before allowing an account to die"]
fn died_fails_if_freezes_exist() {
new_test_ext(|| {
test_set_freeze(DummyFreezeReason::Governance, 1);
AssetsFreezer::died(ASSET_ID, &WHO);
});
}


#[test]
fn died_works() {
new_test_ext(|| {
test_set_freeze(DummyFreezeReason::Governance, 1);
test_thaw(DummyFreezeReason::Governance);
AssetsFreezer::died(ASSET_ID, &WHO);
assert!(FrozenBalances::<Test>::get(ASSET_ID, WHO).is_none());
assert!(Freezes::<Test>::get(ASSET_ID, WHO).is_empty());
Expand Down

0 comments on commit 189d8d4

Please sign in to comment.