-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 #22889
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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") | ||
} | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worthwhile to test this function to ensure no regressions. Is there a function where it is already indirectly exercised? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the failing tests :D |
||
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 | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package testutil | ||
|
||
import ( | ||
"context" | ||
|
||
banktypes "cosmossdk.io/x/bank/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// 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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
took this from the original PR coderabbit suggestion, as it best if we don't panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense!