Ejemplo n.º 1
0
    async def test_post_close_joint_wallet_from_request_missing_param(
            self, mock_generate_merge_transaction):

        mock_generate_merge_transaction.return_value = {
            'wallet_address':
            self.wallet_address,
            'transaction_url':
            reverse('transaction', transaction_hash=self.tx_hash),
            'signers':
            self.singers,
            'xdr':
            self.unsigned_xdr,
            'transaction_hash':
            self.tx_hash
        }

        self.missing_param_parties_wallet = {
            'parties': [{
                'address': 'wallet1',
                'amount': '15'
            }, {
                'address': 'wallet2',
                'amount': '20'
            }],
        }

        url = reverse('close-joint-wallet', wallet_address=self.wallet_address)
        resp = await self.client.request(
            'POST', url, json=self.missing_param_parties_wallet)

        assert resp.status == 400
        text = await resp.json()
        assert text[
            'message'] == 'Parameter \'transaction_source_address\' not found. Please ensure parameters is valid.'
Ejemplo n.º 2
0
 async def setUpAsync(self):
     self.wallet_address = 'wallet_address'
     self.provider_address = 'provider_address'
     self.creator_address = 'creator_address'
     self.transaction_source_address = 'GDSB3JZDYKLYKWZ6NXDPPGPCYJ32ISMTZ2LVF5PYQGY4B4FGNIU2M5BJ'
     self.parties_wallet = [{
         'address': 'wallet1',
         'amount': '15'
     }, {
         'address': 'wallet2',
         'amount': '20'
     }]
     self.wallet_detail = {
         'escrow_address':
         self.wallet_address,
         '@id':
         reverse('escrow-address', escrow_address=self.wallet_address),
         'asset': {
             settings['ASSET_CODE']: '100.0000'
         },
         'generate-wallet':
         reverse('escrow-generate-wallet',
                 escrow_address=self.wallet_address),
         'data': {
             'provider_address': self.provider_address,
             'creator_address': self.creator_address
         },
         'signers': [self.provider_address, self.creator_address],
     }
Ejemplo n.º 3
0
async def generate_joint_wallet(
    transaction_source_address: str,
    deal_address: str,
    parties: List,
    creator: str,
    starting_xlm: Decimal,
    meta: Dict = None,
) -> Dict:
    """Making transaction for generate joint wallet with many parties"""
    wallet = await get_stellar_wallet(transaction_source_address)
    xdr, tx_hash = await build_joint_wallet(transaction_source_address,
                                            deal_address, parties, creator,
                                            starting_xlm, meta,
                                            wallet.sequence)
    parties_signer = [{
        'public_key': party['address'],
        'weight': 1
    } for party in parties]
    signers = parties_signer + [{
        'public_key': creator,
        'weight': 1
    }, {
        'public_key': deal_address,
        'weight': 1
    }]
    result = {
        '@id': reverse('generate-joint-wallet', wallet_address=deal_address),
        '@transaction_url': reverse('transaction', transaction_hash=tx_hash),
        'signers': signers,
        'xdr': xdr,
        'transaction_hash': tx_hash,
    }
    return result
Ejemplo n.º 4
0
    async def test_generate_escrow_wallet_success(self, mock_build, mock_cal, mock_get_stellar_wallet):

        mock_build.return_value = ['xdr', 'tx_hash']
        mock_cal.return_value = 20
        mock_get_stellar_wallet.return_value = Wallet(
            "1",
            [],
            "1",
            {},
            [],
            {},
            {}
        )
        expect = {
            '@id': reverse('escrow-generate-wallet', escrow_address=self.escrow_address),
            '@transaction_url': reverse('transaction', transaction_hash='tx_hash'),
            'signers': [self.escrow_address, self.creator_address, self.provider_address],
            'xdr': 'xdr',
            'transaction_hash': 'tx_hash'
        }

        result = await generate_escrow_wallet(
            escrow_address=self.escrow_address,
            transaction_source_address=self.transaction_source_address,
            creator_address=self.creator_address,
            provider_address=self.provider_address,
            destination_address=self.destination_address,
            starting_balance=self.starting_balance,
            expiration_date=self.expiration_date,
            cost_per_transaction=self.cost_per_transaction
        )

        assert result == expect
        number_of_transaction = 500 / 50 + 2
        mock_cal.assert_called_once_with(8, number_of_transaction)
