update rpc tests (#276)

* update rpc tests

* cleanup

* add log assertion to getTransacionReceipt

* fix queurier_test

* address comment
This commit is contained in:
noot 2020-05-04 18:02:26 -04:00 committed by GitHub
parent 26d4e968e0
commit ce0feb307b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 147 additions and 159 deletions

View File

@ -28,7 +28,7 @@ type Backend interface {
PendingTransactions() ([]*Transaction, error) PendingTransactions() ([]*Transaction, error)
// Used by log filter // Used by log filter
GetTxLogs(txHash common.Hash) ([]*ethtypes.Log, error) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error)
// TODO: Bloom methods // TODO: Bloom methods
} }
@ -154,12 +154,12 @@ func (e *EthermintBackend) getGasLimit() (int64, error) {
return gasLimit, nil return gasLimit, nil
} }
// GetTxLogs returns the logs given a transaction hash. // GetTransactionLogs returns the logs given a transaction hash.
func (e *EthermintBackend) GetTxLogs(txHash common.Hash) ([]*ethtypes.Log, error) { func (e *EthermintBackend) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) {
// do we need to use the block height somewhere? // do we need to use the block height somewhere?
ctx := e.cliCtx ctx := e.cliCtx
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryTxLogs, txHash.Hex()), nil) res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryTransactionLogs, txHash.Hex()), nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -241,9 +241,9 @@ func (e *PublicEthAPI) GetCode(address common.Address, blockNumber BlockNumber)
return out.Code, nil return out.Code, nil
} }
// GetTxLogs returns the logs given a transaction hash. // GetTransactionLogs returns the logs given a transaction hash.
func (e *PublicEthAPI) GetTxLogs(txHash common.Hash) ([]*ethtypes.Log, error) { func (e *PublicEthAPI) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) {
return e.backend.GetTxLogs(txHash) return e.backend.GetTransactionLogs(txHash)
} }
// Sign signs the provided data using the private key of address via Geth's signature standard. // Sign signs the provided data using the private key of address via Geth's signature standard.

View File

