Skip to content

Commit

Permalink
testing: fix random failure in TestAppEmptyAccountsLocal (#2302)
Browse files Browse the repository at this point in the history
The test had two unrelated bugs:
1. We need to call `WaitForCommit` before `reloadLedger` to ensure the block is being written to disk before the blockQ getting reinitialized ( and loose its content ).
2. The calculation of the total rewards unit in `makeNewEmptyBlock` was wrong. I corrected it. For tests that run only one or two rounds, this might be good enough, but for long-running tests, it would start fail pretty quickly.
  • Loading branch information
tsachiherman authored Jun 17, 2021
1 parent 5fb7ac8 commit 65aa0da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ledger/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ return`
Header: txHeader,
ApplicationCallTxnFields: appCallFields,
}
err = l.appendUnvalidatedTx(t, genesisInitState.Accounts, initKeys, appCall, transactions.ApplyData{
err = l.appendUnvalidatedTx(t, nil, initKeys, appCall, transactions.ApplyData{
EvalDelta: basics.EvalDelta{
LocalDeltas: map[uint64]basics.StateDelta{0: {"lk": basics.ValueDelta{
Action: basics.SetBytesAction,
Expand Down Expand Up @@ -975,6 +975,8 @@ return`
err = l.appendUnvalidated(blk)
a.NoError(err)

l.WaitForCommit(3)

// save data into DB and write into local state
l.accts.accountsWriting.Add(1)
l.accts.commitRound(3, 0, 0)
Expand Down
13 changes: 11 additions & 2 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,17 @@ func makeNewEmptyBlock(t *testing.T, l *Ledger, GenesisID string, initAccounts m
proto := config.Consensus[lastBlock.CurrentProtocol]
poolAddr := testPoolAddr
var totalRewardUnits uint64
for _, acctdata := range initAccounts {
totalRewardUnits += acctdata.MicroAlgos.RewardUnits(proto)
if l.Latest() == 0 {
require.NotNil(t, initAccounts)
for _, acctdata := range initAccounts {
if acctdata.Status != basics.NotParticipating {
totalRewardUnits += acctdata.MicroAlgos.RewardUnits(proto)
}
}
} else {
totals, err := l.Totals(l.Latest())
require.NoError(t, err)
totalRewardUnits = totals.RewardUnits()
}
poolBal, err := l.Lookup(l.Latest(), poolAddr)
a.NoError(err, "could not get incentive pool balance")
Expand Down

0 comments on commit 65aa0da

Please sign in to comment.