Ejemplo n.º 1
0
    async def _init_sync_progress(self, parent_header: BlockHeaderAPI, peer: TChainPeer) -> None:
        try:
            latest_block_number = peer.head_info.head_number
        except AttributeError:
            headers = await self._request_headers(peer, peer.head_info.head_hash, 1)
            if headers:
                latest_block_number = headers[0].block_number
            else:
                return

        self.sync_progress = SyncProgress(
            parent_header.block_number,
            parent_header.block_number,
            latest_block_number,
        )
Ejemplo n.º 2
0
@pytest.mark.asyncio
@pytest.mark.parametrize(
    'request_msg, event_bus_setup_fn, expected',
    (
        (
            build_request('eth_syncing'),
            mock_syncing(False),
            {
                'result': False,
                'id': 3,
                'jsonrpc': '2.0'
            },
        ),
        (
            build_request('eth_syncing'),
            mock_syncing(True, SyncProgress(0, 1, 2)),
            {
                'result': {
                    'startingBlock': 0,
                    'currentBlock': 1,
                    'highestBlock': 2
                },
                'id': 3,
                'jsonrpc': '2.0'
            },
        ),
    ),
    ids=[
        'eth_syncing_F',
        'eth_syncing_T',
    ],
Ejemplo n.º 3
0
@pytest.mark.asyncio
@pytest.mark.parametrize(
    'request_msg, event_bus_response, expected',
    (
        (
            build_request('eth_syncing'),
            SyncingResponse(False, None),
            {
                'result': False,
                'id': 3,
                'jsonrpc': '2.0'
            },
        ),
        (
            build_request('eth_syncing'),
            SyncingResponse(True, SyncProgress(0, 1, 2)),
            {
                'result': {
                    'startingBlock': 0,
                    'currentBlock': 1,
                    'highestBlock': 2
                },
                'id': 3,
                'jsonrpc': '2.0'
            },
        ),
    ),
    ids=[
        'eth_syncing_F',
        'eth_syncing_T',
    ],
Ejemplo n.º 4
0
    )
    assert result == expected


@pytest.mark.asyncio
@pytest.mark.parametrize(
    'request_msg, event_bus_setup_fn, expected',
    (
        (
            build_request('eth_syncing'),
            mock_request_response(SyncingRequest, SyncingResponse(False, None)),
            {'result': False, 'id': 3, 'jsonrpc': '2.0'},
        ),
        (
            build_request('eth_syncing'),
            mock_request_response(SyncingRequest, SyncingResponse(True, SyncProgress(0, 1, 2))),
            {'result': {'startingBlock': 0, 'currentBlock': 1, 'highestBlock': 2}, 'id': 3,
             'jsonrpc': '2.0'},
        ),
    ),
    ids=[
        'eth_syncing_F', 'eth_syncing_T',
    ],
)
async def test_eth_over_ipc(
        jsonrpc_ipc_pipe_path,
        request_msg,
        event_bus_setup_fn,
        event_bus,
        expected,
        event_loop,