simapp, types: fix benchmarks panics by honoring skip if set (#8763)

- BenchmarkAccAddressString must initialize the index less than ed25519.PubKeySize to avoid panics
 - BenchmarkFullAppSimulation should be skipped as it has the same logic as tests

Fixes #8762
This commit is contained in:
Cuong Manh Le 2021-03-03 18:54:14 +07:00 committed by GitHub
parent eb8aaf9395
commit 91affb5167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -15,11 +15,15 @@ import (
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/simapp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
func BenchmarkFullAppSimulation(b *testing.B) {
b.ReportAllocs()
config, db, dir, logger, _, err := SetupSimulation("goleveldb-app-sim", "Simulation")
config, db, dir, logger, skip, err := SetupSimulation("goleveldb-app-sim", "Simulation")
if err != nil {
b.Fatalf("simulation setup failed: %s", err.Error())
}
if skip {
b.Skip("skipping benchmark application simulation")
}
defer func() {
db.Close()
err = os.RemoveAll(dir)
@ -59,11 +63,15 @@ func BenchmarkFullAppSimulation(b *testing.B) {
func BenchmarkInvariants(b *testing.B) {
b.ReportAllocs()
config, db, dir, logger, _, err := SetupSimulation("leveldb-app-invariant-bench", "Simulation")
config, db, dir, logger, skip, err := SetupSimulation("leveldb-app-invariant-bench", "Simulation")
if err != nil {
b.Fatalf("simulation setup failed: %s", err.Error())
}
if skip {
b.Skip("skipping benchmark application simulation")
}
config.AllInvariants = false
defer func() {

View File

@ -17,7 +17,7 @@ func BenchmarkAccAddressString(b *testing.B) {
pk := &ed25519.PubKey{Key: pkBz}
a := pk.Address()
pk2 := make([]byte, ed25519.PubKeySize)
for i := 1; i <= ed25519.PubKeySize; i++ {
for i := 1; i < ed25519.PubKeySize; i++ {
pk2[i] = byte(i)
}
a2 := pk.Address()