Ejemplo n.º 5
0
    async def test_generate_payment(self, mock_get_threshold_weight, mock_get_signer, mock_build):
        mock_get_threshold_weight.return_value = 1
        mock_get_signer.return_value = [
            {"public_key": "GDHH7XOUKIWA2NTMGBRD3P245P7SV2DAANU2RIONBAH6DGDLR5WISZZI", "weight": 1}
        ]
        mock_build.return_value = ('xdr', 'tx_hash')

        result = await generate_payment(
            'GDSB3JZDYKLYKWZ6NXDPPGPCYJ32ISMTZ2LVF5PYQGY4B4FGNIU2M5BJ',
            'GDHH7XOUKIWA2NTMGBRD3P245P7SV2DAANU2RIONBAH6DGDLR5WISZZI',
            'GDMZSRU6XQ3MKEO3YVQNACUEKBDT6G75I27CTBIBKXMVY74BDTS3CSA6',
            '100',
            '0',
            None,
            None,
            None,
        )

        expect_data = {
            "@id": reverse(
                'generate-payment', wallet_address='GDHH7XOUKIWA2NTMGBRD3P245P7SV2DAANU2RIONBAH6DGDLR5WISZZI'
            ),
            "@transaction_url": reverse('transaction', transaction_hash='tx_hash'),
            "min_signer": 1,
            "signers": [{"public_key": "GDHH7XOUKIWA2NTMGBRD3P245P7SV2DAANU2RIONBAH6DGDLR5WISZZI", "weight": 1}],
            "xdr": "xdr",
            "transaction_hash": "tx_hash",
        }
        assert result == expect_data
Ejemplo n.º 6
0
    async def test_post_generate_escrow_wallet_from_request_success_with_expiration_date(self, mock_wallet):

        data = {
            'provider_address': self.provider_address,
            'transaction_source_address': self.transaction_source_address,
            'destination_address': self.destination_address,
            'creator_address': self.creator_address,
            'starting_balance': self.starting_balance,
            'cost_per_transaction': self.cost_per_transaction,
            'expiration_date': self.expiration_date
        }

        expect = {
            '@id': reverse('escrow-generate-wallet', escrow_address=self.escrow_address),
            '@transaction_url': reverse('transaction', transaction_hash='tx_hash'),
            'signers': [self.escrow_address, self.creator_address, self.provider_address],
            'xdr': 'xdr',
            'transaction_hash': 'tx-hash'
        }

        mock_wallet.return_value = {
            '@id': reverse('escrow-generate-wallet', escrow_address=self.escrow_address),
            '@transaction_url': reverse('transaction', transaction_hash='tx_hash'),
            'signers': [self.escrow_address, self.creator_address, self.provider_address],
            'xdr': 'xdr',
            'transaction_hash': 'tx-hash'
        }

        url = reverse('escrow-generate-wallet', escrow_address=self.escrow_address)

        resp = await self.client.request('POST', url, json=data)
        assert resp.status == 200
        body = await resp.json()
        assert body == expect
    async def test_get_presigned_tx_xdr(self, mock_biulder, mock_sequence,
                                        mock_signer, mock_threshold):
        mock_biulder.return_value = ('xdr', 'hash')
        mock_sequence.return_value = '1'
        mock_signer.return_value = []
        mock_threshold.return_value = 2
        result = await get_presigned_tx_xdr(
            'GAH6333FKTNQGSFSDLCANJIE52N7IGMS7DUIWR6JIMQZE7XKWEQLJQAY',
            'GDSB3JZDYKLYKWZ6NXDPPGPCYJ32ISMTZ2LVF5PYQGY4B4FGNIU2M5BJ',
            'GABEAFZ7POCHDY4YCQMRAGVVXEEO4XWYKBY4LMHHJRHTC4MZQBWS6NL6',
            Decimal('10.0000000'), Decimal('5'))

        expect = {
            "min_signer":
            2,
            "signers": [],
            "xdr": [{
                "@id": reverse('transaction', transaction_hash='hash'),
                "xdr": "xdr",
                "sequence_number": 2,
                "transaction_hash": "hash"
            }, {
                "@id": reverse('transaction', transaction_hash='hash'),
                "xdr": "xdr",
                "sequence_number": 3,
                "transaction_hash": "hash"
            }]
        }
        assert result == expect
    async def test_get_presigned_tx_xdr_from_request_when_dont_have_payload(
            self, mock_get_transaction, mock_get_wallet):
        escrow_address = "GAH6333FKTNQGSFSDLCANJIE52N7IGMS7DUIWR6JIMQZE7XKWEQLJQAY"
        mock_get_transaction.return_value = {}
        host = settings.get('HOST', None)
        mock_get_wallet.return_value = {
            '@id':
            reverse('escrow-address', escrow_address=''),
            'asset': {
                'HOT': '10.0000000',
                'XLM': '9.9999200'
            },
            'generate-wallet':
            reverse(
                'escrow-generate-wallet',
                escrow_address=
                'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD'),
            'data': {
                'destination_address':
                'GABEAFZ7POCHDY4YCQMRAGVVXEEO4XWYKBY4LMHHJRHTC4MZQBWS6NL6',
                'cost_per_transaction': '5'
            }
        }

        resp = await self.client.request(
            "POST",
            reverse('generate-presigned-transactions',
                    escrow_address=escrow_address))
        assert resp.status == 400
