Пример #1
0
    def test_getBlock(self):
        db_state = Mock(spec=State)
        db_state.get_tx_metadata = MagicMock(return_value=None)
        db_state.get_block = MagicMock(return_value=None)

        p2p_factory = Mock(spec=P2PFactory)
        p2p_factory.pow = Mock(spec=POW)

        chain_manager = ChainManager(db_state)

        qrlnode = QRLNode(mining_address=b'')
        qrlnode.set_chain_manager(chain_manager)
        qrlnode._p2pfactory = p2p_factory
        qrlnode._pow = p2p_factory.pow
        qrlnode._peer_addresses = ['127.0.0.1', '192.168.1.1']

        service = PublicAPIService(qrlnode)

        alice_xmss = get_alice_xmss()
        b = Block.create(block_number=1,
                         prev_headerhash=sha256(b'reveal'),
                         prev_timestamp=10,
                         transactions=[],
                         miner_address=alice_xmss.address)
        db_state.get_block = MagicMock(return_value=b)

        context = Mock(spec=ServicerContext)
        request = qrl_pb2.GetBlockReq(header_hash=b.headerhash)
        response = service.GetBlock(request=request, context=context)
        context.set_code.assert_not_called()
        self.assertEqual(1, response.block.header.block_number)
Пример #2
0
 def _get_blockchain(self, peer_metadata, start_index):
     req = qrl_pb2.GetBlockReq()
     req.index = start_index
     f = peer_metadata.stub.GetBlock.future(
         req, timeout=PeerManager.TIMEOUT_SECS)
     f.pm = peer_metadata
     f.index = start_index
     f.add_done_callback(self._block_received)
Пример #3
0
 def get_block(self, header_hash: str):
     headerhash = bytes(hstr2bin(header_hash))
     response = self._public_stub.GetBlock(
         qrl_pb2.GetBlockReq(header_hash=headerhash))
     return self.to_plain_blocks(response.block)