status-go/tests-functional/tests/test_eth_api.py

61 lines
2.6 KiB
Python
Raw Permalink Normal View History

import pytest
2024-10-11 08:08:39 +00:00
from test_cases import EthRpcTestCase
2024-10-11 08:08:39 +00:00
def validate_header(header, block_number, block_hash):
assert header["number"] == block_number
assert header["hash"] == block_hash
2024-10-11 08:08:39 +00:00
def validate_block(block, block_number, block_hash, expected_tx_hash):
validate_header(block["header"], block_number, block_hash)
tx_hashes = [tx["hash"] for tx in block["transactions"]]
assert expected_tx_hash in tx_hashes
2024-10-11 08:08:39 +00:00
def validate_transaction(tx, tx_hash):
assert tx["tx"]["hash"] == tx_hash
2024-10-11 08:08:39 +00:00
def validate_receipt(receipt, tx_hash, block_number, block_hash):
assert receipt["transactionHash"] == tx_hash
assert receipt["blockNumber"] == block_number
assert receipt["blockHash"] == block_hash
2024-10-11 08:08:39 +00:00
@pytest.mark.rpc
@pytest.mark.ethclient
class TestEth(EthRpcTestCase):
def test_block_number(self):
self.rpc_client.rpc_valid_request("ethclient_blockNumber", [self.network_id])
def test_suggest_gas_price(self):
self.rpc_client.rpc_valid_request("ethclient_suggestGasPrice", [self.network_id])
def test_header_by_number(self, tx_data):
2024-10-11 08:08:39 +00:00
response = self.rpc_client.rpc_valid_request("ethclient_headerByNumber",
[self.network_id, tx_data.block_number])
validate_header(response.json()["result"], tx_data.block_number, tx_data.block_hash)
def test_block_by_number(self, tx_data):
response = self.rpc_client.rpc_valid_request("ethclient_blockByNumber", [self.network_id, tx_data.block_number])
2024-10-11 08:08:39 +00:00
validate_block(response.json()["result"], tx_data.block_number, tx_data.block_hash, tx_data.tx_hash)
def test_header_by_hash(self, tx_data):
response = self.rpc_client.rpc_valid_request("ethclient_headerByHash", [self.network_id, tx_data.block_hash])
2024-10-11 08:08:39 +00:00
validate_header(response.json()["result"], tx_data.block_number, tx_data.block_hash)
def test_block_by_hash(self, tx_data):
response = self.rpc_client.rpc_valid_request("ethclient_blockByHash", [self.network_id, tx_data.block_hash])
2024-10-11 08:08:39 +00:00
validate_block(response.json()["result"], tx_data.block_number, tx_data.block_hash, tx_data.tx_hash)
def test_transaction_by_hash(self, tx_data):
response = self.rpc_client.rpc_valid_request("ethclient_transactionByHash", [self.network_id, tx_data.tx_hash])
2024-10-11 08:08:39 +00:00
validate_transaction(response.json()["result"], tx_data.tx_hash)
def test_transaction_receipt(self, tx_data):
response = self.rpc_client.rpc_valid_request("ethclient_transactionReceipt", [self.network_id, tx_data.tx_hash])
2024-10-11 08:08:39 +00:00
validate_receipt(response.json()["result"], tx_data.tx_hash, tx_data.block_number, tx_data.block_hash)