diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index 1966a201847c..c0248d7f58a7 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -131,10 +131,18 @@ func (s txServer) GetTx(ctx context.Context, req *txtypes.GetTxRequest) (*txtype return nil, status.Error(codes.InvalidArgument, "request cannot be nil") } + if len(req.Hash) == 0 { + return nil, status.Error(codes.InvalidArgument, "tx hash cannot be empty") + } + // TODO We should also check the proof flag in gRPC header. // https://github.com/cosmos/cosmos-sdk/issues/7036. result, err := queryTx(ctx, s.clientCtx, req.Hash) if err != nil { + if strings.Contains(err.Error(), "not found") { + return nil, status.Errorf(codes.NotFound, "tx not found: %s", req.Hash) + } + return nil, err } diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index 4c13e8354df1..e82baca41534 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -328,8 +328,8 @@ func (s IntegrationTestSuite) TestGetTx_GRPC() { expErrMsg string }{ {"nil request", nil, true, "request cannot be nil"}, - {"empty request", &tx.GetTxRequest{}, true, "transaction hash cannot be empty"}, - {"request with dummy hash", &tx.GetTxRequest{Hash: "deadbeef"}, true, "tx (DEADBEEF) not found"}, + {"empty request", &tx.GetTxRequest{}, true, "tx hash cannot be empty"}, + {"request with dummy hash", &tx.GetTxRequest{Hash: "deadbeef"}, true, "code = NotFound desc = tx not found: deadbeef"}, {"good request", &tx.GetTxRequest{Hash: s.txRes.TxHash}, false, ""}, } for _, tc := range testCases { @@ -358,12 +358,12 @@ func (s IntegrationTestSuite) TestGetTx_GRPCGateway() { { "empty params", fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/", val.APIAddress), - true, "transaction hash cannot be empty", + true, "tx hash cannot be empty", }, { "dummy hash", fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, "deadbeef"), - true, "tx (DEADBEEF) not found", + true, "code = NotFound desc = tx not found: deadbeef", }, { "good hash",