diff --git a/CHANGELOG.md b/CHANGELOG.md index 438301dd8d..cd4ff9d9e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (rpc) [#1405](https://github.com/evmos/ethermint/pull/1405) Fix uninitialized chain ID field in gRPC requests. * (analytics) [#1434](https://github.com/evmos/ethermint/pull/1434) Remove unbound labels from custom tendermint metrics. * (rpc) [#1484](https://github.com/evmos/ethermint/pull/1484) Align empty account result for old blocks as ethereum instead of return account not found error. +* (rpc) [#1503](https://github.com/evmos/ethermint/pull/1503) Fix block hashes returned on JSON-RPC filter `eth_newBlockFilter`. ## [v0.19.3] - 2022-10-14 diff --git a/rpc/namespaces/ethereum/eth/filters/api.go b/rpc/namespaces/ethereum/eth/filters/api.go index 500349050e..195e48410a 100644 --- a/rpc/namespaces/ethereum/eth/filters/api.go +++ b/rpc/namespaces/ethereum/eth/filters/api.go @@ -292,12 +292,9 @@ func (api *PublicFilterAPI) NewBlockFilter() rpc.ID { continue } - baseFee := types.BaseFeeFromEvents(data.ResultBeginBlock.Events) - - header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee) api.filtersMu.Lock() if f, found := api.filters[headerSub.ID()]; found { - f.hashes = append(f.hashes, header.Hash()) + f.hashes = append(f.hashes, common.BytesToHash(data.Header.Hash())) } api.filtersMu.Unlock() case <-errCh: diff --git a/tests/integration_tests/test_filters.py b/tests/integration_tests/test_filters.py index e4ec2fba91..324fe1e2ec 100644 --- a/tests/integration_tests/test_filters.py +++ b/tests/integration_tests/test_filters.py @@ -21,6 +21,10 @@ def test_pending_transaction_filter(cluster): txhash = send_successful_transaction(w3) assert txhash in flt.get_new_entries() + # check if tx_hash is valid + tx = w3.eth.get_transaction(txhash) + assert tx.hash == txhash + # without new txs since last call assert flt.get_new_entries() == [] @@ -34,8 +38,14 @@ def test_block_filter(cluster): # with tx send_successful_transaction(w3) - blocks = flt.get_new_entries() - assert len(blocks) >= 1 + block_hashes = flt.get_new_entries() + assert len(block_hashes) >= 1 + + # check if the returned block hash is correct + # getBlockByHash + block = w3.eth.get_block(block_hashes[0]) + # block should exist + assert block.hash == block_hashes[0] # without new txs since last call assert flt.get_new_entries() == [] diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index 2d93148458..dec91afd7b 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -12,6 +12,7 @@ from eth_account import Account from hexbytes import HexBytes from web3._utils.transactions import fill_nonce, fill_transaction_defaults +from web3.exceptions import TimeExhausted load_dotenv(Path(__file__).parent.parent.parent / "scripts/.env") Account.enable_unaudited_hdwallet_features() @@ -149,17 +150,27 @@ def sign_transaction(w3, tx, key=KEYS["validator"]): return acct.sign_transaction(tx) -def send_transaction(w3, tx, key=KEYS["validator"]): +def send_transaction(w3, tx, key=KEYS["validator"], i=0): + if i > 3: + raise TimeExhausted signed = sign_transaction(w3, tx, key) txhash = w3.eth.send_raw_transaction(signed.rawTransaction) - return w3.eth.wait_for_transaction_receipt(txhash) + try: + return w3.eth.wait_for_transaction_receipt(txhash, timeout=20) + except TimeExhausted: + return send_transaction(w3, tx, key, i + 1) -def send_successful_transaction(w3): +def send_successful_transaction(w3, i=0): + if i > 3: + raise TimeExhausted signed = sign_transaction(w3, {"to": ADDRS["community"], "value": 1000}) txhash = w3.eth.send_raw_transaction(signed.rawTransaction) - receipt = w3.eth.wait_for_transaction_receipt(txhash) - assert receipt.status == 1 + try: + receipt = w3.eth.wait_for_transaction_receipt(txhash, timeout=20) + assert receipt.status == 1 + except TimeExhausted: + return send_successful_transaction(w3, i + 1) return txhash