def test_les_protocol_command_round_trips(command_type, payload, snappy_support): cmd = command_type(payload) message = cmd.encode(command_type.protocol_command_id, snappy_support=snappy_support) assert message.command_id == command_type.protocol_command_id result = command_type.decode(message, snappy_support=snappy_support) assert isinstance(result, command_type) assert result.payload == payload assert_type_equality(result.payload, payload)
async def test_eth_api_send_get_node_data(alice, bob): payload = tuple(BlockHashFactory.create_batch(5)) command_fut = asyncio.Future() async def _handle_cmd(connection, cmd): command_fut.set_result(cmd) bob.connection.add_command_handler(GetNodeDataV65, _handle_cmd) alice.eth_api.send_get_node_data(payload) result = await asyncio.wait_for(command_fut, timeout=1) assert isinstance(result, GetNodeDataV65) assert_type_equality(payload, result.payload)
async def test_eth_api_send_status(alice, bob, StatusPayloadFactory_class, Status_class): payload = StatusPayloadFactory_class() command_fut = asyncio.Future() async def _handle_cmd(connection, cmd): command_fut.set_result(cmd) bob.connection.add_command_handler(Status_class, _handle_cmd) alice.eth_api.send_status(payload) result = await asyncio.wait_for(command_fut, timeout=1) assert isinstance(result, Status_class) assert_type_equality(payload, result.payload)
async def test_eth_api_send_get_block_headers(alice, bob): payload = BlockHeadersQueryFactory() command_fut = asyncio.Future() async def _handle_cmd(connection, cmd): command_fut.set_result(cmd) bob.connection.add_command_handler(GetBlockHeadersV65, _handle_cmd) alice.eth_api.send_get_block_headers( block_number_or_hash=payload.block_number_or_hash, max_headers=payload.block_number_or_hash, skip=payload.skip, reverse=payload.reverse, ) result = await asyncio.wait_for(command_fut, timeout=1) assert isinstance(result, GetBlockHeadersV65) assert_type_equality(payload, result.payload)