Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get rid of cosmos-db dep #21373

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/crypto/secp256k1"
cmttypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
protoio "github.com/cosmos/gogoproto/io"
"github.com/cosmos/gogoproto/jsonpb"
"github.com/cosmos/gogoproto/proto"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

coretesting "cosmossdk.io/core/testing"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
pruningtypes "cosmossdk.io/store/pruning/types"
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestABCI_First_block_Height(t *testing.T) {

func TestABCI_InitChain(t *testing.T) {
name := t.Name()
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
logger := log.NewTestLogger(t)
app := baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetChainID("test-chain-id"))

Expand Down Expand Up @@ -204,7 +204,7 @@ func TestABCI_InitChain(t *testing.T) {

func TestABCI_InitChain_WithInitialHeight(t *testing.T) {
name := t.Name()
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

_, err := app.InitChain(
Expand All @@ -221,7 +221,7 @@ func TestABCI_InitChain_WithInitialHeight(t *testing.T) {

func TestABCI_FinalizeBlock_WithInitialHeight(t *testing.T) {
name := t.Name()
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

_, err := app.InitChain(
Expand All @@ -243,7 +243,7 @@ func TestABCI_FinalizeBlock_WithInitialHeight(t *testing.T) {

func TestABCI_FinalizeBlock_WithBeginAndEndBlocker(t *testing.T) {
name := t.Name()
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

app.SetBeginBlocker(func(ctx sdk.Context) (sdk.BeginBlock, error) {
Expand Down Expand Up @@ -310,7 +310,7 @@ func TestABCI_FinalizeBlock_WithBeginAndEndBlocker(t *testing.T) {

func TestABCI_ExtendVote(t *testing.T) {
name := t.Name()
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

app.SetExtendVoteHandler(func(ctx sdk.Context, req *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) {
Expand All @@ -328,7 +328,7 @@ func TestABCI_ExtendVote(t *testing.T) {
return &abci.VerifyVoteExtensionResponse{Status: abci.VERIFY_VOTE_EXTENSION_STATUS_ACCEPT}, nil
})

app.SetParamStore(&paramStore{db: dbm.NewMemDB()})
app.SetParamStore(&paramStore{db: coretesting.NewMemDB()})
_, err := app.InitChain(
&abci.InitChainRequest{
InitialHeight: 1,
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestABCI_ExtendVote(t *testing.T) {
// without having called ExtendVote before.
func TestABCI_OnlyVerifyVoteExtension(t *testing.T) {
name := t.Name()
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

app.SetVerifyVoteExtensionHandler(func(ctx sdk.Context, req *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) {
Expand All @@ -406,7 +406,7 @@ func TestABCI_OnlyVerifyVoteExtension(t *testing.T) {
return &abci.VerifyVoteExtensionResponse{Status: abci.VERIFY_VOTE_EXTENSION_STATUS_ACCEPT}, nil
})

app.SetParamStore(&paramStore{db: dbm.NewMemDB()})
app.SetParamStore(&paramStore{db: coretesting.NewMemDB()})
_, err := app.InitChain(
&abci.InitChainRequest{
InitialHeight: 1,
Expand Down Expand Up @@ -526,7 +526,7 @@ func TestABCI_P2PQuery(t *testing.T) {
}

func TestBaseApp_PrepareCheckState(t *testing.T) {
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
logger := log.NewTestLogger(t)

Expand All @@ -537,7 +537,7 @@ func TestBaseApp_PrepareCheckState(t *testing.T) {
}

app := baseapp.NewBaseApp(name, logger, db, nil)
app.SetParamStore(&paramStore{db: dbm.NewMemDB()})
app.SetParamStore(&paramStore{db: coretesting.NewMemDB()})
_, err := app.InitChain(&abci.InitChainRequest{
ConsensusParams: cp,
})
Expand All @@ -555,7 +555,7 @@ func TestBaseApp_PrepareCheckState(t *testing.T) {
}

func TestBaseApp_Precommit(t *testing.T) {
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
logger := log.NewTestLogger(t)

Expand All @@ -566,7 +566,7 @@ func TestBaseApp_Precommit(t *testing.T) {
}

app := baseapp.NewBaseApp(name, logger, db, nil)
app.SetParamStore(&paramStore{db: dbm.NewMemDB()})
app.SetParamStore(&paramStore{db: coretesting.NewMemDB()})
_, err := app.InitChain(&abci.InitChainRequest{
ConsensusParams: cp,
})
Expand Down Expand Up @@ -1485,10 +1485,10 @@ func TestABCI_Query(t *testing.T) {

func TestABCI_GetBlockRetentionHeight(t *testing.T) {
logger := log.NewTestLogger(t)
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()

snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t))
snapshotStore, err := snapshots.NewStore(coretesting.NewMemDB(), testutil.GetTempDir(t))
require.NoError(t, err)

testCases := map[string]struct {
Expand Down Expand Up @@ -1577,7 +1577,7 @@ func TestABCI_GetBlockRetentionHeight(t *testing.T) {
for name, tc := range testCases {
tc := tc

tc.bapp.SetParamStore(&paramStore{db: dbm.NewMemDB()})
tc.bapp.SetParamStore(&paramStore{db: coretesting.NewMemDB()})
_, err := tc.bapp.InitChain(&abci.InitChainRequest{
ConsensusParams: &cmtproto.ConsensusParams{
Evidence: &cmtproto.EvidenceParams{
Expand All @@ -1598,7 +1598,7 @@ func TestPrepareCheckStateCalledWithCheckState(t *testing.T) {
t.Parallel()

logger := log.NewTestLogger(t)
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil)

Expand All @@ -1621,7 +1621,7 @@ func TestPrecommiterCalledWithDeliverState(t *testing.T) {
t.Parallel()

logger := log.NewTestLogger(t)
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil)

Expand Down Expand Up @@ -2287,7 +2287,7 @@ func TestABCI_HaltChain(t *testing.T) {
}

func TestBaseApp_PreBlocker(t *testing.T) {
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
logger := log.NewTestLogger(t)

Expand Down
4 changes: 2 additions & 2 deletions baseapp/abci_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
cmtsecp256k1 "github.com/cometbft/cometbft/crypto/secp256k1"
cmttypes "github.com/cometbft/cometbft/types"
dbm "github.com/cosmos/cosmos-db"
protoio "github.com/cosmos/gogoproto/io"
"github.com/cosmos/gogoproto/proto"
gogotypes "github.com/cosmos/gogoproto/types"
Expand All @@ -20,6 +19,7 @@ import (

"cosmossdk.io/core/comet"
"cosmossdk.io/core/header"
coretesting "cosmossdk.io/core/testing"
"cosmossdk.io/log"
authtx "cosmossdk.io/x/auth/tx"

Expand Down Expand Up @@ -477,7 +477,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection()

// create a baseapp along with a tx config for tx generation
txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)
app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), dbm.NewMemDB(), txConfig.TxDecoder())
app := baseapp.NewBaseApp(s.T().Name(), log.NewNopLogger(), coretesting.NewMemDB(), txConfig.TxDecoder())

// create a proposal handler
ph := baseapp.NewDefaultProposalHandler(mempool.NoOpMempool{}, app)
Expand Down
6 changes: 3 additions & 3 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/crypto/tmhash"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/core/header"
corestore "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
"cosmossdk.io/store"
Expand Down Expand Up @@ -65,7 +65,7 @@ type BaseApp struct {
mu sync.Mutex // mu protects the fields below.
logger log.Logger
name string // application name from abci.BlockInfo
db dbm.DB // common DB backend
db corestore.KVStoreWithBatch // common DB backend
cms storetypes.CommitMultiStore // Main (uncached) state
qms storetypes.MultiStore // Optional alternative multistore for querying only.
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
Expand Down Expand Up @@ -194,7 +194,7 @@ type BaseApp struct {
// variadic number of option functions, which act on the BaseApp to set
// configuration choices.
func NewBaseApp(
name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp),
name string, logger log.Logger, db corestore.KVStoreWithBatch, txDecoder sdk.TxDecoder, options ...func(*BaseApp),
) *BaseApp {
app := &BaseApp{
logger: logger.With(log.ModuleKey, "baseapp"),
Expand Down
29 changes: 15 additions & 14 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (

abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
dbm "github.com/cosmos/cosmos-db"
"github.com/stretchr/testify/require"

corestore "cosmossdk.io/core/store"
coretesting "cosmossdk.io/core/testing"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
"cosmossdk.io/store/metrics"
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
signingCtx := cdc.InterfaceRegistry().SigningContext()

txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
logBuffer := new(bytes.Buffer)
logger := log.NewLogger(logBuffer, log.ColorOption(false))

Expand All @@ -77,7 +78,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
app.SetInterfaceRegistry(cdc.InterfaceRegistry())
app.MsgServiceRouter().SetInterfaceRegistry(cdc.InterfaceRegistry())
app.MountStores(capKey1, capKey2)
app.SetParamStore(paramStore{db: dbm.NewMemDB()})
app.SetParamStore(paramStore{db: coretesting.NewMemDB()})
app.SetTxDecoder(txConfig.TxDecoder())
app.SetTxEncoder(txConfig.TxEncoder())

Expand All @@ -95,7 +96,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
func getQueryBaseapp(t *testing.T) *baseapp.BaseApp {
t.Helper()

db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

Expand All @@ -115,7 +116,7 @@ func getQueryBaseapp(t *testing.T) *baseapp.BaseApp {
func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...func(*baseapp.BaseApp)) *BaseAppSuite {
t.Helper()
snapshotTimeout := 1 * time.Minute
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t))
snapshotStore, err := snapshots.NewStore(coretesting.NewMemDB(), testutil.GetTempDir(t))
require.NoError(t, err)

suite := NewBaseAppSuite(
Expand Down Expand Up @@ -234,7 +235,7 @@ func TestAnteHandlerGasMeter(t *testing.T) {
func TestLoadVersion(t *testing.T) {
logger := log.NewTestLogger(t)
pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)

Expand Down Expand Up @@ -296,7 +297,7 @@ func TestSetLoader(t *testing.T) {
app.SetStoreLoader(baseapp.DefaultStoreLoader)
}

initStore := func(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
initStore := func(t *testing.T, db corestore.KVStoreWithBatch, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
Expand All @@ -317,7 +318,7 @@ func TestSetLoader(t *testing.T) {
require.Equal(t, int64(1), commitID.Version)
}

checkStore := func(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) {
checkStore := func(t *testing.T, db corestore.KVStoreWithBatch, ver int64, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics())
rs.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault))
Expand Down Expand Up @@ -357,7 +358,7 @@ func TestSetLoader(t *testing.T) {
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
// prepare a db with some data
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
initStore(t, db, tc.origStoreKey, k, v)

// load the app with the existing db
Expand Down Expand Up @@ -386,7 +387,7 @@ func TestSetLoader(t *testing.T) {

func TestVersionSetterGetter(t *testing.T) {
pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningDefault))
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil, pruningOpt)

Expand All @@ -409,7 +410,7 @@ func TestVersionSetterGetter(t *testing.T) {
func TestLoadVersionInvalid(t *testing.T) {
logger := log.NewNopLogger()
pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)

Expand Down Expand Up @@ -446,7 +447,7 @@ func TestOptionFunction(t *testing.T) {
}
}

db := dbm.NewMemDB()
db := coretesting.NewMemDB()
bap := baseapp.NewBaseApp("starting name", log.NewTestLogger(t), db, nil, testChangeNameHelper("new name"))
require.Equal(t, bap.Name(), "new name", "BaseApp should have had name changed via option function")
}
Expand Down Expand Up @@ -695,7 +696,7 @@ func TestBaseAppPostHandler(t *testing.T) {
func TestABCI_CreateQueryContext(t *testing.T) {
t.Parallel()

db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, log.NewTestLogger(t), db, nil)

Expand Down Expand Up @@ -841,7 +842,7 @@ func TestLoadVersionPruning(t *testing.T) {
logger := log.NewNopLogger()
pruningOptions := pruningtypes.NewCustomPruningOptions(10, 15)
pruningOpt := baseapp.SetPruning(pruningOptions)
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
name := t.Name()
app := baseapp.NewBaseApp(name, logger, db, nil, pruningOpt)

Expand Down
4 changes: 2 additions & 2 deletions baseapp/grpcrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"sync"
"testing"

dbm "github.com/cosmos/cosmos-db"
"github.com/stretchr/testify/require"

coretesting "cosmossdk.io/core/testing"
"cosmossdk.io/depinject"
"cosmossdk.io/log"

Expand Down Expand Up @@ -107,7 +107,7 @@ func TestRegisterQueryServiceTwice(t *testing.T) {
),
&appBuilder)
require.NoError(t, err)
db := dbm.NewMemDB()
db := coretesting.NewMemDB()
app := appBuilder.Build(db, nil)

// First time registering service shouldn't panic.
Expand Down
Loading
Loading