Ejemplo n.º 1
0
    def test_iterate_chain_on_empty_block_store(self):
        """Given a block store with no blocks, iterate using predecessor iterator
        and verify that it results in an empty list.
        """
        block_store = BlockStore(DictDatabase())

        self.assertEqual([], [b for b in block_store.get_predecessor_iter()])
Ejemplo n.º 2
0
    def test_iterate_chain_on_empty_block_store(self):
        """Given a block store with no blocks, iterate using predecessor
        iterator and verify that it results in an empty list.
        """
        block_store = BlockStore(
            DictDatabase(indexes=BlockStore.create_index_configuration()))

        self.assertEqual([], [b for b in block_store.get_predecessor_iter()])
Ejemplo n.º 3
0
    def test_iterate_chain(self):
        """Given a block store, create an predecessor iterator.

        1. Create a chain of length 5.
        2. Iterate the chain using the get_predecessor_iter from the chain head
        3. Verify that the block ids match the chain, in reverse order
        """

        block_store = BlockStore(DictDatabase())
        chain = self._create_chain(5)
        block_store.update_chain(chain)

        ids = [b.identifier for b in block_store.get_predecessor_iter()]

        self.assertEqual(['abcd4', 'abcd3', 'abcd2', 'abcd1', 'abcd0'], ids)
Ejemplo n.º 4
0
    def test_iterate_chain(self):
        """Given a block store, create an predecessor iterator.

        1. Create a chain of length 5.
        2. Iterate the chain using the get_predecessor_iter from the chain head
        3. Verify that the block ids match the chain, in reverse order
        """

        block_store = BlockStore(DictDatabase())
        chain = self._create_chain(5)
        block_store.update_chain(chain)

        ids = [b.identifier for b in block_store.get_predecessor_iter()]

        self.assertEqual(
            ['abcd4', 'abcd3', 'abcd2', 'abcd1', 'abcd0'],
            ids)
Ejemplo n.º 5
0
    def test_iterate_chain_from_starting_block(self):
        """Given a block store, iterate if using an predecessor iterator from
        a particular start point in the chain.

        1. Create a chain of length 5.
        2. Iterate the chain using the get_predecessor_iter from block 3
        3. Verify that the block ids match the chain, in reverse order
        """
        block_store = BlockStore(DictDatabase())
        chain = self._create_chain(5)
        block_store.update_chain(chain)

        block = block_store['abcd2']

        ids = [b.identifier for b in block_store.get_predecessor_iter(block)]

        self.assertEqual(['abcd2', 'abcd1', 'abcd0'], ids)
Ejemplo n.º 6
0
    def test_fork_detection_on_iteration(self):
        """Given a block store where a fork occurred while using the predecessor
        iterator, it should throw a PossibleForkDetectedError.

        The fork occurrance will be simulated.
        """
        block_store = BlockStore(DictDatabase())
        chain = self._create_chain(5)
        block_store.update_chain(chain)

        iterator = block_store.get_predecessor_iter()

        self.assertEqual('abcd4', next(iterator).identifier)

        del block_store['abcd3']

        with self.assertRaises(PossibleForkDetectedError):
            next(iterator)
Ejemplo n.º 7
0
    def test_fork_detection_on_iteration(self):
        """Given a block store where a fork occurred while using the predecessor
        iterator, it should throw a PossibleForkDetectedError.

        The fork occurrance will be simulated.
        """
        block_store = BlockStore(DictDatabase())
        chain = self._create_chain(5)
        block_store.update_chain(chain)

        iterator = block_store.get_predecessor_iter()

        self.assertEqual('abcd4', next(iterator).identifier)

        del block_store['abcd3']

        with self.assertRaises(PossibleForkDetectedError):
            next(iterator)
Ejemplo n.º 8
0
    def test_iterate_chain_from_starting_block(self):
        """Given a block store, iterate if using an predecessor iterator from
        a particular start point in the chain.

        1. Create a chain of length 5.
        2. Iterate the chain using the get_predecessor_iter from block 3
        3. Verify that the block ids match the chain, in reverse order
        """
        block_store = BlockStore(DictDatabase())
        chain = self._create_chain(5)
        block_store.update_chain(chain)

        block = block_store['abcd2']

        ids = [b.identifier
               for b in block_store.get_predecessor_iter(block)]

        self.assertEqual(
            ['abcd2', 'abcd1', 'abcd0'],
            ids)