Example #1
0
    def test_invalid_txn_infos(self):
        """Test that the invalid batch information is return correctly.

        - Add valid batch info
        - Add invalid batch info
        - Ensure that the invalid batch info is returned
        - Ensure that modifying the returned info does not affect future calls
        """
        batch_tracker = BatchTracker(batch_committed=lambda batch_id: True)

        batch_tracker.notify_batch_pending(
            make_batch("good_batch", "good_txn"))
        batch_tracker.notify_batch_pending(
            make_batch("bad_batch", "bad_txn"))

        batch_tracker.notify_txn_invalid("bad_txn")

        invalid_info = batch_tracker.get_invalid_txn_info("bad_batch")
        self.assertEqual(1, len(invalid_info))
        self.assertEqual("bad_txn", invalid_info[0]["id"])

        invalid_info[0]["header_signature"] = invalid_info[0].pop("id")

        more_invalid_info = batch_tracker.get_invalid_txn_info("bad_batch")
        self.assertEqual(1, len(more_invalid_info))
        self.assertEqual("bad_txn", more_invalid_info[0]["id"])
Example #2
0
    def test_invalid_txn_infos(self):
        """Test that the invalid batch information is return correctly.

        - Add valid batch info
        - Add invalid batch info
        - Ensure that the invalid batch info is returned
        - Ensure that modifying the returned info does not affect future calls
        """
        block_store = Mock()
        batch_tracker = BatchTracker(block_store)

        batch_tracker.notify_batch_pending(make_batch("good_batch",
                                                      "good_txn"))
        batch_tracker.notify_batch_pending(make_batch("bad_batch", "bad_txn"))

        batch_tracker.notify_txn_invalid("bad_txn")

        invalid_info = batch_tracker.get_invalid_txn_info("bad_batch")
        self.assertEqual(1, len(invalid_info))
        self.assertEqual("bad_txn", invalid_info[0]["id"])

        invalid_info[0]["header_signature"] = invalid_info[0].pop("id")

        more_invalid_info = batch_tracker.get_invalid_txn_info("bad_batch")
        self.assertEqual(1, len(more_invalid_info))
        self.assertEqual("bad_txn", more_invalid_info[0]["id"])
Example #3
0
def make_store_and_tracker(size=3):
    store = MockBlockStore(size=size)
    tracker = BatchTracker(store)
    tracker.notify_batch_pending(make_mock_batch('d'))
    tracker.notify_batch_pending(make_mock_batch('f'))
    tracker.notify_txn_invalid('c' * 127 + 'f', 'error message', b'error data')

    return store, tracker
def get_invalid_txn_infos():
    # create mock object
    block_store = Mock()
    batch_tracker = BatchTracker(block_store)

    batch_tracker.notify_batch_pending(make_batch("good_batch", "good_txn"))
    batch_tracker.notify_batch_pending(make_batch("bad_batch", "bad_txn"))

    batch_tracker.notify_txn_invalid("good_txn")
    batch_tracker.get_invalid_txn_info(batch_id="bad_batch")
Example #5
0
def test_invalid_txn_infos(benchmark):
    """Test that the invalid batch information is return correctly.

        - Add valid batch info
        - Add invalid batch info
        - Ensure that the invalid batch info is returned
        - Ensure that modifying the returned info does not affect future calls
        """
    # create mock object
    block_store = Mock()
    batch_tracker = BatchTracker(block_store)

    batch_tracker.notify_batch_pending(make_batch("good_batch", "good_txn"))
    batch_tracker.notify_batch_pending(make_batch("bad_batch", "bad_txn"))

    batch_tracker.notify_txn_invalid("good_txn")

    invalid_info = benchmark(batch_tracker.get_invalid_txn_info, "bad_batch")
    assert 0 == len(invalid_info)
Example #6
0
def make_store_and_tracker(size=3):
    """
    Creates and returns two related objects for testing:
        * store - a mock block store, with a default start
        * tracker - a batch tracker attached to the store, with one pending batch

    With defaults, the three block ids in the store will be:
        * 'B-0', 'B-1', B-2'
    The three batch ids in the store will be:
        * 'b-0', 'b-1', b-2'
    The pending batch in the tracker will be:
        * 'b-3'
    """
    store = MockBlockStore(size=size)
    tracker = BatchTracker(store)
    store.add_update_observer(tracker)
    tracker.notify_batch_pending('b-pending')

    return store, tracker
Example #7
0
def make_store_and_tracker(size=3):
    """
    Creates and returns two related objects for testing:
        * store - a mock block store, with a default start
        * tracker - a batch tracker attached to the store, with one pending batch

    With defaults, the three block ids in the store will be:
        * 'B-0', 'B-1', B-2'
    The three batch ids in the store will be:
        * 'b-0', 'b-1', b-2'
    The pending batch in the tracker will be:
        * 'b-3'
    """
    store = MockBlockStore(size=size)
    tracker = BatchTracker(store)
    tracker.notify_batch_pending(make_mock_batch('pending'))
    tracker.notify_batch_pending(make_mock_batch('invalid'))
    tracker.notify_txn_invalid('t-invalid', 'error message', b'error data')

    return store, tracker
Example #8
0
def make_store_and_tracker(size=3):
    """
    Creates and returns two related objects for testing:
        * store - a mock block store, with a default start
        * tracker - a batch tracker attached to the store, with one pending batch

    With defaults, the three block ids in the store will be:
        * 'B-0', 'B-1', B-2'
    The three batch ids in the store will be:
        * 'b-0', 'b-1', b-2'
    The pending batch in the tracker will be:
        * 'b-3'
    """
    store = MockBlockStore(size=size)
    tracker = BatchTracker(store)
    store.add_update_observer(tracker)
    tracker.notify_batch_pending(make_mock_batch('pending'))
    tracker.notify_batch_pending(make_mock_batch('invalid'))
    tracker.notify_txn_invalid('t-invalid', 'error message', b'error data')

    return store, tracker
Example #9
0
def make_store_and_tracker(size=3):
    """
    Creates and returns two related objects for testing:
        * store - a mock block store, with a default start

        * tracker - a batch tracker attached to the store, with one
          pending batch

    With defaults, the three block ids in the store will be:
        * 'bbb...0', 'bbb...1', 'bbb...2'
    The three batch ids in the store will be:
        * 'aaa...0', 'aaa...1', 'aaa...2'
    The pending batch in the tracker will be:
        * 'aaa...3'
    """
    store = MockBlockStore(size=size)
    tracker = BatchTracker(store.has_batch)
    tracker.notify_batch_pending(make_mock_batch('d'))
    tracker.notify_batch_pending(make_mock_batch('f'))
    tracker.notify_txn_invalid('c' * 127 + 'f', 'error message', b'error data')

    return store, tracker
Example #10
0
def make_store_and_tracker(size=3):
    """
    Creates and returns two related objects for testing:
        * store - a mock block store, with a default start

        * tracker - a batch tracker attached to the store, with one
          pending batch

    With defaults, the three block ids in the store will be:
        * 'bbb...0', 'bbb...1', 'bbb...2'
    The three batch ids in the store will be:
        * 'aaa...0', 'aaa...1', 'aaa...2'
    The pending batch in the tracker will be:
        * 'aaa...3'
    """
    store = MockBlockStore(size=size)
    tracker = BatchTracker(store)
    tracker.notify_batch_pending(make_mock_batch('d'))
    tracker.notify_batch_pending(make_mock_batch('f'))
    tracker.notify_txn_invalid('c' * 127 + 'f', 'error message', b'error data')

    return store, tracker