From f7d8319f0a0d2c679885658efc0152a7d5c76ae5 Mon Sep 17 00:00:00 2001
From: Benjamin Gallois <business@gallois.cc>
Date: Wed, 13 Nov 2024 15:44:32 +0100
Subject: [PATCH] Deprecate Currency trait (nodes/rust/duniter-v2s!287)

* deprecate Currency trait
---
 pallets/distance/src/benchmarking.rs |  2 +-
 pallets/distance/src/tests.rs        | 10 +++++-----
 pallets/quota/src/benchmarking.rs    |  7 ++++---
 pallets/quota/src/tests.rs           | 30 ++++++++++++++--------------
 4 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/pallets/distance/src/benchmarking.rs b/pallets/distance/src/benchmarking.rs
index bd44e6769..8b3c3e00b 100644
--- a/pallets/distance/src/benchmarking.rs
+++ b/pallets/distance/src/benchmarking.rs
@@ -21,7 +21,7 @@ use super::*;
 
 use codec::Encode;
 use frame_benchmarking::v2::*;
-use frame_support::traits::{Get, OnFinalize, OnInitialize};
+use frame_support::traits::{fungible::Mutate, Get, OnFinalize, OnInitialize};
 use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
 use scale_info::prelude::vec;
 use sp_runtime::Perbill;
diff --git a/pallets/distance/src/tests.rs b/pallets/distance/src/tests.rs
index 4ec3087cb..ab6c19eaf 100644
--- a/pallets/distance/src/tests.rs
+++ b/pallets/distance/src/tests.rs
@@ -15,7 +15,7 @@
 // along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
 
 use crate::{mock::*, *};
-use frame_support::{assert_noop, assert_ok, traits::Currency};
+use frame_support::{assert_noop, assert_ok, traits::fungible::Mutate};
 
 // allow request distance evaluation for oneself
 #[test]
