Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Prev Previous commit
Next Next commit
Test storage removal leads to removal of stroage
  • Loading branch information
pepyakin committed Jul 3, 2018
commit 2e776eb968eb17a4ff994111edf765b931e22fac
32 changes: 32 additions & 0 deletions substrate/runtime/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,35 @@ fn transferring_incomplete_reserved_balance_should_work() {
assert_eq!(Staking::free_balance(&2), 42);
});
}

#[test]
fn account_removal_removes_storage() {
with_externalities(&mut new_test_ext(100, 1, 3, 1, false, 0), || {
// Setup two accounts with free balance above than exsistential threshold.
{
<FreeBalance<Test>>::insert(1, 110);
<StorageOf<Test>>::insert(1, b"foo".to_vec(), b"1".to_vec());
<StorageOf<Test>>::insert(1, b"bar".to_vec(), b"2".to_vec());

<FreeBalance<Test>>::insert(2, 110);
<StorageOf<Test>>::insert(2, b"hello".to_vec(), b"3".to_vec());
<StorageOf<Test>>::insert(2, b"world".to_vec(), b"4".to_vec());
}

// Transfer funds from account 1 of such amount that after this transfer
// the balance of account 1 is will be below than exsistential threshold.
//
// This should lead to the removal of all storage associated with this account.
Staking::transfer(&1, 2.into(), 20);

// Verify that all entries from account 1 is removed, while
// entries from account 2 is in place.
{
assert_eq!(<StorageOf<Test>>::get(1, b"foo".to_vec()), None);
assert_eq!(<StorageOf<Test>>::get(1, b"bar".to_vec()), None);

assert_eq!(<StorageOf<Test>>::get(2, b"hello".to_vec()), Some(b"3".to_vec()));
assert_eq!(<StorageOf<Test>>::get(2, b"world".to_vec()), Some(b"4".to_vec()));
}
});
}