Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit afc09f9

Browse files
mmsqefedekunze
andauthored
fix(rpc): avoid sleep with pending txs tests(#1098)
* avoid pending tx get confirmed when sleep * fix install-tparse which need go >= 1.18 * fix strings.Cut in https://github.com/tharsis/ethermint/runs/6611646254?check_suite_focus=true * for more info, https://dev.to/hgsgtk/go-118-new-function-cut-added-to-stringsbytes-package-5c2f * Revert "fix install-tparse which need go >= 1.18" This reverts commit 5e39c2d. Co-authored-by: Federico Kunze Küllmer <[email protected]>
1 parent 39214c6 commit afc09f9

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

tests/rpc/rpc_pending_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"math/big"
1212
"testing"
13+
"time"
1314

1415
"github.com/ethereum/go-ethereum/common"
1516
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -269,8 +270,9 @@ func TestEth_Pending_GetTransactionByBlockNumberAndIndex(t *testing.T) {
269270
}
270271

271272
func TestEth_Pending_GetTransactionByHash(t *testing.T) {
273+
sleep := 0 * time.Second
272274
// negative case, check that it returns empty.
273-
rpcRes := Call(t, "eth_getTransactionByHash", []interface{}{"0xec5fa15e1368d6ac314f9f64118c5794f076f63c02e66f97ea5fe1de761a8973"})
275+
rpcRes := CallWithSleep(t, "eth_getTransactionByHash", []interface{}{"0xec5fa15e1368d6ac314f9f64118c5794f076f63c02e66f97ea5fe1de761a8973"}, sleep)
274276
var tx map[string]interface{}
275277
err := json.Unmarshal(rpcRes.Result, &tx)
276278
require.NoError(t, err)
@@ -281,17 +283,17 @@ func TestEth_Pending_GetTransactionByHash(t *testing.T) {
281283
param := makePendingTxParams(t)
282284
param[0]["data"] = data
283285

284-
txRes := Call(t, "eth_sendTransaction", param)
286+
txRes := CallWithSleep(t, "eth_sendTransaction", param, sleep)
285287
var txHash common.Hash
286288
err = txHash.UnmarshalJSON(txRes.Result)
287289
require.NoError(t, err)
288290

289-
rpcRes = Call(t, "eth_getTransactionByHash", []interface{}{txHash})
291+
rpcRes = CallWithSleep(t, "eth_getTransactionByHash", []interface{}{txHash}, sleep)
290292
var pendingTx map[string]interface{}
291293
err = json.Unmarshal(rpcRes.Result, &pendingTx)
292294
require.NoError(t, err)
293295

294-
txsRes := Call(t, "eth_getPendingTransactions", []interface{}{})
296+
txsRes := CallWithSleep(t, "eth_getPendingTransactions", []interface{}{}, sleep)
295297
var pendingTxs []map[string]interface{}
296298
err = json.Unmarshal(txsRes.Result, &pendingTxs)
297299
require.NoError(t, err)

tests/rpc/utils.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ func CreateRequest(method string, params interface{}) Request {
6363
}
6464
}
6565

66-
func Call(t *testing.T, method string, params interface{}) *Response {
66+
func CallWithSleep(t *testing.T, method string, params interface{}, sleep time.Duration) *Response {
6767
req, err := json.Marshal(CreateRequest(method, params))
6868
require.NoError(t, err)
6969

7070
var rpcRes *Response
71-
time.Sleep(1 * time.Second)
71+
if sleep > 0 {
72+
time.Sleep(sleep)
73+
}
7274

7375
httpReq, err := http.NewRequestWithContext(context.Background(), "POST", HOST, bytes.NewBuffer(req))
7476
if err != nil {
@@ -94,6 +96,10 @@ func Call(t *testing.T, method string, params interface{}) *Response {
9496
return rpcRes
9597
}
9698

99+
func Call(t *testing.T, method string, params interface{}) *Response {
100+
return CallWithSleep(t, method, params, time.Second)
101+
}
102+
97103
func CallWithError(method string, params interface{}) (*Response, error) {
98104
req, err := json.Marshal(CreateRequest(method, params))
99105
if err != nil {

0 commit comments

Comments
 (0)