Pull setup code into this dir, so we can use leveldb

This commit is contained in:
Ethan Frey 2021-10-07 22:41:28 +02:00
parent b36e25db3c
commit b416224eb6
2 changed files with 64 additions and 3 deletions

62
benchmarks/app_test.go Normal file
View File

@ -0,0 +1,62 @@
package benchmarks
import (
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"
"github.com/CosmWasm/wasmd/app"
"github.com/CosmWasm/wasmd/x/wasm"
)
func setup(withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*app.WasmApp, app.GenesisState) {
db := dbm.NewMemDB()
wasmApp := app.NewWasmApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, app.DefaultNodeHome, invCheckPeriod, wasm.EnableAllProposals, app.EmptyBaseAppOptions{}, opts)
if withGenesis {
return wasmApp, app.NewDefaultGenesisState()
}
return wasmApp, app.GenesisState{}
}
// SetupWithGenesisAccounts initializes a new WasmApp with the provided genesis
// accounts and possible balances.
func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *app.WasmApp {
wasmApp, genesisState := setup(true, 0)
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
encodingConfig := app.MakeEncodingConfig()
appCodec := encodingConfig.Marshaler
genesisState[authtypes.ModuleName] = appCodec.MustMarshalJSON(authGenesis)
totalSupply := sdk.NewCoins()
for _, b := range balances {
totalSupply = totalSupply.Add(b.Coins...)
}
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = appCodec.MustMarshalJSON(bankGenesis)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}
wasmApp.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: app.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
wasmApp.Commit()
wasmApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: wasmApp.LastBlockHeight() + 1}})
return wasmApp
}

View File

@ -19,7 +19,6 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
wasmapp "github.com/CosmWasm/wasmd/app"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)
@ -61,7 +60,7 @@ func BenchmarkNCw20SendTxPerBlock(b *testing.B) {
// construct genesis state
genAccs := []authtypes.GenesisAccount{&acc}
benchmarkApp := wasmapp.SetupWithGenesisAccounts(genAccs, banktypes.Balance{
benchmarkApp := SetupWithGenesisAccounts(genAccs, banktypes.Balance{
Address: addr1.String(),
Coins: sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)),
})
@ -164,7 +163,7 @@ func BenchmarkNBankSendTxsPerBlock(b *testing.B) {
// construct genesis state
genAccs := []authtypes.GenesisAccount{&acc}
benchmarkApp := wasmapp.SetupWithGenesisAccounts(genAccs, banktypes.Balance{
benchmarkApp := SetupWithGenesisAccounts(genAccs, banktypes.Balance{
Address: addr1.String(),
Coins: sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)),
})