def test_check_publish_invalid(self): """ Create a block header with some other block id as the previous id and check that it can be published. This test should verify that only blocks with the NULL_BLOCK_IDENTIFIER as previous should be allowed to be published with this consensus module. """ block_cache = Mock() state_view_factory = Mock() batch_publisher = Mock() data_dir = 'mock_dir' config_dir = 'mock_dir' validator_id = 'validator_001' block_publisher = BlockPublisher(block_cache, state_view_factory, batch_publisher, data_dir, config_dir, validator_id) block_header = BlockHeader( consensus=b'Genesis', previous_block_id='some_other_id') result = block_publisher.check_publish_block(block_header) self.assertFalse(result)
def test_initialize_block(self): """ Create a block header and initialize it using the genesis consensus BlockPublisher. This test should verify that the appropriate header fields are set and the consensus module returns that the block should be built. """ block_cache = Mock() state_view_factory = Mock() batch_publisher = Mock() data_dir = 'mock_dir' config_dir = 'mock_dir' validator_id = 'validator_001' block_publisher = BlockPublisher(block_cache, state_view_factory, batch_publisher, data_dir, config_dir, validator_id) block_header = BlockHeader( previous_block_id=NULL_BLOCK_IDENTIFIER) result = block_publisher.initialize_block(block_header) self.assertTrue(result) self.assertEqual(b'Genesis', block_header.consensus)
def test_initialize_block(self): """ Create a block header and initialize it using the genesis consensus BlockPublisher. This test should verify that the appropriate header fields are set and the consensus module returns that the block should be built. """ block_cache = Mock() state_view_factory = Mock() batch_publisher = Mock() data_dir = 'mock_dir' block_publisher = BlockPublisher(block_cache, state_view_factory, batch_publisher, data_dir) block_header = BlockHeader(previous_block_id=NULL_BLOCK_IDENTIFIER) result = block_publisher.initialize_block(block_header) self.assertTrue(result) self.assertEqual(b'Genesis', block_header.consensus)
def test_finalize_block_valid(self): """ Create a block header with the NULL_BLOCK_IDENTIFIER as the previous id and check that it can be properly finalized. This test should verify that only blocks with the NULL_BLOCK_IDENTIFIER as previous should be allowed to be finalized with this consensus module. """ block_cache = Mock() state_view_factory = Mock() batch_publisher = Mock() data_dir = 'mock_dir' block_publisher = BlockPublisher(block_cache, state_view_factory, batch_publisher, data_dir) block_header = BlockHeader(consensus=b'Genesis', previous_block_id=NULL_BLOCK_IDENTIFIER) result = block_publisher.finalize_block(block_header) self.assertTrue(result)
def test_check_publish_invalid(self): """ Create a block header with some other block id as the previous id and check that it can be published. This test should verify that only blocks with the NULL_BLOCK_IDENTIFIER as previous should be allowed to be published with this consensus module. """ block_cache = Mock() state_view_factory = Mock() batch_publisher = Mock() data_dir = 'mock_dir' validator_id = 'validator_001' block_publisher = BlockPublisher(block_cache, state_view_factory, batch_publisher, data_dir, validator_id) block_header = BlockHeader(consensus=b'Genesis', previous_block_id='some_other_id') result = block_publisher.check_publish_block(block_header) self.assertFalse(result)