laconicd/app/benchmark_test.go

45 lines
1.3 KiB
Go
Raw Normal View History

package app
import (
"encoding/json"
2022-10-10 10:38:33 +00:00
"io"
"testing"
"github.com/cerc-io/laconicd/encoding"
"github.com/cosmos/cosmos-sdk/simapp"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
2022-09-30 06:41:39 +00:00
dbm "github.com/tendermint/tm-db"
)
func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
2022-09-30 06:41:39 +00:00
db := dbm.NewMemDB()
2022-10-10 10:38:33 +00:00
app := NewEthermintApp(log.NewTMLogger(io.Discard), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{})
2022-09-30 06:41:39 +00:00
2022-10-10 10:38:33 +00:00
genesisState := NewTestGenesisState(app.AppCodec())
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
b.Fatal(err)
}
// Initialize the chain
app.InitChain(
abci.RequestInitChain{
ChainId: "ethermint_9000-1",
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)
app.Commit()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
// Making a new app object with the db, so that initchain hasn't been called
2022-10-10 10:38:33 +00:00
app2 := NewEthermintApp(log.NewTMLogger(log.NewSyncWriter(io.Discard)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encoding.MakeConfig(ModuleBasics), simapp.EmptyAppOptions{})
if _, err := app2.ExportAppStateAndValidators(false, []string{}); err != nil {
b.Fatal(err)
}
}
}