def test_publish_block(self): """ Test that the Journal will produce blocks and consume those blocks to extend the chain. :return: """ # construction and wire the journal to the # gossip layer. btm = BlockTreeManager() journal = None try: journal = Journal( block_store=btm.block_store, block_cache=btm.block_cache, state_view_factory=StateViewFactory(DictDatabase()), block_sender=self.block_sender, batch_sender=self.batch_sender, transaction_executor=self.txn_executor, squash_handler=None, identity_signing_key=btm.identity_signing_key, chain_id_manager=None, state_delta_processor=self.state_delta_processor, data_dir=None, config_dir=None ) self.gossip.on_batch_received = journal.on_batch_received self.gossip.on_block_received = journal.on_block_received journal.start() # feed it a batch batch = Batch() journal.on_batch_received(batch) wait_until(lambda: self.block_sender.new_block is not None, 2) self.assertTrue(self.block_sender.new_block is not None) block = BlockWrapper(self.block_sender.new_block) journal.on_block_received(block) # wait for the chain_head to be updated. wait_until(lambda: btm.chain_head.identifier == block.identifier, 2) self.assertTrue(btm.chain_head.identifier == block.identifier) finally: if journal is not None: journal.stop()
def test_publish_block(self): """ Test that the Journal will produce blocks and consume those blocks to extend the chain. :return: """ # construction and wire the journal to the # gossip layer. LOGGER.info("test_publish_block") btm = BlockTreeManager() journal = None try: journal = Journal( consensus=test_mode_consensus, block_store=btm.block_store.store, block_cache=btm.block_cache, block_sender=self.block_sender, transaction_executor=self.txn_executor, squash_handler=None ) self.gossip.on_batch_received = \ journal.on_batch_received self.gossip.on_block_received = \ journal.on_block_received journal.start() # feed it a batch batch = Batch() journal.on_batch_received(batch) wait_until(lambda: self.block_sender.new_block is not None, 2) self.assertTrue(self.block_sender.new_block is not None) block = BlockWrapper(self.block_sender.new_block) journal.on_block_received(block) # wait for the chain_head to be updated. wait_until(lambda: btm.chain_head.identifier == block.identifier, 2) self.assertTrue(btm.chain_head.identifier == block.identifier) finally: if journal is not None: journal.stop()
def test_publish_block(self): """ Test that the Journal will produce blocks and consume those blocks to extend the chain. :return: """ # construction and wire the journal to the # gossip layer. btm = BlockTreeManager() journal = None try: journal = Journal(consensus=test_mode_consensus, block_store=btm.block_store.store, block_cache=btm.block_cache, block_sender=self.block_sender, transaction_executor=self.txn_executor, squash_handler=None) self.gossip.on_batch_received = journal.on_batch_received self.gossip.on_block_received = journal.on_block_received journal.start() # feed it a batch batch = Batch() journal.on_batch_received(batch) wait_until(lambda: self.block_sender.new_block is not None, 2) self.assertTrue(self.block_sender.new_block is not None) block = BlockWrapper(self.block_sender.new_block) journal.on_block_received(block) # wait for the chain_head to be updated. wait_until(lambda: btm.chain_head.identifier == block.identifier, 2) self.assertTrue(btm.chain_head.identifier == block.identifier) finally: if journal is not None: journal.stop()
def do_publish_block(): btm = BlockTreeManager() block_publisher = None chain_controller = None try: block_publisher = BlockPublisher( transaction_executor=testJournal.txn_executor, block_cache=btm.block_cache, state_view_factory=MockStateViewFactory(btm.state_db), settings_cache=SettingsCache( SettingsViewFactory(btm.state_view_factory), ), block_sender=testJournal.block_sender, batch_sender=testJournal.batch_sender, squash_handler=None, chain_head=btm.block_store.chain_head, identity_signer=btm.identity_signer, data_dir=None, config_dir=None, permission_verifier=testJournal.permission_verifier, check_publish_block_frequency=0.1, batch_observers=[], batch_injector_factory=DefaultBatchInjectorFactory( block_store=btm.block_store, state_view_factory=MockStateViewFactory(btm.state_db), signer=btm.identity_signer)) block_validator = BlockValidator( state_view_factory=MockStateViewFactory(btm.state_db), block_cache=btm.block_cache, transaction_executor=testJournal.txn_executor, squash_handler=None, identity_signer=btm.identity_signer, data_dir=None, config_dir=None, permission_verifier=testJournal.permission_verifier) chain_controller = ChainController( block_cache=btm.block_cache, block_validator=block_validator, state_view_factory=MockStateViewFactory(btm.state_db), chain_head_lock=block_publisher.chain_head_lock, on_chain_updated=block_publisher.on_chain_updated, chain_id_manager=None, data_dir=None, config_dir=None, chain_observers=[]) testJournal.gossip.on_batch_received = block_publisher.queue_batch testJournal.gossip.on_block_received = chain_controller.queue_block block_publisher.start() chain_controller.start() # feed it a batch batch = Batch() block_publisher.queue_batch(batch) wait_until(lambda: testJournal.block_sender.new_block is not None, 2) assert testJournal.block_sender.new_block != None block = BlockWrapper(testJournal.block_sender.new_block) chain_controller.queue_block(block) # wait for the chain_head to be updated. wait_until(lambda: btm.chain_head.identifier == block.identifier, 2) # assert btm.chain_head.identifier == block.identifier finally: if block_publisher is not None: block_publisher.stop() if chain_controller is not None: chain_controller.stop() if block_validator is not None: block_validator.stop()