Skip to content

Commit

Permalink
chore: refactory test for init genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Dec 2, 2024
1 parent f0ba241 commit da09b21
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions x/btcstaking/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,36 @@ import (
"strings"
"testing"

"cosmossdk.io/core/header"
"cosmossdk.io/log"
"cosmossdk.io/store"
storemetrics "cosmossdk.io/store/metrics"
"github.com/btcsuite/btcd/chaincfg"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/require"

storetypes "cosmossdk.io/store/types"
"github.com/babylonlabs-io/babylon/app"
v1 "github.com/babylonlabs-io/babylon/app/upgrades/v1"
testnetdata "github.com/babylonlabs-io/babylon/app/upgrades/v1/testnet"
"github.com/babylonlabs-io/babylon/testutil/datagen"
"github.com/babylonlabs-io/babylon/testutil/helper"
testutilk "github.com/babylonlabs-io/babylon/testutil/keeper"
btclightclientt "github.com/babylonlabs-io/babylon/x/btclightclient/types"
"github.com/babylonlabs-io/babylon/x/btcstaking/keeper"
"github.com/babylonlabs-io/babylon/x/btcstaking/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
)

func TestInitGenesis(t *testing.T) {
types.DefaultParams()
bbnApp := app.NewTmpBabylonApp()

storeKey := storetypes.NewKVStoreKey(types.StoreKey)

func TestInitGenesisWithSetParams(t *testing.T) {
db := dbm.NewMemDB()
stateStore := store.NewCommitMultiStore(db, log.NewTestLogger(t), storemetrics.NewNoOpMetrics())
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
require.NoError(t, stateStore.LoadLatestVersion())

ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())
ctx = ctx.WithHeaderInfo(header.Info{})
k, ctx := testutilk.BTCStakingKeeperWithStore(t, db, stateStore, nil, nil, nil)

k := keeper.NewKeeper(bbnApp.AppCodec(), runtime.NewKVStoreService(storeKey), nil, nil, nil, &chaincfg.RegressionNetParams, authtypes.NewModuleAddress(govtypes.ModuleName).String())
err := k.InitGenesis(ctx, *types.DefaultGenesis())
require.NoError(t, err)

params, err := v1.LoadBtcStakingParamsFromData(testnetdata.BtcStakingParamsStr)
require.NoError(t, err)

err = k.SetParams(ctx, params[len(params)-1])
require.NoError(t, err)
for _, p := range params {
err = k.SetParams(ctx, p)
require.NoError(t, err)
}
}

func TestExportGenesis(t *testing.T) {
Expand Down

0 comments on commit da09b21

Please sign in to comment.