Ejemplo n.º 9
0
async def generate_payment(
    transaction_source_address: str,
    source_address: str,
    destination: str,
    amount_hot: Decimal,
    amount_xlm: Decimal,
    tax_amount_hot: Decimal = None,
    sequence: int = None,
    memo: str = None,
) -> Dict:
    """Get unsigned transfer transaction and signers

        Args:
            source_address: Owner of operation
            destination_address: address of receiveing wallet
            amount_hot: amount of HoToken that would be transferred
            amount_xlm: amount of XLM that would be transferred
            sequence: sequence number for generate transaction [optional]
            memo: memo text [optional]
    """
    unsigned_xdr, tx_hash = await build_unsigned_transfer(
        transaction_source_address, source_address, destination, amount_hot,
        amount_xlm, tax_amount_hot, sequence, memo)
    host: str = settings['HOST']
    result = {
        '@id': reverse('generate-payment', wallet_address=source_address),
        '@transaction_url': reverse('transaction', transaction_hash=tx_hash),
        'min_signer': await get_threshold_weight(source_address, 'payment'),
        'signers': await get_signers(source_address),
        'xdr': unsigned_xdr,
        'transaction_hash': tx_hash,
    }
    return result
Ejemplo n.º 10
0
async def test_get_wallet_success_not_trust_hot(mock_address):

    balances = [{'balance': '9.9999200', 'asset_type': 'native'}]
    mock_address.return_value = StellarWallet(balances)

    result = await get_wallet_detail(
        'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD')

    host = host = settings.get('HOST', None)
    url = reverse('wallet-address',
                  wallet_address=
                  'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD')
    expect_data = {
        'wallet_address':
        'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD',
        '@id': f'{host}{url}',
        'trust':
        f"{settings['HOST']}{reverse('change-trust-add-token', wallet_address='GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD')}",
        'asset': {
            'XLM': '9.9999200'
        },
        'sequence': '1',
        'data': {
            'age': '30',
            'name': 'UnitTest'
        },
    }
    assert result == expect_data
Ejemplo n.º 11
0
    async def test_generate_merge_transaction_success(self, mock_wallet_detail,
                                                      mock_merge_transaction,
                                                      mock_get_stellar_wallet):
        mock_wallet_detail.return_value = self.wallet_detail
        mock_merge_transaction.return_value = self.unsigned_xdr, self.tx_hash

        result = await generate_merge_transaction(
            self.transaction_source_address, self.wallet_address,
            self.parties_wallet)

        mock_get_stellar_wallet.return_value = Wallet("1", [], "1", {}, [], {},
                                                      {})

        expect = {
            'wallet_address':
            self.wallet_address,
            'transaction_url':
            reverse('transaction', transaction_hash=self.tx_hash),
            'signers':
            self.wallet_detail['signers'],
            'xdr':
            self.unsigned_xdr,
            'transaction_hash':
            self.tx_hash,
        }

        assert result == expect
 async def test_format_history_sort_desc_success(self):
     url = reverse('wallet-history', wallet_address=self.wallet_address)
     n_offset = self.history['_embedded']['records'][0]['paging_token']
     p_offset = self.history['_embedded']['records'][-1]['paging_token']
     expect = {
         '@id':
         url,
         'history': [{
             "id": "0037667833848532993-0000000001",
             "offset": "37667833848532993-1",
             "address":
             "GDHZCRVQP3W3GUSZMC3ECHRG3WVQQZXVDHY5TOQ5AB5JKRSSUUZ6XDUE",
             "type": "account_created",
             "created_at": "2018-05-03T13:31:45Z",
             "starting_balance": "5.0002000"
         }, {
             "id": "0037667833848532995-0000000001",
             "offset": "37667833848532995-1",
             "address":
             "GDHZCRVQP3W3GUSZMC3ECHRG3WVQQZXVDHY5TOQ5AB5JKRSSUUZ6XDUE",
             "type": "data_created",
             "created_at": "2018-05-03T13:31:45Z"
         }],
         'next':
         f'{url}?offset={p_offset}&limit={self.limit}&sort=desc',
         'previous':
         f'{url}?offset={n_offset}&limit={self.limit}&sort=asc'
     }
     actual = await format_history(history=self.history,
                                   wallet_address=self.wallet_address,
                                   limit=10,
                                   sort='desc')
     assert actual == expect
    async def test_put_transaction_from_request_success(self, mock_tx, mock_dup) -> None:

        mock_dup.return_value = False
        mock_tx.return_value = {'status': 200}
        url = reverse('transaction', transaction_hash='transaction-hash')
        resp = await self.client.request("PUT", url, data=b'test data')
        assert resp.status == 202
async def generate_merge_transaction(
    transaction_source_address: str, wallet_address: str, parties_wallet: List = None
) -> Dict:
    """ Generate close escrow wallet function by escrow address then get escrow wallet detail by
        that address then build generate for return xdr and transaction hash

    Args;
        escrow_address :  Address of escrow wallet
        parties_walles : list of provider address and amount for payback
    return Dict type
        escrow_address : Address of escrow wallet
        transaction_url : Url for GET transaction detail
        signers : Array of signers use for sign xdr
        xdr : Xdr for sign
        transaction_hash: Transaction hash number for get transaction detail
    """
    wallet_detail = await get_escrow_wallet_detail(wallet_address)
    wallet = await get_stellar_wallet(transaction_source_address)
    unsigned_xdr, tx_hash = await build_generate_merge_transaction(
        transaction_source_address, wallet_detail, parties_wallet, wallet.sequence
    )

    return {
        'wallet_address': wallet_address,
        'transaction_url': reverse('transaction', transaction_hash=tx_hash),
        'signers': wallet_detail['signers'],
        'xdr': unsigned_xdr,
        'transaction_hash': tx_hash,
    }
Ejemplo n.º 15
0
    async def test_post_generate_escrow_wallet_from_request_wrong_starting_balance(self):
        url = reverse('escrow-generate-wallet', escrow_address=self.escrow_address)

        data = {
            'provider_address': self.provider_address,
            'transaction_source_address': self.transaction_source_address,
            'destination_address': self.destination_address,
            'creator_address': self.creator_address,
            'starting_balance': 'make-error',
            'cost_per_transaction': 200,
            'expiration_date': self.expiration_date,
        }

        resp = await self.client.request('POST', url, json=data)
        assert resp.status == 400
        body = await resp.json()
        assert body['message'] == "Can not convert to destination_address or cost_per_transaction to Decimal"

        data = {
            'provider_address': self.provider_address,
            'transaction_source_address': self.transaction_source_address,
            'destination_address': self.destination_address,
            'creator_address': self.creator_address,
            'starting_balance': 2000,
            'cost_per_transaction': 3,
            'expiration_date': self.expiration_date,
        }

        resp = await self.client.request('POST', url, json=data)
        assert resp.status == 400
        body = await resp.json()
        assert body['message'] == 'Parameter starting_balance is not match with cost_per_transaction.'
    async def _get_unsigned_transfer(source_address: str,
                                     transaction_source_address,
                                     destination: str, amount: Decimal,
                                     sequence: int) -> Dict:
        """Get unsigned transfer transaction and signers

            Args:
                source_address: Owner of operation
                destination: address of receiving wallet
                amount: amount of money that would be transferred
                sequence: sequence number of escrow account
        """

        unsigned_xdr, tx_hash = await build_unsigned_transfer(
            transaction_source_address,
            source_address,
            destination,
            amount,
            Decimal(0),
            None,
            sequence=sequence)
        host: str = settings['HOST']
        result = {
            '@id': reverse('transaction', transaction_hash=tx_hash),
            'xdr': unsigned_xdr,
            'sequence_number': sequence + 1,
            'transaction_hash': tx_hash
        }
        return result
Ejemplo n.º 17
0
    async def test_post_generate_escrow_wallet_from_request_wrong_expiration_date(self):

        url = reverse('escrow-generate-wallet', escrow_address=self.escrow_address)

        data = {
            'provider_address': self.provider_address,
            'transaction_source_address': self.transaction_source_address,
            'destination_address': self.destination_address,
            'creator_address': self.creator_address,
            'starting_balance': 2000,
            'cost_per_transaction': 20,
            'expiration_date': 'make-error',
        }

        resp = await self.client.request('POST', url, json=data)
        assert resp.status == 400
        body = await resp.json()
        assert body['message'] == "invalid literal for int() with base 10: b'make'"

        data = {
            'provider_address': self.provider_address,
            'transaction_source_address': self.transaction_source_address,
            'destination_address': self.destination_address,
            'creator_address': self.creator_address,
            'starting_balance': 2000,
            'cost_per_transaction': 20,
            'expiration_date': '2018-05-08T01:38:25',
        }

        resp = await self.client.request('POST', url, json=data)
        assert resp.status == 400
        body = await resp.json()
        assert body['message'] == 'Parameter expiration date is not valid.'
Ejemplo n.º 18
0
async def get_unsigned_change_trust(source_address: str,
                                    transaction_source_address: str) -> Dict:
    """Get unsigned transfer transaction and signers"""
    wallet = await get_stellar_wallet(transaction_source_address)
    unsigned_xdr, tx_hash = build_unsigned_change_trust(
        source_address, transaction_source_address, wallet.sequence)
    host: str = settings['HOST']
    result = {
        '@id': reverse('change-trust', wallet_address=source_address),
        '@transaction_url': reverse('transaction', transaction_hash=tx_hash),
        'min_signer': await get_threshold_weight(source_address,
                                                 'change-trust'),
        'signers': await get_signers(source_address),
        'xdr': unsigned_xdr,
        'transaction_hash': tx_hash,
    }
    return result
Ejemplo n.º 19
0
 async def test_get_transaction_from_request(self,
                                             mock_get_transaction) -> None:
     mock_get_transaction.return_value = {}
     tx_hash = '4c239561b64f2353819452073f2ec7f62a5ad66f533868f89f7af862584cdee9'
     resp = await self.client.request(
         'GET', reverse('transaction', transaction_hash=tx_hash))
     assert resp.status == 200
     mock_get_transaction.assert_called_once_with(tx_hash)
 async def test_post_generate_trust_wallet_from_request_json_data_missing(
         self):
     url = reverse('generate-trust-wallet',
                   wallet_address=self.wallet_address)
     resp = await self.client.request("POST", url)
     assert resp.status == 400
     text = await resp.json()
     assert 'Bad request, JSON data missing.' in text['message']
    async def test_generate_joint_wallet_with_meta(self, mock_build,
                                                   mock_get_stellar_wallet):
        deal_address = 'deal_address'
        parties = [{
            'address': 'address1',
            'amount': 10
        }, {
            'address': 'address2',
            'amount': 20
        }]
        mock_get_stellar_wallet.return_value = Wallet("1", [], "1", {}, [], {},
                                                      {})
        creator = 'creator_address'
        meta = {"expiration_date": "2018-05-15"}
        transaction_source_address = 'GDSB3JZDYKLYKWZ6NXDPPGPCYJ32ISMTZ2LVF5PYQGY4B4FGNIU2M5BJ'
        mock_build.return_value = ('create_joint_wallet_xdr',
                                   'create_joint_wallet_tx_hash')
        result = await generate_joint_wallet(transaction_source_address,
                                             deal_address, parties, creator, 5,
                                             meta)

        expect = {
            "@id":
            reverse('generate-joint-wallet', wallet_address='deal_address'),
            "@transaction_url":
            reverse('transaction',
                    transaction_hash='create_joint_wallet_tx_hash'),
            "signers": [{
                "public_key": "address1",
                "weight": 1
            }, {
                "public_key": "address2",
                "weight": 1
            }, {
                "public_key": "creator_address",
                "weight": 1
            }, {
                "public_key": "deal_address",
                "weight": 1
            }],
            "xdr":
            "create_joint_wallet_xdr",
            "transaction_hash":
            "create_joint_wallet_tx_hash"
        }
        assert result == expect
 async def test_put_transaction_from_request_with_duplicate_transaction(self, mock_tx, mock_dup) -> None:
     mock_dup.return_value = True
     mock_tx.return_value = {'status': 200}
     url = reverse('transaction', transaction_hash='transaction-hash')
     resp = await self.client.request("PUT", url, data=b'test data')
     assert resp.status == 400
     text = await resp.json()
     assert 'message' in text
Ejemplo n.º 23
0
async def test_get_wallet_from_request(mock_get_wallet):
    mock_get_wallet.return_value = {}
    wallet_address = 'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD'
    req = make_mocked_request('GET',
                              reverse('wallet-address',
                                      wallet_address=wallet_address),
                              match_info={'wallet_address': wallet_address})
    await get_wallet_from_request(req)
    assert mock_get_wallet.call_count == 1
async def generate_escrow_wallet(
    escrow_address: str,
    transaction_source_address: str,
    creator_address: str,
    destination_address: str,
    provider_address: str,
    starting_balance: str,
    cost_per_transaction: str,
    expiration_date: str = None,
) -> Dict:
    '''Making transaction for creating escrow wallet

        number_of_transaction + 2 due to transfer to merchant and merge back to hotnow
        number of entries is 8 due to escrow account have 1 trust line, add 2 signers and 5 data entries

        Args:
        * escrow_address: an address of new escrow account.
        * transaction_source_address an address from wallet pool
        * creator_address: an address of transaction owner.
        * destination_address: an address of transaction owner.
        * provider_address: an address of ,
        * starting_balance: startung amount of custom asset(HOT) in new wallet.
        * expiration_date: date and time in ISO 8601 format. For futher detail see https://www.w3.org/TR/NOTE-datetime.
    '''
    starting_custom_asset: Decimal = Decimal(starting_balance)
    cost_per_tx_decimal: Decimal = Decimal(cost_per_transaction)

    number_of_transaction: Decimal = (starting_custom_asset /
                                      cost_per_tx_decimal) + 2
    starting_xlm: Decimal = calculate_initial_xlm(Decimal(8),
                                                  number_of_transaction)

    wallet = await get_stellar_wallet(transaction_source_address)
    xdr, tx_hash = await build_generate_escrow_wallet_transaction(
        escrow_address=escrow_address,
        transaction_source_address=transaction_source_address,
        provider_address=provider_address,
        creator_address=creator_address,
        destination_address=destination_address,
        cost_per_transaction=cost_per_tx_decimal,
        expiration_date=expiration_date,
        starting_native_asset=starting_xlm,
        starting_custom_asset=starting_custom_asset,
        sequence=wallet.sequence,
    )

    host = settings['HOST']
    return {
        '@id': reverse('escrow-generate-wallet',
                       escrow_address=escrow_address),
        '@transaction_url':
        f"{host}{reverse('transaction', transaction_hash=tx_hash)}",
        'signers': [escrow_address, creator_address, provider_address],
        'xdr': xdr,
        'transaction_hash': tx_hash,
    }
Ejemplo n.º 25
0
 async def test_get_transaction_hash_by_memo_from_reqeust(
         self, mock_get_transaction) -> None:
     mock_get_transaction.return_value = {}
     resp = await self.client.request(
         'GET',
         reverse('get-transaction-hash-memo',
                 wallet_address='address',
                 memo='hello'))
     assert resp.status == 204
     mock_get_transaction.assert_called_once_with('address', 'hello')
Ejemplo n.º 26
0
 async def setUpAsync(self):
     self.wallet_address = 'wallet_address'
     self.provider_address = 'provider_address'
     self.creator_address = 'creator_address'
     self.wallet_detail = {
         '@id':
         reverse('escrow-address', escrow_address=self.wallet_address),
         'asset': {
             settings['ASSET_CODE']: '100.0000'
         },
         'generate-wallet':
         reverse('escrow-generate-wallet',
                 escrow_address=self.wallet_address),
         'data': {
             'provider_address': self.provider_address,
             'creator_address': self.creator_address
         },
         'signers': [self.provider_address, self.creator_address],
     }
    async def test_get_presigned_tx_xdr_from_request(self,
                                                     mock_get_transaction,
                                                     mock_get_wallet):
        escrow_address = "GAH6333FKTNQGSFSDLCANJIE52N7IGMS7DUIWR6JIMQZE7XKWEQLJQAY"
        transaction_source_address = "GDSB3JZDYKLYKWZ6NXDPPGPCYJ32ISMTZ2LVF5PYQGY4B4FGNIU2M5BJ"
        mock_get_transaction.return_value = {}
        host = settings.get('HOST', None)
        mock_get_wallet.return_value = {
            '@id':
            reverse('escrow-address', escrow_address=''),
            'asset': {
                'HOT': '10.0000000',
                'XLM': '9.9999200'
            },
            'generate-wallet':
            reverse(
                'escrow-generate-wallet',
                escrow_address=
                'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD'),
            'data': {
                'destination_address':
                'GABEAFZ7POCHDY4YCQMRAGVVXEEO4XWYKBY4LMHHJRHTC4MZQBWS6NL6',
                'cost_per_transaction': '5'
            }
        }

        resp = await self.client.request(
            "POST",
            reverse('generate-presigned-transactions',
                    escrow_address=escrow_address),
            json={'transaction_source_address': transaction_source_address})
        assert resp.status == 200

        mock_get_wallet.assert_called_once_with(escrow_address)

        destination_address = "GABEAFZ7POCHDY4YCQMRAGVVXEEO4XWYKBY4LMHHJRHTC4MZQBWS6NL6"
        balance = Decimal("10.0000000")
        cost_per_tx = Decimal("5")

        mock_get_transaction.assert_called_once_with(
            escrow_address, transaction_source_address, destination_address,
            balance, cost_per_tx)
Ejemplo n.º 28
0
async def get_wallet_detail(wallet_address: str) -> Dict:
    """Get wallet balances from stellar network"""
    def _format_balance(balance: STELLAR_BALANCE) -> BALANCE_RESPONSE:
        """Format balance in pattern dict {asset_code: balance}"""
        if balance['asset_type'] == 'native':
            return {'XLM': balance['balance']}
        elif balance['asset_code'] == settings['ASSET_CODE'] and balance[
                'asset_issuer'] == settings['ISSUER']:
            return {
                'HOT': balance['balance'],
                settings['ASSET_CODE']: balance['balance']
            }
        return {}

    def _merge_balance(balances: STELLAR_BALANCES) -> Dict[str, str]:
        """Merge all balances to one Dict"""
        asset: Union[Dict, Dict[str, str]] = {}
        for balance in balances:
            asset.update(_format_balance(balance))
        return asset

    def _trusted_hot(
            balances: STELLAR_BALANCES) -> Union[Dict, Dict[str, str]]:
        """Return URL for making trust HOT"""
        if (len(
                list(
                    filter(
                        lambda b: b.get('asset_code', None)
                        == settings['ASSET_CODE'] and b.get(
                            'asset_issuer', None) == settings['ISSUER'],
                        balances,
                    ))) == 0):
            return {
                'trust':
                f"{settings['HOST']}{reverse('change-trust-add-token', wallet_address=wallet_address)}"
            }
        return {}

    def _format_data(data: Dict[str, str]) -> Dict:
        """ Decode base64 data """
        return {k: b64decode(v).decode('utf-8') for k, v in data.items()}

    wallet = await get_wallet(wallet_address)
    result: Dict[str, Any] = {
        '@id': reverse('wallet-address', wallet_address=wallet_address),
        'wallet_address': wallet.address,
        'asset': _merge_balance(wallet.balances),
        'sequence': wallet.sequence,
        'data': _format_data(wallet.data),
    }

    result.update(_trusted_hot(wallet.balances))

    return result
Ejemplo n.º 29
0
    async def test_post_generate_wallet_from_request_is_duplicate_wallet_address(self, mock):
        url = reverse('generate-wallet', wallet_address=self.wallet_address)
        json_request = {
            'target_address': self.target_address,
            'transaction_source_address': self.transaction_source_address,
            'amount_xlm': self.amount_xlm
        }

        result = await self.client.request("POST", url, json=json_request)
        assert result.status == 400
        text = await result.json()
        assert 'Target address is already used.' in text['message']
 async def test_get_wallet_history_from_request_with_minimum_params_success(
         self, history, format_history):
     format_history.return_value = history.return_value = {
         'status': 200,
         '@id': 'test-id',
         'next': 'test-next',
         'previous': 'test-previous'
     }
     get_wallet_history_url = reverse('wallet-history',
                                      wallet_address=self.wallet_address)
     resp = await self.client.request("GET", get_wallet_history_url)
     assert resp.status == 200