Exemplo n.º 1
0
def test_set_available_nodes_call_order(kusama_manager):
    """Test `_set_available_nodes_call_order()` sets the available nodes sorted
    by preference; currently own node first and then by the highest 'weight_block'.
    """
    # Due to `available_node_attributes_map` is a dict we must fake a key for
    # testing purposes as currently KusamaNodeName only has PARITY
    fake_kusama_node_name = object()
    node_attrs_item_1 = (
        KusamaNodeName.OWN,
        NodeNameAttributes(
            node_interface=object(),
            weight_block=1000,
        ),
    )
    node_attrs_item_2 = (
        fake_kusama_node_name,
        NodeNameAttributes(
            node_interface=object(),
            weight_block=750,
        ),
    )
    node_attrs_item_3 = (
        KusamaNodeName.PARITY,
        NodeNameAttributes(
            node_interface=object(),
            weight_block=1000,
        ),
    )
    available_node_attributes_map = dict([  # noqa: C406
        node_attrs_item_3,
        node_attrs_item_2,
        node_attrs_item_1,
    ])
    kusama_manager.available_node_attributes_map = available_node_attributes_map
    kusama_manager._set_available_nodes_call_order()

    assert kusama_manager.available_nodes_call_order == [
        node_attrs_item_1,
        node_attrs_item_3,
        node_attrs_item_2,
    ]
Exemplo n.º 2
0
    def attempt_connect_node(node: NodeName) -> Tuple[NodeName, Optional[NodeNameAttributes]]:
        try:
            node_interface = SubstrateInterface(
                url=node.endpoint(),
                type_registry_preset=si_attributes.type_registry_preset,
                use_remote_preset=True,
            )
        except (requests.exceptions.RequestException, SubstrateRequestException) as e:
            message = (
                f'Substrate tests failed to connect to {node} node at '
                f'endpoint: {node.endpoint()}. Connection error: {str(e)}.',
            )
            log.error(message)
            return node, None

        log.info(f'Substrate tests connected to {node} node at endpoint: {node_interface.url}.')
        node_attributes = NodeNameAttributes(
            node_interface=node_interface,
            weight_block=BlockNumber(0),
        )
        return node, node_attributes