Skip to content

Commit

Permalink
fix sufficients issue
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Aug 21, 2023
1 parent 891c9bb commit 763a3ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ impl<T: Config> Pallet<T> {
who: &T::AccountId,
amount: BalanceType,
) -> DispatchResult {
if !Balance::<T>::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!(
Expand All @@ -332,6 +335,7 @@ impl<T: Config> Pallet<T> {
entry_tot.principal += amount;
<TotalIssuance<T>>::insert(community_id, entry_tot);
<Balance<T>>::insert(community_id, who, entry_who);

Self::deposit_event(Event::Issued(community_id, who.clone(), amount));
debug!(target: LOG, "issue {:?} for {:?}", amount, who);
Ok(())
Expand Down
7 changes: 6 additions & 1 deletion balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,10 @@ fn transfer_all_native_wont_remove_account_with_remaining_community_balance() {
Balances::minimum_balance() * 100,
));
assert!(frame_system::Account::<TestRuntime>::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::<TestRuntime>::contains_key(cid, &alice));

// create bob account by sending him some CC
Expand All @@ -410,10 +412,13 @@ fn transfer_all_native_wont_remove_account_with_remaining_community_balance() {
));
assert!(frame_system::Account::<TestRuntime>::contains_key(&bob));
assert!(EncointerBalanceStorage::<TestRuntime>::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::<TestRuntime>::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));
Expand Down

0 comments on commit 763a3ef

Please sign in to comment.