2020-12-15 19:52:09 +00:00
|
|
|
// This is a test utility for Ethermint's Web3 JSON-RPC services.
|
|
|
|
//
|
|
|
|
// To run these tests please first ensure you have the ethermintd running
|
|
|
|
//
|
2021-04-17 10:00:07 +00:00
|
|
|
// You can configure the desired HOST and MODE as well in integration-test-all.sh
|
2021-05-11 11:54:55 +00:00
|
|
|
package rpc
|
2020-12-15 19:52:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2021-04-17 10:00:07 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-12-15 19:52:09 +00:00
|
|
|
|
2021-10-01 14:49:22 +00:00
|
|
|
rpctypes "github.com/tharsis/ethermint/rpc/ethereum/types"
|
2020-12-15 19:52:09 +00:00
|
|
|
)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
// func TestMain(m *testing.M) {
|
|
|
|
// if MODE != "pending" {
|
|
|
|
// _, _ = fmt.Fprintln(os.Stdout, "Skipping pending RPC test")
|
|
|
|
// return
|
|
|
|
// }
|
2020-12-15 19:52:09 +00:00
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
// var err error
|
|
|
|
// from, err = GetAddress()
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Printf("failed to get account: %s\n", err)
|
|
|
|
// os.Exit(1)
|
|
|
|
// }
|
2020-12-15 19:52:09 +00:00
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
// // Start all tests
|
|
|
|
// code := m.Run()
|
|
|
|
// os.Exit(code)
|
|
|
|
// }
|
2020-12-15 19:52:09 +00:00
|
|
|
|
|
|
|
func TestEth_Pending_GetBalance(t *testing.T) {
|
2021-10-07 16:41:27 +00:00
|
|
|
// There is no pending block concept in Ethermint
|
|
|
|
t.Skip("skipping TestEth_Pending_GetBalance")
|
|
|
|
|
2020-12-15 19:52:09 +00:00
|
|
|
var res hexutil.Big
|
2021-07-12 10:34:47 +00:00
|
|
|
var resTxHash common.Hash
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes := Call(t, "eth_getBalance", []string{addrA, "latest"})
|
2020-12-15 19:52:09 +00:00
|
|
|
err := res.UnmarshalJSON(rpcRes.Result)
|
|
|
|
require.NoError(t, err)
|
|
|
|
preTxLatestBalance := res.ToInt()
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBalance", []string{addrA, "pending"})
|
2020-12-15 19:52:09 +00:00
|
|
|
err = res.UnmarshalJSON(rpcRes.Result)
|
|
|
|
require.NoError(t, err)
|
|
|
|
preTxPendingBalance := res.ToInt()
|
|
|
|
|
|
|
|
t.Logf("Got pending balance %s for %s pre tx\n", preTxPendingBalance, addrA)
|
|
|
|
t.Logf("Got latest balance %s for %s pre tx\n", preTxLatestBalance, addrA)
|
|
|
|
|
|
|
|
param := make([]map[string]string, 1)
|
|
|
|
param[0] = make(map[string]string)
|
|
|
|
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
|
|
|
param[0]["to"] = addrA
|
|
|
|
param[0]["value"] = "0xA"
|
|
|
|
param[0]["gasLimit"] = "0x5208"
|
|
|
|
param[0]["gasPrice"] = "0x1"
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes := Call(t, "personal_unlockAccount", []interface{}{param[0]["from"], ""})
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, rpcRes.Error)
|
|
|
|
|
2021-07-12 10:34:47 +00:00
|
|
|
err = resTxHash.UnmarshalJSON(rpcRes.Result)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
rpcRes = Call(t, "eth_getTransactionByHash", []string{resTxHash.Hex()})
|
|
|
|
require.Nil(t, rpcRes.Error)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBalance", []string{addrA, "pending"})
|
2020-12-15 19:52:09 +00:00
|
|
|
err = res.UnmarshalJSON(rpcRes.Result)
|
|
|
|
require.NoError(t, err)
|
|
|
|
postTxPendingBalance := res.ToInt()
|
|
|
|
t.Logf("Got pending balance %s for %s post tx\n", postTxPendingBalance, addrA)
|
|
|
|
|
|
|
|
require.Equal(t, preTxPendingBalance.Add(preTxPendingBalance, big.NewInt(10)), postTxPendingBalance)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBalance", []string{addrA, "latest"})
|
2020-12-15 19:52:09 +00:00
|
|
|
err = res.UnmarshalJSON(rpcRes.Result)
|
|
|
|
require.NoError(t, err)
|
|
|
|
postTxLatestBalance := res.ToInt()
|
|
|
|
t.Logf("Got latest balance %s for %s post tx\n", postTxLatestBalance, addrA)
|
|
|
|
|
|
|
|
require.Equal(t, preTxLatestBalance, postTxLatestBalance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth_Pending_GetTransactionCount(t *testing.T) {
|
2021-05-11 11:54:55 +00:00
|
|
|
prePendingNonce := GetNonce(t, "pending")
|
2020-12-15 19:52:09 +00:00
|
|
|
t.Logf("Pending nonce before tx is %d", prePendingNonce)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
currentNonce := GetNonce(t, "latest")
|
2020-12-15 19:52:09 +00:00
|
|
|
t.Logf("Current nonce is %d", currentNonce)
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Equal(t, prePendingNonce, currentNonce)
|
2020-12-15 19:52:09 +00:00
|
|
|
|
2021-11-23 15:00:25 +00:00
|
|
|
param := makePendingTxParams(t)
|
2021-10-07 16:41:27 +00:00
|
|
|
txRes := Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
|
|
|
|
2021-10-07 16:41:27 +00:00
|
|
|
var hash hexutil.Bytes
|
|
|
|
err := json.Unmarshal(txRes.Result, &hash)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
receipt := waitForReceipt(t, hash)
|
|
|
|
require.NotNil(t, receipt)
|
|
|
|
require.Equal(t, "0x1", receipt["status"].(string))
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
pendingNonce := GetNonce(t, "pending")
|
|
|
|
latestNonce := GetNonce(t, "latest")
|
2021-04-17 10:00:07 +00:00
|
|
|
|
2020-12-15 19:52:09 +00:00
|
|
|
t.Logf("Latest nonce is %d", latestNonce)
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Equal(t, currentNonce+1, latestNonce)
|
|
|
|
|
2020-12-15 19:52:09 +00:00
|
|
|
t.Logf("Pending nonce is %d", pendingNonce)
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Equal(t, latestNonce, pendingNonce)
|
2020-12-15 19:52:09 +00:00
|
|
|
|
|
|
|
require.Equal(t, uint64(prePendingNonce)+uint64(1), uint64(pendingNonce))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth_Pending_GetBlockTransactionCountByNumber(t *testing.T) {
|
2021-10-07 16:41:27 +00:00
|
|
|
// There is no pending block concept in Ethermint
|
|
|
|
t.Skip("skipping TestEth_Pending_GetBlockTransactionCountByNumber")
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes := Call(t, "eth_getBlockTransactionCountByNumber", []interface{}{"pending"})
|
2020-12-15 19:52:09 +00:00
|
|
|
var preTxPendingTxCount hexutil.Uint
|
|
|
|
err := json.Unmarshal(rpcRes.Result, &preTxPendingTxCount)
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Logf("Pre tx pending nonce is %d", preTxPendingTxCount)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBlockTransactionCountByNumber", []interface{}{"latest"})
|
2020-12-15 19:52:09 +00:00
|
|
|
var preTxLatestTxCount hexutil.Uint
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &preTxLatestTxCount)
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Logf("Pre tx latest nonce is %d", preTxLatestTxCount)
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Equal(t, preTxPendingTxCount, preTxLatestTxCount)
|
|
|
|
|
2020-12-15 19:52:09 +00:00
|
|
|
param := make([]map[string]string, 1)
|
|
|
|
param[0] = make(map[string]string)
|
|
|
|
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
|
|
|
param[0]["to"] = addrA
|
|
|
|
param[0]["value"] = "0xA"
|
|
|
|
param[0]["gasLimit"] = "0x5208"
|
|
|
|
param[0]["gasPrice"] = "0x1"
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes := Call(t, "personal_unlockAccount", []interface{}{param[0]["from"], ""})
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes = Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBlockTransactionCountByNumber", []interface{}{"pending"})
|
2020-12-15 19:52:09 +00:00
|
|
|
var postTxPendingTxCount hexutil.Uint
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &postTxPendingTxCount)
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Logf("Post tx pending nonce is %d", postTxPendingTxCount)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBlockTransactionCountByNumber", []interface{}{"latest"})
|
2020-12-15 19:52:09 +00:00
|
|
|
var postTxLatestTxCount hexutil.Uint
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &postTxLatestTxCount)
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Logf("Post tx latest nonce is %d", postTxLatestTxCount)
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Equal(t, postTxPendingTxCount, postTxLatestTxCount)
|
|
|
|
|
|
|
|
require.Equal(t, uint64(preTxPendingTxCount), uint64(postTxPendingTxCount))
|
|
|
|
require.Equal(t, uint64(postTxPendingTxCount)-uint64(preTxPendingTxCount), uint64(postTxLatestTxCount)-uint64(preTxLatestTxCount))
|
2020-12-15 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth_Pending_GetBlockByNumber(t *testing.T) {
|
2021-10-07 16:41:27 +00:00
|
|
|
// There is no pending block concept in Ethermint
|
|
|
|
t.Skip("skipping TestEth_Pending_GetBlockByNumber")
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes := Call(t, "eth_getBlockByNumber", []interface{}{"latest", true})
|
2020-12-15 19:52:09 +00:00
|
|
|
var preTxLatestBlock map[string]interface{}
|
|
|
|
err := json.Unmarshal(rpcRes.Result, &preTxLatestBlock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
preTxLatestTxs := len(preTxLatestBlock["transactions"].([]interface{}))
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBlockByNumber", []interface{}{"pending", true})
|
2020-12-15 19:52:09 +00:00
|
|
|
var preTxPendingBlock map[string]interface{}
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &preTxPendingBlock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
preTxPendingTxs := len(preTxPendingBlock["transactions"].([]interface{}))
|
|
|
|
|
|
|
|
param := make([]map[string]string, 1)
|
|
|
|
param[0] = make(map[string]string)
|
|
|
|
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
|
|
|
param[0]["to"] = addrA
|
|
|
|
param[0]["value"] = "0xA"
|
|
|
|
param[0]["gasLimit"] = "0x5208"
|
|
|
|
param[0]["gasPrice"] = "0x1"
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes := Call(t, "personal_unlockAccount", []interface{}{param[0]["from"], ""})
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes = Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBlockByNumber", []interface{}{"pending", true})
|
2020-12-15 19:52:09 +00:00
|
|
|
var postTxPendingBlock map[string]interface{}
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &postTxPendingBlock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
postTxPendingTxs := len(postTxPendingBlock["transactions"].([]interface{}))
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Equal(t, postTxPendingTxs, preTxPendingTxs)
|
2020-12-15 19:52:09 +00:00
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getBlockByNumber", []interface{}{"latest", true})
|
2020-12-15 19:52:09 +00:00
|
|
|
var postTxLatestBlock map[string]interface{}
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &postTxLatestBlock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
postTxLatestTxs := len(postTxLatestBlock["transactions"].([]interface{}))
|
|
|
|
require.Equal(t, preTxLatestTxs, postTxLatestTxs)
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Equal(t, postTxPendingTxs, preTxPendingTxs)
|
2020-12-15 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth_Pending_GetTransactionByBlockNumberAndIndex(t *testing.T) {
|
2021-10-07 16:41:27 +00:00
|
|
|
// There is no pending block concept in Ethermint
|
|
|
|
t.Skip("skipping TestEth_Pending_GetTransactionByBlockNumberAndIndex")
|
|
|
|
|
2021-05-10 16:34:00 +00:00
|
|
|
var pendingTx []*rpctypes.RPCTransaction
|
2021-05-11 11:54:55 +00:00
|
|
|
resPendingTxs := Call(t, "eth_pendingTransactions", []string{})
|
2020-12-15 19:52:09 +00:00
|
|
|
err := json.Unmarshal(resPendingTxs.Result, &pendingTx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
pendingTxCount := len(pendingTx)
|
|
|
|
|
|
|
|
data := "0x608060405234801561001057600080fd5b5061011e806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063bc9c707d14602d575b600080fd5b603360ab565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101560715780820151818401526020810190506058565b50505050905090810190601f168015609d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60606040518060400160405280600681526020017f617261736b61000000000000000000000000000000000000000000000000000081525090509056fea2646970667358221220a31fa4c1ce0b3651fbf5401c511b483c43570c7de4735b5c3b0ad0db30d2573164736f6c63430007050033"
|
|
|
|
param := make([]map[string]string, 1)
|
|
|
|
param[0] = make(map[string]string)
|
|
|
|
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
|
|
|
param[0]["to"] = addrA
|
|
|
|
param[0]["value"] = "0xA"
|
|
|
|
param[0]["gasLimit"] = "0x5208"
|
|
|
|
param[0]["gasPrice"] = "0x1"
|
|
|
|
param[0]["data"] = data
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes := Call(t, "personal_unlockAccount", []interface{}{param[0]["from"], ""})
|
2021-04-17 10:00:07 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes = Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, txRes.Error)
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
// test will be blocked here until tx gets confirmed
|
|
|
|
var txHash common.Hash
|
|
|
|
err = json.Unmarshal(txRes.Result, &txHash)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes := Call(t, "eth_getTransactionByBlockNumberAndIndex", []interface{}{"latest", "0x" + fmt.Sprintf("%X", pendingTxCount)})
|
2021-04-17 10:00:07 +00:00
|
|
|
var latestBlockTx map[string]interface{}
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &latestBlockTx)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// verify the pending tx has all the correct fields from the tx sent.
|
2021-04-17 10:00:07 +00:00
|
|
|
require.NotEmpty(t, latestBlockTx["hash"])
|
|
|
|
require.Equal(t, latestBlockTx["value"], "0xa")
|
|
|
|
require.Equal(t, data, latestBlockTx["input"])
|
2020-12-15 19:52:09 +00:00
|
|
|
|
2021-05-11 11:54:55 +00:00
|
|
|
rpcRes = Call(t, "eth_getTransactionByBlockNumberAndIndex", []interface{}{"pending", "0x" + fmt.Sprintf("%X", pendingTxCount)})
|
2021-04-17 10:00:07 +00:00
|
|
|
var pendingBlock map[string]interface{}
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &pendingBlock)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-17 10:00:07 +00:00
|
|
|
// verify the transaction does not exist in the pending block info.
|
|
|
|
require.Empty(t, pendingBlock)
|
2020-12-15 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth_Pending_GetTransactionByHash(t *testing.T) {
|
2021-08-11 11:15:11 +00:00
|
|
|
// negative case, check that it returns empty.
|
|
|
|
rpcRes := Call(t, "eth_getTransactionByHash", []interface{}{"0xec5fa15e1368d6ac314f9f64118c5794f076f63c02e66f97ea5fe1de761a8973"})
|
2021-10-07 16:41:27 +00:00
|
|
|
var tx map[string]interface{}
|
|
|
|
err := json.Unmarshal(rpcRes.Result, &tx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, tx)
|
2021-08-11 11:15:11 +00:00
|
|
|
|
|
|
|
// create a transaction.
|
2020-12-15 19:52:09 +00:00
|
|
|
data := "0x608060405234801561001057600080fd5b5061011e806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806302eb691b14602d575b600080fd5b603360ab565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101560715780820151818401526020810190506058565b50505050905090810190601f168015609d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60606040518060400160405280600d81526020017f617261736b61776173686572650000000000000000000000000000000000000081525090509056fea264697066735822122060917c5c2fab8c058a17afa6d3c1d23a7883b918ea3c7157131ea5b396e1aa7564736f6c63430007050033"
|
2021-11-23 15:00:25 +00:00
|
|
|
param := makePendingTxParams(t)
|
2020-12-15 19:52:09 +00:00
|
|
|
param[0]["data"] = data
|
|
|
|
|
2021-10-07 16:41:27 +00:00
|
|
|
txRes := Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
var txHash common.Hash
|
2021-10-07 16:41:27 +00:00
|
|
|
err = txHash.UnmarshalJSON(txRes.Result)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-08-11 11:15:11 +00:00
|
|
|
rpcRes = Call(t, "eth_getTransactionByHash", []interface{}{txHash})
|
2021-10-07 16:41:27 +00:00
|
|
|
var pendingTx map[string]interface{}
|
|
|
|
err = json.Unmarshal(rpcRes.Result, &pendingTx)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-12 17:42:53 +00:00
|
|
|
txsRes := Call(t, "eth_getPendingTransactions", []interface{}{})
|
|
|
|
var pendingTxs []map[string]interface{}
|
|
|
|
err = json.Unmarshal(txsRes.Result, &pendingTxs)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, pendingTxs)
|
|
|
|
|
2020-12-15 19:52:09 +00:00
|
|
|
// verify the pending tx has all the correct fields from the tx sent.
|
2021-10-07 16:41:27 +00:00
|
|
|
require.NotEmpty(t, pendingTx)
|
|
|
|
require.NotEmpty(t, pendingTx["hash"])
|
|
|
|
require.Equal(t, pendingTx["value"], "0xa")
|
|
|
|
require.Equal(t, pendingTx["input"], data)
|
2020-12-15 19:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEth_Pending_SendTransaction_PendingNonce(t *testing.T) {
|
2021-05-11 11:54:55 +00:00
|
|
|
currNonce := GetNonce(t, "latest")
|
2021-11-23 15:00:25 +00:00
|
|
|
param := makePendingTxParams(t)
|
2021-04-17 10:00:07 +00:00
|
|
|
|
2020-12-15 19:52:09 +00:00
|
|
|
// first transaction
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes1 := Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, txRes1.Error)
|
2021-05-11 11:54:55 +00:00
|
|
|
pendingNonce1 := GetNonce(t, "pending")
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Greater(t, uint64(pendingNonce1), uint64(currNonce))
|
|
|
|
|
|
|
|
// second transaction
|
|
|
|
param[0]["to"] = "0x7f0f463c4d57b1bd3e3b79051e6c5ab703e803d9"
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes2 := Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, txRes2.Error)
|
2021-05-11 11:54:55 +00:00
|
|
|
pendingNonce2 := GetNonce(t, "pending")
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Greater(t, uint64(pendingNonce2), uint64(currNonce))
|
|
|
|
require.Greater(t, uint64(pendingNonce2), uint64(pendingNonce1))
|
|
|
|
|
|
|
|
// third transaction
|
|
|
|
param[0]["to"] = "0x7fb24493808b3f10527e3e0870afeb8a953052d2"
|
2021-05-11 11:54:55 +00:00
|
|
|
txRes3 := Call(t, "eth_sendTransaction", param)
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Nil(t, txRes3.Error)
|
2021-05-11 11:54:55 +00:00
|
|
|
pendingNonce3 := GetNonce(t, "pending")
|
2020-12-15 19:52:09 +00:00
|
|
|
require.Greater(t, uint64(pendingNonce3), uint64(currNonce))
|
|
|
|
require.Greater(t, uint64(pendingNonce3), uint64(pendingNonce2))
|
|
|
|
}
|
2021-10-07 16:41:27 +00:00
|
|
|
|
2021-11-23 15:00:25 +00:00
|
|
|
func makePendingTxParams(t *testing.T) []map[string]string {
|
|
|
|
gasPrice := GetGasPrice(t)
|
|
|
|
|
2021-10-07 16:41:27 +00:00
|
|
|
param := make([]map[string]string, 1)
|
|
|
|
param[0] = make(map[string]string)
|
|
|
|
param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
|
|
|
|
param[0]["to"] = addrA
|
|
|
|
param[0]["value"] = "0xA"
|
|
|
|
param[0]["gasLimit"] = "0x5208"
|
2021-11-23 15:00:25 +00:00
|
|
|
param[0]["gasPrice"] = gasPrice
|
2021-10-07 16:41:27 +00:00
|
|
|
return param
|
|
|
|
}
|