Exemplo n.º 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
        """
        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"])
Exemplo n.º 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
        """
        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"])
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")