Example #1
0
    def test_tf_events(self):
        """Test that tf events are generated correctly."""
        gen_data = [
            ["test1", "test2"],
            ["test3"],
            ["test4", "test5", "test6"],
        ]
        event_sets = [
            [
                Event(event_type=event_type)
                for event_type in events
            ] for events in gen_data
        ]
        receipts = [
            TransactionReceipt(events=events)
            for events in event_sets
        ]
        extractor = ReceiptEventExtractor(receipts)

        events = extractor.extract([])
        self.assertEqual([], events)

        events = extractor.extract([
            EventSubscription(event_type="test1"),
            EventSubscription(event_type="test5"),
        ])
        self.assertEqual(events, [event_sets[0][0], event_sets[2][1]])
    def do_tf_events():
        gen_data = [
            ["test1", "test2"],
            ["test3"],
            ["test4", "test5", "test6"],
        ]
        event_sets = [[Event(event_type=event_type) for event_type in events]
                      for events in gen_data]
        receipts = [TransactionReceipt(events=events) for events in event_sets]
        extractor = ReceiptEventExtractor(receipts)

        events = extractor.extract([])
        assert [] == events

        events = extractor.extract([
            EventSubscription(event_type="test1"),
            EventSubscription(event_type="test5"),
        ])
        assert events == [event_sets[0][0], event_sets[2][1]]
Example #3
0
    def test_tf_events(self):
        """Test that tf events are generated correctly."""
        gen_data = [
            ["test1", "test2"],
            ["test3"],
            ["test4", "test5", "test6"],
        ]
        event_sets = [[Event(event_type=event_type) for event_type in events]
                      for events in gen_data]
        receipts = [TransactionReceipt(events=events) for events in event_sets]
        extractor = ReceiptEventExtractor(receipts)

        events = extractor.extract([])
        self.assertEqual([], events)

        events = extractor.extract([
            EventSubscription(event_type="test1"),
            EventSubscription(event_type="test5"),
        ])
        self.assertEqual(events, [event_sets[0][0], event_sets[2][1]])
Example #4
0
    def test_state_delta_events(self):
        """Test that sawtooth/state-delta events are generated correctly."""
        gen_data = [
            [("a", b"a", StateChange.SET), ("b", b"b", StateChange.DELETE)],
            [("a", b"a", StateChange.DELETE), ("d", b"d", StateChange.SET)],
            [("e", b"e", StateChange.SET)],
        ]
        change_sets = [[
            StateChange(address=address, value=value, type=change_type)
            for address, value, change_type in state_changes
        ] for state_changes in gen_data]
        receipts = [
            TransactionReceipt(state_changes=state_changes)
            for state_changes in change_sets
        ]
        extractor = ReceiptEventExtractor(receipts)

        factory = EventFilterFactory()
        events = extractor.extract([
            EventSubscription(event_type="sawtooth/state-delta",
                              filters=[factory.create("address", "a")]),
            EventSubscription(
                event_type="sawtooth/state-delta",
                filters=[
                    factory.create("address", "[ce]", EventFilter.REGEX_ANY)
                ],
            )
        ])
        self.assertEqual(events, [
            Event(
                event_type="sawtooth/state-delta",
                attributes=[
                    Event.Attribute(key="address", value=address)
                    for address in ["e", "d", "a", "b"]
                ],
                data=StateChangeList(state_changes=[
                    change_sets[2][0],
                    change_sets[1][1],
                    change_sets[1][0],
                    change_sets[0][1],
                ]).SerializeToString(),
            )
        ])
Example #5
0
    def test_state_delta_events(self):
        """Test that sawtooth/state-delta events are generated correctly."""
        gen_data = [
            [("a", b"a", StateChange.SET), ("b", b"b", StateChange.DELETE)],
            [("a", b"a", StateChange.DELETE), ("d", b"d", StateChange.SET)],
            [("e", b"e", StateChange.SET)],
        ]
        change_sets = [
            [
                StateChange(address=address, value=value, type=change_type)
                for address, value, change_type in state_changes
            ] for state_changes in gen_data
        ]
        receipts = [
            TransactionReceipt(state_changes=state_changes)
            for state_changes in change_sets
        ]
        extractor = ReceiptEventExtractor(receipts)

        factory = EventFilterFactory()
        events = extractor.extract([
            EventSubscription(
                event_type="sawtooth/state-delta",
                filters=[factory.create("address", "a")]),
            EventSubscription(
                event_type="sawtooth/state-delta",
                filters=[factory.create(
                    "address", "[ce]", EventFilter.REGEX_ANY)],
            )
        ])
        self.assertEqual(events, [Event(
            event_type="sawtooth/state-delta",
            attributes=[
                Event.Attribute(key="address", value=address)
                for address in ["e", "d", "a", "b"]
            ],
            data=StateChangeList(state_changes=[
                change_sets[2][0], change_sets[1][1],
                change_sets[1][0], change_sets[0][1],
            ]).SerializeToString(),
        )])
    def get_events_for_block(self, blkw, subscriptions):
        receipts = []
        for batch in blkw.block.batches:
            for txn in batch.transactions:
                try:
                    receipts.append(
                        self._receipt_store.get(txn.header_signature))
                except KeyError:
                    LOGGER.warning(
                        "Transaction id %s not found in receipt store "
                        " while looking"
                        " up events for block id %s",
                        txn.header_signature[:10], blkw.identifier[:10])

        block_event_extractor = BlockEventExtractor(blkw)
        receipt_event_extractor = ReceiptEventExtractor(receipts=receipts)

        events = []
        events.extend(block_event_extractor.extract(subscriptions))
        events.extend(receipt_event_extractor.extract(subscriptions))

        return events
Example #7
0
    def get_events_for_block(self, blkw, subscriptions):
        receipts = []
        for batch in blkw.block.batches:
            for txn in batch.transactions:
                try:
                    receipts.append(self._receipt_store.get(
                        txn.header_signature))
                except KeyError:
                    LOGGER.warning(
                        "Transaction id %s not found in receipt store "
                        " while looking"
                        " up events for block id %s",
                        txn.header_signature[:10],
                        blkw.identifier[:10])

        block_event_extractor = BlockEventExtractor(blkw)
        receipt_event_extractor = ReceiptEventExtractor(receipts=receipts)

        events = []
        events.extend(block_event_extractor.extract(subscriptions))
        events.extend(receipt_event_extractor.extract(subscriptions))

        return events