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

test: fix failing tests after protocompat changes (backport #22889) #22897

Merged
merged 3 commits into from
Dec 16, 2024
Merged
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
32 changes: 22 additions & 10 deletions baseapp/internal/protocompat/protocompat.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,13 @@ func makeGogoHybridHandler(prefMethod protoreflect.MethodDescriptor, cdc codec.B
return fmt.Errorf("invalid request type %T, method %s does not accept protov2 messages", inReq, prefMethod.FullName())
}
resp, err := method.Handler(handler, ctx, func(msg any) error {
setPointer(msg, inReq)
return nil
return setPointer(msg, inReq)
}, nil)
if err != nil {
return err
}
setPointer(outResp, resp)
return nil

return setPointer(outResp, resp)
}, nil
}
// this is a gogo handler, and we have a protov2 counterparty.
Expand Down Expand Up @@ -161,14 +160,13 @@ func makeGogoHybridHandler(prefMethod protoreflect.MethodDescriptor, cdc codec.B
case gogoproto.Message:
// we can just call the handler after making a copy of the message, for safety reasons.
resp, err := method.Handler(handler, ctx, func(msg any) error {
setPointer(msg, m)
return nil
return setPointer(msg, m)
}, nil)
if err != nil {
return err
}
setPointer(outResp, resp)
return nil

return setPointer(outResp, resp)
default:
panic("unreachable")
}
Expand Down Expand Up @@ -235,6 +233,20 @@ func ResponseFullNameFromMethodDesc(sd *grpc.ServiceDesc, method grpc.MethodDesc

// since proto.Merge breaks due to the custom cosmos sdk any, we are forced to do this ugly setPointer hack.
// ref: https://github.com/cosmos/cosmos-sdk/issues/22779
func setPointer(dst, src any) {
reflect.ValueOf(dst).Elem().Set(reflect.ValueOf(src).Elem())
func setPointer(dst, src any) error {
dstValue := reflect.ValueOf(dst)
srcValue := reflect.ValueOf(src)
if !dstValue.IsValid() || !srcValue.IsValid() {
return fmt.Errorf("dst and src must be valid")
}
if dstValue.IsNil() || srcValue.IsNil() {
return fmt.Errorf("dst and src must be non-nil")
}
dstElem := dstValue.Elem()
srcElem := srcValue.Elem()
if dstElem.Type() != srcElem.Type() {
return fmt.Errorf("dst and src must have the same type")
}
dstElem.Set(srcElem)
return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ go 1.23.2
module github.com/cosmos/cosmos-sdk

require (
buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.2-20241120201313-68e42a58b301.1
buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.2-20241120201313-68e42a58b301.1 // indirect
cosmossdk.io/api v0.8.0-rc.2 // main
cosmossdk.io/collections v0.4.1-0.20241209183624-332d0b106d1b // main
cosmossdk.io/core v1.0.0-alpha.6
Expand Down
2 changes: 1 addition & 1 deletion scripts/mockgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $mockgen_cmd -source=x/mint/types/expected_keepers.go -package testutil -destina
$mockgen_cmd -source=x/auth/tx/config/expected_keepers.go -package testutil -destination x/auth/tx/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/types/expected_keepers.go -package testutil -destination x/auth/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/ante/expected_keepers.go -package testutil -destination x/auth/ante/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/authz/expected_keepers.go -package testutil -destination x/authz/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/authz/testutil/expected_keepers.go -package testutil -destination x/authz/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/bank/types/expected_keepers.go -package testutil -destination x/bank/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/group/testutil/expected_keepers.go -package testutil -destination x/group/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/evidence/types/expected_keepers.go -package testutil -destination x/evidence/testutil/expected_keepers_mocks.go
Expand Down
1 change: 1 addition & 0 deletions x/authz/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (s *TestSuite) SetupTest() {
s.accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()

s.bankKeeper = authztestutil.NewMockBankKeeper(ctrl)
s.bankKeeper.EXPECT().Send(gomock.Any(), gomock.Any()).Return(&banktypes.MsgSendResponse{}, nil).AnyTimes()
banktypes.RegisterInterfaces(s.encCfg.InterfaceRegistry)
banktypes.RegisterMsgServer(s.baseApp.MsgServiceRouter(), s.bankKeeper)

Expand Down
29 changes: 0 additions & 29 deletions x/authz/testutil/bank_helpers.go

This file was deleted.

27 changes: 27 additions & 0 deletions x/authz/testutil/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package testutil

import (
"context"

"cosmossdk.io/core/address"
banktypes "cosmossdk.io/x/bank/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// AccountKeeper defines the expected account keeper (noalias)
type AccountKeeper interface {
AddressCodec() address.Codec
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
}

// BankKeeper extends bank `MsgServer` to mock `Send` and to register handlers in MsgServiceRouter
type BankKeeper interface {
banktypes.MsgServer

SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}
137 changes: 118 additions & 19 deletions x/authz/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading