def test_GetLastBlockHeader(self): self.block_header_params["blocknumber"] = 20 block_header = BlockHeader.create(**self.block_header_params) self.chain_manager.height = 200 self.qrlnode.get_blockheader_and_metadata = MagicMock( return_value=[block_header, BlockMetadata()]) req = qrlmining_pb2.GetLastBlockHeaderReq(height=20) answer = self.service.GetLastBlockHeader(request=req, context=None) self.assertEqual(180, answer.depth) self.assertEqual(200, answer.height)
def getlastblockheader(height=0): stub = get_mining_stub() request = qrlmining_pb2.GetLastBlockHeaderReq(height=height) grpc_response = stub.GetLastBlockHeader(request=request, timeout=10) block_header = { 'difficulty': grpc_response.difficulty, 'height': grpc_response.height, 'timestamp': grpc_response.timestamp, 'reward': grpc_response.reward, 'hash': grpc_response.hash, 'depth': grpc_response.depth } resp = {"block_header": block_header, "status": "OK"} return resp