def finalize_block(self, data): request = consensus_pb2.ConsensusFinalizeBlockRequest(data=data) response_type = consensus_pb2.ConsensusFinalizeBlockResponse response = self._send( request=request, message_type=Message.CONSENSUS_FINALIZE_BLOCK_REQUEST, response_type=response_type) status = response.status if status == response_type.INVALID_STATE: raise exceptions.InvalidState( 'Cannot finalize block in current state') if status == response_type.BLOCK_NOT_READY: raise exceptions.BLOCK_NOT_READY( 'Block not ready to be finalized') if status != response_type.OK: raise exceptions.ReceiveError( 'Failed with status {}'.format(status)) return response.block_id
def test_finalize_block(self): self.mock_stream.send.return_value = self._make_future( message_type=Message.CONSENSUS_FINALIZE_BLOCK_RESPONSE, content=consensus_pb2.ConsensusFinalizeBlockResponse( status=consensus_pb2.ConsensusFinalizeBlockResponse.OK)) self.service.finalize_block(data=b'test') self.mock_stream.send.assert_called_with( message_type=Message.CONSENSUS_FINALIZE_BLOCK_REQUEST, content=consensus_pb2.ConsensusFinalizeBlockRequest( data=b'test').SerializeToString())