Skip to content
Snippets Groups Projects
Commit 12ac2190 authored by Éloïs's avatar Éloïs
Browse files

fix(accounts): providers should be inc as soon as the account recv money

providers should be incremented as soon as the account receive funds
parent 39fb1d0a
No related branches found
No related tags found
No related merge requests found
......@@ -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),
......
......@@ -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!(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment