def test_get_chain_head(self): block = consensus_pb2.ConsensusBlock(block_id=b'block', previous_id=b'block0', signer_id=b'signer', block_num=1, payload=b'test') self.mock_stream.send.return_value = self._make_future( message_type=Message.CONSENSUS_CHAIN_HEAD_GET_RESPONSE, content=consensus_pb2.ConsensusChainHeadGetResponse( status=consensus_pb2.ConsensusChainHeadGetResponse.OK, block=block).SerializeToString()) chain_head = self.service.get_chain_head() self.mock_stream.send.assert_called_with( message_type=Message.CONSENSUS_CHAIN_HEAD_GET_REQUEST, content=consensus_pb2.ConsensusChainHeadGetRequest( ).SerializeToString()) self.assertEqual(chain_head.block_id, b'block') self.assertEqual(chain_head.previous_id, b'block0') self.assertEqual(chain_head.signer_id, b'signer') self.assertEqual(chain_head.block_num, 1) self.assertEqual(chain_head.payload, b'test')
def get_chain_head(self): request = consensus_pb2.ConsensusChainHeadGetRequest() response_type = consensus_pb2.ConsensusChainHeadGetResponse response = self._send( request=request, message_type=Message.CONSENSUS_CHAIN_HEAD_GET_REQUEST, response_type=response_type) status = response.status if status == response_type.NO_CHAIN_HEAD: raise exceptions.NoChainHead() if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status)) return Block(response.block)
def get_chain_head(self, parent_id=None, new_parent_id=None, is_new=False): request = consensus_pb2.ConsensusChainHeadGetRequest( parent_id=parent_id, new_parent_id=new_parent_id, is_new=is_new) response_type = consensus_pb2.ConsensusChainHeadGetResponse response = self._send( request=request, message_type=Message.CONSENSUS_CHAIN_HEAD_GET_REQUEST, response_type=response_type) status = response.status if status == response_type.NO_CHAIN_HEAD: raise exceptions.NoChainHead() if status == response_type.TOO_MANY_BRANCH: raise exceptions.TooManyBranch() if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status)) #LOGGER.debug('get_chain_head: block=%s',response.block) return Block(response.block)