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

Fix QueryByEvents with multiple events and empty pagination request #8029

Merged
merged 20 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 10 additions & 3 deletions x/auth/tx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/hex"
"fmt"
"net/url"
"strings"

gogogrpc "github.com/gogo/protobuf/grpc"
Expand Down Expand Up @@ -56,11 +57,17 @@ func (s txServer) GetTxsEvent(ctx context.Context, req *txtypes.GetTxsEventReque

var events []string

if strings.Contains(req.Event, "&") {
events = strings.Split(req.Event, "&")
eve, err := url.QueryUnescape(req.Event)
if err != nil {
return nil, err
}

if strings.Contains(eve, "&") {
events = strings.Split(eve, "&")
} else {
events = append(events, req.Event)
events = append(events, eve)
}

tmEvents := make([]string, len(events))
for i, event := range events {
if !strings.Contains(event, "=") {
Expand Down
5 changes: 3 additions & 2 deletions x/auth/tx/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tx_test
import (
"context"
"fmt"
"net/url"
"testing"

"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -134,7 +135,7 @@ func (s IntegrationTestSuite) TestGetTxEvents() {
// Query the tx via gRPC no pagination.
_, err = s.queryClient.GetTxsEvent(
context.Background(),
&tx.GetTxsEventRequest{Event: "message.action=send"},
&tx.GetTxsEventRequest{Event: url.QueryEscape(fmt.Sprintf("message.action=%s&transfer.sender=%s", "send", val.Address))},
)
s.Require().NoError(err)

Expand Down Expand Up @@ -164,7 +165,7 @@ func (s IntegrationTestSuite) TestGetTxEvents() {
s.Require().NoError(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))
restRes, err = rest.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?event=%s&pagination.offset=%d&pagination.limit=%d", val.APIAddress, "message.action%3Dsend", 0, 1))
s.Require().NoError(err)
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(restRes, &getTxRes))
s.Require().Equal(len(getTxRes.Txs), 1)
Expand Down