Skip to content

Commit

Permalink
move common function to keeper_internal_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
zsystm committed Sep 24, 2024
1 parent caafe45 commit 95b2020
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 60 deletions.
28 changes: 0 additions & 28 deletions client/x/evmengine/keeper/db_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@ package keeper
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

moduletestutil "github.com/piplabs/story/client/x/evmengine/testutil"
"github.com/piplabs/story/lib/ethclient/mock"

"go.uber.org/mock/gomock"
)

func createTestKeeper(t *testing.T) (sdk.Context, *Keeper) {
t.Helper()
cdc := getCodec(t)
txConfig := authtx.NewTxConfig(cdc, nil)

mockEngine, err := newMockEngineAPI(0)
require.NoError(t, err)

ctrl := gomock.NewController(t)
mockClient := mock.NewMockClient(ctrl)
ak := moduletestutil.NewMockAccountKeeper(ctrl)
esk := moduletestutil.NewMockEvmStakingKeeper(ctrl)
uk := moduletestutil.NewMockUpgradeKeeper(ctrl)
ctx, storeService := setupCtxStore(t, nil)
ctx = ctx.WithExecMode(sdk.ExecModeFinalize)
keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk)
require.NoError(t, err)

return ctx, keeper
}

func TestKeeper_InsertGenesisHead(t *testing.T) {
t.Parallel()

Expand Down
32 changes: 0 additions & 32 deletions client/x/evmengine/keeper/genesis_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,13 @@ import (
"context"
"testing"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

moduletestutil "github.com/piplabs/story/client/x/evmengine/testutil"
"github.com/piplabs/story/client/x/evmengine/types"
"github.com/piplabs/story/lib/ethclient/mock"

"go.uber.org/mock/gomock"
)

func createTestKeeper(t *testing.T) (context.Context, *Keeper) {
t.Helper()

cdc := getCodec(t)
txConfig := authtx.NewTxConfig(cdc, nil)
mockEngine, err := newMockEngineAPI(0)
require.NoError(t, err)

cmtAPI := newMockCometAPI(t, nil)
header := cmtproto.Header{Height: 1}

ctrl := gomock.NewController(t)
mockClient := mock.NewMockClient(ctrl)
ak := moduletestutil.NewMockAccountKeeper(ctrl)
esk := moduletestutil.NewMockEvmStakingKeeper(ctrl)
uk := moduletestutil.NewMockUpgradeKeeper(ctrl)

ctx, storeService := setupCtxStore(t, &header)

keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk)
require.NoError(t, err)
keeper.SetCometAPI(cmtAPI)

return ctx, keeper
}

func TestKeeper_InitGenesis(t *testing.T) {
t.Parallel()
dummyExecutionHead := common.HexToHash("0x047e24c3455107d87c68dffa307b3b7fa1877f3e9d7f30c7ee359f2eff3a75d9")
Expand Down
26 changes: 26 additions & 0 deletions client/x/evmengine/keeper/keeper_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ type args struct {
header func(height int64, address []byte) cmtproto.Header
}

func createTestKeeper(t *testing.T) (context.Context, *Keeper) {
t.Helper()

cdc := getCodec(t)
txConfig := authtx.NewTxConfig(cdc, nil)
mockEngine, err := newMockEngineAPI(0)
require.NoError(t, err)

cmtAPI := newMockCometAPI(t, nil)
header := cmtproto.Header{Height: 1}

ctrl := gomock.NewController(t)
mockClient := mock.NewMockClient(ctrl)
ak := moduletestutil.NewMockAccountKeeper(ctrl)
esk := moduletestutil.NewMockEvmStakingKeeper(ctrl)
uk := moduletestutil.NewMockUpgradeKeeper(ctrl)

ctx, storeService := setupCtxStore(t, &header)

keeper, err := NewKeeper(cdc, storeService, &mockEngine, mockClient, txConfig, ak, esk, uk)
require.NoError(t, err)
keeper.SetCometAPI(cmtAPI)

return ctx, keeper
}

func createKeeper(t *testing.T, args args) (sdk.Context, *mockCometAPI, *Keeper) {
t.Helper()

Expand Down

0 comments on commit 95b2020

Please sign in to comment.