2024-10-04 12:55:28 +00:00
|
|
|
import pytest
|
2024-10-11 08:08:39 +00:00
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
from test_cases import EthRpcTestCase
|
2024-10-04 12:55:28 +00:00
|
|
|
|
2024-10-11 08:08:39 +00:00
|
|
|
|
|
|
|
def validate_header(header, block_number, block_hash):
|
2024-10-04 12:55:28 +00:00
|
|
|
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)
|
2024-10-04 12:55:28 +00:00
|
|
|
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):
|
2024-10-04 12:55:28 +00:00
|
|
|
assert tx["tx"]["hash"] == tx_hash
|
|
|
|
|
2024-10-11 08:08:39 +00:00
|
|
|
|
|
|
|
def validate_receipt(receipt, tx_hash, block_number, block_hash):
|
2024-10-04 12:55:28 +00:00
|
|
|
assert receipt["transactionHash"] == tx_hash
|
|
|
|
assert receipt["blockNumber"] == block_number
|
|
|
|
assert receipt["blockHash"] == block_hash
|
|
|
|
|
2024-10-11 08:08:39 +00:00
|
|
|
|
2024-10-04 12:55:28 +00:00
|
|
|
@pytest.mark.rpc
|
|
|
|
@pytest.mark.ethclient
|
2024-10-07 15:40:18 +00:00
|
|
|
class TestEth(EthRpcTestCase):
|
|
|
|
|
2024-10-04 12:55:28 +00:00
|
|
|
def test_block_number(self):
|
2024-10-07 15:40:18 +00:00
|
|
|
self.rpc_client.rpc_valid_request("ethclient_blockNumber", [self.network_id])
|
2024-10-04 12:55:28 +00:00
|
|
|
|
|
|
|
def test_suggest_gas_price(self):
|
2024-10-07 15:40:18 +00:00
|
|
|
self.rpc_client.rpc_valid_request("ethclient_suggestGasPrice", [self.network_id])
|
2024-10-04 12:55:28 +00:00
|
|
|
|
|
|
|
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)
|
2024-10-04 12:55:28 +00:00
|
|
|
|
|
|
|
def test_block_by_number(self, tx_data):
|
2024-10-07 15:40:18 +00:00
|
|
|
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)
|
2024-10-04 12:55:28 +00:00
|
|
|
|
|
|
|
def test_header_by_hash(self, tx_data):
|
2024-10-07 15:40:18 +00:00
|
|
|
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)
|
2024-10-04 12:55:28 +00:00
|
|
|
|
|
|
|
def test_block_by_hash(self, tx_data):
|
2024-10-07 15:40:18 +00:00
|
|
|
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)
|
2024-10-04 12:55:28 +00:00
|
|
|
|
|
|
|
def test_transaction_by_hash(self, tx_data):
|
2024-10-07 15:40:18 +00:00
|
|
|
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)
|
2024-10-04 12:55:28 +00:00
|
|
|
|
|
|
|
def test_transaction_receipt(self, tx_data):
|
2024-10-07 15:40:18 +00:00
|
|
|
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)
|