From f1c54dc7609629458189d33957102eef4c24b24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= <cem.moreau@gmail.com> Date: Sun, 4 Feb 2024 08:13:00 +0100 Subject: [PATCH] Remove account creation fee (nodes/rust/duniter-v2s!238) * fix(#187): clippy * fix(#187): remove PendingNewAccounts in benchmarks * fix(#187): remove identity creation fee --- .../account_creation.feature | 20 ++-- pallets/duniter-account/src/benchmarking.rs | 42 +-------- pallets/duniter-account/src/lib.rs | 89 +----------------- pallets/duniter-account/src/weights.rs | 3 - pallets/universal-dividend/src/weights.rs | 2 - resources/metadata.scale | Bin 111870 -> 111612 bytes runtime/common/src/pallets_config.rs | 4 - runtime/common/src/weights/pallet_balances.rs | 8 -- .../src/weights/pallet_duniter_account.rs | 6 -- runtime/common/src/weights/pallet_treasury.rs | 4 - .../src/weights/pallet_universal_dividend.rs | 4 - runtime/gdev/tests/integration_tests.rs | 86 +---------------- 12 files changed, 19 insertions(+), 249 deletions(-) diff --git a/end2end-tests/cucumber-features/account_creation.feature b/end2end-tests/cucumber-features/account_creation.feature index 2ea18058a..82c115dc4 100644 --- a/end2end-tests/cucumber-features/account_creation.feature +++ b/end2end-tests/cucumber-features/account_creation.feature @@ -5,26 +5,26 @@ Feature: Account creation Then dave should have 5 ÄžD When 1 block later """ - The blockchain should automatically withdraw account creation tax (3 ÄžD) + The blockchain did not automatically withdraw account creation tax (3 ÄžD) because this feature has been removed """ - Then dave should have 2 ÄžD + Then dave should have 5 ÄžD Scenario: Create a new account without enough funds then retry with enough funds When alice sends 2 ÄžD to eve Then eve should have 2 ÄžD When 1 block later """ - The blockchain should automatically destroy Eve account - because Eve does not have enough funds to pay the new account tax + The blockchain did not automatically destroy Eve account for Eve not having enough funds to pay the new account tax + Because this feature has been removed """ - Then eve should have 0 ÄžD + Then eve should have 2 ÄžD When alice send 5 ÄžD to eve - Then eve should have 5 ÄžD + Then eve should have 7 ÄžD When 1 block later """ - The blockchain should automatically withdraw account creation tax (3 ÄžD) + The blockchain did not automatically withdraw account creation tax (3 ÄžD) because this feature has been removed """ - Then eve should have 2 ÄžD + Then eve should have 7 ÄžD @ignoreErrors Scenario: Create a new account without any funds @@ -37,6 +37,6 @@ Feature: Account creation Then eve should have 5 ÄžD When 1 block later """ - The blockchain should automatically withdraw account creation tax (3 ÄžD) + The blockchain did not automatically withdraw account creation tax (3 ÄžD) because this feature has been removed """ - Then eve should have 2 ÄžD + Then eve should have 5 ÄžD diff --git a/pallets/duniter-account/src/benchmarking.rs b/pallets/duniter-account/src/benchmarking.rs index b5594e7d2..1ff3ec030 100644 --- a/pallets/duniter-account/src/benchmarking.rs +++ b/pallets/duniter-account/src/benchmarking.rs @@ -18,53 +18,13 @@ use super::*; -use frame_benchmarking::{account, benchmarks, whitelisted_caller}; -use frame_support::sp_runtime::{traits::One, Saturating}; -use frame_support::traits::{Currency, Get}; +use frame_benchmarking::{account, benchmarks}; use crate::Pallet; -fn create_pending_accounts<T: Config>( - i: u32, - is_balance: bool, - is_sufficient: bool, -) -> Result<(), &'static str> { - for _ in 0..i { - let caller: T::AccountId = whitelisted_caller(); - if is_balance { - let existential_deposit = T::ExistentialDeposit::get(); - let balance = existential_deposit.saturating_mul((200u32).into()); - let _ = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::make_free_balance_be( - &caller, balance, - ); - } else { - assert!( - frame_system::Pallet::<T>::get(&caller).free - < T::NewAccountPrice::get() + T::ExistentialDeposit::get() - ); - } - if is_sufficient { - frame_system::Pallet::<T>::inc_sufficients(&caller); - } else { - assert!(frame_system::Pallet::<T>::sufficients(&caller) == 0); - } - PendingNewAccounts::<T>::insert(caller, ()); - } - Ok(()) -} - benchmarks! { unlink_identity { let account = account("Alice", 1, 1); let origin = frame_system::RawOrigin::Signed(account); }: _<T::RuntimeOrigin>(origin.into()) - on_initialize_sufficient { - let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, true)?; - }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); } - on_initialize_with_balance { - let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, true, false)?; - }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); } - on_initialize_no_balance { - let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, false)?; - }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); } } diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index 596554ec7..346dab976 100644 --- a/pallets/duniter-account/src/lib.rs +++ b/pallets/duniter-account/src/lib.rs @@ -29,12 +29,12 @@ pub use types::*; pub use weights::WeightInfo; use frame_support::pallet_prelude::*; -use frame_support::traits::{Currency, ExistenceRequirement, StorageVersion}; -use frame_support::traits::{OnUnbalanced, StoredMap}; +use frame_support::traits::StoredMap; +use frame_support::traits::{Currency, StorageVersion}; use frame_system::pallet_prelude::*; use pallet_quota::traits::RefundFee; use pallet_transaction_payment::OnChargeTransaction; -use sp_runtime::traits::{Convert, DispatchInfoOf, PostDispatchInfoOf, Saturating}; +use sp_runtime::traits::{DispatchInfoOf, PostDispatchInfoOf, Saturating}; use sp_std::fmt::Debug; #[frame_support::pallet] @@ -63,30 +63,16 @@ pub mod pallet { + pallet_treasury::Config<Currency = pallet_balances::Pallet<Self>> + pallet_quota::Config { - type AccountIdToSalt: Convert<Self::AccountId, [u8; 32]>; - #[pallet::constant] - type MaxNewAccountsPerBlock: Get<u32>; - #[pallet::constant] - type NewAccountPrice: Get<Self::Balance>; /// The overarching event type. type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; /// Type representing the weight of this pallet type WeightInfo: WeightInfo; - /// Handler for the unbalanced reduction when the requestor pays fees. - type OnUnbalanced: OnUnbalanced<pallet_balances::NegativeImbalance<Self>>; /// wrapped type type InnerOnChargeTransaction: OnChargeTransaction<Self>; /// type implementing refund behavior type Refund: pallet_quota::traits::RefundFee<Self>; } - // STORAGE // - - #[pallet::storage] - #[pallet::getter(fn pending_new_accounts)] - pub type PendingNewAccounts<T: Config> = - StorageMap<_, Blake2_128Concat, T::AccountId, (), OptionQuery>; - // GENESIS STUFFÂ // #[pallet::genesis_config] @@ -158,11 +144,6 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event<T: Config> { - /// Forced destruction of an account due to insufficient free balance to cover the account creation price. - ForceDestroy { - who: T::AccountId, - balance: T::Balance, - }, /// account linked to identity AccountLinked { who: T::AccountId, @@ -212,69 +193,6 @@ pub mod pallet { }; } } - - // HOOKS // - #[pallet::hooks] - impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { - // on initialize, withdraw account creation tax - fn on_initialize(_: BlockNumberFor<T>) -> Weight { - let mut total_weight = Weight::zero(); - for account_id in PendingNewAccounts::<T>::iter_keys() - .drain() - .take(T::MaxNewAccountsPerBlock::get() as usize) - { - if frame_system::Pallet::<T>::sufficients(&account_id) > 0 { - // If the account is self-sufficient, it is exempt from account creation fees - total_weight += <T as pallet::Config>::WeightInfo::on_initialize_sufficient( - T::MaxNewAccountsPerBlock::get(), - ); - } else { - // If the account is not self-sufficient, it must pay the account creation fees - let account_data = frame_system::Pallet::<T>::get(&account_id); - let price = T::NewAccountPrice::get(); - if account_data.free >= T::ExistentialDeposit::get() + price { - // The account can pay the new account price, we should: - // 1. Withdraw the "new account price" amount - // 2. Manage the funds collected - let res = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::withdraw( - &account_id, - price, - frame_support::traits::WithdrawReasons::FEE, - ExistenceRequirement::KeepAlive, - ); - debug_assert!( - res.is_ok(), - "Cannot fail because we checked that the free balance was sufficient" - ); - if let Ok(imbalance) = res { - T::OnUnbalanced::on_unbalanced(imbalance); - total_weight += - <T as pallet::Config>::WeightInfo::on_initialize_with_balance( - T::MaxNewAccountsPerBlock::get(), - ); - } - } else { - // The charges could not be deducted, we must destroy the account - let balance_to_suppr = - account_data.free.saturating_add(account_data.reserved); - // Force account data supression - frame_system::Account::<T>::remove(&account_id); - Self::deposit_event(Event::ForceDestroy { - who: account_id, - balance: balance_to_suppr, - }); - T::OnUnbalanced::on_unbalanced(pallet_balances::NegativeImbalance::new( - balance_to_suppr, - )); - total_weight += <T as pallet::Config>::WeightInfo::on_initialize_no_balance( - T::MaxNewAccountsPerBlock::get(), - ); - } - } - } - total_weight - } - } } // implement account linker @@ -341,7 +259,6 @@ where // the account has just been created, increment its provider (false, true) => { frame_system::Pallet::<T>::inc_providers(account_id); - PendingNewAccounts::<T>::insert(account_id, ()); } // the account was existing but is not anymore, decrement the provider (true, false) => { diff --git a/pallets/duniter-account/src/weights.rs b/pallets/duniter-account/src/weights.rs index f4bbe1588..d6e9cf5db 100644 --- a/pallets/duniter-account/src/weights.rs +++ b/pallets/duniter-account/src/weights.rs @@ -40,7 +40,6 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1)) } - // Storage: Account PendingNewAccounts (r:1 w:0) // Storage: Babe EpochIndex (r:1 w:0) /// The range of component `i` is `[0, 1]`. fn on_initialize_sufficient(i: u32) -> Weight { @@ -53,7 +52,6 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((6 as u64).saturating_mul(i as u64))) } - // Storage: Account PendingNewAccounts (r:1 w:0) // Storage: Babe EpochIndex (r:1 w:0) /// The range of component `i` is `[0, 1]`. fn on_initialize_with_balance(i: u32) -> Weight { @@ -66,7 +64,6 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((6 as u64).saturating_mul(i as u64))) } - // Storage: Account PendingNewAccounts (r:1 w:0) /// The range of component `i` is `[0, 1]`. fn on_initialize_no_balance(i: u32) -> Weight { // Minimum execution time: 12_912 nanoseconds. diff --git a/pallets/universal-dividend/src/weights.rs b/pallets/universal-dividend/src/weights.rs index 27d0f739c..e24b561ae 100644 --- a/pallets/universal-dividend/src/weights.rs +++ b/pallets/universal-dividend/src/weights.rs @@ -38,7 +38,6 @@ impl WeightInfo for () { // Storage: UniversalDividend CurrentUd (r:1 w:0) // Storage: System Account (r:1 w:1) - // Storage: Account PendingNewAccounts (r:0 w:1) fn transfer_ud() -> Weight { Weight::from_parts(53_401_000, 0) .saturating_add(RocksDbWeight::get().reads(2)) @@ -47,7 +46,6 @@ impl WeightInfo for () { // Storage: UniversalDividend CurrentUd (r:1 w:0) // Storage: System Account (r:1 w:1) - // Storage: Account PendingNewAccounts (r:0 w:1) fn transfer_ud_keep_alive() -> Weight { Weight::from_parts(33_420_000, 0) .saturating_add(RocksDbWeight::get().reads(2)) diff --git a/resources/metadata.scale b/resources/metadata.scale index 26b30e4664d0ced1c6e5a8bb586ccfd1ace71403..dbdacee03619badb7ff92ebbd10897a279747ec5 100644 GIT binary patch delta 45 zcmezOlI_oPwhej$j2x3M3)nI;OcoThV`OX&5ZoRh$e5?i#=y9fk+EXCk}cz%asXe| B4Y2?K delta 289 zcmezKobBIBwhej${5%G3`9;a8E~&*OMfsH+lkKfUCpXA**K34WSve)<B<3ZjGBB{r zWCW{9QAh!)D@`uR%+FKEPg6+DQ%Fos&M(a?QAjCGRVc|<$jmD)O-sv6&P)Z0r4^;7 zDkMQn0ZAt3m!%ddlw_pBbtM<2CV~wsD9TJu)iZH~nC3ItLcoNPadNJJ9V1io8iDO= z1Q_$QQy68S@+=+!sd*`xdFg(s<xrtw21XVph8`9M2F9I?j1?RazKIn`vH__@PC5C> e*#ZKL3_xImkO~0VETNzS7H44Cu3*D>ryKykv0iil diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index a2262503e..6a17704a6 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -101,14 +101,10 @@ type RuntimeTask = (); impl pallet_duniter_account::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type AccountIdToSalt = sp_runtime::traits::ConvertInto; - type MaxNewAccountsPerBlock = frame_support::pallet_prelude::ConstU32<1>; - type NewAccountPrice = frame_support::traits::ConstU64<300>; type WeightInfo = common_runtime::weights::pallet_duniter_account::WeightInfo<Runtime>; // does currency adapter in any case, but adds "refund with quota" feature type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>; type Refund = Quota; - type OnUnbalanced = Treasury; } // QUOTA // diff --git a/runtime/common/src/weights/pallet_balances.rs b/runtime/common/src/weights/pallet_balances.rs index 20d538cb4..4ddad9594 100644 --- a/runtime/common/src/weights/pallet_balances.rs +++ b/runtime/common/src/weights/pallet_balances.rs @@ -49,8 +49,6 @@ pub struct WeightInfo<T>(PhantomData<T>); impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> { /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`) - /// Storage: `Account::PendingNewAccounts` (r:0 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) fn transfer_allow_death() -> Weight { // Proof Size summary in bytes: // Measured: `0` @@ -63,8 +61,6 @@ impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> { } /// Storage: System Account (r:1 w:1) /// Proof: System Account (max_values: None, max_size: Some(126), added: 2601, mode: MaxEncodedLen) - /// Storage: Account PendingNewAccounts (r:0 w:1) - /// Proof Skipped: Account PendingNewAccounts (max_values: None, max_size: None, mode: Measured) fn transfer_keep_alive() -> Weight { // Proof Size summary in bytes: // Measured: `0` @@ -77,8 +73,6 @@ impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> { } /// Storage: System Account (r:2 w:2) /// Proof: System Account (max_values: None, max_size: Some(126), added: 2601, mode: MaxEncodedLen) - /// Storage: Account PendingNewAccounts (r:0 w:1) - /// Proof Skipped: Account PendingNewAccounts (max_values: None, max_size: None, mode: Measured) fn force_transfer() -> Weight { // Proof Size summary in bytes: // Measured: `64` @@ -115,8 +109,6 @@ impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> { } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`) - /// Storage: `Account::PendingNewAccounts` (r:0 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) fn transfer_all() -> Weight { // Proof Size summary in bytes: // Measured: `0` diff --git a/runtime/common/src/weights/pallet_duniter_account.rs b/runtime/common/src/weights/pallet_duniter_account.rs index 3dcee20a0..749b642ca 100644 --- a/runtime/common/src/weights/pallet_duniter_account.rs +++ b/runtime/common/src/weights/pallet_duniter_account.rs @@ -59,8 +59,6 @@ impl<T: frame_system::Config> pallet_duniter_account::WeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `Account::PendingNewAccounts` (r:1 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `Babe::EpochIndex` (r:1 w:0) /// Proof: `Babe::EpochIndex` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// The range of component `i` is `[0, 1]`. @@ -78,8 +76,6 @@ impl<T: frame_system::Config> pallet_duniter_account::WeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().writes((6_u64).saturating_mul(i.into()))) .saturating_add(Weight::from_parts(0, 309).saturating_mul(i.into())) } - /// Storage: `Account::PendingNewAccounts` (r:1 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`) /// Storage: `Babe::EpochIndex` (r:1 w:0) @@ -99,8 +95,6 @@ impl<T: frame_system::Config> pallet_duniter_account::WeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().writes((6_u64).saturating_mul(i.into()))) .saturating_add(Weight::from_parts(0, 309).saturating_mul(i.into())) } - /// Storage: `Account::PendingNewAccounts` (r:1 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `i` is `[0, 1]`. fn on_initialize_no_balance(i: u32, ) -> Weight { // Proof Size summary in bytes: diff --git a/runtime/common/src/weights/pallet_treasury.rs b/runtime/common/src/weights/pallet_treasury.rs index 578f56c09..2f74e8d48 100644 --- a/runtime/common/src/weights/pallet_treasury.rs +++ b/runtime/common/src/weights/pallet_treasury.rs @@ -120,8 +120,6 @@ impl<T: frame_system::Config> pallet_treasury::WeightInfo for WeightInfo<T> { /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) /// Storage: `Treasury::Proposals` (r:99 w:99) /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(92), added: 2567, mode: `MaxEncodedLen`) - /// Storage: `Account::PendingNewAccounts` (r:0 w:99) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `p` is `[0, 99]`. fn on_initialize_proposals(p: u32, ) -> Weight { // Proof Size summary in bytes: @@ -149,8 +147,6 @@ impl<T: frame_system::Config> pallet_treasury::WeightInfo for WeightInfo<T> { /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(61), added: 2536, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`) - /// Storage: `Account::PendingNewAccounts` (r:0 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) fn payout() -> Weight { // Proof Size summary in bytes: // Measured: `180` diff --git a/runtime/common/src/weights/pallet_universal_dividend.rs b/runtime/common/src/weights/pallet_universal_dividend.rs index 889e7c999..b2e5d7650 100644 --- a/runtime/common/src/weights/pallet_universal_dividend.rs +++ b/runtime/common/src/weights/pallet_universal_dividend.rs @@ -72,8 +72,6 @@ impl<T: frame_system::Config> pallet_universal_dividend::WeightInfo for WeightIn /// Proof: `UniversalDividend::CurrentUd` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`) - /// Storage: `Account::PendingNewAccounts` (r:0 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) fn transfer_ud() -> Weight { // Proof Size summary in bytes: // Measured: `157` @@ -88,8 +86,6 @@ impl<T: frame_system::Config> pallet_universal_dividend::WeightInfo for WeightIn /// Proof: `UniversalDividend::CurrentUd` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(126), added: 2601, mode: `MaxEncodedLen`) - /// Storage: `Account::PendingNewAccounts` (r:0 w:1) - /// Proof: `Account::PendingNewAccounts` (`max_values`: None, `max_size`: None, mode: `Measured`) fn transfer_ud_keep_alive() -> Weight { // Proof Size summary in bytes: // Measured: `93` diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index bd6332369..4f0b442f0 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -943,66 +943,6 @@ fn test_smith_process() { }) } -/// test create new account with balance lower than existential deposit -// the treasury gets the dust -#[test] -fn test_create_new_account_with_insufficient_balance() { - ExtBuilder::new(1, 3, 4) - .with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 1_000)]) - .build() - .execute_with(|| { - run_to_block(2); - // Treasury should start empty - // FIXME it actually starts with ED - assert_eq!(Balances::free_balance(Treasury::account_id()), 100); - - // Should be able to transfer 4 units to a new account - assert_ok!(Balances::transfer_allow_death( - frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(), - MultiAddress::Id(AccountKeyring::Eve.to_account_id()), - 300 - )); - - System::assert_has_event(RuntimeEvent::System(frame_system::Event::NewAccount { - account: AccountKeyring::Eve.to_account_id(), - })); - System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Endowed { - account: AccountKeyring::Eve.to_account_id(), - free_balance: 300, - })); - System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Transfer { - from: AccountKeyring::Alice.to_account_id(), - to: AccountKeyring::Eve.to_account_id(), - amount: 300, - })); - - // At next block, the new account must be reaped because its balance is not sufficient - // to pay the "new account tax" - run_to_block(3); - - System::assert_has_event(RuntimeEvent::Account( - pallet_duniter_account::Event::ForceDestroy { - who: AccountKeyring::Eve.to_account_id(), - balance: 300, - }, - )); - System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit { - who: Treasury::account_id(), - amount: 300, - })); - System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit { - value: 300, - })); - - assert_eq!( - Balances::free_balance(AccountKeyring::Eve.to_account_id()), - 0 - ); - // 100 initial + 300 recycled from Eve account's destruction - assert_eq!(Balances::free_balance(Treasury::account_id()), 400); - }); -} - /// test new account creation #[test] fn test_create_new_account() { @@ -1033,35 +973,19 @@ fn test_create_new_account() { amount: 500, })); - // At next block, the new account must be created, - // and new account tax should be collected and deposited in the treasury - run_to_block(3); - - System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Withdraw { - who: AccountKeyring::Eve.to_account_id(), - amount: 300, - })); - System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Deposit { - who: Treasury::account_id(), - amount: 300, - })); - System::assert_has_event(RuntimeEvent::Treasury(pallet_treasury::Event::Deposit { - value: 300, - })); - + // The new account must be created immediately assert_eq!( Balances::free_balance(AccountKeyring::Eve.to_account_id()), - 200 + 500 ); - // 100 initial + 300 deposit - assert_eq!(Balances::free_balance(Treasury::account_id()), 400); + // 100 initial + no deposit (there is no account creation fee) + assert_eq!(Balances::free_balance(Treasury::account_id()), 100); - run_to_block(4); // can remove an account using transfer assert_ok!(Balances::transfer_allow_death( frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(), MultiAddress::Id(AccountKeyring::Alice.to_account_id()), - 200 + 500 )); // Account reaped assert_eq!( -- GitLab