Skip to content

Commit

Permalink
cleaned up UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Oct 30, 2024
1 parent 6a191d1 commit 9c43988
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
33 changes: 19 additions & 14 deletions mod/state-transition/pkg/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/berachain/beacon-kit/mod/node-core/pkg/components"
"github.com/berachain/beacon-kit/mod/storage/pkg/beacondb"
"github.com/berachain/beacon-kit/mod/storage/pkg/db"
depositstore "github.com/berachain/beacon-kit/mod/storage/pkg/deposit"
"github.com/berachain/beacon-kit/mod/storage/pkg/encoding"
dbm "github.com/cosmos/cosmos-db"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -54,18 +55,20 @@ var (
testCodec = &encoding.SSZInterfaceCodec[*types.ExecutionPayloadHeader]{}
)

func initTestStore() (
func initTestStores() (
*beacondb.KVStore[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.Validators,
], error) {
],
*depositstore.KVStore[*types.Deposit],
error) {
db, err := db.OpenDB("", dbm.MemDBBackend)
if err != nil {
return nil, fmt.Errorf("failed opening mem db: %w", err)
return nil, nil, fmt.Errorf("failed opening mem db: %w", err)
}
var (
nopLog = log.NewNopLogger()
Expand All @@ -81,19 +84,21 @@ func initTestStore() (
ctx := sdk.NewContext(cms, true, nopLog)
cms.MountStoreWithDB(testStoreKey, storetypes.StoreTypeIAVL, nil)
if err = cms.LoadLatestVersion(); err != nil {
return nil, fmt.Errorf("failed to load latest version: %w", err)
return nil, nil, fmt.Errorf("failed to load latest version: %w", err)
}
testStoreService := &testKVStoreService{ctx: ctx}

return beacondb.New[
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.Validators,
](
testStoreService,
testCodec,
), nil
*types.BeaconBlockHeader,
*types.Eth1Data,
*types.ExecutionPayloadHeader,
*types.Fork,
*types.Validator,
types.Validators,
](
testStoreService,
testCodec,
),
depositstore.NewStore[*types.Deposit](testStoreService),
nil
}
7 changes: 3 additions & 4 deletions mod/state-transition/pkg/core/state_processor_genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func TestInitialize(t *testing.T) {
*types.ExecutionPayloadHeader,
engineprimitives.Withdrawals,
](t)
kvStore, depositStore, err := initTestStores()
require.NoError(t, err)
mocksSigner := &cryptomocks.BLSSigner{}

sp := core.NewStateProcessor[
Expand All @@ -108,14 +110,11 @@ func TestInitialize(t *testing.T) {
](
cs,
execEngine,
nil, // TODO: add deposit store
depositStore,
mocksSigner,
)

// create test inputs
kvStore, err := initTestStore()
require.NoError(t, err)

var (
beaconState = new(TestBeaconStateT).NewFromDB(kvStore, cs)
deposits = []*types.Deposit{
Expand Down

0 comments on commit 9c43988

Please sign in to comment.