diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index 0615fbd99f8ddc6b5bb031a5616f8d84b6c77b41..be7fcaa59eeb4aecbf809d8152941fefb2cfe523 100644 --- a/pallets/duniter-account/src/lib.rs +++ b/pallets/duniter-account/src/lib.rs @@ -164,14 +164,12 @@ pub mod pallet { let price = T::NewAccountPrice::get(); if account_data.free >= T::ExistentialDeposit::get() + price { // The account can pay the new account price, we should: - // 1. Increment providers to create the account for frame_system point of view - // 2. Withdraw the "new account price" amount - // 3. Increment consumers to prevent the destruction of the account before + // 1. Withdraw the "new account price" amount + // 2. Increment consumers to prevent the destruction of the account before // the random id is assigned - // 4. Manage the funds collected - // 5. Submit random id generation request - // 6. Save the id of the random generation request. - frame_system::Pallet::<T>::inc_providers(&account_id); + // 3. Manage the funds collected + // 4. Submit random id generation request + // 5. Save the id of the random generation request. let res = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::withdraw( &account_id, price, @@ -287,10 +285,9 @@ where if !frame_system::Pallet::<T>::account_exists(account_id) { // If the account does not exist, we should program its creation PendingNewAccounts::<T>::insert(account_id, ()); - } else { - // If the account already exists, we should register increment providers directly - frame_system::Pallet::<T>::inc_providers(account_id); } + // We should increment the "balances" provider + frame_system::Pallet::<T>::inc_providers(account_id); } else if was_providing && !is_providing { match frame_system::Pallet::<T>::dec_providers(account_id)? { frame_system::DecRefStatus::Reaped => return Ok(result), diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index 9f67f73a25023ce02fbb63bfc1515688308b6bd9..29b97c40ac10fc840b8b26d905d21ad75240adf9 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -169,16 +169,22 @@ fn test_create_new_account_with_insufficient_balance() { )); let events = System::events(); //println!("{:#?}", events); - assert_eq!(events.len(), 2); + assert_eq!(events.len(), 3); assert_eq!( System::events()[0].event, + Event::System(frame_system::Event::NewAccount { + account: AccountKeyring::Eve.to_account_id(), + }) + ); + assert_eq!( + System::events()[1].event, Event::Balances(pallet_balances::Event::Endowed { account: AccountKeyring::Eve.to_account_id(), free_balance: 400, }) ); assert_eq!( - System::events()[1].event, + System::events()[2].event, Event::Balances(pallet_balances::Event::Transfer { from: AccountKeyring::Alice.to_account_id(), to: AccountKeyring::Eve.to_account_id(), @@ -234,16 +240,22 @@ fn test_create_new_account() { )); let events = System::events(); //println!("{:#?}", events); - assert_eq!(events.len(), 2); + assert_eq!(events.len(), 3); assert_eq!( System::events()[0].event, + Event::System(frame_system::Event::NewAccount { + account: AccountKeyring::Eve.to_account_id(), + }) + ); + assert_eq!( + System::events()[1].event, Event::Balances(pallet_balances::Event::Endowed { account: AccountKeyring::Eve.to_account_id(), free_balance: 500, }) ); assert_eq!( - System::events()[1].event, + System::events()[2].event, Event::Balances(pallet_balances::Event::Transfer { from: AccountKeyring::Alice.to_account_id(), to: AccountKeyring::Eve.to_account_id(), @@ -256,29 +268,23 @@ fn test_create_new_account() { run_to_block(3); let events = System::events(); println!("{:#?}", events); - assert_eq!(events.len(), 4); + assert_eq!(events.len(), 3); assert_eq!( System::events()[0].event, - Event::System(frame_system::Event::NewAccount { - account: AccountKeyring::Eve.to_account_id(), - }) - ); - assert_eq!( - System::events()[1].event, Event::Balances(pallet_balances::Event::Withdraw { who: AccountKeyring::Eve.to_account_id(), amount: 300, }) ); assert_eq!( - System::events()[2].event, + System::events()[1].event, Event::Balances(pallet_balances::Event::Deposit { who: Treasury::account_id(), amount: 300, }) ); assert_eq!( - System::events()[3].event, + System::events()[2].event, Event::Treasury(pallet_treasury::Event::Deposit { value: 300 }) ); assert_eq!(