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 5e39c2d7351ebbd6b789df214f2396e6c5dfb28e. Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
39214c69a9
commit
afc09f9d59
@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
@ -269,8 +270,9 @@ func TestEth_Pending_GetTransactionByBlockNumberAndIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEth_Pending_GetTransactionByHash(t *testing.T) {
|
||||
sleep := 0 * time.Second
|
||||
// negative case, check that it returns empty.
|
||||
rpcRes := Call(t, "eth_getTransactionByHash", []interface{}{"0xec5fa15e1368d6ac314f9f64118c5794f076f63c02e66f97ea5fe1de761a8973"})
|
||||
rpcRes := CallWithSleep(t, "eth_getTransactionByHash", []interface{}{"0xec5fa15e1368d6ac314f9f64118c5794f076f63c02e66f97ea5fe1de761a8973"}, sleep)
|
||||
var tx map[string]interface{}
|
||||
err := json.Unmarshal(rpcRes.Result, &tx)
|
||||
require.NoError(t, err)
|
||||
@ -281,17 +283,17 @@ func TestEth_Pending_GetTransactionByHash(t *testing.T) {
|
||||
param := makePendingTxParams(t)
|
||||
param[0]["data"] = data
|
||||
|
||||
txRes := Call(t, "eth_sendTransaction", param)
|
||||
txRes := CallWithSleep(t, "eth_sendTransaction", param, sleep)
|
||||
var txHash common.Hash
|
||||
err = txHash.UnmarshalJSON(txRes.Result)
|
||||
require.NoError(t, err)
|
||||
|
||||
rpcRes = Call(t, "eth_getTransactionByHash", []interface{}{txHash})
|
||||
rpcRes = CallWithSleep(t, "eth_getTransactionByHash", []interface{}{txHash}, sleep)
|
||||
var pendingTx map[string]interface{}
|
||||
err = json.Unmarshal(rpcRes.Result, &pendingTx)
|
||||
require.NoError(t, err)
|
||||
|
||||
txsRes := Call(t, "eth_getPendingTransactions", []interface{}{})
|
||||
txsRes := CallWithSleep(t, "eth_getPendingTransactions", []interface{}{}, sleep)
|
||||
var pendingTxs []map[string]interface{}
|
||||
err = json.Unmarshal(txsRes.Result, &pendingTxs)
|
||||
require.NoError(t, err)
|
||||
|
@ -63,12 +63,14 @@ func CreateRequest(method string, params interface{}) Request {
|
||||
}
|
||||
}
|
||||
|
||||
func Call(t *testing.T, method string, params interface{}) *Response {
|
||||
func CallWithSleep(t *testing.T, method string, params interface{}, sleep time.Duration) *Response {
|
||||
req, err := json.Marshal(CreateRequest(method, params))
|
||||
require.NoError(t, err)
|
||||
|
||||
var rpcRes *Response
|
||||
time.Sleep(1 * time.Second)
|
||||
if sleep > 0 {
|
||||
time.Sleep(sleep)
|
||||
}
|
||||
|
||||
httpReq, err := http.NewRequestWithContext(context.Background(), "POST", HOST, bytes.NewBuffer(req))
|
||||
if err != nil {
|
||||
@ -94,6 +96,10 @@ func Call(t *testing.T, method string, params interface{}) *Response {
|
||||
return rpcRes
|
||||
}
|
||||
|
||||
func Call(t *testing.T, method string, params interface{}) *Response {
|
||||
return CallWithSleep(t, method, params, time.Second)
|
||||
}
|
||||
|
||||
func CallWithError(method string, params interface{}) (*Response, error) {
|
||||
req, err := json.Marshal(CreateRequest(method, params))
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user