From 189d8d452f8ab6938d330b82b08e0025c14b4f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Sun, 3 Nov 2024 18:49:26 -0500 Subject: [PATCH] change(pallet-assets-freezer): handle `assert_debug`s when calling `died` --- substrate/frame/assets-freezer/src/impls.rs | 9 +++++++++ substrate/frame/assets-freezer/src/tests.rs | 11 +++++++++++ 2 files changed, 20 insertions(+) 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());