|
| 1 | +// Copyright (C) 2019-2021 Algorand, Inc. |
| 2 | +// This file is part of go-algorand |
| 3 | +// |
| 4 | +// go-algorand is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as |
| 6 | +// published by the Free Software Foundation, either version 3 of the |
| 7 | +// License, or (at your option) any later version. |
| 8 | +// |
| 9 | +// go-algorand is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with go-algorand. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package testing |
| 18 | + |
| 19 | +import ( |
| 20 | + gotesting "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | + |
| 24 | + "github.com/algorand/go-algorand/config" |
| 25 | + "github.com/algorand/go-algorand/data/basics" |
| 26 | + "github.com/algorand/go-algorand/ledger/ledgercore" |
| 27 | +) |
| 28 | + |
| 29 | +// CalculateNewRoundAccountTotals calculates the accounts totals for a given round |
| 30 | +func CalculateNewRoundAccountTotals(t *gotesting.T, newRoundDeltas ledgercore.AccountDeltas, newRoundRewardLevel uint64, newRoundConsensusParams config.ConsensusParams, prevRoundBalances map[basics.Address]basics.AccountData, prevRoundTotals ledgercore.AccountTotals) (newTotals ledgercore.AccountTotals) { |
| 31 | + newTotals = prevRoundTotals |
| 32 | + var ot basics.OverflowTracker |
| 33 | + newTotals.ApplyRewards(newRoundRewardLevel, &ot) |
| 34 | + for i := 0; i < newRoundDeltas.Len(); i++ { |
| 35 | + addr, ad := newRoundDeltas.GetByIdx(i) |
| 36 | + newTotals.DelAccount(newRoundConsensusParams, prevRoundBalances[addr], &ot) |
| 37 | + newTotals.AddAccount(newRoundConsensusParams, ad, &ot) |
| 38 | + } |
| 39 | + require.False(t, ot.Overflowed) |
| 40 | + return |
| 41 | +} |
0 commit comments