Esempio n. 1
0
 def test_monthly_expanses(self):
     """Test monthly expanses logic"""
     pubkey, call_sign = 'pubkey', 'call_sign'
     self.internal_test_create_user(pubkey, call_sign)
     monthly_expanses = db.get_monthly_expanses(pubkey)
     self.assertEqual(monthly_expanses, 0, 'monthly expanses are incorrect')
     db.update_test(pubkey, 'basic', 1)
     payment_address = db.get_payment_address(pubkey, 500, 'BTC', 'BUL')
     db.set_purchase(pubkey, payment_address, 'BTC', 500, 'BUL', 1)
     monthly_expanses = db.get_monthly_expanses(pubkey)
     self.assertEqual(monthly_expanses, 500,
                      'monthly expanses are incorrect')
     payment_address = db.get_payment_address(pubkey, 600, 'ETH', 'XLM')
     db.set_purchase(pubkey, payment_address, 'ETH', 500, 'XLM', 1)
     monthly_expanses = db.get_monthly_expanses(pubkey)
     self.assertEqual(monthly_expanses, 1100,
                      'monthly expanses are incorrect')
Esempio n. 2
0
 def test_update_purchase(self):
     """Test purchase updating."""
     pubkey, call_sign = 'pubkey', 'call_sign'
     self.internal_test_create_user(pubkey, call_sign)
     db.update_test(pubkey, 'basic', 1)
     address = db.get_payment_address(pubkey, 700, 'BTC', 'XLM')
     db.set_purchase(pubkey, address, 'BTC', 700, 'XLM', 1)
     purchase = db.get_paid_purchases()[0]
     self.assertEqual(purchase['paid'], 1, 'purchase does not updated')
Esempio n. 3
0
def purchase_bul_handler(user_pubkey, euro_cents, payment_currency):
    """
    Request the purchase of BULs.
    Returns an address to send ETH or BTC to.
    """
    return {
        'status':
        201,
        'payment_pubkey':
        db.get_payment_address(user_pubkey, euro_cents, payment_currency,
                               'BUL')
    }
Esempio n. 4
0
def purchase_xlm_handler(user_pubkey, euro_cents, payment_currency):
    """
    Request the purchase of Stellar lumens.
    Returns an address to send ETH or BTC to.
    """
    return {
        'status':
        201,
        'payment_pubkey':
        db.get_payment_address(user_pubkey, euro_cents, payment_currency,
                               'XLM')
    }
Esempio n. 5
0
    def test_check_purchases_addresses(self):
        """Test for check_purchases_addresses routine"""
        users = db.get_users()
        full_paid_addresses = [
            db.get_payment_address(users['callsign_0']['pubkey'],
                                   self.purchase_amount, 'ETH', 'XLM'),
            db.get_payment_address(users['callsign_1']['pubkey'],
                                   self.purchase_amount, 'ETH', 'BUL')
        ]
        half_paid_addresses = [
            db.get_payment_address(users['callsign_2']['pubkey'],
                                   self.purchase_amount, 'ETH', 'BUL'),
            db.get_payment_address(users['callsign_3']['pubkey'],
                                   self.purchase_amount, 'ETH', 'XLM')
        ]

        original_function = routines.get_balance
        routines.get_balance = lambda address, _: \
            self.eth_full_payment if address in full_paid_addresses else self.eth_half_payment

        routines.check_purchases_addresses()
        purchases = db.get_unpaid_purchases()
        self.assertNotEqual(len(purchases), 0)
        for purchase in purchases:
            if purchase['payment_pubkey'] in full_paid_addresses:
                self.assertEqual(
                    purchase['paid'], 1,
                    "purchase with full funded address %s has unpaid status" %
                    purchase['payment_pubkey'])
            if (purchase['payment_pubkey'] not in full_paid_addresses
                    or purchase['payment_pubkey'] in half_paid_addresses):
                self.assertEqual(
                    purchase['paid'], 0,
                    "purchase without full funded address %s"
                    "has wrong paid status: %s" %
                    (purchase['payment_pubkey'], purchase['paid']))
        routines.get_balance = original_function
Esempio n. 6
0
 def test_get_payment_address(self):
     """Test get payment address"""
     pubkey, call_sign = 'pubkey', 'call_sign'
     self.internal_test_create_user(pubkey, call_sign)
     db.update_test('pubkey', 'basic', 1)
     payment_address = db.get_payment_address(pubkey, 500, 'BTC', 'BUL')
     purchase = db.get_unpaid_purchases()[0]
     self.assertEqual(payment_address, purchase['payment_pubkey'],
                      'payment address was not created for user')
     self.assertEqual(pubkey, purchase['user_pubkey'],
                      'payment address was created for another user')
     self.assertEqual(500, purchase['euro_cents'],
                      'created record has wrong euro_cents value')
     self.assertEqual('BTC', purchase['payment_currency'],
                      'created record has wrong payment_currency value')
     self.assertEqual('BUL', purchase['requested_currency'],
                      'created record has wrong requested_currency value')
Esempio n. 7
0
 def test_get_unpaid(self):
     """Test get unpaid purchases"""
     pubkey, call_sign = 'pubkey', 'call_sign'
     self.internal_test_create_user(pubkey, call_sign)
     db.update_test(pubkey, 'basic', 1)
     purchase_amount = 5
     payment_addresses = [
         db.get_payment_address(pubkey, 700, 'BTC', 'XLM')
         for _ in range(purchase_amount)
     ]
     unpaid = db.get_unpaid_purchases()
     self.assertEqual(
         len(unpaid), purchase_amount,
         'actual purchases amount does not correspond to control value')
     for address in payment_addresses:
         with self.subTest():
             self.assertIn(
                 address, (purchase['payment_pubkey']
                           for purchase in unpaid),
                 'created payment address does not present among unpaid purchases'
             )
Esempio n. 8
0
    def test_send_requested_currency(self):
        """Test for send_requested_currency"""
        users = db.get_users()
        successful_address = [
            db.get_payment_address(users['callsign_0']['pubkey'],
                                   self.purchase_amount, 'ETH', 'XLM'),
            db.get_payment_address(users['callsign_1']['pubkey'],
                                   self.purchase_amount, 'ETH', 'XLM'),
            db.get_payment_address(users['callsign_2']['pubkey'],
                                   self.purchase_amount, 'ETH', 'BUL')
        ]
        failed_address = [
            db.get_payment_address(users['callsign_3']['pubkey'],
                                   self.purchase_amount, 'ETH', 'BUL'),
            db.get_payment_address(users['callsign_4']['pubkey'],
                                   self.purchase_amount, 'ETH', 'BUL'),
            db.get_payment_address(users['callsign_5']['pubkey'],
                                   self.purchase_amount, 'ETH', 'BUL')
        ]
        routines.create_new_account(users['callsign_5']['pubkey'], 50000000)
        set_trust(users['callsign_5']['pubkey'],
                  self.actual_keypairs[users['callsign_5']['pubkey']], 1000000)
        set_trust(users['callsign_2']['pubkey'],
                  self.actual_keypairs[users['callsign_2']['pubkey']])

        original_function = routines.get_balance
        routines.get_balance = lambda address, _: self.eth_full_payment

        routines.check_purchases_addresses()
        routines.send_requested_currency()
        purchases = db.get_paid_purchases()
        self.assertEqual(len(purchases), 0)
        for purchase in db.get_current_purchases():
            if purchase['payment_pubkey'] in successful_address:
                self.assertEqual(
                    purchase['paid'], 2,
                    "purchase with address: {} has paid status: {} but expected: 2"
                    .format(purchase['payment_pubkey'], purchase['paid']))
            if purchase['payment_pubkey'] in failed_address:
                self.assertEqual(
                    purchase['paid'], -1,
                    "purchase with address: {} has paid status: {} but expected: -1"
                    .format(purchase['payment_pubkey'], purchase['paid']))
        routines.get_balance = original_function