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

fix(account): When a self-sufficient accounts receive money for the first...

fix(account): When a self-sufficient accounts receive money for the first time, that should trigger the random id assignment (!90)

* ci: not execute live tests in non-scheduled jobs

* fix(account): bug #85

When a self-sufficient accounts receive money for the first time, that should trigger the random id assignment

* tests: reproduce bug #85

Conflicts:
	.cargo/config
	pallets/duniter-account/src/lib.rs
parent 650f9044
No related branches found
No related tags found
No related merge requests found
......@@ -185,7 +185,7 @@ pub mod pallet {
frame_system::Pallet::<T>::inc_consumers_without_limit(&account_id);
debug_assert!(
res.is_ok(),
"Cannot fail because providers are incremented just before"
"Cannot fail because any account with funds should have providers"
);
T::OnUnbalanced::on_unbalanced(imbalance);
let request_id = pallet_provide_randomness::Pallet::<T>::force_request(
......@@ -282,12 +282,8 @@ where
let result = f(&mut some_data)?;
let is_providing = some_data.is_some();
if !was_providing && is_providing {
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, ());
}
// We should increment the "balances" provider
frame_system::Pallet::<T>::inc_providers(account_id);
PendingNewAccounts::<T>::insert(account_id, ());
} else if was_providing && !is_providing {
match frame_system::Pallet::<T>::dec_providers(account_id)? {
frame_system::DecRefStatus::Reaped => return Ok(result),
......
......@@ -282,30 +282,19 @@ fn test_create_new_account() {
MultiAddress::Id(AccountKeyring::Eve.to_account_id()),
500
));
let events = System::events();
//println!("{:#?}", events);
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()[2].event,
Event::Balances(pallet_balances::Event::Transfer {
from: AccountKeyring::Alice.to_account_id(),
to: AccountKeyring::Eve.to_account_id(),
amount: 500,
})
);
//println!("{:#?}", System::events());
System::assert_has_event(Event::System(frame_system::Event::NewAccount {
account: AccountKeyring::Eve.to_account_id(),
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Endowed {
account: AccountKeyring::Eve.to_account_id(),
free_balance: 500,
}));
System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer {
from: AccountKeyring::Alice.to_account_id(),
to: AccountKeyring::Eve.to_account_id(),
amount: 500,
}));
// At next block, the new account must be created,
// and new account tax should be collected and deposited in the treasury
......@@ -400,3 +389,44 @@ fn test_create_new_idty() {
);
});
}
#[test]
fn test_create_new_idty_without_founds() {
ExtBuilder::new(1, 3, 4)
.with_initial_balances(vec![(AccountKeyring::Alice.to_account_id(), 1_000)])
.build()
.execute_with(|| {
run_to_block(2);
// Should be able to create an identity without founds
assert_ok!(Identity::create_identity(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
AccountKeyring::Eve.to_account_id(),
));
// At next block, nothing should be preleved
run_to_block(3);
let events = System::events();
assert_eq!(events.len(), 0);
// Deposit some founds on the identity account,
// this should trigger the random id assignemt
assert_ok!(Balances::transfer(
frame_system::RawOrigin::Signed(AccountKeyring::Alice.to_account_id()).into(),
MultiAddress::Id(AccountKeyring::Eve.to_account_id()),
200
));
// At next block, nothing should be preleved,
// and a random id request should be registered
run_to_block(4);
assert_eq!(
Balances::free_balance(AccountKeyring::Eve.to_account_id()),
200
);
assert_eq!(
Account::pending_random_id_assignments(0),
Some(AccountKeyring::Eve.to_account_id())
);
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment