Destroy balances of expired accounts

parent 4939fbbb
Pipeline #23634953 passed with stages
in 19 minutes 10 seconds
......@@ -285,11 +285,12 @@ grant_fee_deposits(
Data1#data{fee_deposit_short=0, fee_deposit_long=DepositLong - TakenDepositLong + ReturnedDeposit}.
-spec remove_old_and_unlock_accounts(data()) -> data().
remove_old_and_unlock_accounts(Data=#data{accounts=AccountsTree, height=Height, fee_deposit_long=FeeDepositLong}) ->
{NewAccountsTree, CollectedBalance} = remove_old_and_unlock_accounts_from_tree(AccountsTree, Height),
Data#data{accounts=NewAccountsTree, fee_deposit_long=FeeDepositLong + CollectedBalance}.
remove_old_and_unlock_accounts(Data=#data{accounts=AccountsTree, height=Height}) ->
{NewAccountsTree, _} = remove_old_and_unlock_accounts_from_tree(AccountsTree, Height),
Data#data{accounts=NewAccountsTree}.
-spec remove_old_and_unlock_accounts_from_tree(gb_merkle_trees:tree(), block_height()) -> {gb_merkle_trees:tree(), non_neg_integer()}.
%% @doc Remove old and unlock accounts, returning a new tree and total balance of destroyed accounts.
remove_old_and_unlock_accounts_from_tree(AccountsTree, Height) ->
gb_merkle_trees:foldr(
fun ({Address, AccountBin}, {TreeAcc, BalanceAcc}) ->
......
......@@ -118,7 +118,7 @@ prop_end_block_increments_height() ->
data(),
get_value(height, end_block(Data)) =:= get_value(height, Data) + 1).
prop_end_block_expires_accounts_and_puts_balances_into_long_deposit() ->
prop_end_block_expires_accounts() ->
?FORALL(
{Data, Account},
data_with_account(),
......@@ -127,7 +127,7 @@ prop_end_block_expires_accounts_and_puts_balances_into_long_deposit() ->
ExpiringData = ercoin_account:put(ExpiringAccount, Data),
NewData = end_block(ExpiringData),
ercoin_account:get(Account#account.address, NewData) =:= none andalso
NewData#data.fee_deposit_long >= Account#account.balance
ercoin_data:money_supply(NewData) =< ercoin_data:money_supply(Data) - Account#account.balance
end).
%% TODO: Give this more attention, ensure that the right thing is tested.
......
%% @doc Helper functions for playing with data.
-module(ercoin_data).
-export(
[money_supply/1]).
-include_lib("include/ercoin_test.hrl").
-spec money_supply(data()) -> non_neg_integer().
money_supply(#data{accounts=Accounts, fee_deposit_short=FeeDepositShort, fee_deposit_long=FeeDepositLong}) ->
AccountsBalance =
gb_merkle_trees:foldr(
fun (AccountSerialized, Sum) ->
#account{balance=Balance} = ercoin_account:deserialize(AccountSerialized),
Balance + Sum
end,
0,
Accounts),
AccountsBalance + FeeDepositShort + FeeDepositLong.
......@@ -27,17 +27,6 @@
data_sks_and_lock_tx/0,
data_sks_and_vote_tx/0]).
money_supply(#data{accounts=Accounts, fee_deposit_short=FeeDepositShort, fee_deposit_long=FeeDepositLong}) ->
AccountsBalance =
gb_merkle_trees:foldr(
fun (AccountSerialized, Sum) ->
#account{balance=Balance} = ercoin_account:deserialize(AccountSerialized),
Balance + Sum
end,
0,
Accounts),
AccountsBalance + FeeDepositShort + FeeDepositLong.
-define(
SAMPLE_TRANSFER_TX,
#transfer_tx{
......@@ -155,4 +144,4 @@ prop_non_burn_tx_does_not_change_money_supply() ->
data_with_tx(),
?IMPLIES(
not is_record(Tx, burn_tx),
money_supply(ercoin_tx:apply(Tx, Data)) =:= money_supply(Data))).
ercoin_data:money_supply(ercoin_tx:apply(Tx, Data)) =:= ercoin_data:money_supply(Data))).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment