Esempio n. 1
0
 def test_non_unique_call_sign(self):
     """Test user creation on non unique call sign"""
     keypair = paket_stellar.get_keypair()
     call_sign = 'test_user'
     self.internal_test_create_user(keypair, call_sign)
     another_keypair = paket_stellar.get_keypair()
     self.call('create_user',
               400,
               'created user with non uniq call sign',
               another_keypair.seed(),
               user_pubkey=another_keypair.address(),
               call_sign=call_sign)
Esempio n. 2
0
 def test_create_with_infos(self):
     """Test create user with provided user info."""
     keypair = paket_stellar.get_keypair()
     call_sign = 'test_user'
     full_name = 'Kapitoshka Vodyanovych'
     phone_number = '+380 67 13 666'
     address = 'Vulychna 14, Trypillya'
     user = self.internal_test_create_user(keypair,
                                           call_sign,
                                           full_name=full_name,
                                           phone_number=phone_number,
                                           address=address)
     user_infos = db.get_user_infos(user['pubkey'])
     self.assertEqual(
         user_infos['full_name'], full_name,
         "stored full name: {} does not match given: {}".format(
             user_infos['full_name'], full_name))
     self.assertEqual(
         user_infos['phone_number'], phone_number,
         "stored phone number: {} does not match given: {}".format(
             user_infos['phone_number'], phone_number))
     self.assertEqual(
         user_infos['address'], address,
         "stored address: {} does not match given: {}".format(
             user_infos['address'], address))
Esempio n. 3
0
 def test_with_user_creation(self):
     """Test for getting user infos."""
     keypair = paket_stellar.get_keypair()
     call_sign = 'test_user'
     full_name = 'Kapitoshka Vodyanovych'
     phone_number = '+380 67 13 666'
     address = 'Vulychna 14, Trypillya'
     self.internal_test_create_user(keypair,
                                    call_sign,
                                    full_name=full_name,
                                    phone_number=phone_number,
                                    address=address)
     user_infos = self.call('user_infos',
                            200,
                            'could not get user infos',
                            seed=keypair.seed(),
                            user_pubkey=keypair.address())['user_details']
     self.assertEqual(
         user_infos['full_name'], full_name,
         "stored full name: {} does not match given: {}".format(
             user_infos['full_name'], full_name))
     self.assertEqual(
         user_infos['phone_number'], phone_number,
         "stored phone number: {} does not match given: {}".format(
             user_infos['phone_number'], phone_number))
     self.assertEqual(
         user_infos['address'], address,
         "stored address: {} does not match given: {}".format(
             user_infos['address'], address))
Esempio n. 4
0
 def call(self,
          path,
          expected_code=None,
          fail_message=None,
          seed=None,
          **kwargs):
     """Post data to API server."""
     LOGGER.info("calling %s", path)
     if seed:
         fingerprint = webserver.validation.generate_fingerprint(
             "{}/v{}/{}".format(self.host, routes.VERSION, path), kwargs)
         signature = webserver.validation.sign_fingerprint(
             fingerprint, seed)
         headers = {
             'Pubkey':
             paket_stellar.get_keypair(seed=seed).address().decode(),
             'Fingerprint': fingerprint,
             'Signature': signature
         }
     else:
         headers = None
     response = self.app.post("/v{}/{}".format(routes.VERSION, path),
                              headers=headers,
                              data=kwargs)
     response = dict(real_status_code=response.status_code,
                     **json.loads(response.data.decode()))
     if expected_code:
         self.assertEqual(
             response['real_status_code'], expected_code,
             "{} ({})".format(fail_message, response.get('error')))
     return response
Esempio n. 5
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.app = APP.test_client()
     self.host = 'http://localhost'
     self.funded_seed = 'SDJGBJZMQ7Z4W3KMSMO2HYEV56DJPOZ7XRR7LJ5X2KW6VKBSLELR7MRQ'
     self.funded_account = paket_stellar.get_keypair(seed=self.funded_seed)
     self.funded_pubkey = self.funded_account.address().decode()
     LOGGER.info('init done')
Esempio n. 6
0
 def test_invalid_call_sign(self):
     """Test create user with invalid call_sign"""
     keypair = paket_stellar.get_keypair()
     self.call('create_user',
               400,
               'created user with invalid call_sign',
               seed=keypair.seed(),
               call_sign=keypair.address().decode())
Esempio n. 7
0
    def test_submit_signed(self):
        """Test submitting signed transactions."""
        keypair = paket_stellar.get_keypair()
        new_pubkey = keypair.address().decode()
        new_seed = keypair.seed().decode()

        # checking create_account transaction
        unsigned_account = self.call(
            'prepare_account',
            200,
            'could not get create account transaction',
            from_pubkey=self.funder_pubkey,
            new_pubkey=new_pubkey)['transaction']
        signed_account = self.sign_transaction(unsigned_account,
                                               self.funder_seed)
        LOGGER.info('Submitting signed create_account transaction')
        self.call(
            path='submit_transaction',
            expected_code=200,
            fail_message=
            'unexpected server response for submitting signed create_account transaction',
            seed=self.funder_seed,
            transaction=signed_account)

        # checking trust transaction
        unsigned_trust = self.call('prepare_trust',
                                   200,
                                   'could not get trust transaction',
                                   from_pubkey=new_pubkey)['transaction']
        signed_trust = self.sign_transaction(unsigned_trust, new_seed)
        LOGGER.info('Submitting signed trust transaction')
        self.call(
            path='submit_transaction',
            expected_code=200,
            fail_message=
            'unexpected server response for submitting signed trust transaction',
            seed=new_seed,
            transaction=signed_trust)

        # checking send_buls transaction
        unsigned_send_buls = self.call(
            'prepare_send_buls',
            200,
            "can not prepare send from {} to {}".format(
                self.funder_pubkey, new_pubkey),
            from_pubkey=self.funder_pubkey,
            to_pubkey=new_pubkey,
            amount_buls=5)['transaction']
        signed_send_buls = self.sign_transaction(unsigned_send_buls,
                                                 self.funder_seed)
        LOGGER.info('Submitting signed send_buls transaction')
        self.call(
            path='submit_transaction',
            expected_code=200,
            fail_message=
            'unexpected server response for submitting signed send_buls transaction',
            seed=self.funder_seed,
            transaction=signed_send_buls)
Esempio n. 8
0
 def test_create_user(self):
     """Test create user."""
     keypair = paket_stellar.get_keypair()
     call_sign = 'test_user'
     self.internal_test_create_user(keypair, call_sign)
     users = db.get_users()
     self.assertEqual(
         len(users), 1,
         "number of existing users: {} should be 1".format(len(users)))
Esempio n. 9
0
 def test_submit_anauth(self):
     """Test submitting unsigned transaction."""
     new_keypair = paket_stellar.get_keypair()
     pubkey = new_keypair.address().decode()
     builder = paket_stellar.gen_builder(pubkey=self.regular_account_pubkey)
     builder.append_create_account_op(destination=pubkey,
                                      starting_balance='5')
     with self.assertRaises(paket_stellar.StellarTransactionFailed):
         paket_stellar.submit(builder)
Esempio n. 10
0
    def test_create_relay(self):
        """Test creating relay transactions."""

        relay_pubkey, _ = setup_account(RELAY_SEED,
                                        new_account=True,
                                        add_trust=True)
        relayer_keypair = paket_stellar.get_keypair()
        relayee_keypair = paket_stellar.get_keypair()

        relay_details = paket_stellar.prepare_relay(
            relay_pubkey,
            relayer_keypair.address().decode(),
            relayee_keypair.address().decode(), 100000000, 150000000,
            1568455600)

        self.assertTrue(relay_details['set_options_transaction']
                        and relay_details['relay_transaction']
                        and relay_details['sequence_merge_transaction']
                        and relay_details['timelock_merge_transaction'])
Esempio n. 11
0
 def test_submit(self):
     """Test submitting properly created and signed transaction."""
     new_keypair = paket_stellar.get_keypair()
     pubkey = new_keypair.address().decode()
     create_account_transaction = paket_stellar.prepare_create_account(
         self.regular_account_pubkey, pubkey, 50000000)
     result = paket_stellar.submit_transaction_envelope(
         create_account_transaction, self.regular_account_seed)
     self.assertIn('result_xdr', result)
     self.assertEqual(result['result_xdr'],
                      'AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA=')
Esempio n. 12
0
 def test_prepare_account(self):
     """Test preparing transaction for creating account."""
     keypair = paket_stellar.get_keypair()
     pubkey = keypair.address().decode()
     LOGGER.info('preparing create account transaction for public key: %s',
                 pubkey)
     self.call('prepare_account',
               200,
               'could not get create account transaction',
               from_pubkey=self.funder_pubkey,
               new_pubkey=pubkey)
Esempio n. 13
0
 def test_prepare_trust(self):
     """Test preparing transaction for trusting BULs."""
     keypair = paket_stellar.get_keypair()
     pubkey = keypair.address().decode()
     self.create_account(from_pubkey=self.funder_pubkey,
                         new_pubkey=pubkey,
                         seed=self.funder_seed)
     LOGGER.info('querying prepare trust for user: %s', pubkey)
     self.call('prepare_trust',
               200,
               'could not get trust transaction',
               from_pubkey=pubkey)
Esempio n. 14
0
 def test_get_user_by_call_sign(self):
     """Test get user by call sign."""
     keypair = paket_stellar.get_keypair()
     call_sign = 'test_user'
     user = self.internal_test_create_user(keypair, call_sign)
     stored_user = self.call('get_user',
                             200,
                             'could not get user',
                             call_sign=call_sign)['user']
     self.assertEqual(
         stored_user['call_sign'], user['call_sign'],
         "stored user: {} does not match created one: {}".format(
             stored_user['call_sign'], user['call_sign']))
Esempio n. 15
0
 def create_and_setup_new_account(self, amount_buls=None, trust_limit=None):
     """Create account. Add trust and send initial ammount of BULs (if specified)"""
     keypair = paket_stellar.get_keypair()
     pubkey = keypair.address().decode()
     seed = keypair.seed().decode()
     self.create_account(from_pubkey=self.funded_pubkey,
                         new_pubkey=pubkey,
                         seed=self.funded_seed)
     self.trust(pubkey, seed, trust_limit)
     if amount_buls is not None:
         self.send(from_seed=self.funded_seed,
                   to_pubkey=pubkey,
                   amount_buls=amount_buls)
     return pubkey, seed
Esempio n. 16
0
 def test_get_non_existent_user(self):
     """Test get user on non existent publik key and call sign."""
     keypair = paket_stellar.get_keypair()
     self.internal_test_create_user(keypair, 'call_sign')
     self.call('get_user',
               404,
               'does not get not found status code on non-existed pubkey',
               keypair.seed(),
               pubkey='public key')
     self.call(
         'get_user',
         404,
         'does not get not found status code on non-existed call sign',
         keypair.seed(),
         call_sign='another call sign')
Esempio n. 17
0
 def send(self, from_seed, to_pubkey, amount_buls):
     """Send BULs between accounts."""
     from_pubkey = paket_stellar.get_keypair(
         seed=from_seed).address().decode()
     description = "sending {} from {} to {}".format(
         amount_buls, from_pubkey, to_pubkey)
     LOGGER.info(description)
     unsigned = self.call('prepare_send_buls',
                          200,
                          "can not prepare send from {} to {}".format(
                              from_pubkey, to_pubkey),
                          from_pubkey=from_pubkey,
                          to_pubkey=to_pubkey,
                          amount_buls=amount_buls)['transaction']
     return self.submit(unsigned, seed=from_seed, description=description)
Esempio n. 18
0
 def create_and_setup_new_account(self,
                                  starting_balance=50000000,
                                  buls_amount=None,
                                  trust_limit=None):
     """Create account. Add trust and send initial amount of BULs (if specified)."""
     keypair = paket_stellar.get_keypair()
     pubkey = keypair.address().decode()
     seed = keypair.seed().decode()
     self.create_account(from_pubkey=self.funder_pubkey,
                         new_pubkey=pubkey,
                         seed=self.funder_seed,
                         starting_balance=starting_balance)
     self.trust(pubkey, seed, trust_limit)
     if buls_amount is not None:
         self.send(from_seed=self.funder_seed,
                   to_pubkey=pubkey,
                   amount_buls=buls_amount)
     return pubkey, seed
Esempio n. 19
0
 def test_purchase(self):
     """Test for purchasing BUL."""
     keypair = paket_stellar.get_keypair()
     full_name = 'New Name'
     phone_number = '+48 045 237 27 36'
     address = 'New Address'
     self.internal_test_create_user(keypair,
                                    'new_user',
                                    full_name=full_name,
                                    phone_number=phone_number,
                                    address=address)
     # need to add generated address checking
     self.call('purchase_bul',
               201,
               'could not purchase xlm',
               keypair.seed(),
               user_pubkey=keypair.address(),
               euro_cents=500,
               payment_currency='ETH')
Esempio n. 20
0
    def setUp(self):
        """Clear table and refill them with new data"""
        tests.init_db()

        self.actual_keypairs.clear()
        LOGGER.info('generating new keypairs...')
        for number in range(USERS_NUMBER):
            new_keypair = paket_stellar.get_keypair()
            db.create_user(new_keypair.address(), 'callsign_{}'.format(number))
            if number % 2 == 0:
                LOGGER.info("creating account for address: %s",
                            new_keypair.address())
                routines.create_new_account(new_keypair.address(), 50000000)
            db.set_internal_user_info(new_keypair.address(),
                                      full_name='Full Name',
                                      phone_number='+380991128370',
                                      address='address')
            self.actual_keypairs[
                new_keypair.address().decode()] = new_keypair.seed().decode()
Esempio n. 21
0
    def test_bul_account(self):
        """Test getting existing account."""
        accounts = []
        # additionally create 3 new accounts
        for _ in range(3):
            keypair = paket_stellar.get_keypair()
            pubkey = keypair.address().decode()
            seed = keypair.seed().decode()
            self.create_account(from_pubkey=self.funder_pubkey,
                                new_pubkey=pubkey,
                                seed=self.funder_seed)
            self.trust(pubkey, seed)
            accounts.append(pubkey)

        for account in accounts:
            with self.subTest(account=account):
                LOGGER.info('getting information about account: %s', account)
                self.call('bul_account',
                          200,
                          'could not verify account exist',
                          queried_pubkey=account)
Esempio n. 22
0
def setup_account(seed, new_account=False, add_trust=False):
    """Generate new keypair, and optionally create account and set trust."""
    keypair = paket_stellar.get_keypair(seed=seed)
    pubkey = keypair.address().decode()
    seed = keypair.seed().decode()

    if new_account:
        try:
            account = paket_stellar.get_bul_account(pubkey,
                                                    accept_untrusted=True)
        except paket_stellar.StellarAccountNotExists:
            LOGGER.info("%s not exist and will be created", pubkey)
            create_account_transaction = paket_stellar.prepare_create_account(
                paket_stellar.ISSUER, pubkey, START_ACCOUNT_BALANCE)
            paket_stellar.submit_transaction_envelope(
                create_account_transaction, paket_stellar.ISSUER_SEED)
        else:
            LOGGER.info("%s already exist", pubkey)
            if account['xlm_balance'] < MINIMUM_ACCOUNT_BALANCE:
                LOGGER.info("%s has %s XLM on balance and need to be funded",
                            pubkey, account['xlm_balance'])
                send_xlm_transaction = paket_stellar.prepare_send_lumens(
                    paket_stellar.ISSUER, pubkey, START_ACCOUNT_BALANCE)
                paket_stellar.submit_transaction_envelope(
                    send_xlm_transaction, paket_stellar.ISSUER_SEED)
            else:
                LOGGER.info("%s has %s XLM on balance", pubkey,
                            account['xlm_balance'])

    if new_account and add_trust:
        try:
            paket_stellar.get_bul_account(pubkey)
        except paket_stellar.TrustError:
            LOGGER.info("BUL trustline will be added to %s", pubkey)
            trust_transaction = paket_stellar.prepare_trust(pubkey)
            paket_stellar.submit_transaction_envelope(trust_transaction, seed)
        else:
            LOGGER.info("%s already trust BUL", pubkey)

    return pubkey, seed
Esempio n. 23
0
 def test_adding_portions(self):
     """Test for adding info by portions."""
     keypair = paket_stellar.get_keypair()
     call_sign = 'test_user'
     self.internal_test_create_user(keypair, call_sign)
     user_details = {
         'full_name': 'Kapitoshka Vodyanovych',
         'phone_number': '+380 67 13 666',
         'address': 'Vulychna 14, Trypillya'
     }
     passed_details = {}
     for key, value in user_details.items():
         stored_user_details = self.call(
             'user_infos', 200,
             "could not add new user's detail: {}={}".format(key, value),
             keypair.seed(), **{key: value})['user_details']
         passed_details[key] = value
         for detail_name, detail_value in passed_details.items():
             self.assertIn(
                 detail_name, stored_user_details,
                 "user details does not contails new detail: {}={}".format(
                     detail_name, detail_value))
             self.assertEqual(
                 stored_user_details[detail_name], detail_value,
                 "new added detail: {} does not match given: {}".format(
                     stored_user_details[detail_name], detail_value))
             test_result = db.get_test_result(keypair.address().decode(),
                                              'basic')
             self.assertEqual(
                 test_result, 1 if len(passed_details) == 3 else 0,
                 "got unexpected test result: {} for user with details: {}".
                 format(
                     test_result, ''.join([
                         "{}={}".format(key, value)
                         for key, value in passed_details.items()
                     ])))
Esempio n. 24
0
 def test_get_random(self):
     """Test for getting random keypair."""
     keypair = paket_stellar.get_keypair()
     self.assertIsNotNone(keypair.signing_key)
     self.assertIsNotNone(keypair.address())
Esempio n. 25
0
 def test_get_from_seed(self):
     """Test for getting keypair from seed."""
     keypair = paket_stellar.get_keypair(seed=self.seed)
     self.assertEqual(keypair.address().decode(), self.pubkey)
Esempio n. 26
0
 def test_get_from_pubkey(self):
     """Test for getting keypair from pubkey."""
     keypair = paket_stellar.get_keypair(pubkey=self.pubkey)
     self.assertIsNone(keypair.signing_key)
Esempio n. 27
0
 def test_get_from_invalid_pubkey(self):
     """Test for getting from invalid pubkey."""
     with self.assertRaises(paket_stellar.stellar_base.exceptions.
                            StellarAddressInvalidError):
         paket_stellar.get_keypair(pubkey=self.invalid_pubkey)
Esempio n. 28
0
 def test_get_from_invalid_seed(self):
     """Test for getting keypair from invalid seed."""
     with self.assertRaises(paket_stellar.stellar_base.exceptions.
                            StellarSecretInvalidError):
         paket_stellar.get_keypair(seed=self.invalid_seed)
Esempio n. 29
0
 def generate_keypair():
     """Generate new stellar keypair."""
     keypair = paket_stellar.get_keypair()
     pubkey = keypair.address().decode()
     seed = keypair.seed().decode()
     return pubkey, seed