diff --git a/substrate/frame/assets-freezer/src/impls.rs b/substrate/frame/assets-freezer/src/impls.rs index 11fb4d77ad87..b1a203297cf4 100644 --- a/substrate/frame/assets-freezer/src/impls.rs +++ b/substrate/frame/assets-freezer/src/impls.rs @@ -36,6 +36,15 @@ impl, I: 'static> FrozenBalance::get(asset.clone(), who).is_empty(), + "The list of Freezes should be empty before allowing an account to die" + ); + defensive_assert!( + FrozenBalances::::get(asset.clone(), who).is_none(), + "There should not be a frozen balance before allowing to die" + ); + FrozenBalances::::remove(asset.clone(), who); Freezes::::remove(asset, who); } diff --git a/substrate/frame/assets-freezer/src/tests.rs b/substrate/frame/assets-freezer/src/tests.rs index cee14a90d16a..ea514458eb34 100644 --- a/substrate/frame/assets-freezer/src/tests.rs +++ b/substrate/frame/assets-freezer/src/tests.rs @@ -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::::get(ASSET_ID, WHO).is_none()); assert!(Freezes::::get(ASSET_ID, WHO).is_empty());