Skip to content

Commit

Permalink
test(x/upgrade): fix tests (#21582)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 7, 2024
1 parent a48a75f commit 02b20f9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package baseapp

import (
"context"
"cosmossdk.io/core/server"
"errors"
"fmt"
"maps"
Expand All @@ -18,6 +17,7 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/core/header"
"cosmossdk.io/core/server"
corestore "cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
Expand Down
2 changes: 1 addition & 1 deletion baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package baseapp

import (
"context"
"cosmossdk.io/core/server"
"errors"
"fmt"
"io"
"math"

"cosmossdk.io/core/server"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/store/metrics"
pruningtypes "cosmossdk.io/store/pruning/types"
Expand Down
2 changes: 1 addition & 1 deletion baseapp/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package baseapp_test
import (
"bytes"
"context"
"cosmossdk.io/core/server"
"encoding/binary"
"encoding/json"
"errors"
Expand All @@ -21,6 +20,7 @@ import (
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"cosmossdk.io/core/address"
"cosmossdk.io/core/server"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
errorsmod "cosmossdk.io/errors"
Expand Down
3 changes: 2 additions & 1 deletion server/v2/stf/core_branch_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"errors"
"testing"

gogotypes "github.com/cosmos/gogoproto/types"

appmodulev2 "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/server/v2/stf/branch"
"cosmossdk.io/server/v2/stf/gas"
"cosmossdk.io/server/v2/stf/mock"
gogotypes "github.com/cosmos/gogoproto/types"
)

func TestBranchService(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions x/consensus/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package consensus

import (
"context"

modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/server"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
"cosmossdk.io/x/consensus/keeper"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
Expand Down
19 changes: 19 additions & 0 deletions x/upgrade/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/header"
"cosmossdk.io/core/server"
coretesting "cosmossdk.io/core/testing"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -132,6 +133,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite {
s.env = runtime.NewEnvironment(storeService, coretesting.NewNopLogger(), runtime.EnvWithMsgRouterService(s.baseApp.MsgServiceRouter()), runtime.EnvWithQueryRouterService(s.baseApp.GRPCQueryRouter()))

s.baseApp.SetParamStore(&paramStore{params: cmtproto.ConsensusParams{Version: &cmtproto.VersionParams{App: 1}}})
s.baseApp.SetVersionModifier(newMockedVersionModifier(1))

authority, err := addresscodec.NewBech32Codec("cosmos").BytesToString(authtypes.NewModuleAddress(govModuleName))
require.NoError(t, err)
Expand All @@ -144,6 +146,23 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite {
return &s
}

func newMockedVersionModifier(startingVersion uint64) server.VersionModifier {
return &mockedVersionModifier{version: startingVersion}
}

type mockedVersionModifier struct {
version uint64
}

func (m *mockedVersionModifier) SetAppVersion(ctx context.Context, u uint64) error {
m.version = u
return nil
}

func (m *mockedVersionModifier) AppVersion(ctx context.Context) (uint64, error) {
return m.version, nil
}

func TestRequireFutureBlock(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height - 1})
Expand Down
2 changes: 2 additions & 0 deletions x/upgrade/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (s *KeeperTestSuite) SetupTest() {
s.encCfg.TxConfig.TxDecoder(),
)
s.baseApp.SetParamStore(&paramStore{params: cmttypes.DefaultConsensusParams().ToProto()})
s.baseApp.SetVersionModifier(newMockedVersionModifier(0))

appVersion, err := s.baseApp.AppVersion(context.Background())
s.Require().NoError(err)
s.Require().Equal(uint64(0), appVersion)
Expand Down

0 comments on commit 02b20f9

Please sign in to comment.