Skip to content

Commit 1581289

Browse files
authored
fix: return 404 on non-existing tx (#10992)
1 parent 96bc6a5 commit 1581289

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
151151

152152
### Bug Fixes
153153

154+
* (grpc) [\#10985](https://github.com/cosmos/cosmos-sdk/pull/10992) The `/cosmos/tx/v1beta1/txs/{hash}` endpoint returns a 404 when a tx does not exist.
154155
* (rosetta) [\#10340](https://github.com/cosmos/cosmos-sdk/pull/10340) Use `GenesisChunked(ctx)` instead `Genesis(ctx)` to get genesis block height
155156
* [#10180](https://github.com/cosmos/cosmos-sdk/issues/10180) Documentation: make references to Cosmos SDK consistent
156157
* [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter.

x/auth/tx/service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,18 @@ func (s txServer) GetTx(ctx context.Context, req *txtypes.GetTxRequest) (*txtype
131131
return nil, status.Error(codes.InvalidArgument, "request cannot be nil")
132132
}
133133

134+
if len(req.Hash) == 0 {
135+
return nil, status.Error(codes.InvalidArgument, "tx hash cannot be empty")
136+
}
137+
134138
// TODO We should also check the proof flag in gRPC header.
135139
// https://github.com/cosmos/cosmos-sdk/issues/7036.
136140
result, err := QueryTx(s.clientCtx, req.Hash)
137141
if err != nil {
142+
if strings.Contains(err.Error(), "not found") {
143+
return nil, status.Errorf(codes.NotFound, "tx not found: %s", req.Hash)
144+
}
145+
138146
return nil, err
139147
}
140148

x/auth/tx/service_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ func (s IntegrationTestSuite) TestGetTx_GRPC() {
341341
expErrMsg string
342342
}{
343343
{"nil request", nil, true, "request cannot be nil"},
344-
{"empty request", &tx.GetTxRequest{}, true, "transaction hash cannot be empty"},
345-
{"request with dummy hash", &tx.GetTxRequest{Hash: "deadbeef"}, true, "tx (DEADBEEF) not found"},
344+
{"empty request", &tx.GetTxRequest{}, true, "tx hash cannot be empty"},
345+
{"request with dummy hash", &tx.GetTxRequest{Hash: "deadbeef"}, true, "code = NotFound desc = tx not found: deadbeef"},
346346
{"good request", &tx.GetTxRequest{Hash: s.txRes.TxHash}, false, ""},
347347
}
348348
for _, tc := range testCases {
@@ -371,12 +371,12 @@ func (s IntegrationTestSuite) TestGetTx_GRPCGateway() {
371371
{
372372
"empty params",
373373
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/", val.APIAddress),
374-
true, "transaction hash cannot be empty",
374+
true, "tx hash cannot be empty",
375375
},
376376
{
377377
"dummy hash",
378378
fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, "deadbeef"),
379-
true, "tx (DEADBEEF) not found",
379+
true, "code = NotFound desc = tx not found: deadbeef",
380380
},
381381
{
382382
"good hash",

0 commit comments

Comments
 (0)