Skip to content

Commit abc4058

Browse files
authored
testing: avoid division by zero during TestBasicCatchpointWriter (#2502)
The `randomFullAccountData` method was dividing by `lastCreatableID` which could be zero. The probability for that is pretty slim, but given that it was found during a travis run, we should fix it.
1 parent af8c2ce commit abc4058

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ledger/accountdb_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func randomFullAccountData(rewardsLevel, lastCreatableID uint64) (basics.Account
9797
data.AssetParams[basics.AssetIndex(lastCreatableID)] = ap
9898
}
9999
}
100-
if 1 == (crypto.RandUint64() % 2) {
100+
if 1 == (crypto.RandUint64()%2) && lastCreatableID > 0 {
101101
// if account owns assets
102102
data.Assets = make(map[basics.AssetIndex]basics.AssetHolding)
103103
ownedAssetsCount := crypto.RandUint64()%20 + 1
@@ -113,7 +113,7 @@ func randomFullAccountData(rewardsLevel, lastCreatableID uint64) (basics.Account
113113
crypto.RandBytes(data.AuthAddr[:])
114114
}
115115

116-
if 1 == (crypto.RandUint64() % 3) {
116+
if 1 == (crypto.RandUint64()%3) && lastCreatableID > 0 {
117117
data.AppLocalStates = make(map[basics.AppIndex]basics.AppLocalState)
118118
appStatesCount := crypto.RandUint64()%20 + 1
119119
for i := uint64(0); i < appStatesCount; i++ {

0 commit comments

Comments
 (0)