|
1 | | -import asyncio |
2 | | -from unittest.mock import MagicMock, patch |
| 1 | +from unittest.mock import AsyncMock, patch |
3 | 2 |
|
4 | 3 | import pytest |
5 | 4 |
|
|
9 | 8 | from starknet_py.net.account.account import Account |
10 | 9 | from starknet_py.net.client_errors import ClientError |
11 | 10 | from starknet_py.net.client_models import ( |
| 11 | + BlockHashAndNumber, |
12 | 12 | ContractClass, |
13 | 13 | DeclareTransaction, |
14 | 14 | SierraContractClass, |
| 15 | + SyncStatus, |
15 | 16 | TransactionType, |
16 | 17 | ) |
17 | 18 | from starknet_py.net.full_node_client import _to_rpc_felt |
18 | 19 | from starknet_py.net.models import StarknetChainId |
| 20 | +from starknet_py.tests.e2e.utils import create_empty_block |
19 | 21 |
|
20 | 22 |
|
21 | 23 | def _parse_event_name(event: str) -> str: |
@@ -100,30 +102,26 @@ async def test_method_raises_on_both_block_hash_and_number(full_node_client): |
100 | 102 | @pytest.mark.asyncio |
101 | 103 | async def test_pending_transactions(full_node_client): |
102 | 104 | with patch( |
103 | | - "starknet_py.net.http_client.RpcHttpClient.call", MagicMock() |
| 105 | + "starknet_py.net.http_client.RpcHttpClient.call", AsyncMock() |
104 | 106 | ) as mocked_http_call: |
105 | | - result = asyncio.Future() |
106 | | - result.set_result( |
107 | | - [ |
108 | | - { |
109 | | - "transaction_hash": "0x01", |
110 | | - "class_hash": "0x05", |
111 | | - "version": "0x0", |
112 | | - "type": "DEPLOY", |
113 | | - "contract_address": "0x02", |
114 | | - "contract_address_salt": "0x0", |
115 | | - "constructor_calldata": [], |
116 | | - } |
117 | | - ] |
118 | | - ) |
119 | | - mocked_http_call.return_value = result |
| 107 | + mocked_http_call.return_value = [ |
| 108 | + { |
| 109 | + "transaction_hash": "0x01", |
| 110 | + "class_hash": "0x05", |
| 111 | + "version": "0x0", |
| 112 | + "type": "DEPLOY", |
| 113 | + "contract_address": "0x02", |
| 114 | + "contract_address_salt": "0x0", |
| 115 | + "constructor_calldata": [], |
| 116 | + } |
| 117 | + ] |
120 | 118 |
|
121 | 119 | pending_transactions = await full_node_client.get_pending_transactions() |
122 | 120 |
|
123 | | - assert len(pending_transactions) == 1 |
124 | | - assert pending_transactions[0].hash == 0x1 |
125 | | - assert pending_transactions[0].signature == [] |
126 | | - assert pending_transactions[0].max_fee == 0 |
| 121 | + assert len(pending_transactions) == 1 |
| 122 | + assert pending_transactions[0].hash == 0x1 |
| 123 | + assert pending_transactions[0].signature == [] |
| 124 | + assert pending_transactions[0].max_fee == 0 |
127 | 125 |
|
128 | 126 |
|
129 | 127 | @pytest.mark.asyncio |
@@ -350,3 +348,64 @@ async def test_get_events_nonexistent_starting_block( |
350 | 348 | follow_continuation_token=False, |
351 | 349 | chunk_size=1, |
352 | 350 | ) |
| 351 | + |
| 352 | + |
| 353 | +@pytest.mark.asyncio |
| 354 | +async def test_get_block_number(full_node_client): |
| 355 | + block_number = await full_node_client.get_block_number() |
| 356 | + |
| 357 | + # pylint: disable=protected-access |
| 358 | + await create_empty_block(full_node_client._client) |
| 359 | + |
| 360 | + new_block_number = await full_node_client.get_block_number() |
| 361 | + assert new_block_number == block_number + 1 |
| 362 | + |
| 363 | + |
| 364 | +@pytest.mark.asyncio |
| 365 | +async def test_get_block_hash_and_number(full_node_client): |
| 366 | + block_hash_and_number = await full_node_client.get_block_hash_and_number() |
| 367 | + |
| 368 | + assert isinstance(block_hash_and_number, BlockHashAndNumber) |
| 369 | + |
| 370 | + # pylint: disable=protected-access |
| 371 | + await create_empty_block(full_node_client._client) |
| 372 | + |
| 373 | + new_block_hash_and_number = await full_node_client.get_block_hash_and_number() |
| 374 | + |
| 375 | + assert ( |
| 376 | + new_block_hash_and_number.block_number == block_hash_and_number.block_number + 1 |
| 377 | + ) |
| 378 | + assert new_block_hash_and_number.block_hash > 0 |
| 379 | + |
| 380 | + |
| 381 | +@pytest.mark.asyncio |
| 382 | +async def test_get_chain_id(full_node_client): |
| 383 | + chain_id = await full_node_client.get_chain_id() |
| 384 | + |
| 385 | + assert chain_id == hex(StarknetChainId.TESTNET.value) |
| 386 | + |
| 387 | + |
| 388 | +@pytest.mark.asyncio |
| 389 | +async def test_get_syncing_status_false(full_node_client): |
| 390 | + sync_status = await full_node_client.get_syncing_status() |
| 391 | + |
| 392 | + assert sync_status is False |
| 393 | + |
| 394 | + |
| 395 | +@pytest.mark.asyncio |
| 396 | +async def test_get_syncing_status(full_node_client): |
| 397 | + with patch( |
| 398 | + "starknet_py.net.http_client.RpcHttpClient.call", AsyncMock() |
| 399 | + ) as mocked_status: |
| 400 | + mocked_status.return_value = { |
| 401 | + "starting_block_num": "0xc8023", |
| 402 | + "current_block_num": "0xc9773", |
| 403 | + "highest_block_num": "0xc9773", |
| 404 | + "starting_block_hash": "0x60be3a55621597c15a53a1f83e977ca5e52e775ab2ebf572d2ebd6a8168fc88", |
| 405 | + "current_block_hash": "0x79abcb48e71524ad2e123624b0ee3d5f69f99759a23441f6f363794d0687a66", |
| 406 | + "highest_block_hash": "0x79abcb48e71524ad2e123624b0ee3d5f69f99759a23441f6f363794d0687a66", |
| 407 | + } |
| 408 | + |
| 409 | + sync_status = await full_node_client.get_syncing_status() |
| 410 | + |
| 411 | + assert isinstance(sync_status, SyncStatus) |
0 commit comments