forked from cerc-io/laconicd-deprecated
fix rpc-test action (#402)
This commit is contained in:
+92
-99
@@ -117,6 +117,88 @@ func hexToBigInt(t *testing.T, in string) *big.Int {
|
||||
return big.NewInt(0).SetBytes(b)
|
||||
}
|
||||
|
||||
func TestBlockBloom(t *testing.T) {
|
||||
hash := deployTestContractWithFunction(t)
|
||||
receipt := waitForReceipt(t, hash)
|
||||
|
||||
number := receipt["blockNumber"].(string)
|
||||
param := []interface{}{number, false}
|
||||
rpcRes := call(t, "eth_getBlockByNumber", param)
|
||||
|
||||
block := make(map[string]interface{})
|
||||
err := json.Unmarshal(rpcRes.Result, &block)
|
||||
require.NoError(t, err)
|
||||
|
||||
lb := hexToBigInt(t, block["logsBloom"].(string))
|
||||
require.NotEqual(t, big.NewInt(0), lb)
|
||||
require.Equal(t, hash.String(), block["transactions"].([]interface{})[0])
|
||||
}
|
||||
|
||||
func TestEth_GetLogs_NoLogs(t *testing.T) {
|
||||
param := make([]map[string][]string, 1)
|
||||
param[0] = make(map[string][]string)
|
||||
param[0]["topics"] = []string{}
|
||||
call(t, "eth_getLogs", param)
|
||||
}
|
||||
|
||||
func TestEth_GetLogs_Topics_AB(t *testing.T) {
|
||||
// TODO: this test passes on when run on its own, but fails when run with the other tests
|
||||
if testing.Short() {
|
||||
t.Skip("skipping TestEth_GetLogs_Topics_AB")
|
||||
}
|
||||
|
||||
rpcRes := call(t, "eth_blockNumber", []string{})
|
||||
|
||||
var res hexutil.Uint64
|
||||
err := res.UnmarshalJSON(rpcRes.Result)
|
||||
require.NoError(t, err)
|
||||
|
||||
param := make([]map[string]interface{}, 1)
|
||||
param[0] = make(map[string]interface{})
|
||||
param[0]["topics"] = []string{helloTopic, worldTopic}
|
||||
param[0]["fromBlock"] = res.String()
|
||||
|
||||
hash := deployTestContractWithFunction(t)
|
||||
waitForReceipt(t, hash)
|
||||
|
||||
rpcRes = call(t, "eth_getLogs", param)
|
||||
|
||||
var logs []*ethtypes.Log
|
||||
err = json.Unmarshal(rpcRes.Result, &logs)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, 1, len(logs))
|
||||
}
|
||||
|
||||
func TestEth_GetTransactionCount(t *testing.T) {
|
||||
// TODO: this test passes on when run on its own, but fails when run with the other tests
|
||||
if testing.Short() {
|
||||
t.Skip("skipping TestEth_GetLogs_Topics_AB")
|
||||
}
|
||||
|
||||
prev := getNonce(t)
|
||||
sendTestTransaction(t)
|
||||
post := getNonce(t)
|
||||
require.Equal(t, prev, post-1)
|
||||
}
|
||||
|
||||
func TestEth_GetTransactionLogs(t *testing.T) {
|
||||
// TODO: this test passes on when run on its own, but fails when run with the other tests
|
||||
if testing.Short() {
|
||||
t.Skip("skipping TestEth_GetLogs_Topics_AB")
|
||||
}
|
||||
|
||||
hash, _ := deployTestContract(t)
|
||||
|
||||
param := []string{hash.String()}
|
||||
rpcRes := call(t, "eth_getTransactionLogs", param)
|
||||
|
||||
logs := new([]*ethtypes.Log)
|
||||
err := json.Unmarshal(rpcRes.Result, logs)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(*logs))
|
||||
}
|
||||
|
||||
func TestEth_protocolVersion(t *testing.T) {
|
||||
expectedRes := hexutil.Uint(version.ProtocolVersion)
|
||||
|
||||
@@ -272,7 +354,7 @@ func TestEth_NewFilter(t *testing.T) {
|
||||
param[0]["topics"] = []string{"0x0000000000000000000000000000000000000000000000000000000012341234"}
|
||||
rpcRes := call(t, "eth_newFilter", param)
|
||||
|
||||
var ID hexutil.Bytes
|
||||
var ID string
|
||||
err := json.Unmarshal(rpcRes.Result, &ID)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -280,7 +362,7 @@ func TestEth_NewFilter(t *testing.T) {
|
||||
func TestEth_NewBlockFilter(t *testing.T) {
|
||||
rpcRes := call(t, "eth_newBlockFilter", []string{})
|
||||
|
||||
var ID hexutil.Bytes
|
||||
var ID string
|
||||
err := json.Unmarshal(rpcRes.Result, &ID)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -288,13 +370,13 @@ func TestEth_NewBlockFilter(t *testing.T) {
|
||||
func TestEth_GetFilterChanges_BlockFilter(t *testing.T) {
|
||||
rpcRes := call(t, "eth_newBlockFilter", []string{})
|
||||
|
||||
var ID hexutil.Bytes
|
||||
var ID string
|
||||
err := json.Unmarshal(rpcRes.Result, &ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
|
||||
changesRes := call(t, "eth_getFilterChanges", []string{ID})
|
||||
var hashes []ethcmn.Hash
|
||||
err = json.Unmarshal(changesRes.Result, &hashes)
|
||||
require.NoError(t, err)
|
||||
@@ -307,13 +389,11 @@ func TestEth_GetFilterChanges_NoLogs(t *testing.T) {
|
||||
param[0]["topics"] = []string{}
|
||||
rpcRes := call(t, "eth_newFilter", param)
|
||||
|
||||
var ID hexutil.Bytes
|
||||
var ID string
|
||||
err := json.Unmarshal(rpcRes.Result, &ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Log(ID.String())
|
||||
|
||||
changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
|
||||
changesRes := call(t, "eth_getFilterChanges", []string{ID})
|
||||
|
||||
var logs []*ethtypes.Log
|
||||
err = json.Unmarshal(changesRes.Result, &logs)
|
||||
@@ -437,17 +517,6 @@ func waitForReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
|
||||
|
||||
return nil
|
||||
}
|
||||
func TestEth_GetTransactionLogs(t *testing.T) {
|
||||
hash, _ := deployTestContract(t)
|
||||
|
||||
param := []string{hash.String()}
|
||||
rpcRes := call(t, "eth_getTransactionLogs", param)
|
||||
|
||||
logs := new([]*ethtypes.Log)
|
||||
err := json.Unmarshal(rpcRes.Result, logs)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(*logs))
|
||||
}
|
||||
|
||||
func TestEth_GetFilterChanges_NoTopics(t *testing.T) {
|
||||
rpcRes := call(t, "eth_blockNumber", []string{})
|
||||
@@ -605,37 +674,6 @@ func TestEth_GetFilterChanges_Topics_XXC(t *testing.T) {
|
||||
// TODO: call test function, need tx receipts to determine contract address
|
||||
}
|
||||
|
||||
func TestEth_GetLogs_NoLogs(t *testing.T) {
|
||||
param := make([]map[string][]string, 1)
|
||||
param[0] = make(map[string][]string)
|
||||
param[0]["topics"] = []string{}
|
||||
call(t, "eth_getLogs", param)
|
||||
}
|
||||
|
||||
func TestEth_GetLogs_Topics_AB(t *testing.T) {
|
||||
rpcRes := call(t, "eth_blockNumber", []string{})
|
||||
|
||||
var res hexutil.Uint64
|
||||
err := res.UnmarshalJSON(rpcRes.Result)
|
||||
require.NoError(t, err)
|
||||
|
||||
param := make([]map[string]interface{}, 1)
|
||||
param[0] = make(map[string]interface{})
|
||||
param[0]["topics"] = []string{helloTopic, worldTopic}
|
||||
param[0]["fromBlock"] = res.String()
|
||||
|
||||
hash := deployTestContractWithFunction(t)
|
||||
waitForReceipt(t, hash)
|
||||
|
||||
rpcRes = call(t, "eth_getLogs", param)
|
||||
|
||||
var logs []*ethtypes.Log
|
||||
err = json.Unmarshal(rpcRes.Result, &logs)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, 1, len(logs))
|
||||
}
|
||||
|
||||
func TestEth_PendingTransactionFilter(t *testing.T) {
|
||||
rpcRes := call(t, "eth_newPendingTransactionFilter", []string{})
|
||||
|
||||
@@ -661,44 +699,6 @@ func TestEth_PendingTransactionFilter(t *testing.T) {
|
||||
require.True(t, len(txs) >= 2, "could not get any txs", "changesRes.Result", string(changesRes.Result))
|
||||
}
|
||||
|
||||
func TestBlockBloom(t *testing.T) {
|
||||
hash := deployTestContractWithFunction(t)
|
||||
receipt := waitForReceipt(t, hash)
|
||||
|
||||
number := receipt["blockNumber"].(string)
|
||||
t.Log(number)
|
||||
|
||||
param := []interface{}{number, false}
|
||||
rpcRes := call(t, "eth_getBlockByNumber", param)
|
||||
|
||||
block := make(map[string]interface{})
|
||||
err := json.Unmarshal(rpcRes.Result, &block)
|
||||
require.NoError(t, err)
|
||||
|
||||
lb := hexToBigInt(t, block["logsBloom"].(string))
|
||||
require.NotEqual(t, big.NewInt(0), lb)
|
||||
require.Equal(t, hash.String(), block["transactions"].([]interface{})[0])
|
||||
}
|
||||
|
||||
func TestBlockBloom_Hash(t *testing.T) {
|
||||
hash := deployTestContractWithFunction(t)
|
||||
receipt := waitForReceipt(t, hash)
|
||||
|
||||
time.Sleep(time.Second * 3)
|
||||
|
||||
blockHash := receipt["blockHash"].(string)
|
||||
|
||||
param := []interface{}{blockHash, false}
|
||||
rpcRes := call(t, "eth_getBlockByHash", param)
|
||||
|
||||
block := make(map[string]interface{})
|
||||
err := json.Unmarshal(rpcRes.Result, &block)
|
||||
require.NoError(t, err)
|
||||
|
||||
lb := hexToBigInt(t, block["logsBloom"].(string))
|
||||
require.NotEqual(t, big.NewInt(0), lb)
|
||||
}
|
||||
|
||||
func getNonce(t *testing.T) hexutil.Uint64 {
|
||||
from := getAddress(t)
|
||||
param := []interface{}{hexutil.Bytes(from), "latest"}
|
||||
@@ -710,13 +710,6 @@ func getNonce(t *testing.T) hexutil.Uint64 {
|
||||
return nonce
|
||||
}
|
||||
|
||||
func TestEth_GetTransactionCount(t *testing.T) {
|
||||
prev := getNonce(t)
|
||||
sendTestTransaction(t)
|
||||
post := getNonce(t)
|
||||
require.Equal(t, prev, post-1)
|
||||
}
|
||||
|
||||
func TestEth_EstimateGas(t *testing.T) {
|
||||
from := getAddress(t)
|
||||
param := make([]map[string]string, 1)
|
||||
@@ -730,7 +723,7 @@ func TestEth_EstimateGas(t *testing.T) {
|
||||
err := json.Unmarshal(rpcRes.Result, &gas)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, hexutil.Bytes{0xf7, 0xa6}, gas)
|
||||
require.Equal(t, hexutil.Bytes{0xf7, 0xa3}, gas)
|
||||
}
|
||||
|
||||
func TestEth_EstimateGas_ContractDeployment(t *testing.T) {
|
||||
@@ -748,12 +741,12 @@ func TestEth_EstimateGas_ContractDeployment(t *testing.T) {
|
||||
err := json.Unmarshal(rpcRes.Result, &gas)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, hexutil.Uint64(0x1d46e), gas)
|
||||
require.Equal(t, hexutil.Uint64(0x1d46b), gas)
|
||||
}
|
||||
|
||||
func TestEth_ExportAccount(t *testing.T) {
|
||||
param := []string{}
|
||||
param = append(param, "0x1122334455667788990011223344556677889900")
|
||||
param = append(param, "0x1122334455667788990011223344556677889901")
|
||||
param = append(param, "latest")
|
||||
rpcRes := call(t, "eth_exportAccount", param)
|
||||
|
||||
@@ -765,7 +758,7 @@ func TestEth_ExportAccount(t *testing.T) {
|
||||
err = json.Unmarshal([]byte(res), &account)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "0x1122334455667788990011223344556677889900", account.Address.Hex())
|
||||
require.Equal(t, "0x1122334455667788990011223344556677889901", account.Address.Hex())
|
||||
require.Equal(t, big.NewInt(0), account.Balance)
|
||||
require.Equal(t, hexutil.Bytes(nil), account.Code)
|
||||
require.Equal(t, types.Storage(nil), account.Storage)
|
||||
|
||||
Reference in New Issue
Block a user