package reactor

import (
	"git.cw.tr/mukan-network/mukan-consensus/abci/example/kvstore"
	"git.cw.tr/mukan-network/mukan-consensus/config"
	mempl "git.cw.tr/mukan-network/mukan-consensus/mempool"
	"git.cw.tr/mukan-network/mukan-consensus/proxy"
)

var mempool mempl.Mempool

func init() {
	app := kvstore.NewInMemoryApplication()
	cc := proxy.NewLocalClientCreator(app)
	appConnMem, _ := cc.NewABCIClient()
	err := appConnMem.Start()
	if err != nil {
		panic(err)
	}

	cfg := config.DefaultMempoolConfig()
	cfg.Broadcast = false
	mempool = mempl.NewCListMempool(cfg, appConnMem, 0)
}

func Fuzz(data []byte) int {
	err := mempool.CheckTx(data, nil, mempl.TxInfo{})
	if err != nil {
		return 0
	}

	return 1
}
