def test_get_user_account_assets(dbsession, registry, mock_eth_service, eth_network_id, eth_asset_id):
    """get_user_assets() gives sane results."""

    with transaction.manager:
        user = create_user(dbsession, registry)
        setup_user_account(user)

    mock_create_addresses(mock_eth_service, dbsession)

    # Play around with user accounts
    with transaction.manager:

        # No accounts yet
        assert UserCryptoAddress.get_user_asset_accounts(user) == []

        # User gets a deposit, an account gets created
        user = dbsession.query(User).first()
        network = dbsession.query(AssetNetwork).get(eth_network_id)
        asset = dbsession.query(Asset).get(eth_asset_id)
        address = UserCryptoAddress.get_default(user, network)
        account = address.address.get_or_create_account(asset)
        account.account.do_withdraw_or_deposit(Decimal("+10"), "Top up")

        current_accounts = UserCryptoAddress.get_user_asset_accounts(user)
        assert len(current_accounts) == 1
        current_address, current_account = current_accounts[0]
        assert current_account == account
        assert current_address == address
Esempio n. 2
0
def test_get_user_account_assets(dbsession, registry, mock_eth_service,
                                 eth_network_id, eth_asset_id):
    """get_user_assets() gives sane results."""

    with transaction.manager:
        user = create_user(dbsession, registry)
        setup_user_account(user, do_mainnet=True)

    mock_create_addresses(mock_eth_service, dbsession)

    # Play around with user accounts
    with transaction.manager:

        # No accounts yet
        assert UserCryptoAddress.get_user_asset_accounts(user) == []

        # User gets a deposit, an account gets created
        user = dbsession.query(User).first()
        network = dbsession.query(AssetNetwork).get(eth_network_id)
        asset = dbsession.query(Asset).get(eth_asset_id)
        address = UserCryptoAddress.get_default(user, network)
        account = address.address.get_or_create_account(asset)
        account.account.do_withdraw_or_deposit(Decimal("+10"), "Top up")

        current_accounts = UserCryptoAddress.get_user_asset_accounts(user)
        assert len(current_accounts) == 1
        current_address, current_account = current_accounts[0]
        assert current_account == account
        assert current_address == address