Skip to content

Commit 7248b95

Browse files
authored
Add totals checks into acct updates tests (#3367)
## Summary After #2922 there is some leftover unused code for totals calculations. Turned this code into actual asserts. ## Test Plan This is tests update
1 parent 8a335bb commit 7248b95

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

ledger/acctupdates_test.go

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ func TestAcctUpdates(t *testing.T) {
412412
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
413413
updates.Upsert(testPoolAddr, newPool)
414414
totals[testPoolAddr] = newPool
415+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
416+
require.Equal(t, prevTotals.All(), curTotals.All())
415417

416418
blk := bookkeeping.Block{
417419
BlockHeader: bookkeeping.BlockHeader{
@@ -424,7 +426,7 @@ func TestAcctUpdates(t *testing.T) {
424426
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
425427
delta.Accts.MergeAccounts(updates)
426428
delta.Creatables = creatablesFromUpdates(base, updates, knownCreatables)
427-
delta.Totals = accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
429+
delta.Totals = curTotals
428430
au.newBlock(blk, delta)
429431
accts = append(accts, totals)
430432
rewardsLevels = append(rewardsLevels, rewardLevel)
@@ -515,6 +517,8 @@ func TestAcctUpdatesFastUpdates(t *testing.T) {
515517
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
516518
updates.Upsert(testPoolAddr, newPool)
517519
totals[testPoolAddr] = newPool
520+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
521+
require.Equal(t, prevTotals.All(), curTotals.All())
518522

519523
blk := bookkeeping.Block{
520524
BlockHeader: bookkeeping.BlockHeader{
@@ -526,6 +530,7 @@ func TestAcctUpdatesFastUpdates(t *testing.T) {
526530

527531
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
528532
delta.Accts.MergeAccounts(updates)
533+
delta.Totals = curTotals
529534
au.newBlock(blk, delta)
530535
accts = append(accts, totals)
531536
rewardsLevels = append(rewardsLevels, rewardLevel)
@@ -602,6 +607,8 @@ func BenchmarkBalancesChanges(b *testing.B) {
602607
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
603608
updates.Upsert(testPoolAddr, newPool)
604609
totals[testPoolAddr] = newPool
610+
curTotals := accumulateTotals(b, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
611+
require.Equal(b, prevTotals.All(), curTotals.All())
605612

606613
blk := bookkeeping.Block{
607614
BlockHeader: bookkeeping.BlockHeader{
@@ -613,6 +620,7 @@ func BenchmarkBalancesChanges(b *testing.B) {
613620

614621
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
615622
delta.Accts.MergeAccounts(updates)
623+
delta.Totals = curTotals
616624
au.newBlock(blk, delta)
617625
accts = append(accts, totals)
618626
rewardsLevels = append(rewardsLevels, rewardLevel)
@@ -729,6 +737,8 @@ func TestLargeAccountCountCatchpointGeneration(t *testing.T) {
729737
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
730738
updates.Upsert(testPoolAddr, newPool)
731739
totals[testPoolAddr] = newPool
740+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
741+
require.Equal(t, prevTotals.All(), curTotals.All())
732742

733743
blk := bookkeeping.Block{
734744
BlockHeader: bookkeeping.BlockHeader{
@@ -740,6 +750,7 @@ func TestLargeAccountCountCatchpointGeneration(t *testing.T) {
740750

741751
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
742752
delta.Accts.MergeAccounts(updates)
753+
delta.Totals = curTotals
743754
au.newBlock(blk, delta)
744755
accts = append(accts, totals)
745756
rewardsLevels = append(rewardsLevels, rewardLevel)
@@ -1288,8 +1299,8 @@ func TestCompactDeltas(t *testing.T) {
12881299

12891300
}
12901301

1291-
// TestCachesInitialization test the functionality of the initializeCaches cache.
1292-
func TestCachesInitialization(t *testing.T) {
1302+
// TestAcctUpdatesCachesInitialization test the functionality of the initializeCaches cache.
1303+
func TestAcctUpdatesCachesInitialization(t *testing.T) {
12931304
partitiontest.PartitionTest(t)
12941305

12951306
protocolVersion := protocol.ConsensusCurrentVersion
@@ -1340,6 +1351,8 @@ func TestCachesInitialization(t *testing.T) {
13401351
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
13411352
updates.Upsert(testPoolAddr, newPool)
13421353
totals[testPoolAddr] = newPool
1354+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1355+
require.Equal(t, prevTotals.All(), curTotals.All())
13431356

13441357
blk := bookkeeping.Block{
13451358
BlockHeader: bookkeeping.BlockHeader{
@@ -1351,7 +1364,7 @@ func TestCachesInitialization(t *testing.T) {
13511364

13521365
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
13531366
delta.Accts.MergeAccounts(updates)
1354-
delta.Totals = accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1367+
delta.Totals = curTotals
13551368
ml.addMockBlock(blockEntry{block: blk}, delta)
13561369
au.newBlock(blk, delta)
13571370
ml.trackers.committedUpTo(basics.Round(i))
@@ -1382,8 +1395,8 @@ func TestCachesInitialization(t *testing.T) {
13821395
require.Equal(t, recoveredLedgerRound-basics.Round(proto.MaxBalLookback), au.cachedDBRound)
13831396
}
13841397

1385-
// TestSplittingConsensusVersionCommits tests the a sequence of commits that spans over multiple consensus versions works correctly.
1386-
func TestSplittingConsensusVersionCommits(t *testing.T) {
1398+
// TestAcctUpdatesSplittingConsensusVersionCommits tests the a sequence of commits that spans over multiple consensus versions works correctly.
1399+
func TestAcctUpdatesSplittingConsensusVersionCommits(t *testing.T) {
13871400
partitiontest.PartitionTest(t)
13881401

13891402
initProtocolVersion := protocol.ConsensusV20
@@ -1439,6 +1452,8 @@ func TestSplittingConsensusVersionCommits(t *testing.T) {
14391452
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
14401453
updates.Upsert(testPoolAddr, newPool)
14411454
totals[testPoolAddr] = newPool
1455+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1456+
require.Equal(t, prevTotals.All(), curTotals.All())
14421457

14431458
blk := bookkeeping.Block{
14441459
BlockHeader: bookkeeping.BlockHeader{
@@ -1450,7 +1465,7 @@ func TestSplittingConsensusVersionCommits(t *testing.T) {
14501465

14511466
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
14521467
delta.Accts.MergeAccounts(updates)
1453-
delta.Totals = accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1468+
delta.Totals = curTotals
14541469
ml.addMockBlock(blockEntry{block: blk}, delta)
14551470
au.newBlock(blk, delta)
14561471
accts = append(accts, totals)
@@ -1474,6 +1489,8 @@ func TestSplittingConsensusVersionCommits(t *testing.T) {
14741489
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
14751490
updates.Upsert(testPoolAddr, newPool)
14761491
totals[testPoolAddr] = newPool
1492+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1493+
require.Equal(t, prevTotals.All(), curTotals.All())
14771494

14781495
blk := bookkeeping.Block{
14791496
BlockHeader: bookkeeping.BlockHeader{
@@ -1485,7 +1502,7 @@ func TestSplittingConsensusVersionCommits(t *testing.T) {
14851502

14861503
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
14871504
delta.Accts.MergeAccounts(updates)
1488-
delta.Totals = accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1505+
delta.Totals = curTotals
14891506
ml.addMockBlock(blockEntry{block: blk}, delta)
14901507
au.newBlock(blk, delta)
14911508
accts = append(accts, totals)
@@ -1498,9 +1515,9 @@ func TestSplittingConsensusVersionCommits(t *testing.T) {
14981515

14991516
}
15001517

1501-
// TestSplittingConsensusVersionCommitsBoundry tests the a sequence of commits that spans over multiple consensus versions works correctly, and
1502-
// in particular, complements TestSplittingConsensusVersionCommits by testing the commit boundary.
1503-
func TestSplittingConsensusVersionCommitsBoundry(t *testing.T) {
1518+
// TestAcctUpdatesSplittingConsensusVersionCommitsBoundry tests the a sequence of commits that spans over multiple consensus versions works correctly, and
1519+
// in particular, complements TestAcctUpdatesSplittingConsensusVersionCommits by testing the commit boundary.
1520+
func TestAcctUpdatesSplittingConsensusVersionCommitsBoundry(t *testing.T) {
15041521
partitiontest.PartitionTest(t)
15051522

15061523
initProtocolVersion := protocol.ConsensusV20
@@ -1556,6 +1573,8 @@ func TestSplittingConsensusVersionCommitsBoundry(t *testing.T) {
15561573
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
15571574
updates.Upsert(testPoolAddr, newPool)
15581575
totals[testPoolAddr] = newPool
1576+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1577+
require.Equal(t, prevTotals.All(), curTotals.All())
15591578

15601579
blk := bookkeeping.Block{
15611580
BlockHeader: bookkeeping.BlockHeader{
@@ -1567,7 +1586,7 @@ func TestSplittingConsensusVersionCommitsBoundry(t *testing.T) {
15671586

15681587
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
15691588
delta.Accts.MergeAccounts(updates)
1570-
delta.Totals = accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1589+
delta.Totals = curTotals
15711590
ml.addMockBlock(blockEntry{block: blk}, delta)
15721591
au.newBlock(blk, delta)
15731592
accts = append(accts, totals)
@@ -1590,6 +1609,8 @@ func TestSplittingConsensusVersionCommitsBoundry(t *testing.T) {
15901609
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
15911610
updates.Upsert(testPoolAddr, newPool)
15921611
totals[testPoolAddr] = newPool
1612+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1613+
require.Equal(t, prevTotals.All(), curTotals.All())
15931614

15941615
blk := bookkeeping.Block{
15951616
BlockHeader: bookkeeping.BlockHeader{
@@ -1601,7 +1622,7 @@ func TestSplittingConsensusVersionCommitsBoundry(t *testing.T) {
16011622

16021623
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
16031624
delta.Accts.MergeAccounts(updates)
1604-
delta.Totals = accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1625+
delta.Totals = curTotals
16051626
ml.addMockBlock(blockEntry{block: blk}, delta)
16061627
au.newBlock(blk, delta)
16071628
accts = append(accts, totals)
@@ -1626,6 +1647,8 @@ func TestSplittingConsensusVersionCommitsBoundry(t *testing.T) {
16261647
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
16271648
updates.Upsert(testPoolAddr, newPool)
16281649
totals[testPoolAddr] = newPool
1650+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1651+
require.Equal(t, prevTotals.All(), curTotals.All())
16291652

16301653
blk := bookkeeping.Block{
16311654
BlockHeader: bookkeeping.BlockHeader{
@@ -1637,7 +1660,7 @@ func TestSplittingConsensusVersionCommitsBoundry(t *testing.T) {
16371660

16381661
delta := ledgercore.MakeStateDelta(&blk.BlockHeader, 0, updates.Len(), 0)
16391662
delta.Accts.MergeAccounts(updates)
1640-
delta.Totals = accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
1663+
delta.Totals = curTotals
16411664
ml.addMockBlock(blockEntry{block: blk}, delta)
16421665
au.newBlock(blk, delta)
16431666
accts = append(accts, totals)

ledger/catchpointtracker_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ func TestReproducibleCatchpointLabels(t *testing.T) {
317317
newPool.MicroAlgos.Raw -= prevTotals.RewardUnits() * rewardLevelDelta
318318
updates.Upsert(testPoolAddr, newPool)
319319
totals[testPoolAddr] = newPool
320+
curTotals := accumulateTotals(t, protocol.ConsensusCurrentVersion, []map[basics.Address]basics.AccountData{totals}, rewardLevel)
321+
require.Equal(t, prevTotals.All(), curTotals.All())
320322

321323
newTotals := ledgertesting.CalculateNewRoundAccountTotals(t, updates, rewardLevel, protoParams, base, prevTotals)
324+
require.Equal(t, newTotals.All(), curTotals.All())
322325

323326
blk := bookkeeping.Block{
324327
BlockHeader: bookkeeping.BlockHeader{

0 commit comments

Comments
 (0)