Skip to content

Commit fc65faf

Browse files
authored
fix(rpc/json): avoid strict checks on jsonrpc code (#1880)
## Overview This PR fixes a flaky test `TestREST` which has happening due to strict checks on json rpc error codes. Fixes #1798 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Updated expected JSON-RPC error codes in test cases to a generic error indication for improved error handling. - Introduced additional logic to handle potential delays in response during testing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a93cc9f commit fc65faf

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

rpc/json/service_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package json
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/base64"
67
"encoding/hex"
78
"encoding/json"
9+
"errors"
810
"fmt"
911
"net/http"
1012
"net/http/httptest"
@@ -64,10 +66,10 @@ func TestREST(t *testing.T) {
6466
bodyContains string
6567
}{
6668

67-
{"valid/malformed request", "/block?so{}wrong!", http.StatusOK, int(json2.E_INTERNAL), ``},
69+
{"valid/malformed request", "/block?so{}wrong!", http.StatusOK, -1, `"result":{"block_id":`},
6870
// to keep test simple, allow returning application error in following case
6971
{"invalid/missing required param", "/tx", http.StatusOK, int(json2.E_INVALID_REQ), `missing param 'hash'`},
70-
{"valid/missing optional param", "/block", http.StatusOK, int(json2.E_INTERNAL), "failed to load hash from index"},
72+
{"valid/missing optional param", "/block", http.StatusOK, -1, `"result":{"block_id":`},
7173
{"valid/included block tag param", "/block?height=included", http.StatusOK, int(json2.E_INTERNAL), "failed to load hash from index"},
7274
{"valid/no params", "/abci_info", http.StatusOK, -1, `"last_block_height":"345"`},
7375
{"valid/int param", "/block?height=321", http.StatusOK, int(json2.E_INTERNAL), "failed to load hash from index"},
@@ -86,6 +88,19 @@ func TestREST(t *testing.T) {
8688
handler, err := GetHTTPHandler(local, log.TestingLogger())
8789
require.NoError(err)
8890

91+
// wait for blocks
92+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
93+
defer cancel()
94+
for {
95+
if errors.Is(err, context.DeadlineExceeded) {
96+
t.FailNow()
97+
}
98+
resp, err := local.Header(ctx, nil)
99+
if err == nil && resp.Header.Height > 1 {
100+
break
101+
}
102+
}
103+
89104
for _, c := range cases {
90105
t.Run(c.name, func(t *testing.T) {
91106
req := httptest.NewRequest(http.MethodPost, c.uri, nil)

0 commit comments

Comments
 (0)