@@ -23,7 +23,7 @@ fn test_request_distance_evaluation() {
     new_test_ext().execute_with(|| {
         run_to_block(1);
         // give enough for reserve
-        Balances::make_free_balance_be(&1, 10_000);
+        Balances::set_balance(&1, 10_000);
 
         // call request
         assert_ok!(Distance::request_distance_evaluation(
@@ -45,7 +45,7 @@ fn test_request_distance_evaluation_for() {
     new_test_ext().execute_with(|| {
         run_to_block(1);
         // give enough for reserve
-        Balances::make_free_balance_be(&1, 10_000);
+        Balances::set_balance(&1, 10_000);
         assert_ok!(Identity::create_identity(RuntimeOrigin::signed(1), 5));
         assert_ok!(Identity::confirm_identity(
             RuntimeOrigin::signed(5),
@@ -73,7 +73,7 @@ fn test_request_distance_evaluation_non_member() {
     new_test_ext().execute_with(|| {
         run_to_block(1);
         // give enough for reserve
-        Balances::make_free_balance_be(&5, 10_000);
+        Balances::set_balance(&5, 10_000);
 
         assert_noop!(
             Distance::request_distance_evaluation_for(RuntimeOrigin::signed(5), 1),
@@ -93,7 +93,7 @@ fn test_request_distance_evaluation_twice() {
     new_test_ext().execute_with(|| {
         run_to_block(1);
         // give enough for reserve
-        Balances::make_free_balance_be(&1, 10_000);
+        Balances::set_balance(&1, 10_000);
 
         assert_ok!(Distance::request_distance_evaluation(
             RuntimeOrigin::signed(1)
diff --git a/pallets/quota/src/benchmarking.rs b/pallets/quota/src/benchmarking.rs
index 24dcd895e..b34678f80 100644
--- a/pallets/quota/src/benchmarking.rs
+++ b/pallets/quota/src/benchmarking.rs
@@ -18,6 +18,7 @@
 
 use super::*;
 use frame_benchmarking::{account, v2::*};
+use frame_support::traits::fungible::Mutate;
 use sp_runtime::traits::One;
 
 fn assert_has_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
@@ -98,7 +99,7 @@ mod benchmarks {
                 amount: 10u64.into(),
             },
         );
-        let _ = CurrencyOf::<T>::make_free_balance_be(&T::RefundAccount::get(), u32::MAX.into());
+        let _ = CurrencyOf::<T>::set_balance(&T::RefundAccount::get(), u32::MAX.into());
         // The worst-case scenario is when the refund fails
         // and can only be triggered if the account is dead,
         // in this case by having no balance in the account.
@@ -119,7 +120,7 @@ mod benchmarks {
     #[benchmark]
     fn do_refund() {
         let account: T::AccountId = account("Alice", 1, 1);
-        let _ = CurrencyOf::<T>::make_free_balance_be(&T::RefundAccount::get(), u32::MAX.into());
+        let _ = CurrencyOf::<T>::set_balance(&T::RefundAccount::get(), u32::MAX.into());
         // The worst-case scenario is when the refund fails
         // and can only be triggered if the account is dead,
         // in this case by having no balance in the account.
@@ -161,7 +162,7 @@ mod benchmarks {
                 amount: 10u64.into(),
             },
         );
-        let _ = CurrencyOf::<T>::make_free_balance_be(&T::RefundAccount::get(), u32::MAX.into());
+        let _ = CurrencyOf::<T>::set_balance(&T::RefundAccount::get(), u32::MAX.into());
         // The worst-case scenario is when the refund fails
         // and can only be triggered if the account is dead,
         // in this case by having no balance in the account.
diff --git a/pallets/quota/src/tests.rs b/pallets/quota/src/tests.rs
index 40f746928..e5e080e43 100644
--- a/pallets/quota/src/tests.rs
+++ b/pallets/quota/src/tests.rs
@@ -15,7 +15,7 @@
 // along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
 
 use crate::{mock::*, Weight};
-use frame_support::traits::Currency;
+use frame_support::traits::fungible::Mutate;
 use sp_core::Get;
 
 // Note: values for reload rate and max quota defined in mock file
@@ -150,10 +150,10 @@ fn test_process_refund_queue() {
     .execute_with(|| {
         run_to_block(5);
         // give enough currency to accounts and treasury and double check
-        Balances::make_free_balance_be(&account(1), 1000);
-        Balances::make_free_balance_be(&account(2), 1000);
-        Balances::make_free_balance_be(&account(3), 1000);
-        Balances::make_free_balance_be(
+        Balances::set_balance(&account(1), 1000);
+        Balances::set_balance(&account(2), 1000);
+        Balances::set_balance(&account(3), 1000);
+        Balances::set_balance(
             &<Test as pallet_quota::Config>::RefundAccount::get(),
             10_000,
         );
@@ -208,8 +208,8 @@ fn test_not_enough_treasury() {
     })
     .execute_with(|| {
         run_to_block(5);
-        Balances::make_free_balance_be(&account(1), 1000);
-        Balances::make_free_balance_be(&<Test as pallet_quota::Config>::RefundAccount::get(), 1200);
+        Balances::set_balance(&account(1), 1000);
+        Balances::set_balance(&<Test as pallet_quota::Config>::RefundAccount::get(), 1200);
         Quota::queue_refund(pallet_quota::Refund {
             account: account(1),
             identity: 1,
@@ -246,10 +246,10 @@ fn test_process_refund_queue_weight_with_quotas() {
     .execute_with(|| {
         run_to_block(15);
         // give enough currency to accounts and treasury and double check
-        Balances::make_free_balance_be(&account(1), 1000);
-        Balances::make_free_balance_be(&account(2), 1000);
-        Balances::make_free_balance_be(&account(3), 1000);
-        Balances::make_free_balance_be(
+        Balances::set_balance(&account(1), 1000);
+        Balances::set_balance(&account(2), 1000);
+        Balances::set_balance(&account(3), 1000);
+        Balances::set_balance(
             &<Test as pallet_quota::Config>::RefundAccount::get(),
             10_000,
         );
@@ -314,10 +314,10 @@ fn test_process_refund_queue_weight_no_quotas() {
     .execute_with(|| {
         run_to_block(15);
         // give enough currency to accounts and treasury and double check
-        Balances::make_free_balance_be(&account(1), 1000);
-        Balances::make_free_balance_be(&account(2), 1000);
-        Balances::make_free_balance_be(&account(3), 1000);
-        Balances::make_free_balance_be(
+        Balances::set_balance(&account(1), 1000);
+        Balances::set_balance(&account(2), 1000);
+        Balances::set_balance(&account(3), 1000);
+        Balances::set_balance(
             &<Test as pallet_quota::Config>::RefundAccount::get(),
             10_000,
         );
-- 
GitLab