From a51eac4f15a7f8110e529df9460fa7126c427aa3 Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1413@users.noreply.github.com> Date: Tue, 1 Dec 2020 09:48:35 +0530 Subject: [PATCH] Fix QueryByEvents with multiple events and empty pagination request (#8029) * fix pagination issue * Fix querying with multiple events * reuse ParsePagination * update tests * change event type to array * fix test * review changes * add test case for escape params * review changes * resolve conflicts * fix test * fix test Co-authored-by: anilCSE Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- proto/cosmos/tx/v1beta1/service.proto | 4 +- server/grpc/server_test.go | 4 +- types/tx/service.pb.go | 104 +++++++++++++------------- x/auth/tx/service.go | 29 ++----- x/auth/tx/service_test.go | 73 +++++++++++++++--- 5 files changed, 127 insertions(+), 87 deletions(-) diff --git a/proto/cosmos/tx/v1beta1/service.proto b/proto/cosmos/tx/v1beta1/service.proto index d78216d031e4..68eaaae83395 100644 --- a/proto/cosmos/tx/v1beta1/service.proto +++ b/proto/cosmos/tx/v1beta1/service.proto @@ -28,8 +28,8 @@ service Service { // GetTxsEventRequest is the request type for the Service.TxsByEvents // RPC method. message GetTxsEventRequest { - // event is the transaction event type. - string event = 1; + // events is the list of transaction event type. + repeated string events = 1; // pagination defines an pagination for the request. cosmos.base.query.v1beta1.PageRequest pagination = 2; } diff --git a/server/grpc/server_test.go b/server/grpc/server_test.go index 9afa0b750b04..59c726c6abaf 100644 --- a/server/grpc/server_test.go +++ b/server/grpc/server_test.go @@ -107,12 +107,12 @@ func (s *IntegrationTestSuite) TestGRPCServer() { _, err = txServiceClient.GetTxsEvent( context.Background(), &tx.GetTxsEventRequest{ - Event: "message.action=send", + Events: []string{"message.action=send"}, }, ) // TODO Once https://github.com/cosmos/cosmos-sdk/pull/8029 is merged, this // should not error anymore. - s.Require().Error(err) + s.Require().NoError(err) } // Test and enforce that we upfront reject any connections to baseapp containing diff --git a/types/tx/service.pb.go b/types/tx/service.pb.go index 2302593c5c75..44242b03116d 100644 --- a/types/tx/service.pb.go +++ b/types/tx/service.pb.go @@ -33,8 +33,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GetTxsEventRequest is the request type for the Service.TxsByEvents // RPC method. type GetTxsEventRequest struct { - // event is the transaction event type. - Event string `protobuf:"bytes,1,opt,name=event,proto3" json:"event,omitempty"` + // events is the list of transaction event type. + Events []string `protobuf:"bytes,1,rep,name=events,proto3" json:"events,omitempty"` // pagination defines an pagination for the request. Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } @@ -72,11 +72,11 @@ func (m *GetTxsEventRequest) XXX_DiscardUnknown() { var xxx_messageInfo_GetTxsEventRequest proto.InternalMessageInfo -func (m *GetTxsEventRequest) GetEvent() string { +func (m *GetTxsEventRequest) GetEvents() []string { if m != nil { - return m.Event + return m.Events } - return "" + return nil } func (m *GetTxsEventRequest) GetPagination() *query.PageRequest { @@ -370,40 +370,40 @@ func init() { proto.RegisterFile("cosmos/tx/v1beta1/service.proto", fileDescript var fileDescriptor_e0b00a618705eca7 = []byte{ // 563 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xae, 0x1d, 0xfa, 0xc3, 0xa4, 0x08, 0x58, 0x7e, 0x14, 0x99, 0xe2, 0x06, 0xa7, 0x69, 0x23, - 0x24, 0xbc, 0x6a, 0xb8, 0xf4, 0x80, 0x84, 0x84, 0x54, 0x22, 0x6e, 0xc8, 0xed, 0x89, 0x4b, 0xb5, - 0x09, 0x5b, 0xc7, 0x22, 0xf1, 0xba, 0xde, 0x4d, 0xb4, 0x15, 0xf4, 0xc2, 0x91, 0x13, 0x12, 0x2f, - 0xc5, 0x31, 0x12, 0x17, 0x8e, 0x28, 0xe1, 0x0d, 0x78, 0x01, 0xe4, 0xf5, 0x3a, 0x71, 0xa8, 0x4d, - 0x7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0xe6, 0x47, 0x68, 0xd5, 0x8a, 0x01, 0xda, 0x70, 0x47, 0x19, 0xda, 0x64, 0xcb, + 0x5b, 0x76, 0xd5, 0xde, 0xc7, 0x64, 0xea, 0x97, 0xe4, 0x13, 0x54, 0x72, 0x37, 0x43, 0x1a, 0x45, + 0xb2, 0x0b, 0xa7, 0x6c, 0xed, 0x5e, 0x07, 0xd3, 0x3d, 0xd8, 0xaa, 0x87, 0x2a, 0xd9, 0x5c, 0xda, + 0x83, 0x78, 0xf5, 0xf2, 0xfb, 0xc4, 0x36, 0xc6, 0x13, 0xdb, 0xf8, 0x35, 0xb1, 0x8d, 0xaf, 0x53, + 0x7b, 0x65, 0x3c, 0xb5, 0x57, 0x7e, 0x4e, 0xed, 0x95, 0x77, 0x8d, 0x20, 0xc4, 0xee, 0xb0, 0xed, + 0x76, 0x78, 0x3f, 0xe3, 0xa6, 0x3f, 0xcf, 0xc4, 0xfb, 0x0f, 0x1e, 0x5e, 0xc4, 0x2c, 0x11, 0x6b, + 0x97, 0xd5, 0x07, 0xe7, 0xf9, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x62, 0x59, 0xdc, 0x70, 0x31, 0x05, 0x00, 0x00, } @@ -597,12 +597,14 @@ func (m *GetTxsEventRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Event) > 0 { - i -= len(m.Event) - copy(dAtA[i:], m.Event) - i = encodeVarintService(dAtA, i, uint64(len(m.Event))) - i-- - dAtA[i] = 0xa + if len(m.Events) > 0 { + for iNdEx := len(m.Events) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Events[iNdEx]) + copy(dAtA[i:], m.Events[iNdEx]) + i = encodeVarintService(dAtA, i, uint64(len(m.Events[iNdEx]))) + i-- + dAtA[i] = 0xa + } } return len(dAtA) - i, nil } @@ -846,9 +848,11 @@ func (m *GetTxsEventRequest) Size() (n int) { } var l int _ = l - l = len(m.Event) - if l > 0 { - n += 1 + l + sovService(uint64(l)) + if len(m.Events) > 0 { + for _, s := range m.Events { + l = len(s) + n += 1 + l + sovService(uint64(l)) + } } if m.Pagination != nil { l = m.Pagination.Size() @@ -979,7 +983,7 @@ func (m *GetTxsEventRequest) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Event", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Events", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1007,7 +1011,7 @@ func (m *GetTxsEventRequest) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Event = string(dAtA[iNdEx:postIndex]) + m.Events = append(m.Events, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex case 2: if wireType != 2 { diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index b12808a16403..751c8fbb22b2 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -49,32 +49,17 @@ const ( // TxsByEvents implements the ServiceServer.TxsByEvents RPC method. func (s txServer) GetTxsEvent(ctx context.Context, req *txtypes.GetTxsEventRequest) (*txtypes.GetTxsEventResponse, error) { - offset := int(req.Pagination.Offset) - limit := int(req.Pagination.Limit) - if offset < 0 { - return nil, status.Error(codes.InvalidArgument, "offset must greater than 0") - } - if len(req.Event) == 0 { - return nil, status.Error(codes.InvalidArgument, "must declare at least one event to search") + page, limit, err := pagination.ParsePagination(req.Pagination) + if err != nil { + return nil, err } - if limit < 0 { - return nil, status.Error(codes.InvalidArgument, "limit must greater than 0") - } else if limit == 0 { - limit = pagination.DefaultLimit + if len(req.Events) == 0 { + return nil, status.Error(codes.InvalidArgument, "must declare at least one event to search") } - page := offset/limit + 1 - - var events []string - - if strings.Contains(req.Event, "&") { - events = strings.Split(req.Event, "&") - } else { - events = append(events, req.Event) - } - tmEvents := make([]string, len(events)) - for i, event := range events { + tmEvents := make([]string, len(req.Events)) + for i, event := range req.Events { if !strings.Contains(event, "=") { return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid event; event %s should be of the format: %s", event, eventFormat)) } else if strings.Count(event, "=") > 1 { diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index 54fe14fd72f3..480529541794 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -124,11 +124,18 @@ func (s IntegrationTestSuite) TestGetTxEvents() { s.Require().NoError(s.network.WaitForNextBlock()) + // Query the tx via gRPC empty params. + _, err = s.queryClient.GetTxsEvent( + context.Background(), + &tx.GetTxsEventRequest{}, + ) + s.Require().Error(err) + // Query the tx via gRPC. grpcRes, err := s.queryClient.GetTxsEvent( context.Background(), &tx.GetTxsEventRequest{ - Event: "message.action=send", + Events: []string{"message.action=send"}, Pagination: &query.PageRequest{ CountTotal: false, Offset: 0, @@ -145,21 +152,65 @@ func (s IntegrationTestSuite) TestGetTxEvents() { grpcRes, err = s.queryClient.GetTxsEvent( context.Background(), &tx.GetTxsEventRequest{ - Event: "message.action=send", + Events: []string{"message.action=send"}, }, ) // TODO Once https://github.com/cosmos/cosmos-sdk/pull/8029 is merged, this // should not error anymore. - s.Require().Error(err) - - // Query the tx via grpc-gateway. - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?event=%s&pagination.offset=%d&pagination.limit=%d", val.APIAddress, "message.action=send", 0, 1)) s.Require().NoError(err) - var getTxRes tx.GetTxsEventResponse - s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(restRes, &getTxRes)) - s.Require().Equal(len(getTxRes.Txs), 1) - s.Require().Equal("foobar", getTxRes.Txs[0].Body.Memo) - s.Require().NotZero(getTxRes.TxResponses[0].Height) + + rpcTests := []struct { + name string + url string + expectErr bool + expErrMsg string + }{ + { + "empty params", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.APIAddress), + true, + "must declare at least one event to search", + }, + { + "without pagination", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action=send"), + false, + "", + }, + { + "with pagination", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&pagination.offset=%d&pagination.limit=%d", val.APIAddress, "message.action=send", 0, 10), + false, + "", + }, + { + "expect pass with multiple-events", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s&events=%s", val.APIAddress, "message.action=send", "message.module=bank"), + false, + "", + }, + { + "expect pass with escape event", + fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?events=%s", val.APIAddress, "message.action%3Dsend"), + false, + "", + }, + } + for _, tc := range rpcTests { + s.Run(tc.name, func() { + res, err := rest.GetRequest(tc.url) + s.Require().NoError(err) + if tc.expectErr { + s.Require().Contains(string(res), tc.expErrMsg) + } else { + var result tx.GetTxsEventResponse + val.ClientCtx.JSONMarshaler.UnmarshalJSON(res, &result) + s.Require().GreaterOrEqual(len(result.Txs), 1) + s.Require().Equal("foobar", result.Txs[0].Body.Memo) + s.Require().NotZero(result.TxResponses[0].Height) + } + }) + } } func (s IntegrationTestSuite) TestGetTx() {