Exemple #1
0
    def create(self, validated_data):
        """
        Handle banks primary validator updated notice

        A response of True indicates to the requesting bank that self (this validator) will remain on the same network
        Delete banks switching to different networks
        """
        bank = validated_data['node_identifier']
        ip_address = validated_data['ip_address']
        port = validated_data['port']
        protocol = validated_data['protocol']

        self_configuration = get_self_configuration(
            exception_class=RuntimeError)

        if self.primary_validator_synchronized(
                ip_address=ip_address, self_configuration=self_configuration):
            return True

        if (self_configuration.node_type == CONFIRMATION_VALIDATOR
                and bank == get_most_trusted_bank()):
            address = format_address(ip_address=ip_address,
                                     port=port,
                                     protocol=protocol)
            try:
                config = fetch(url=f'{address}/config', headers={})
            except Exception as e:
                capture_exception(e)
                logger.exception(e)
            else:
                sync_with_primary_validator.delay(config=config)
                return True

        bank.delete()
        raise serializers.ValidationError('Networks out of sync')
Exemple #2
0
def test_primary_validator_updated_400_low_trust(
        client, signing_key, bank, confirmation_validator_configuration,
        validator):
    primary_validator = validator

    bank.trust = get_most_trusted_bank().trust - 1
    bank.save()

    result = primary_validator_updated(client, signing_key, primary_validator,
                                       HTTP_400_BAD_REQUEST)
    assert result == ['Networks out of sync']
    def validate_node_identifier(node_identifier):
        """Validate node_identifier is that of most trusted bank"""
        bank = Bank.objects.filter(node_identifier=node_identifier).first()

        if not bank:
            raise serializers.ValidationError(
                'Bank with that node identifier does not exists')

        if bank != get_most_trusted_bank():
            raise serializers.ValidationError('Bank is not the most trusted')

        return node_identifier
Exemple #4
0
def test_primary_validator_updated_200_not_available(
        client, signing_key, bank, confirmation_validator_configuration,
        validator):
    primary_validator = validator
    primary_validator.ip_address = '127.0.0.1'

    bank.trust = get_most_trusted_bank().trust + 1
    bank.save()

    result = primary_validator_updated(client, signing_key, primary_validator,
                                       HTTP_400_BAD_REQUEST)
    assert result == ['Networks out of sync']
Exemple #5
0
    def create(self, validated_data):
        """
        Handle banks primary validator updated notice
        A response of True indicates to the requesting bank that self (this validator) will remain on the same network
        Delete banks switching to different networks
        """

        bank = validated_data['node_identifier']
        ip_address = validated_data['ip_address']
        port = validated_data['port']
        protocol = validated_data['protocol']

        if self.primary_validator_synchronized(ip_address=ip_address):
            return True

        if bank == get_most_trusted_bank():
            sync_to_new_primary_validator(ip_address=ip_address, port=port, protocol=protocol)
            return True

        bank.delete()
        raise serializers.ValidationError('Networks out of sync')
def test_upgrade_request(
    request, self_configuration, node, node_type_before, node_type_after, status,
    client, bank, signing_key, celery_worker
):
    self_configuration = request.getfixturevalue(self_configuration)
    node = request.getfixturevalue(node)

    bank.trust = get_most_trusted_bank().trust + 1
    bank.save()

    client.post_json(
        reverse('upgrade_request-list'),
        generate_signed_request(
            data={
                'validator_node_identifier': node.node_identifier
            },
            nid_signing_key=signing_key
        ),
        expected=status
    )

    self_configuration.refresh_from_db()
    assert self_configuration.node_type == node_type_after