diff --git a/app/app.go b/app/app.go index ff551496b..b6e0f9d8c 100644 --- a/app/app.go +++ b/app/app.go @@ -291,7 +291,7 @@ type App struct { CronKeeper cronkeeper.Keeper RouterKeeper *routerkeeper.Keeper - WasmMsgServer wasmtypes.MsgServer + WasmMsgServer *wasmtypes.MsgServer RouterModule router.AppModule @@ -683,8 +683,9 @@ func New( ) wasmHooks.ContractKeeper = &app.WasmKeeper - app.WasmMsgServer = wasmkeeper.NewMsgServerImpl(&app.WasmKeeper) // to use in upgrade - app.CronKeeper.WasmMsgServer = app.WasmMsgServer + wasmMsgServer := wasmkeeper.NewMsgServerImpl(&app.WasmKeeper) + app.WasmMsgServer = &wasmMsgServer // to use in upgrade + app.CronKeeper.WasmMsgServer = *app.WasmMsgServer cronModule := cron.NewAppModule(appCodec, app.CronKeeper) transferIBCModule := transferSudo.NewIBCModule( @@ -1026,7 +1027,7 @@ func (app *App) setupUpgradeHandlers() { BuilderKeeper: app.BuilderKeeper, ContractManagerKeeper: app.ContractManagerKeeper, AdminModuleKeeper: app.AdminmoduleKeeper, - WasmMsgServer: app.WasmMsgServer, + WasmMsgServer: *app.WasmMsgServer, GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName), CcvConsumerSubspace: app.GetSubspace(ccvconsumertypes.ModuleName), }, diff --git a/app/upgrades/expected_keepers.go b/app/upgrades/expected_keepers.go new file mode 100644 index 000000000..c60825eba --- /dev/null +++ b/app/upgrades/expected_keepers.go @@ -0,0 +1,11 @@ +package upgrades + +import ( + "context" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" +) + +type WasmMsgServer interface { + MigrateContract(context.Context, *wasmtypes.MsgMigrateContract) (*wasmtypes.MsgMigrateContractResponse, error) + // Methods imported from account should be defined here +} diff --git a/app/upgrades/nextupgrade/upgrades.go b/app/upgrades/nextupgrade/upgrades.go index 96f8959ee..38f844c11 100644 --- a/app/upgrades/nextupgrade/upgrades.go +++ b/app/upgrades/nextupgrade/upgrades.go @@ -115,10 +115,12 @@ func CreateUpgradeHandler( return vm, err } - err = migrateDaoContracts(ctx, keepers) - if err != nil { - ctx.Logger().Error("failed to migrate DAO contracts", "err", err) - return vm, err + if plan.Info != "testing_turn_off_contract_migrations" { + err = migrateDaoContracts(ctx, keepers) + if err != nil { + ctx.Logger().Error("failed to migrate DAO contracts", "err", err) + return vm, err + } } ctx.Logger().Info("Upgrade complete") @@ -429,8 +431,8 @@ func migrateDaoContracts(ctx sdk.Context, keepers *upgrades.UpgradeKeepers) erro } func migrateContract(ctx sdk.Context, keepers *upgrades.UpgradeKeepers, contractAddress string, codeId uint64, msg string) error { - _, err := keepers.WasmMsgServer.MigrateContract(ctx.Context(), &wasmtypes.MsgMigrateContract{ - Sender: "maindao", + _, err := keepers.WasmMsgServer.MigrateContract(sdk.WrapSDKContext(ctx), &wasmtypes.MsgMigrateContract{ + Sender: "neutron1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrstdxvff", // main dao Contract: contractAddress, CodeID: codeId, Msg: []byte(msg), diff --git a/app/upgrades/nextupgrade/upgrades_test.go b/app/upgrades/nextupgrade/upgrades_test.go index f3146ae7a..bc54d1486 100644 --- a/app/upgrades/nextupgrade/upgrades_test.go +++ b/app/upgrades/nextupgrade/upgrades_test.go @@ -1,6 +1,7 @@ package nextupgrade_test import ( + "github.com/neutron-org/neutron/app/upgrades/nextupgrade" "testing" adminmoduletypes "github.com/cosmos/admin-module/x/adminmodule/types" @@ -24,7 +25,6 @@ import ( ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" "github.com/stretchr/testify/suite" - "github.com/neutron-org/neutron/app/upgrades/nextupgrade" "github.com/neutron-org/neutron/testutil" ) @@ -66,11 +66,16 @@ func (suite *UpgradeTestSuite) SetupTest() { } func (suite *UpgradeTestSuite) TestGlobalFeesUpgrade() { + //ctrl := gomock.NewController(suite.T()) + //defer ctrl.Finish() + var ( app = suite.GetNeutronZoneApp(suite.ChainA) globalFeeSubspace = app.GetSubspace(globalfee.ModuleName) ctx = suite.ChainA.GetContext() ) + //app.WasmMsgServer = mock_upgrades.NewMockWasmMsgServer(ctrl) + //feeKeeper.EXPECT().DistributeAcknowledgementFee(ctx, relayerAddress, feetypes.NewPacketID(p.SourcePort, p.SourceChannel, p.Sequence)) suite.Require().True(globalFeeSubspace.Has(ctx, globalfeetypes.ParamStoreKeyMinGasPrices)) suite.Require().True(globalFeeSubspace.Has(ctx, globalfeetypes.ParamStoreKeyBypassMinFeeMsgTypes)) @@ -78,7 +83,7 @@ func (suite *UpgradeTestSuite) TestGlobalFeesUpgrade() { upgrade := upgradetypes.Plan{ Name: nextupgrade.UpgradeName, - Info: "some text here", + Info: "testing_turn_off_contract_migrations", Height: 100, } app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade) @@ -129,7 +134,7 @@ func (suite *UpgradeTestSuite) TestRewardDenomsUpgrade() { upgrade := upgradetypes.Plan{ Name: nextupgrade.UpgradeName, - Info: "some text here", + Info: "testing_turn_off_contract_migrations", Height: 100, } app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade) @@ -157,7 +162,7 @@ func (suite *UpgradeTestSuite) TestAdminModuleUpgrade() { upgrade := upgradetypes.Plan{ Name: nextupgrade.UpgradeName, - Info: "some text here", + Info: "testing_turn_off_contract_migrations", Height: 100, } app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade) diff --git a/app/upgrades/types.go b/app/upgrades/types.go index a0c51c3f8..f6dc8eb0b 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -1,7 +1,6 @@ package upgrades import ( - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" adminmodulekeeper "github.com/cosmos/admin-module/x/adminmodule/keeper" "github.com/cosmos/cosmos-sdk/codec" store "github.com/cosmos/cosmos-sdk/store/types" @@ -48,7 +47,7 @@ type UpgradeKeepers struct { BuilderKeeper builderkeeper.Keeper ContractManagerKeeper contractmanagerkeeper.Keeper AdminModuleKeeper adminmodulekeeper.Keeper - WasmMsgServer wasmtypes.MsgServer + WasmMsgServer WasmMsgServer // subspaces GlobalFeeSubspace paramtypes.Subspace CcvConsumerSubspace paramtypes.Subspace diff --git a/testutil/mocks/gomock.go b/testutil/mocks/gomock.go index b9f0de766..8926dbc45 100644 --- a/testutil/mocks/gomock.go +++ b/testutil/mocks/gomock.go @@ -8,3 +8,4 @@ package mocks //go:generate mockgen -source=./../../x/transfer/types/expected_keepers.go -destination ./transfer/types/expected_keepers.go //go:generate mockgen -source=./../../x/feeburner/types/expected_keepers.go -destination ./feeburner/types/expected_keepers.go //go:generate mockgen -source=./../../x/cron/types/expected_keepers.go -destination ./cron/types/expected_keepers.go +//go:generate mockgen -source=./../../x/app/upgrades/expected_keepers.go -destination ./upgrades/types/expected_keepers.go diff --git a/testutil/mocks/upgrades/types/expected_keepers.go b/testutil/mocks/upgrades/types/expected_keepers.go new file mode 100644 index 000000000..632b336a3 --- /dev/null +++ b/testutil/mocks/upgrades/types/expected_keepers.go @@ -0,0 +1,51 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./../../app/upgrades/expected_keepers.go + +// Package mock_upgrades is a generated GoMock package. +package mock_upgrades + +import ( + context "context" + reflect "reflect" + + types "github.com/CosmWasm/wasmd/x/wasm/types" + gomock "github.com/golang/mock/gomock" +) + +// MockWasmMsgServer is a mock of WasmMsgServer interface. +type MockWasmMsgServer struct { + ctrl *gomock.Controller + recorder *MockWasmMsgServerMockRecorder +} + +// MockWasmMsgServerMockRecorder is the mock recorder for MockWasmMsgServer. +type MockWasmMsgServerMockRecorder struct { + mock *MockWasmMsgServer +} + +// NewMockWasmMsgServer creates a new mock instance. +func NewMockWasmMsgServer(ctrl *gomock.Controller) *MockWasmMsgServer { + mock := &MockWasmMsgServer{ctrl: ctrl} + mock.recorder = &MockWasmMsgServerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWasmMsgServer) EXPECT() *MockWasmMsgServerMockRecorder { + return m.recorder +} + +// MigrateContract mocks base method. +func (m *MockWasmMsgServer) MigrateContract(arg0 context.Context, arg1 *types.MsgMigrateContract) (*types.MsgMigrateContractResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MigrateContract", arg0, arg1) + ret0, _ := ret[0].(*types.MsgMigrateContractResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// MigrateContract indicates an expected call of MigrateContract. +func (mr *MockWasmMsgServerMockRecorder) MigrateContract(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MigrateContract", reflect.TypeOf((*MockWasmMsgServer)(nil).MigrateContract), arg0, arg1) +}