@ -273,7 +273,7 @@ func (f *Filter) checkMatches(block map[string]interface{}) ([]*ethtypes.Log, er
unfiltered := []*ethtypes.Log{} unfiltered := []*ethtypes.Log{}
for _, tx := range transactions { for _, tx := range transactions {
logs, err := f.backend.GetTxLogs(common.BytesToHash(tx[:])) logs, err := f.backend.GetTransactionLogs(common.BytesToHash(tx[:]))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -12,7 +12,6 @@ package tests
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"net/http" "net/http"
@ -83,52 +82,35 @@ func createRequest(method string, params interface{}) Request {
} }
} }
func call(t *testing.T, method string, params interface{}) (*Response, error) { func call(t *testing.T, method string, params interface{}) *Response {
req, err := json.Marshal(createRequest(method, params)) req, err := json.Marshal(createRequest(method, params))
if err != nil { require.NoError(t, err)
return nil, err
}
var rpcRes *Response var rpcRes *Response
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
/* #nosec */ /* #nosec */
res, err := http.Post(ETHERMINT_NODE_HOST, "application/json", bytes.NewBuffer(req)) res, err := http.Post(ETHERMINT_NODE_HOST, "application/json", bytes.NewBuffer(req))
if err != nil { require.NoError(t, err)
t.Log("could not http.Post, ", "err", err)
return nil, err
}
decoder := json.NewDecoder(res.Body) decoder := json.NewDecoder(res.Body)
rpcRes = new(Response) rpcRes = new(Response)
err = decoder.Decode(&rpcRes) err = decoder.Decode(&rpcRes)
if err != nil { require.NoError(t, err)
t.Log("could not decoder.Decode, ", "err", err)
return nil, err
}
err = res.Body.Close() err = res.Body.Close()
if err != nil { require.NoError(t, err)
t.Log("could not Body.Close, ", "err", err) require.Nil(t, rpcRes.Error)
return nil, err
}
if rpcRes.Error != nil {
t.Log("could not rpcRes.Error, ", "err", err)
return nil, errors.New(rpcRes.Error.Message)
}
return rpcRes, nil
return rpcRes
} }
func TestEth_protocolVersion(t *testing.T) { func TestEth_protocolVersion(t *testing.T) {
expectedRes := hexutil.Uint(version.ProtocolVersion) expectedRes := hexutil.Uint(version.ProtocolVersion)
rpcRes, err := call(t, "eth_protocolVersion", []string{}) rpcRes := call(t, "eth_protocolVersion", []string{})
require.NoError(t, err)
var res hexutil.Uint var res hexutil.Uint
err = res.UnmarshalJSON(rpcRes.Result) err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
t.Logf("Got protocol version: %s\n", res.String()) t.Logf("Got protocol version: %s\n", res.String())
@ -136,22 +118,20 @@ func TestEth_protocolVersion(t *testing.T) {
} }
func TestEth_blockNumber(t *testing.T) { func TestEth_blockNumber(t *testing.T) {
rpcRes, err := call(t, "eth_blockNumber", []string{}) rpcRes := call(t, "eth_blockNumber", []string{})
require.NoError(t, err)
var res hexutil.Uint64 var res hexutil.Uint64
err = res.UnmarshalJSON(rpcRes.Result) err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
t.Logf("Got block number: %s\n", res.String()) t.Logf("Got block number: %s\n", res.String())
} }
func TestEth_GetBalance(t *testing.T) { func TestEth_GetBalance(t *testing.T) {
rpcRes, err := call(t, "eth_getBalance", []string{addrA, zeroString}) rpcRes := call(t, "eth_getBalance", []string{addrA, zeroString})
require.NoError(t, err)
var res hexutil.Big var res hexutil.Big
err = res.UnmarshalJSON(rpcRes.Result) err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
t.Logf("Got balance %s for %s\n", res.String(), addrA) t.Logf("Got balance %s for %s\n", res.String(), addrA)
@ -164,11 +144,10 @@ func TestEth_GetBalance(t *testing.T) {
func TestEth_GetStorageAt(t *testing.T) { func TestEth_GetStorageAt(t *testing.T) {
expectedRes := hexutil.Bytes{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} expectedRes := hexutil.Bytes{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
rpcRes, err := call(t, "eth_getStorageAt", []string{addrA, string(addrAStoreKey), zeroString}) rpcRes := call(t, "eth_getStorageAt", []string{addrA, string(addrAStoreKey), zeroString})
require.NoError(t, err)
var storage hexutil.Bytes var storage hexutil.Bytes
err = storage.UnmarshalJSON(rpcRes.Result) err := storage.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
t.Logf("Got value [%X] for %s with key %X\n", storage, addrA, addrAStoreKey) t.Logf("Got value [%X] for %s with key %X\n", storage, addrA, addrAStoreKey)
@ -178,11 +157,10 @@ func TestEth_GetStorageAt(t *testing.T) {
func TestEth_GetCode(t *testing.T) { func TestEth_GetCode(t *testing.T) {
expectedRes := hexutil.Bytes{} expectedRes := hexutil.Bytes{}
rpcRes, err := call(t, "eth_getCode", []string{addrA, zeroString}) rpcRes := call(t, "eth_getCode", []string{addrA, zeroString})
require.NoError(t, err)
var code hexutil.Bytes var code hexutil.Bytes
err = code.UnmarshalJSON(rpcRes.Result) err := code.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
@ -191,11 +169,10 @@ func TestEth_GetCode(t *testing.T) {
} }
func getAddress(t *testing.T) []byte { func getAddress(t *testing.T) []byte {
rpcRes, err := call(t, "eth_accounts", []string{}) rpcRes := call(t, "eth_accounts", []string{})
require.NoError(t, err)
var res []hexutil.Bytes var res []hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &res) err := json.Unmarshal(rpcRes.Result, &res)
require.NoError(t, err) require.NoError(t, err)
return res[0] return res[0]
@ -209,11 +186,10 @@ func TestEth_SendTransaction(t *testing.T) {
param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029" param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029"
rpcRes, err := call(t, "eth_sendTransaction", param) rpcRes := call(t, "eth_sendTransaction", param)
require.NoError(t, err)
var hash hexutil.Bytes var hash hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &hash) err := json.Unmarshal(rpcRes.Result, &hash)
require.NoError(t, err) require.NoError(t, err)
} }
@ -221,20 +197,18 @@ func TestEth_NewFilter(t *testing.T) {
param := make([]map[string][]string, 1) param := make([]map[string][]string, 1)
param[0] = make(map[string][]string) param[0] = make(map[string][]string)
param[0]["topics"] = []string{"0x0000000000000000000000000000000000000000000000000000000012341234"} param[0]["topics"] = []string{"0x0000000000000000000000000000000000000000000000000000000012341234"}
rpcRes, err := call(t, "eth_newFilter", param) rpcRes := call(t, "eth_newFilter", param)
require.NoError(t, err)
var ID hexutil.Bytes var ID hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &ID) err := json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err) require.NoError(t, err)
} }
func TestEth_NewBlockFilter(t *testing.T) { func TestEth_NewBlockFilter(t *testing.T) {
rpcRes, err := call(t, "eth_newBlockFilter", []string{}) rpcRes := call(t, "eth_newBlockFilter", []string{})
require.NoError(t, err)
var ID hexutil.Bytes var ID hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &ID) err := json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err) require.NoError(t, err)
} }
@ -242,15 +216,13 @@ func TestEth_GetFilterChanges_NoLogs(t *testing.T) {
param := make([]map[string][]string, 1) param := make([]map[string][]string, 1)
param[0] = make(map[string][]string) param[0] = make(map[string][]string)
param[0]["topics"] = []string{} param[0]["topics"] = []string{}
rpcRes, err := call(t, "eth_newFilter", param) rpcRes := call(t, "eth_newFilter", param)
require.NoError(t, err)
var ID hexutil.Bytes var ID hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &ID) err := json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err) require.NoError(t, err)
changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
require.NoError(t, err)
var logs []*ethtypes.Log var logs []*ethtypes.Log
err = json.Unmarshal(changesRes.Result, &logs) err = json.Unmarshal(changesRes.Result, &logs)
@ -258,8 +230,23 @@ func TestEth_GetFilterChanges_NoLogs(t *testing.T) {
} }
func TestEth_GetFilterChanges_WrongID(t *testing.T) { func TestEth_GetFilterChanges_WrongID(t *testing.T) {
_, err := call(t, "eth_getFilterChanges", []string{"0x1122334400000077"}) req, err := json.Marshal(createRequest("eth_getFilterChanges", []string{"0x1122334400000077"}))
require.NotNil(t, err) require.NoError(t, err)
var rpcRes *Response
time.Sleep(1 * time.Second)
/* #nosec */
res, err := http.Post(ETHERMINT_NODE_HOST, "application/json", bytes.NewBuffer(req))
require.NoError(t, err)
decoder := json.NewDecoder(res.Body)
rpcRes = new(Response)
err = decoder.Decode(&rpcRes)
require.NoError(t, err)
err = res.Body.Close()
require.NoError(t, err)
require.NotNil(t, "invalid filter ID", rpcRes.Error.Message)
} }
// sendTestTransaction sends a dummy transaction // sendTestTransaction sends a dummy transaction
@ -269,10 +256,10 @@ func sendTestTransaction(t *testing.T) hexutil.Bytes {
param[0] = make(map[string]string) param[0] = make(map[string]string)
param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["to"] = "0x1122334455667788990011223344556677889900" param[0]["to"] = "0x1122334455667788990011223344556677889900"
rpcRes, err := call(t, "eth_sendTransaction", param) rpcRes := call(t, "eth_sendTransaction", param)
require.NoError(t, err)
var hash hexutil.Bytes var hash hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &hash) err := json.Unmarshal(rpcRes.Result, &hash)
require.NoError(t, err) require.NoError(t, err)
return hash return hash
} }
@ -283,77 +270,96 @@ func TestEth_GetTransactionReceipt(t *testing.T) {
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
param := []string{hash.String()} param := []string{hash.String()}
rpcRes, err := call(t, "eth_getTransactionReceipt", param) rpcRes := call(t, "eth_getTransactionReceipt", param)
require.NoError(t, err)
receipt := make(map[string]interface{}) receipt := make(map[string]interface{})
err = json.Unmarshal(rpcRes.Result, &receipt) err := json.Unmarshal(rpcRes.Result, &receipt)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "0x1", receipt["status"].(string)) require.Equal(t, "0x1", receipt["status"].(string))
} }
// deployTestContract deploys a contract that emits an event in the constructor // deployTestContract deploys a contract that emits an event in the constructor
func deployTestContract(t *testing.T) hexutil.Bytes { func deployTestContract(t *testing.T) (hexutil.Bytes, map[string]interface{}) {
from := getAddress(t) from := getAddress(t)
param := make([]map[string]string, 1) param := make([]map[string]string, 1)
param[0] = make(map[string]string) param[0] = make(map[string]string)
param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["data"] = "0x60806040526000805534801561001457600080fd5b5060d2806100236000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80634f2be91f1460415780636deebae31460495780638ada066e146051575b600080fd5b6047606d565b005b604f6080565b005b60576094565b6040518082815260200191505060405180910390f35b6000808154809291906001019190505550565b600080815480929190600190039190505550565b6000805490509056fea265627a7a723158207b1aaa18c3100d8aa67f26a53f3cb83d2c69342d17327bd11e1b17c248957bfa64736f6c634300050c0032" param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029"
param[0]["gas"] = "0x200000" param[0]["gas"] = "0x200000"
rpcRes, err := call(t, "eth_sendTransaction", param) rpcRes := call(t, "eth_sendTransaction", param)
require.NoError(t, err)
var hash hexutil.Bytes var hash hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &hash) err := json.Unmarshal(rpcRes.Result, &hash)
require.NoError(t, err) require.NoError(t, err)
return hash receipt := waitForReceipt(t, hash)
require.NotNil(t, receipt, "transaction failed")
require.Equal(t, "0x1", receipt["status"].(string))
return hash, receipt
} }
func TestEth_GetTransactionReceipt_ContractDeployment(t *testing.T) { func TestEth_GetTransactionReceipt_ContractDeployment(t *testing.T) {
hash := deployTestContract(t) hash, _ := deployTestContract(t)
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
param := []string{hash.String()} param := []string{hash.String()}
rpcRes, err := call(t, "eth_getTransactionReceipt", param) rpcRes := call(t, "eth_getTransactionReceipt", param)
require.NoError(t, err)
receipt := make(map[string]interface{}) receipt := make(map[string]interface{})
err = json.Unmarshal(rpcRes.Result, &receipt) err := json.Unmarshal(rpcRes.Result, &receipt)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "0x1", receipt["status"].(string)) require.Equal(t, "0x1", receipt["status"].(string))
require.NotEqual(t, ethcmn.Address{}.String(), receipt["contractAddress"].(string)) require.NotEqual(t, ethcmn.Address{}.String(), receipt["contractAddress"].(string))
// TODO: assert logs exist require.NotNil(t, receipt["logs"])
} }
func TestEth_GetTxLogs(t *testing.T) { func getTransactionReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
hash := deployTestContract(t)
time.Sleep(time.Second * 5)
param := []string{hash.String()} param := []string{hash.String()}
rpcRes, err := call(t, "eth_getTxLogs", param) rpcRes := call(t, "eth_getTransactionReceipt", param)
receipt := make(map[string]interface{})
err := json.Unmarshal(rpcRes.Result, &receipt)
require.NoError(t, err) require.NoError(t, err)
logs := new([]*ethtypes.Log) return receipt
err = json.Unmarshal(rpcRes.Result, logs) }
require.NoError(t, err)
func waitForReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
for i := 0; i < 12; i++ {
receipt := getTransactionReceipt(t, hash)
if receipt != nil {
return receipt
}
require.Equal(t, 1, len(*logs))
t.Log((*logs)[0])
time.Sleep(time.Second) time.Sleep(time.Second)
} }
func TestEth_GetFilterChanges_NoTopics(t *testing.T) { return nil
rpcRes, err := call(t, "eth_blockNumber", []string{}) }
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.NoError(t, err)
require.Equal(t, 1, len(*logs))
}
func TestEth_GetFilterChanges_NoTopics(t *testing.T) {
rpcRes := call(t, "eth_blockNumber", []string{})
var res hexutil.Uint64 var res hexutil.Uint64
err = res.UnmarshalJSON(rpcRes.Result) err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
param := make([]map[string]interface{}, 1) param := make([]map[string]interface{}, 1)
@ -362,39 +368,31 @@ func TestEth_GetFilterChanges_NoTopics(t *testing.T) {
param[0]["fromBlock"] = res.String() param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = zeroString // latest param[0]["toBlock"] = zeroString // latest
// deploy contract, emitting some event // instantiate new filter
deployTestContract(t) rpcRes = call(t, "eth_newFilter", param)
rpcRes, err = call(t, "eth_newFilter", param)
require.NoError(t, err)
var ID hexutil.Bytes var ID hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &ID) err = json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err) require.NoError(t, err)
time.Sleep(time.Second) // deploy contract, emitting some event
deployTestContract(t)
// get filter changes // get filter changes
changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
require.NoError(t, err)
var logs []*ethtypes.Log var logs []*ethtypes.Log
err = json.Unmarshal(changesRes.Result, &logs) err = json.Unmarshal(changesRes.Result, &logs)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(logs)) require.Equal(t, 1, len(logs))
time.Sleep(time.Second)
//t.Log(logs[0])
// TODO: why is the tx hash in the log not the same as the tx hash of the transaction?
//require.Equal(t, logs[0].TxHash, common.BytesToHash(hash))
} }
func TestEth_GetFilterChanges_Addresses(t *testing.T) { func TestEth_GetFilterChanges_Addresses(t *testing.T) {
t.Skip()
// TODO: need transaction receipts to determine contract deployment address // TODO: need transaction receipts to determine contract deployment address
} }
func TestEth_GetFilterChanges_BlockHash(t *testing.T) { func TestEth_GetFilterChanges_BlockHash(t *testing.T) {
t.Skip()
// TODO: need transaction receipts to determine tx block // TODO: need transaction receipts to determine tx block
} }
@ -428,14 +426,18 @@ func deployTestContractWithFunction(t *testing.T) hexutil.Bytes {
param[0] = make(map[string]string) param[0] = make(map[string]string)
param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["from"] = "0x" + fmt.Sprintf("%x", from)
param[0]["data"] = bytecode param[0]["data"] = bytecode
param[0]["gas"] = "0x200000"
rpcRes, err := call(t, "eth_sendTransaction", param) rpcRes := call(t, "eth_sendTransaction", param)
require.NoError(t, err)
var hash hexutil.Bytes var hash hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &hash) err := json.Unmarshal(rpcRes.Result, &hash)
require.NoError(t, err) require.NoError(t, err)
receipt := waitForReceipt(t, hash)
require.NotNil(t, receipt, "transaction failed")
require.Equal(t, "0x1", receipt["status"].(string))
return hash return hash
} }
@ -443,11 +445,10 @@ func deployTestContractWithFunction(t *testing.T) hexutil.Bytes {
func TestEth_GetFilterChanges_Topics_AB(t *testing.T) { func TestEth_GetFilterChanges_Topics_AB(t *testing.T) {
time.Sleep(time.Second) time.Sleep(time.Second)
rpcRes, err := call(t, "eth_blockNumber", []string{}) rpcRes := call(t, "eth_blockNumber", []string{})
require.NoError(t, err)
var res hexutil.Uint64 var res hexutil.Uint64
err = res.UnmarshalJSON(rpcRes.Result) err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
param := make([]map[string]interface{}, 1) param := make([]map[string]interface{}, 1)
@ -456,35 +457,29 @@ func TestEth_GetFilterChanges_Topics_AB(t *testing.T) {
param[0]["fromBlock"] = res.String() param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = zeroString // latest param[0]["toBlock"] = zeroString // latest
deployTestContractWithFunction(t) // instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
rpcRes, err = call(t, "eth_newFilter", param)
require.NoError(t, err)
var ID hexutil.Bytes var ID hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &ID) err = json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err) require.NoError(t, err)
time.Sleep(time.Second * 2) deployTestContractWithFunction(t)
// get filter changes // get filter changes
changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
require.NoError(t, err)
var logs []*ethtypes.Log var logs []*ethtypes.Log
err = json.Unmarshal(changesRes.Result, &logs) err = json.Unmarshal(changesRes.Result, &logs)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(logs)) require.Equal(t, 1, len(logs))
time.Sleep(time.Second * 2)
} }
func TestEth_GetFilterChanges_Topics_XB(t *testing.T) { func TestEth_GetFilterChanges_Topics_XB(t *testing.T) {
rpcRes, err := call(t, "eth_blockNumber", []string{}) rpcRes := call(t, "eth_blockNumber", []string{})
require.NoError(t, err)
var res hexutil.Uint64 var res hexutil.Uint64
err = res.UnmarshalJSON(rpcRes.Result) err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
param := make([]map[string]interface{}, 1) param := make([]map[string]interface{}, 1)
@ -493,30 +488,26 @@ func TestEth_GetFilterChanges_Topics_XB(t *testing.T) {
param[0]["fromBlock"] = res.String() param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = "0x0" // latest param[0]["toBlock"] = "0x0" // latest
deployTestContractWithFunction(t) // instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
rpcRes, err = call(t, "eth_newFilter", param)
require.NoError(t, err)
var ID hexutil.Bytes var ID hexutil.Bytes
err = json.Unmarshal(rpcRes.Result, &ID) err = json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err) require.NoError(t, err)
time.Sleep(time.Second * 2) deployTestContractWithFunction(t)
// get filter changes // get filter changes
changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
require.NoError(t, err)
var logs []*ethtypes.Log var logs []*ethtypes.Log
err = json.Unmarshal(changesRes.Result, &logs) err = json.Unmarshal(changesRes.Result, &logs)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(logs)) require.Equal(t, 1, len(logs))
time.Sleep(time.Second)
} }
func TestEth_GetFilterChanges_Topics_XXC(t *testing.T) { func TestEth_GetFilterChanges_Topics_XXC(t *testing.T) {
t.Skip()
// TODO: call test function, need tx receipts to determine contract address // TODO: call test function, need tx receipts to determine contract address
} }
@ -524,16 +515,14 @@ func TestEth_GetLogs_NoLogs(t *testing.T) {
param := make([]map[string][]string, 1) param := make([]map[string][]string, 1)
param[0] = make(map[string][]string) param[0] = make(map[string][]string)
param[0]["topics"] = []string{} param[0]["topics"] = []string{}
_, err := call(t, "eth_getLogs", param) call(t, "eth_getLogs", param)
require.NoError(t, err)
} }
func TestEth_GetLogs_Topics_AB(t *testing.T) { func TestEth_GetLogs_Topics_AB(t *testing.T) {
rpcRes, err := call(t, "eth_blockNumber", []string{}) rpcRes := call(t, "eth_blockNumber", []string{})
require.NoError(t, err)
var res hexutil.Uint64 var res hexutil.Uint64
err = res.UnmarshalJSON(rpcRes.Result) err := res.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
param := make([]map[string]interface{}, 1) param := make([]map[string]interface{}, 1)
@ -542,10 +531,10 @@ func TestEth_GetLogs_Topics_AB(t *testing.T) {
param[0]["fromBlock"] = res.String() param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = zeroString // latest param[0]["toBlock"] = zeroString // latest
deployTestContractWithFunction(t) hash := deployTestContractWithFunction(t)
waitForReceipt(t, hash)
rpcRes, err = call(t, "eth_getLogs", param) rpcRes = call(t, "eth_getLogs", param)
require.NoError(t, err)
var logs []*ethtypes.Log var logs []*ethtypes.Log
err = json.Unmarshal(rpcRes.Result, &logs) err = json.Unmarshal(rpcRes.Result, &logs)
@ -554,12 +543,11 @@ func TestEth_GetLogs_Topics_AB(t *testing.T) {
require.Equal(t, 1, len(logs)) require.Equal(t, 1, len(logs))
} }
func TestEth_NewPendingTransactionFilter(t *testing.T) { func TestEth_PendingTransactionFilter(t *testing.T) {
rpcRes, err := call(t, "eth_newPendingTransactionFilter", []string{}) rpcRes := call(t, "eth_newPendingTransactionFilter", []string{})
require.NoError(t, err)
var code hexutil.Bytes var code hexutil.Bytes
err = code.UnmarshalJSON(rpcRes.Result) err := code.UnmarshalJSON(rpcRes.Result)
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, code) require.NotNil(t, code)
@ -570,8 +558,7 @@ func TestEth_NewPendingTransactionFilter(t *testing.T) {
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
// get filter changes // get filter changes
changesRes, err := call(t, "eth_getFilterChanges", []string{code.String()}) changesRes := call(t, "eth_getFilterChanges", []string{code.String()})
require.NoError(t, err)
require.NotNil(t, changesRes) require.NotNil(t, changesRes)
var txs []*hexutil.Bytes var txs []*hexutil.Bytes

View File

@ -19,7 +19,7 @@ const (
QueryCode = types.QueryCode QueryCode = types.QueryCode
QueryNonce = types.QueryNonce QueryNonce = types.QueryNonce
QueryHashToHeight = types.QueryHashToHeight QueryHashToHeight = types.QueryHashToHeight
QueryTxLogs = types.QueryTxLogs QueryTransactionLogs = types.QueryTransactionLogs
QueryLogsBloom = types.QueryLogsBloom QueryLogsBloom = types.QueryLogsBloom
QueryLogs = types.QueryLogs QueryLogs = types.QueryLogs
QueryAccount = types.QueryAccount QueryAccount = types.QueryAccount

View File

@ -120,7 +120,6 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
ethHash := common.BytesToHash(txHash) ethHash := common.BytesToHash(txHash)
st := types.StateTransition{ st := types.StateTransition{
Sender: common.BytesToAddress(msg.From.Bytes()),
AccountNonce: msg.AccountNonce, AccountNonce: msg.AccountNonce,
Price: msg.Price.BigInt(), Price: msg.Price.BigInt(),
GasLimit: msg.GasLimit, GasLimit: msg.GasLimit,
@ -129,6 +128,7 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
Csdb: k.CommitStateDB.WithContext(ctx), Csdb: k.CommitStateDB.WithContext(ctx),
ChainID: intChainID, ChainID: intChainID,
TxHash: &ethHash, TxHash: &ethHash,
Sender: common.BytesToAddress(msg.From.Bytes()),
Simulate: ctx.IsCheckTx(), Simulate: ctx.IsCheckTx(),
} }

View File

@ -280,7 +280,7 @@ func (suite *EvmTestSuite) TestQueryTxLogs() {
suite.Require().Equal(logs, resultData.Logs) suite.Require().Equal(logs, resultData.Logs)
// query tx logs // query tx logs
path := []string{"txLogs", fmt.Sprintf("0x%x", hash)} path := []string{"transactionLogs", fmt.Sprintf("0x%x", hash)}
res, err := suite.querier(suite.ctx, path, abci.RequestQuery{}) res, err := suite.querier(suite.ctx, path, abci.RequestQuery{})
suite.Require().NoError(err, "failed to query txLogs") suite.Require().NoError(err, "failed to query txLogs")

View File

@ -36,8 +36,8 @@ func NewQuerier(keeper Keeper) sdk.Querier {
return queryNonce(ctx, path, keeper) return queryNonce(ctx, path, keeper)
case types.QueryHashToHeight: case types.QueryHashToHeight:
return queryHashToHeight(ctx, path, keeper) return queryHashToHeight(ctx, path, keeper)
case types.QueryTxLogs: case types.QueryTransactionLogs:
return queryTxLogs(ctx, path, keeper) return queryTransactionLogs(ctx, path, keeper)
case types.QueryLogsBloom: case types.QueryLogsBloom:
return queryBlockLogsBloom(ctx, path, keeper) return queryBlockLogsBloom(ctx, path, keeper)
case types.QueryLogs: case types.QueryLogs:
@ -161,8 +161,9 @@ func queryBlockLogsBloom(ctx sdk.Context, path []string, keeper Keeper) ([]byte,
return bz, nil return bz, nil
} }
func queryTxLogs(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) { func queryTransactionLogs(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
txHash := ethcmn.HexToHash(path[1]) txHash := ethcmn.HexToHash(path[1])
logs, err := keeper.GetLogs(ctx, txHash) logs, err := keeper.GetLogs(ctx, txHash)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -26,7 +26,7 @@ func (suite *KeeperTestSuite) TestQuerier() {
{"code", []string{types.QueryCode, "0x0"}, func() {}, true}, {"code", []string{types.QueryCode, "0x0"}, func() {}, true},
{"nonce", []string{types.QueryNonce, "0x0"}, func() {}, true}, {"nonce", []string{types.QueryNonce, "0x0"}, func() {}, true},
// {"hash to height", []string{types.QueryHashToHeight, "0x0"}, func() {}, true}, // {"hash to height", []string{types.QueryHashToHeight, "0x0"}, func() {}, true},
{"tx logs", []string{types.QueryTxLogs, "0x0"}, func() {}, true}, {"tx logs", []string{types.QueryTransactionLogs, "0x0"}, func() {}, true},
// {"logs bloom", []string{types.QueryLogsBloom, "0x0"}, func() {}, true}, // {"logs bloom", []string{types.QueryLogsBloom, "0x0"}, func() {}, true},
{"logs", []string{types.QueryLogs, "0x0"}, func() {}, true}, {"logs", []string{types.QueryLogs, "0x0"}, func() {}, true},
{"account", []string{types.QueryAccount, "0x0"}, func() {}, true}, {"account", []string{types.QueryAccount, "0x0"}, func() {}, true},

View File

@ -15,7 +15,7 @@ const (
QueryCode = "code" QueryCode = "code"
QueryNonce = "nonce" QueryNonce = "nonce"
QueryHashToHeight = "hashToHeight" QueryHashToHeight = "hashToHeight"
QueryTxLogs = "txLogs" QueryTransactionLogs = "transactionLogs"
QueryLogsBloom = "logsBloom" QueryLogsBloom = "logsBloom"
QueryLogs = "logs" QueryLogs = "logs"
QueryAccount = "account" QueryAccount = "account"