From 260d204a541d2513c1e03e841113eb352c5b4bdd Mon Sep 17 00:00:00 2001
From: Manuel Mauro <manuel.mauro@protonmail.com>
Date: Tue, 28 Jan 2025 15:51:40 +0100
Subject: [PATCH] feat: :sparkles: support feature insecure_zero_ed in
 benchmarks and tests

---
 substrate/frame/balances/src/benchmarking.rs         | 6 ++++++
 substrate/frame/balances/src/tests/currency_tests.rs | 1 +
 2 files changed, 7 insertions(+)

diff --git a/substrate/frame/balances/src/benchmarking.rs b/substrate/frame/balances/src/benchmarking.rs
index c825300218d..a8f92e9b52c 100644
--- a/substrate/frame/balances/src/benchmarking.rs
+++ b/substrate/frame/balances/src/benchmarking.rs
@@ -65,7 +65,9 @@ mod benchmarks {
 		#[extrinsic_call]
 		_(RawOrigin::Signed(caller.clone()), recipient_lookup, transfer_amount);
 
+		#[cfg(not(feature = "insecure_zero_ed"))]
 		assert_eq!(Balances::<T, I>::free_balance(&caller), Zero::zero());
+
 		assert_eq!(Balances::<T, I>::free_balance(&recipient), transfer_amount);
 	}
 
@@ -173,7 +175,9 @@ mod benchmarks {
 		#[extrinsic_call]
 		_(RawOrigin::Root, source_lookup, recipient_lookup, transfer_amount);
 
+		#[cfg(not(feature = "insecure_zero_ed"))]
 		assert_eq!(Balances::<T, I>::free_balance(&source), Zero::zero());
+
 		assert_eq!(Balances::<T, I>::free_balance(&recipient), transfer_amount);
 	}
 
@@ -208,7 +212,9 @@ mod benchmarks {
 		#[extrinsic_call]
 		transfer_allow_death(RawOrigin::Signed(caller.clone()), recipient_lookup, transfer_amount);
 
+		#[cfg(not(feature = "insecure_zero_ed"))]
 		assert_eq!(Balances::<T, I>::free_balance(&caller), Zero::zero());
+
 		assert_eq!(Balances::<T, I>::free_balance(&recipient), transfer_amount);
 	}
 
diff --git a/substrate/frame/balances/src/tests/currency_tests.rs b/substrate/frame/balances/src/tests/currency_tests.rs
index a6377c3ad72..3525fb26193 100644
--- a/substrate/frame/balances/src/tests/currency_tests.rs
+++ b/substrate/frame/balances/src/tests/currency_tests.rs
@@ -1136,6 +1136,7 @@ fn operations_on_dead_account_should_not_change_state() {
 
 #[test]
 #[should_panic = "The existential deposit must be greater than zero!"]
+#[cfg(not(feature = "insecure_zero_ed"))]
 fn zero_ed_is_prohibited() {
 	// These functions all use `mutate_account` which may introduce a storage change when
 	// the account never existed to begin with, and shouldn't exist in the end.
-- 
GitLab