Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
makemake-kbo committed Jan 8, 2024
1 parent 844dc3e commit 7352ce6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
53 changes: 51 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python = "^3.11"
fastapi = "^0.108.0"
uvicorn = {extras = ["standard"], version = "^0.25.0"}
exceptiongroup = "^1.2.0"
pytest = "^7.4.4"


[tool.poetry.group.dev.dependencies]
Expand Down
37 changes: 37 additions & 0 deletions tests/test_handle_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest
from hrotti.methods import handle_request, RPCRequest, BlockInfo

test_block_info = BlockInfo(
head="0x1", chain_id="0x4", coinbase="0x123", gasprice="0x5208", balance="0x0"
)


# Define a fixture for RPCRequest
@pytest.fixture
def rpc_request():
return RPCRequest(jsonrpc="2.0", id=1, method="", params=[])


# Test for eth_blockNumber
def test_handle_request_eth_blockNumber(rpc_request):
rpc_request.method = "eth_blockNumber"
response = handle_request(test_block_info, rpc_request)
assert response == {"jsonrpc": "2.0", "id": 1, "result": test_block_info.head}


# Test for eth_accounts
def test_handle_request_eth_accounts(rpc_request):
rpc_request.method = "eth_accounts"
response = handle_request(test_block_info, rpc_request)
assert response == {
"jsonrpc": "2.0",
"id": 1,
"result": ["0x407d73d8a49eeb85d32cf465507dd71d507100c1"],
}


# Test for a method that doesn't exist
def test_method_not_exist():
request = RPCRequest(jsonrpc="2.0", method="non_existent_method", params=[], id=1)
expected_response = {"jsonrpc": "2.0", "id": 1, "error": "Method does not exist!"}
assert handle_request(test_block_info, request) == expected_response

0 comments on commit 7352ce6

Please sign in to comment.