Пример #1
0
 def get_blockchain(self):
     """
     :return: The blockchain received from the relay.
     """
     print("Getting blockchain")
     response = client.get(self.url, "blockchain")
     if response.status == 200:
         print("Blockchain successfully received")
     else:
         print("A problem occured while getting the blockchain from %s" %
               self.url)
     return Blockchain.parse(response.data)
Пример #2
0
def test_select_payment(client, campaign):
    """
    Test if we can select a payment and a perk
    """
    perk = campaign.perks.last()
    resp = client.get(reverse('select_payment', args=[campaign.key]) + '?perk={}'.format(perk.id))
    assert resp.status_code == 200
    dom = html.fromstring(resp.content)

    # title must be there
    perk_title = dom.cssselect('#perk-title')[0].text
    assert perk_title == perk.title

    # the amount must be high enough
    dom_amount = dom.cssselect('#id_amount')[0]
    assert Decimal(dom_amount.value) >= perk.amount
Пример #3
0
 def ready(self):
     log.debug(
         "Initializing relay server by getting blockchain from master")
     user = settings.RELAY_CREDENTIALS['username']
     pwd = settings.RELAY_CREDENTIALS['password']
     server = Relay()
     try:
         response = client.get(settings.MASTER_IP,
                               "blockchain",
                               basic_auth=(user, pwd))
     except ConnectionError:
         print(
             "Error: MasterNode is not running at '%s' (check settings file)."
             % settings.MASTER_IP)
         sys.exit(1)
     server.blockchain = Blockchain.parse(response.data)
Пример #4
0
 def get_transaction(self, excludes_list):
     """
     Get transaction from relay.
     :param excludes: TX hashes to be excluded on the request.
     :return: The transaction received if exist, otherwise None.
     """
     response = client.get(self.url, "transactions",
                           {"exclude_hash": excludes_list})
     if response.status == 200:
         print("Transaction successfully received")
         return Transaction.parse(response.data)
     elif response.status == 404:
         # print("no request to be received")
         return None
     else:
         print("Unknown error while requesting transaction")
         return None
Пример #5
0
def test_select_payment(client, campaign):
    """
    Test if we can select a payment and a perk
    """
    perk = campaign.perks.last()
    resp = client.get(
        reverse('select_payment', args=[campaign.key]) +
        '?perk={}'.format(perk.id))
    assert resp.status_code == 200
    dom = html.fromstring(resp.content)

    # title must be there
    perk_title = dom.cssselect('#perk-title')[0].text
    assert perk_title == perk.title

    # the amount must be high enough
    dom_amount = dom.cssselect('#id_amount')[0]
    assert Decimal(dom_amount.value) >= perk.amount
Пример #6
0
 def post(self, request):
     # TODO make sure that only master node can request this
     try:
         block = Block.parse(request.data)
     except ParseException as e:
         return Response({'errors': str(e)},
                         status=status.HTTP_406_NOT_ACCEPTABLE)
     logger.debug("Adding block '%s' to blockchain" % block.header)
     updated = self.server.update_blockchain(block)
     # TODO test when the blockchain is not updated
     if not updated:
         logger.debug("Blockchain not up to date, requesting part of.")
         response = client.get(
             settings.MASTER_IP,
             'blockchain?start=%d' % (self.server.blockchain_size - 1))
         blockchain = Blockchain.parse(response.data)
         self.server.add_blocks(blockchain.blocks)
     return Response(status=status.HTTP_201_CREATED)