From 02b20f99afbd61e407730c14b2d2d825ae514efa Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 7 Sep 2024 16:41:33 +0200 Subject: [PATCH] test(x/upgrade): fix tests (#21582) --- baseapp/baseapp.go | 2 +- baseapp/options.go | 2 +- baseapp/utils_test.go | 2 +- server/v2/stf/core_branch_service_test.go | 3 ++- x/consensus/depinject.go | 2 ++ x/upgrade/keeper/abci_test.go | 19 +++++++++++++++++++ x/upgrade/keeper/keeper_test.go | 2 ++ 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 05c0a5ce1638..89748eadf053 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -2,7 +2,6 @@ package baseapp import ( "context" - "cosmossdk.io/core/server" "errors" "fmt" "maps" @@ -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" diff --git a/baseapp/options.go b/baseapp/options.go index 05c4467a0ef4..53286b2540b9 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -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" diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 6794a4ae1617..0cf141055fa9 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -3,7 +3,6 @@ package baseapp_test import ( "bytes" "context" - "cosmossdk.io/core/server" "encoding/binary" "encoding/json" "errors" @@ -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" diff --git a/server/v2/stf/core_branch_service_test.go b/server/v2/stf/core_branch_service_test.go index 0394ce0f3b1a..420fefb3e50b 100644 --- a/server/v2/stf/core_branch_service_test.go +++ b/server/v2/stf/core_branch_service_test.go @@ -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) { diff --git a/x/consensus/depinject.go b/x/consensus/depinject.go index 07048b4c8684..f5e71717c724 100644 --- a/x/consensus/depinject.go +++ b/x/consensus/depinject.go @@ -2,6 +2,7 @@ package consensus import ( "context" + modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" @@ -9,6 +10,7 @@ import ( "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" diff --git a/x/upgrade/keeper/abci_test.go b/x/upgrade/keeper/abci_test.go index 5ae0fd23ff7d..200594436f95 100644 --- a/x/upgrade/keeper/abci_test.go +++ b/x/upgrade/keeper/abci_test.go @@ -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" @@ -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(¶mStore{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) @@ -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}) diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 0aabb13500b9..d211c8fedcfe 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -60,6 +60,8 @@ func (s *KeeperTestSuite) SetupTest() { s.encCfg.TxConfig.TxDecoder(), ) s.baseApp.SetParamStore(¶mStore{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)