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") block_store = {} journal = None try: journal = Journal( consensus=test_mode_consensus, block_store=block_store, send_message=self.gossip.send_message, transaction_executor=self.txn_executor, squash_handler=None, first_state_root="000000") self.gossip.on_batch_received = \ journal.on_batch_received self.gossip.on_block_received = \ journal.on_block_received self.gossip.on_block_request = \ journal.on_block_request journal.start() # feed it a batch batch = Batch() journal.on_batch_received(batch) # wait for a block message to arrive should be soon to = TimeOut(2) while len(self.gossip.messages) == 0: time.sleep(0.1) LOGGER.info("Batches: %s", self.gossip.messages) self.assertTrue(len(self.gossip.messages) != 0) block = self.gossip.messages[0] # dispatch the message self.gossip.dispatch_messages() # wait for the chain_head to be updated. to = TimeOut(2) while block_store['chain_head_id'] != block.header_signature: time.sleep(0.1) self.assertTrue(block_store['chain_head_id'] == block.header_signature) 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( 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 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") block_store = { 'chain_head_id': 'genesis', 'genesis': BlockState( block_wrapper=_generate_genesis_block(), weight=0, status=BlockStatus.Valid) } journal = None try: journal = Journal( consensus=test_mode_consensus, block_store=block_store, 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 self.gossip.on_block_request = \ journal.on_block_request journal.start() # feed it a batch batch = Batch() journal.on_batch_received(batch) # wait for a block message to arrive should be soon to = TimeOut(2) while (self.block_sender.new_block is None): time.sleep(0.1) self.assertTrue(self.block_sender.new_block is not None) self.gossip.messages.append(self.block_sender.new_block) block = self.gossip.messages[0] # dispatch the message self.gossip.dispatch_messages() # wait for the chain_head to be updated. to = TimeOut(2) while block_store['chain_head_id'] != block.header_signature: time.sleep(0.1) self.assertTrue(block_store['chain_head_id'] == block.header_signature) finally: if journal is not None: journal.stop()