Beispiel #1
0
    def test_filter(self):
        """Test that a regex filter matches properly against an event."""
        self.assertIn(
            events_pb2.Event(attributes=[
                events_pb2.Event.Attribute(
                    key="address", value="000000" + "f" * 64)]),
            FILTER_FACTORY.create(key="address", match_string="000000.*",
                filter_type=EventFilterType.regex_any))

        self.assertIn(
            events_pb2.Event(attributes=[
                events_pb2.Event.Attribute(key="abc", value="123")]),
            FILTER_FACTORY.create(key="abc", match_string="123"))
Beispiel #2
0
 def test_subscription(self):
     """Test that an event correctly matches against a subscription."""
     self.assertIn(
         events_pb2.Event(event_type="test", attributes=[
             events_pb2.Event.Attribute(key="test", value="test")]),
         EventSubscription(
             event_type="test",
             filters=[FILTER_FACTORY.create(key="test", match_string="test")]))
Beispiel #3
0
    def test_add_event(self):
        event = events_pb2.Event(event_type="add_event")
        mock_context_manager = Mock()
        handler = TpAddEventHandler(mock_context_manager)
        request = state_context_pb2.TpAddEventRequest(event=event).SerializeToString()

        response = handler.handle("test_conn_id", request)

        self.assertEqual(HandlerStatus.RETURN, response.status)
Beispiel #4
0
def create_receipt(txn_id, key_values):
    events = []
    for key, value in key_values:
        event = events_pb2.Event()
        event.event_type = "sawtooth/block-commit"
        attribute = event.attributes.add()
        attribute.key = key
        attribute.value = value
        events.append(event)

    receipt = transaction_receipt_pb2.TransactionReceipt(transaction_id=txn_id)
    receipt.events.extend(events)
    return receipt