fuzz: don't panic on expected errors (#8423)

In the conversion to Go 1.18 fuzzing in e4991fd862,
a `return 0` was converted to a panic. A `return 0` is a hint to the fuzzer, not
a failing testcase.

While here, clean up the test by folding setup code into it.
This commit is contained in:
elias-orijtech
2022-04-27 16:26:21 +02:00
committed by GitHub
parent b626b0a719
commit e741d01231

View File

@@ -13,10 +13,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
)
var mp *mempool.TxMempool
var getMp func() mempool.Mempool
func init() {
func FuzzMempool(f *testing.F) {
app := kvstore.NewApplication()
logger := log.NewNopLogger()
conn := abciclient.NewLocalClient(logger, app)
@@ -28,19 +25,9 @@ func init() {
cfg := config.DefaultMempoolConfig()
cfg.Broadcast = false
getMp = func() mempool.Mempool {
if mp == nil {
mp = mempool.NewTxMempool(logger, cfg, conn)
}
return mp
}
}
mp := mempool.NewTxMempool(logger, cfg, conn)
func FuzzMempool(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
err := getMp().CheckTx(context.Background(), data, nil, mempool.TxInfo{})
if err != nil {
panic(err)
}
_ = mp.CheckTx(context.Background(), data, nil, mempool.TxInfo{})
})
}