Beispiel #1
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
    async def test_get_threshold_weight_high_threshold(self, mock_address):
        balances = [{'balance': '9.9999200', 'asset_type': 'native'}]
        mock_address.return_value = StellarWallet(balances)

        result = await get_threshold_weight(
            'GDHH7XOUKIWA2NTMGBRD3P245P7SV2DAANU2RIONBAH6DGDLR5WISZZI',
            'set_signer')
        assert result == 2
Beispiel #3
0
async def test_get_wallet_success_trusted_hot(mock_address):

    balances = [
        {
            'balance': '7.0000000',
            'limit': '922337203685.4775807',
            'asset_type': 'credit_alphanum4',
            'asset_code': settings['ASSET_CODE'],
            'asset_issuer': settings['ISSUER'],
        },
        {
            'balance': '10.0000000',
            'limit': '1000',
            'asset_type': 'credit_alphanum4',
            'asset_code': 'HTKN',
            'asset_issuer': settings['ISSUER'],
        },
        {
            'balance': '9.9999200',
            'asset_type': 'native'
        },
    ]
    mock_address.return_value = StellarWallet(balances)

    result = await get_wallet_detail(
        'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD')

    host = settings.get('HOST', None)
    url = reverse('wallet-address',
                  wallet_address=
                  'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD')
    expect_data = {
        'wallet_address':
        'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD',
        '@id': f'{host}{url}',
        'asset': {
            settings['ASSET_CODE']: '7.0000000',
            'XLM': '9.9999200'
        },
        'sequence': '1',
        'data': {
            'age': '30',
            'name': 'UnitTest'
        },
    }

    assert result == expect_data
Beispiel #4
0
    async def test_get_transaction_from_request_with_invalid_target(self, mock_generate_payment, mock_address):
        mock_generate_payment.return_value = {}
        balances = [{'balance': '9.9999200', 'asset_type': 'native'}]
        mock_address.return_value = StellarWallet(balances)
        source_address = 'GDHH7XOUKIWA2NTMGBRD3P245P7SV2DAANU2RIONBAH6DGDLR5WISZZI'
        destination_address = 'GDMZSRU6XQ3MKEO3YVQNACUEKBDT6G75I27CTBIBKXMVY74BDTS3CSA6'
        transaction_source_address = 'GDSB3JZDYKLYKWZ6NXDPPGPCYJ32ISMTZ2LVF5PYQGY4B4FGNIU2M5BJ'

        data = {
            'target_address': 'invalid',
            'transaction_source_address': transaction_source_address,
            'amount_xlm': 10,
            'amount_hot': 5,
            'sequence_number': 3,
        }
        url = reverse('generate-payment', wallet_address=source_address)
        resp = await self.client.request('POST', url, json=data)
        assert resp.status == 400
        mock_generate_payment.assert_not_called()
Beispiel #5
0
    async def test_get_transaction_from_request_already_submitted(self, mock_address, mock_transaction_by_memo):
        balances = [{'balance': '9.9999200', 'asset_type': 'native'}]
        mock_address.return_value = StellarWallet(balances)
        source_address = 'GDHH7XOUKIWA2NTMGBRD3P245P7SV2DAANU2RIONBAH6DGDLR5WISZZI'
        transaction_source_address = 'GDSB3JZDYKLYKWZ6NXDPPGPCYJ32ISMTZ2LVF5PYQGY4B4FGNIU2M5BJ'
        destination_address = 'GBFAIH5WKAJQ77NG6BZG7TGVGXHPX4SQLIJ7BENJMCVCZSUZPSISCLU5'
        memo = 'testmemo'

        data = {
            'target_address': destination_address,
            'transaction_source_address': transaction_source_address,
            'amount_xlm': 10,
            'amount_hot': 5,
            'memo': memo,
            'sequence_number': 3,
        }
        url = reverse('generate-payment', wallet_address=source_address)
        resp = await self.client.request('POST', url, json=data)
        assert resp.status == 400
        body = await resp.json()
        assert body['message'] == 'Transaction is already submitted'
        mock_transaction_by_memo.assert_called_once_with(source_address, memo)
async def test_get_escrow_wallet_success_trusted_hot(mock_address):

    balances = [
        {
            'balance': '7.0000000',
            'limit': '922337203685.4775807',
            'asset_type': 'credit_alphanum4',
            'asset_code': settings['ASSET_CODE'],
            'asset_issuer': settings['ISSUER'],
        },
        {
            'balance': '10.0000000',
            'limit': '1000',
            'asset_type': 'credit_alphanum4',
            'asset_code': 'PTKN',
            'asset_issuer': settings['ISSUER'],
        },
        {
            'balance': '9.9999200',
            'asset_type': 'native'
        },
    ]
    mock_address.return_value = StellarWallet(balances)
    instance = mock_address.return_value
    instance.signers = [
        {
            'public_key': 'provider_address',
            'weight': 1
        },
        {
            'public_key': 'creator_address',
            'weight': 1
        },
        {
            'public_key': 'destination_address',
            'weight': 0
        },
    ]

    actual_data = await get_escrow_wallet_detail(
        'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD')
    host = settings.get('HOST', None)
    expect_data = {
        '@id':
        reverse('escrow-address',
                escrow_address=
                'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD'),
        'escrow_address':
        'GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD',
        'asset': {
            settings['ASSET_CODE']: '7.0000000',
            'XLM': '9.9999200'
        },
        'sequence':
        '1',
        'generate-wallet':
        f"{host}{reverse('escrow-generate-wallet', escrow_address='GBVJJJH6VS5NNM5B4FZ3JQHWN6ANEAOSCEU4STPXPB24BHD5JO5VTGAD')}",
        'data': {
            'name': 'UnitTest',
            'age': '30'
        },
        'signers': [{
            'public_key': 'provider_address',
            'weight': 1
        }, {
            'public_key': 'creator_address',
            'weight': 1
        }],
    }
    assert actual_data == expect_data