diff --git a/balances/src/lib.rs b/balances/src/lib.rs index 9ddd144f..1e42e0d7 100644 --- a/balances/src/lib.rs +++ b/balances/src/lib.rs @@ -322,6 +322,9 @@ impl Pallet { who: &T::AccountId, amount: BalanceType, ) -> DispatchResult { + if !Balance::::contains_key(community_id, &who) { + Self::new_account(&who)?; + } let mut entry_who = Self::balance_entry_updated(community_id, who); let mut entry_tot = Self::total_issuance_entry_updated(community_id); ensure!( @@ -332,6 +335,7 @@ impl Pallet { entry_tot.principal += amount; >::insert(community_id, entry_tot); >::insert(community_id, who, entry_who); + Self::deposit_event(Event::Issued(community_id, who.clone(), amount)); debug!(target: LOG, "issue {:?} for {:?}", amount, who); Ok(()) diff --git a/balances/src/tests.rs b/balances/src/tests.rs index 19d4e01e..7a433485 100644 --- a/balances/src/tests.rs +++ b/balances/src/tests.rs @@ -397,8 +397,10 @@ fn transfer_all_native_wont_remove_account_with_remaining_community_balance() { Balances::minimum_balance() * 100, )); assert!(frame_system::Account::::contains_key(&alice)); + assert_eq!(System::account(&alice).providers, 1); // issue CC assert_ok!(EncointerBalances::issue(cid, &alice, BalanceType::from_num(50))); + assert_eq!(System::account(&alice).sufficients, 1); assert!(EncointerBalanceStorage::::contains_key(cid, &alice)); // create bob account by sending him some CC @@ -410,10 +412,13 @@ fn transfer_all_native_wont_remove_account_with_remaining_community_balance() { )); assert!(frame_system::Account::::contains_key(&bob)); assert!(EncointerBalanceStorage::::contains_key(cid, bob.clone())); + assert_eq!(System::account(&bob).sufficients, 1); // reap Alice native but keep CC, so Alice should stay alive - assert_ok!(Balances::transfer_all(Some(alice.clone()).into(), bob.clone(), false)); + assert_ok!(Balances::transfer_all(Some(alice.clone()).into(), charlie.clone(), false)); assert!(frame_system::Account::::contains_key(&alice)); + assert_eq!(System::account(&alice).providers, 0); + assert_eq!(System::account(&alice).sufficients, 1); // reap Bob's CC so his account should be killed assert_ok!(EncointerBalances::transfer_all(Some(bob.clone()).into(), charlie.clone(), cid));