def import_from_raw_text_signature(cls, raw_event_signature): try: text_signature = normalize_event_signature(raw_event_signature) except ValueError: logger.error("error event signature: %s", raw_event_signature) return None else: logger.info("importing event signature: %s", text_signature) return cls.objects.get_or_create(text_signature=text_signature, )
def test_create_complex_signature(api_client): text_signature = 'getOrdersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[])' # noqa: E501 response = api_client.post(EVENT_API_URL, {'text_signature': text_signature}) assert response.status_code == status.HTTP_201_CREATED data = response.data assert data['text_signature'] == text_signature assert data['bytes_signature'] == force_text( event_signature_to_log_topic( normalize_event_signature(data['text_signature']))) assert data[ 'hex_signature'] == '0x7e9d74dc5e5d1a841950b2603b1fc48e0a1c1391bbb4ed24915c26cf1ff33ccb'
def validate_text_signature(self, value): validated_signatures = dict() exceptions_messages = [] try: normalized_function_signature = normalize_function_signature(value) validated_signatures.update( {'function_signature': normalized_function_signature}) except ValueError as e: exceptions_messages.append(f'Function import error: {str(e)}.') try: normalized_event_signature = normalize_event_signature(value) validated_signatures.update( {'event_signature': normalized_event_signature}) except ValueError as e: exceptions_messages.append(f'Event import error: {str(e)}.') if len(validated_signatures) == 0: raise ValueError(' '.join(exceptions_messages)) return validated_signatures
def validate_text_signature(self, value): validated_signatures = dict() exceptions = [] try: normalized_function_signature = normalize_function_signature(value) validated_signatures.update( {'function_signature': normalized_function_signature}) except ValueError as e: exceptions.append(e) try: normalized_event_signature = normalize_event_signature(value) validated_signatures.update( {'event_signature': normalized_event_signature}) except ValueError as e: exceptions.append(e) if len(validated_signatures) == 0: raise ValueError(exceptions) return validated_signatures
def validate_text_signature(self, data): try: signature = normalize_event_signature(data) except ValueError: raise serializers.ValidationError('Unknown event signature format') return signature
def test_bad_event_signatures(raw_signature): with pytest.raises(ValueError): normalize_event_signature(raw_signature)
def test_normalizing_event_signatures(raw_signature, expected): actual = normalize_event_signature(raw_signature) assert actual == expected
def clean_fields(self, exclude=None): try: self.text_signature = normalize_event_signature( self.text_signature) except ValueError: raise ValidationError('Unknown event signature format')