Skip to content

Commit

Permalink
clean up and fix accounts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 committed May 16, 2024
2 parents a975d34 + 4f3c49c commit e31f02a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* Every module has the codec already, passing it created an unneeded dependency.
* Additionally, to reflect this change, the module manager does not take a codec either.
* (runtime) [#19747](https://github.com/cosmos/cosmos-sdk/pull/19747) `runtime.ValidatorAddressCodec` and `runtime.ConsensusAddressCodec` have been moved to `core`.
* [#19839](https://github.com/cosmos/cosmos-sdk/pull/19839) `Tx.GetMsgsV2` has been replaced with `Tx.GetReflectMessages`, and `Codec.GetMsgV1Signers` and `Codec.GetMsgV2Signers` have been replaced with `GetMsgSigners` and `GetReflectMsgSigners` respectively. These API changes clear up confusin as to the use and purpose of these methods.
* [#19839](https://github.com/cosmos/cosmos-sdk/pull/19839) `Tx.GetMsgsV2` has been replaced with `Tx.GetReflectMessages`, and `Codec.GetMsgV1Signers` and `Codec.GetMsgV2Signers` have been replaced with `GetMsgSigners` and `GetReflectMsgSigners` respectively. These API changes clear up confusion as to the use and purpose of these methods.
* (baseapp) [#19993](https://github.com/cosmos/cosmos-sdk/pull/19993) Indicate pruning with error code "not found" rather than "invalid request".
* (x/consensus) [#20010](https://github.com/cosmos/cosmos-sdk/pull/20010) Move consensus module to be its own go.mod
* (server) [#20140](https://github.com/cosmos/cosmos-sdk/pull/20140) Remove embedded grpc-web proxy in favor of standalone grpc-web proxy. [Envoy Proxy](https://www.envoyproxy.io/docs/envoy/latest/start/start)
Expand Down
21 changes: 0 additions & 21 deletions x/accounts/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"errors"
"fmt"

gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/runtime/protoiface"

"cosmossdk.io/collections"
Expand Down Expand Up @@ -37,25 +35,6 @@ var (
AccountByNumber = collections.NewPrefix(2)
)

// QueryRouter represents a router which can be used to route queries to the correct module.
// It returns the handler given the message name, if multiple handlers are returned, then
// it is up to the caller to choose which one to call.
type QueryRouter interface {
HybridHandlerByRequestName(name string) []func(ctx context.Context, req, resp implementation.ProtoMsg) error
}

// MsgRouter represents a router which can be used to route messages to the correct module.
type MsgRouter interface {
HybridHandlerByMsgName(msgName string) func(ctx context.Context, req, resp implementation.ProtoMsg) error
ResponseNameByMsgName(name string) string
}

// SignerProvider defines an interface used to get the expected sender from a message.
type SignerProvider interface {
// GetMsgSigners returns the signers of the message.
GetMsgSigners(msg gogoproto.Message) ([][]byte, protoreflect.Message, error)
}

type InterfaceRegistry interface {
RegisterInterface(name string, iface any, impls ...protoiface.MessageV1)
RegisterImplementations(iface any, impls ...protoiface.MessageV1)
Expand Down
21 changes: 8 additions & 13 deletions x/accounts/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

gogoproto "github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/runtime/protoiface"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
"cosmossdk.io/collections/colltest"
"cosmossdk.io/core/address"
"cosmossdk.io/core/event"
Expand Down Expand Up @@ -88,22 +88,17 @@ type bankQueryServer struct {
bankv1beta1.UnimplementedQueryServer
}

var _ SignerProvider = (*mockSigner)(nil)

type mockSigner func(msg implementation.ProtoMsg) ([]byte, error)

func (m mockSigner) GetMsgSigners(msg gogoproto.Message) ([][]byte, protoreflect.Message, error) {
s, err := m(msg)
if err != nil {
return nil, nil, err
}
return [][]byte{s}, nil, nil
}

type bankMsgServer struct {
bankv1beta1.UnimplementedMsgServer
}

func (b bankQueryServer) Balance(context.Context, *bankv1beta1.QueryBalanceRequest) (*bankv1beta1.QueryBalanceResponse, error) {
return &bankv1beta1.QueryBalanceResponse{Balance: &basev1beta1.Coin{
Denom: "atom",
Amount: "1000",
}}, nil
}

func (b bankMsgServer) Send(context.Context, *bankv1beta1.MsgSend) (*bankv1beta1.MsgSendResponse, error) {
return &bankv1beta1.MsgSendResponse{}, nil
}

0 comments on commit e31f02a

Please sign in to comment.