From ce0feb307bea79737be3f5fb4354108cc8ef9eb5 Mon Sep 17 00:00:00 2001 From: noot <36753753+noot@users.noreply.github.com> Date: Mon, 4 May 2020 18:02:26 -0400 Subject: [PATCH] update rpc tests (#276) * update rpc tests * cleanup * add log assertion to getTransacionReceipt * fix queurier_test * address comment --- rpc/backend.go | 8 +- rpc/eth_api.go | 6 +- rpc/filters.go | 2 +- tests/rpc_test.go | 273 +++++++++++++++++------------------ x/evm/alias.go | 2 +- x/evm/handler.go | 2 +- x/evm/handler_test.go | 2 +- x/evm/keeper/querier.go | 7 +- x/evm/keeper/querier_test.go | 2 +- x/evm/types/querier.go | 2 +- 10 files changed, 147 insertions(+), 159 deletions(-) diff --git a/rpc/backend.go b/rpc/backend.go index fc4b6581..fafe92c7 100644 --- a/rpc/backend.go +++ b/rpc/backend.go @@ -28,7 +28,7 @@ type Backend interface { PendingTransactions() ([]*Transaction, error) // Used by log filter - GetTxLogs(txHash common.Hash) ([]*ethtypes.Log, error) + GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) // TODO: Bloom methods } @@ -154,12 +154,12 @@ func (e *EthermintBackend) getGasLimit() (int64, error) { return gasLimit, nil } -// GetTxLogs returns the logs given a transaction hash. -func (e *EthermintBackend) GetTxLogs(txHash common.Hash) ([]*ethtypes.Log, error) { +// GetTransactionLogs returns the logs given a transaction hash. +func (e *EthermintBackend) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) { // do we need to use the block height somewhere? 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 { return nil, err } diff --git a/rpc/eth_api.go b/rpc/eth_api.go index e76cc158..5f598c5a 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -241,9 +241,9 @@ func (e *PublicEthAPI) GetCode(address common.Address, blockNumber BlockNumber) return out.Code, nil } -// GetTxLogs returns the logs given a transaction hash. -func (e *PublicEthAPI) GetTxLogs(txHash common.Hash) ([]*ethtypes.Log, error) { - return e.backend.GetTxLogs(txHash) +// GetTransactionLogs returns the logs given a transaction hash. +func (e *PublicEthAPI) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) { + return e.backend.GetTransactionLogs(txHash) } // Sign signs the provided data using the private key of address via Geth's signature standard. diff --git a/rpc/filters.go b/rpc/filters.go index 37280f36..4f71edc0 100644 --- a/rpc/filters.go +++ b/rpc/filters.go @@ -273,7 +273,7 @@ func (f *Filter) checkMatches(block map[string]interface{}) ([]*ethtypes.Log, er unfiltered := []*ethtypes.Log{} for _, tx := range transactions { - logs, err := f.backend.GetTxLogs(common.BytesToHash(tx[:])) + logs, err := f.backend.GetTransactionLogs(common.BytesToHash(tx[:])) if err != nil { return nil, err } diff --git a/tests/rpc_test.go b/tests/rpc_test.go index 3bcc8311..e87c9f5d 100644 --- a/tests/rpc_test.go +++ b/tests/rpc_test.go @@ -12,7 +12,6 @@ package tests import ( "bytes" "encoding/json" - "errors" "fmt" "math/big" "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)) - if err != nil { - return nil, 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)) - if err != nil { - t.Log("could not http.Post, ", "err", err) - return nil, err - } + require.NoError(t, err) decoder := json.NewDecoder(res.Body) rpcRes = new(Response) err = decoder.Decode(&rpcRes) - if err != nil { - t.Log("could not decoder.Decode, ", "err", err) - return nil, err - } + require.NoError(t, err) err = res.Body.Close() - if err != nil { - t.Log("could not Body.Close, ", "err", err) - 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 + require.NoError(t, err) + require.Nil(t, rpcRes.Error) + return rpcRes } func TestEth_protocolVersion(t *testing.T) { expectedRes := hexutil.Uint(version.ProtocolVersion) - rpcRes, err := call(t, "eth_protocolVersion", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_protocolVersion", []string{}) var res hexutil.Uint - err = res.UnmarshalJSON(rpcRes.Result) + err := res.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) 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) { - rpcRes, err := call(t, "eth_blockNumber", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_blockNumber", []string{}) var res hexutil.Uint64 - err = res.UnmarshalJSON(rpcRes.Result) + err := res.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) t.Logf("Got block number: %s\n", res.String()) } func TestEth_GetBalance(t *testing.T) { - rpcRes, err := call(t, "eth_getBalance", []string{addrA, zeroString}) - require.NoError(t, err) + rpcRes := call(t, "eth_getBalance", []string{addrA, zeroString}) var res hexutil.Big - err = res.UnmarshalJSON(rpcRes.Result) + err := res.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) 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) { 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}) - require.NoError(t, err) + rpcRes := call(t, "eth_getStorageAt", []string{addrA, string(addrAStoreKey), zeroString}) var storage hexutil.Bytes - err = storage.UnmarshalJSON(rpcRes.Result) + err := storage.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) 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) { expectedRes := hexutil.Bytes{} - rpcRes, err := call(t, "eth_getCode", []string{addrA, zeroString}) - require.NoError(t, err) + rpcRes := call(t, "eth_getCode", []string{addrA, zeroString}) var code hexutil.Bytes - err = code.UnmarshalJSON(rpcRes.Result) + err := code.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) @@ -191,11 +169,10 @@ func TestEth_GetCode(t *testing.T) { } func getAddress(t *testing.T) []byte { - rpcRes, err := call(t, "eth_accounts", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_accounts", []string{}) var res []hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &res) + err := json.Unmarshal(rpcRes.Result, &res) require.NoError(t, err) return res[0] @@ -209,11 +186,10 @@ func TestEth_SendTransaction(t *testing.T) { param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029" - rpcRes, err := call(t, "eth_sendTransaction", param) - require.NoError(t, err) + rpcRes := call(t, "eth_sendTransaction", param) var hash hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &hash) + err := json.Unmarshal(rpcRes.Result, &hash) require.NoError(t, err) } @@ -221,20 +197,18 @@ func TestEth_NewFilter(t *testing.T) { param := make([]map[string][]string, 1) param[0] = make(map[string][]string) param[0]["topics"] = []string{"0x0000000000000000000000000000000000000000000000000000000012341234"} - rpcRes, err := call(t, "eth_newFilter", param) - require.NoError(t, err) + rpcRes := call(t, "eth_newFilter", param) var ID hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &ID) + err := json.Unmarshal(rpcRes.Result, &ID) require.NoError(t, err) } func TestEth_NewBlockFilter(t *testing.T) { - rpcRes, err := call(t, "eth_newBlockFilter", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_newBlockFilter", []string{}) var ID hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &ID) + err := json.Unmarshal(rpcRes.Result, &ID) require.NoError(t, err) } @@ -242,15 +216,13 @@ func TestEth_GetFilterChanges_NoLogs(t *testing.T) { param := make([]map[string][]string, 1) param[0] = make(map[string][]string) param[0]["topics"] = []string{} - rpcRes, err := call(t, "eth_newFilter", param) - require.NoError(t, err) + rpcRes := call(t, "eth_newFilter", param) var ID hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &ID) + err := json.Unmarshal(rpcRes.Result, &ID) require.NoError(t, err) - changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) - require.NoError(t, err) + changesRes := call(t, "eth_getFilterChanges", []string{ID.String()}) var logs []*ethtypes.Log err = json.Unmarshal(changesRes.Result, &logs) @@ -258,8 +230,23 @@ func TestEth_GetFilterChanges_NoLogs(t *testing.T) { } func TestEth_GetFilterChanges_WrongID(t *testing.T) { - _, err := call(t, "eth_getFilterChanges", []string{"0x1122334400000077"}) - require.NotNil(t, err) + req, err := json.Marshal(createRequest("eth_getFilterChanges", []string{"0x1122334400000077"})) + 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 @@ -269,10 +256,10 @@ func sendTestTransaction(t *testing.T) hexutil.Bytes { param[0] = make(map[string]string) param[0]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["to"] = "0x1122334455667788990011223344556677889900" - rpcRes, err := call(t, "eth_sendTransaction", param) - require.NoError(t, err) + rpcRes := call(t, "eth_sendTransaction", param) + var hash hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &hash) + err := json.Unmarshal(rpcRes.Result, &hash) require.NoError(t, err) return hash } @@ -283,77 +270,96 @@ func TestEth_GetTransactionReceipt(t *testing.T) { time.Sleep(time.Second * 5) param := []string{hash.String()} - rpcRes, err := call(t, "eth_getTransactionReceipt", param) - require.NoError(t, err) + rpcRes := call(t, "eth_getTransactionReceipt", param) receipt := make(map[string]interface{}) - err = json.Unmarshal(rpcRes.Result, &receipt) + err := json.Unmarshal(rpcRes.Result, &receipt) require.NoError(t, err) require.Equal(t, "0x1", receipt["status"].(string)) } // 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) param := make([]map[string]string, 1) param[0] = make(map[string]string) param[0]["from"] = "0x" + fmt.Sprintf("%x", from) - param[0]["data"] = "0x60806040526000805534801561001457600080fd5b5060d2806100236000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80634f2be91f1460415780636deebae31460495780638ada066e146051575b600080fd5b6047606d565b005b604f6080565b005b60576094565b6040518082815260200191505060405180910390f35b6000808154809291906001019190505550565b600080815480929190600190039190505550565b6000805490509056fea265627a7a723158207b1aaa18c3100d8aa67f26a53f3cb83d2c69342d17327bd11e1b17c248957bfa64736f6c634300050c0032" + param[0]["data"] = "0x6080604052348015600f57600080fd5b5060117f775a94827b8fd9b519d36cd827093c664f93347070a554f65e4a6f56cd73889860405160405180910390a2603580604b6000396000f3fe6080604052600080fdfea165627a7a723058206cab665f0f557620554bb45adf266708d2bd349b8a4314bdff205ee8440e3c240029" param[0]["gas"] = "0x200000" - rpcRes, err := call(t, "eth_sendTransaction", param) - require.NoError(t, err) + rpcRes := call(t, "eth_sendTransaction", param) var hash hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &hash) + err := json.Unmarshal(rpcRes.Result, &hash) 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) { - hash := deployTestContract(t) + hash, _ := deployTestContract(t) time.Sleep(time.Second * 5) param := []string{hash.String()} - rpcRes, err := call(t, "eth_getTransactionReceipt", param) - require.NoError(t, err) + rpcRes := call(t, "eth_getTransactionReceipt", param) receipt := make(map[string]interface{}) - err = json.Unmarshal(rpcRes.Result, &receipt) + err := json.Unmarshal(rpcRes.Result, &receipt) require.NoError(t, err) require.Equal(t, "0x1", receipt["status"].(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) { - hash := deployTestContract(t) - - time.Sleep(time.Second * 5) - +func getTransactionReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} { 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) + return receipt +} + +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 + } + + time.Sleep(time.Second) + } + + 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) + err := json.Unmarshal(rpcRes.Result, logs) require.NoError(t, err) require.Equal(t, 1, len(*logs)) - t.Log((*logs)[0]) - time.Sleep(time.Second) } func TestEth_GetFilterChanges_NoTopics(t *testing.T) { - rpcRes, err := call(t, "eth_blockNumber", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_blockNumber", []string{}) var res hexutil.Uint64 - err = res.UnmarshalJSON(rpcRes.Result) + err := res.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) param := make([]map[string]interface{}, 1) @@ -362,39 +368,31 @@ func TestEth_GetFilterChanges_NoTopics(t *testing.T) { param[0]["fromBlock"] = res.String() param[0]["toBlock"] = zeroString // latest - // deploy contract, emitting some event - deployTestContract(t) - - rpcRes, err = call(t, "eth_newFilter", param) - require.NoError(t, err) - + // instantiate new filter + rpcRes = call(t, "eth_newFilter", param) var ID hexutil.Bytes err = json.Unmarshal(rpcRes.Result, &ID) require.NoError(t, err) - time.Sleep(time.Second) + // deploy contract, emitting some event + deployTestContract(t) // get filter changes - changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) - require.NoError(t, err) + changesRes := call(t, "eth_getFilterChanges", []string{ID.String()}) var logs []*ethtypes.Log err = json.Unmarshal(changesRes.Result, &logs) require.NoError(t, err) - 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) { + t.Skip() // TODO: need transaction receipts to determine contract deployment address } func TestEth_GetFilterChanges_BlockHash(t *testing.T) { + t.Skip() // 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]["from"] = "0x" + fmt.Sprintf("%x", from) param[0]["data"] = bytecode + param[0]["gas"] = "0x200000" - rpcRes, err := call(t, "eth_sendTransaction", param) - require.NoError(t, err) + rpcRes := call(t, "eth_sendTransaction", param) var hash hexutil.Bytes - err = json.Unmarshal(rpcRes.Result, &hash) + err := json.Unmarshal(rpcRes.Result, &hash) require.NoError(t, err) + receipt := waitForReceipt(t, hash) + require.NotNil(t, receipt, "transaction failed") + require.Equal(t, "0x1", receipt["status"].(string)) + return hash } @@ -443,11 +445,10 @@ func deployTestContractWithFunction(t *testing.T) hexutil.Bytes { func TestEth_GetFilterChanges_Topics_AB(t *testing.T) { time.Sleep(time.Second) - rpcRes, err := call(t, "eth_blockNumber", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_blockNumber", []string{}) var res hexutil.Uint64 - err = res.UnmarshalJSON(rpcRes.Result) + err := res.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) 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]["toBlock"] = zeroString // latest - deployTestContractWithFunction(t) - - rpcRes, err = call(t, "eth_newFilter", param) - require.NoError(t, err) - + // instantiate new filter + rpcRes = call(t, "eth_newFilter", param) var ID hexutil.Bytes err = json.Unmarshal(rpcRes.Result, &ID) require.NoError(t, err) - time.Sleep(time.Second * 2) + deployTestContractWithFunction(t) // get filter changes - changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) - require.NoError(t, err) + changesRes := call(t, "eth_getFilterChanges", []string{ID.String()}) var logs []*ethtypes.Log err = json.Unmarshal(changesRes.Result, &logs) require.NoError(t, err) require.Equal(t, 1, len(logs)) - time.Sleep(time.Second * 2) } func TestEth_GetFilterChanges_Topics_XB(t *testing.T) { - rpcRes, err := call(t, "eth_blockNumber", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_blockNumber", []string{}) var res hexutil.Uint64 - err = res.UnmarshalJSON(rpcRes.Result) + err := res.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) 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]["toBlock"] = "0x0" // latest - deployTestContractWithFunction(t) - - rpcRes, err = call(t, "eth_newFilter", param) - require.NoError(t, err) - + // instantiate new filter + rpcRes = call(t, "eth_newFilter", param) var ID hexutil.Bytes err = json.Unmarshal(rpcRes.Result, &ID) require.NoError(t, err) - time.Sleep(time.Second * 2) + deployTestContractWithFunction(t) // get filter changes - changesRes, err := call(t, "eth_getFilterChanges", []string{ID.String()}) - require.NoError(t, err) + changesRes := call(t, "eth_getFilterChanges", []string{ID.String()}) var logs []*ethtypes.Log err = json.Unmarshal(changesRes.Result, &logs) require.NoError(t, err) require.Equal(t, 1, len(logs)) - time.Sleep(time.Second) } func TestEth_GetFilterChanges_Topics_XXC(t *testing.T) { + t.Skip() // 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[0] = make(map[string][]string) param[0]["topics"] = []string{} - _, err := call(t, "eth_getLogs", param) - require.NoError(t, err) + call(t, "eth_getLogs", param) } func TestEth_GetLogs_Topics_AB(t *testing.T) { - rpcRes, err := call(t, "eth_blockNumber", []string{}) - require.NoError(t, err) + rpcRes := call(t, "eth_blockNumber", []string{}) var res hexutil.Uint64 - err = res.UnmarshalJSON(rpcRes.Result) + err := res.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) 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]["toBlock"] = zeroString // latest - deployTestContractWithFunction(t) + hash := deployTestContractWithFunction(t) + waitForReceipt(t, hash) - rpcRes, err = call(t, "eth_getLogs", param) - require.NoError(t, err) + rpcRes = call(t, "eth_getLogs", param) var logs []*ethtypes.Log err = json.Unmarshal(rpcRes.Result, &logs) @@ -554,12 +543,11 @@ func TestEth_GetLogs_Topics_AB(t *testing.T) { require.Equal(t, 1, len(logs)) } -func TestEth_NewPendingTransactionFilter(t *testing.T) { - rpcRes, err := call(t, "eth_newPendingTransactionFilter", []string{}) - require.NoError(t, err) +func TestEth_PendingTransactionFilter(t *testing.T) { + rpcRes := call(t, "eth_newPendingTransactionFilter", []string{}) var code hexutil.Bytes - err = code.UnmarshalJSON(rpcRes.Result) + err := code.UnmarshalJSON(rpcRes.Result) require.NoError(t, err) require.NotNil(t, code) @@ -570,8 +558,7 @@ func TestEth_NewPendingTransactionFilter(t *testing.T) { time.Sleep(10 * time.Second) // get filter changes - changesRes, err := call(t, "eth_getFilterChanges", []string{code.String()}) - require.NoError(t, err) + changesRes := call(t, "eth_getFilterChanges", []string{code.String()}) require.NotNil(t, changesRes) var txs []*hexutil.Bytes diff --git a/x/evm/alias.go b/x/evm/alias.go index dc5e2822..03ad6792 100644 --- a/x/evm/alias.go +++ b/x/evm/alias.go @@ -19,7 +19,7 @@ const ( QueryCode = types.QueryCode QueryNonce = types.QueryNonce QueryHashToHeight = types.QueryHashToHeight - QueryTxLogs = types.QueryTxLogs + QueryTransactionLogs = types.QueryTransactionLogs QueryLogsBloom = types.QueryLogsBloom QueryLogs = types.QueryLogs QueryAccount = types.QueryAccount diff --git a/x/evm/handler.go b/x/evm/handler.go index 72788b79..b6e5a589 100644 --- a/x/evm/handler.go +++ b/x/evm/handler.go @@ -120,7 +120,6 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk ethHash := common.BytesToHash(txHash) st := types.StateTransition{ - Sender: common.BytesToAddress(msg.From.Bytes()), AccountNonce: msg.AccountNonce, Price: msg.Price.BigInt(), GasLimit: msg.GasLimit, @@ -129,6 +128,7 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk Csdb: k.CommitStateDB.WithContext(ctx), ChainID: intChainID, TxHash: ðHash, + Sender: common.BytesToAddress(msg.From.Bytes()), Simulate: ctx.IsCheckTx(), } diff --git a/x/evm/handler_test.go b/x/evm/handler_test.go index 8b5f80ee..54de8c0c 100644 --- a/x/evm/handler_test.go +++ b/x/evm/handler_test.go @@ -280,7 +280,7 @@ func (suite *EvmTestSuite) TestQueryTxLogs() { suite.Require().Equal(logs, resultData.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{}) suite.Require().NoError(err, "failed to query txLogs") diff --git a/x/evm/keeper/querier.go b/x/evm/keeper/querier.go index aac88c13..5d85d9fd 100644 --- a/x/evm/keeper/querier.go +++ b/x/evm/keeper/querier.go @@ -36,8 +36,8 @@ func NewQuerier(keeper Keeper) sdk.Querier { return queryNonce(ctx, path, keeper) case types.QueryHashToHeight: return queryHashToHeight(ctx, path, keeper) - case types.QueryTxLogs: - return queryTxLogs(ctx, path, keeper) + case types.QueryTransactionLogs: + return queryTransactionLogs(ctx, path, keeper) case types.QueryLogsBloom: return queryBlockLogsBloom(ctx, path, keeper) case types.QueryLogs: @@ -161,8 +161,9 @@ func queryBlockLogsBloom(ctx sdk.Context, path []string, keeper Keeper) ([]byte, 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]) + logs, err := keeper.GetLogs(ctx, txHash) if err != nil { return nil, err diff --git a/x/evm/keeper/querier_test.go b/x/evm/keeper/querier_test.go index 939ce1aa..d6d7d688 100644 --- a/x/evm/keeper/querier_test.go +++ b/x/evm/keeper/querier_test.go @@ -26,7 +26,7 @@ func (suite *KeeperTestSuite) TestQuerier() { {"code", []string{types.QueryCode, "0x0"}, func() {}, true}, {"nonce", []string{types.QueryNonce, "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", []string{types.QueryLogs, "0x0"}, func() {}, true}, {"account", []string{types.QueryAccount, "0x0"}, func() {}, true}, diff --git a/x/evm/types/querier.go b/x/evm/types/querier.go index 6bfb9a51..80089b82 100644 --- a/x/evm/types/querier.go +++ b/x/evm/types/querier.go @@ -15,7 +15,7 @@ const ( QueryCode = "code" QueryNonce = "nonce" QueryHashToHeight = "hashToHeight" - QueryTxLogs = "txLogs" + QueryTransactionLogs = "transactionLogs" QueryLogsBloom = "logsBloom" QueryLogs = "logs" QueryAccount = "account"