Skip to content

Commit

Permalink
fix: return 404 on non-existing tx (cosmos#10992)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Jan 24, 2022
1 parent 96bc6a5 commit 1581289
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (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.
* (rosetta) [\#10340](https://github.com/cosmos/cosmos-sdk/pull/10340) Use `GenesisChunked(ctx)` instead `Genesis(ctx)` to get genesis block height
* [#10180](https://github.com/cosmos/cosmos-sdk/issues/10180) Documentation: make references to Cosmos SDK consistent
* [\#9651](https://github.com/cosmos/cosmos-sdk/pull/9651) Change inconsistent limit of `0` to `MaxUint64` on InfiniteGasMeter and add GasRemaining func to GasMeter.
Expand Down
8 changes: 8 additions & 0 deletions x/auth/tx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(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
}

Expand Down
8 changes: 4 additions & 4 deletions x/auth/tx/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,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 {
Expand Down Expand Up @@ -371,12 +371,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",
Expand Down

0 comments on commit 1581289

Please sign in to comment.