Skip to content

Commit 6f96443

Browse files
authored
Fix regression in TestReproducibleCatchpointLabels (#3037)
Fix the test TestReproducibleCatchpointLabels, by provide proper calculation of the account totals.
1 parent 4c45443 commit 6f96443

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ledger/acctupdates_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,8 @@ func TestReproducibleCatchpointLabels(t *testing.T) {
15371537
updates.Upsert(testPoolAddr, newPool)
15381538
totals[testPoolAddr] = newPool
15391539

1540+
newTotals := ledgertesting.CalculateNewRoundAccountTotals(t, updates, rewardLevel, protoParams, base, prevTotals)
1541+
15401542
blk := bookkeeping.Block{
15411543
BlockHeader: bookkeeping.BlockHeader{
15421544
Round: basics.Round(i),
@@ -1547,6 +1549,8 @@ func TestReproducibleCatchpointLabels(t *testing.T) {
15471549
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
15481550
delta.Accts.MergeAccounts(updates)
15491551
delta.Creatables = creatablesFromUpdates(base, updates, knownCreatables)
1552+
delta.Totals = newTotals
1553+
15501554
au.newBlock(blk, delta)
15511555
au.committedUpTo(i)
15521556
ml.addMockBlock(blockEntry{block: blk}, delta)

ledger/testing/accountsTotals.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)