Beispiel #1
0
def test_ui_create_address(logged_in_wallet_user_browser: DriverAPI, dbsession: Session, mock_eth_service):
    """Create new account through UI."""

    b = logged_in_wallet_user_browser
    b.find_by_css("#nav-wallet").click()
    b.find_by_css("#nav-wallet-accounts").click()
    b.find_by_css("#btn-create-account").click()
    b.fill("name", "Foboti")
    b.find_by_css("button[type='submit']").click()

    # Now in transaction list page
    assert b.is_element_present_by_css("#msg-account-created")

    # Pick the freshly created account for the transaction list
    rows = b.find_by_css(".row-operation")
    rows[0].find_by_css("a")[0].click()

    assert b.is_element_present_by_css("#heading-op")  # Page renders without errors
    assert b.is_element_present_by_css("#op-state-waiting")  # Op has not run yet

    # Create the account
    mock_create_addresses(mock_eth_service, dbsession, address="0x7C0d52faAB596C08F484E3478AeBc6205F3f5D8C")

    # Reload the page
    b.visit(b.url)

    # All details filled in
    assert b.is_element_present_by_css("#heading-op")  # Page renders without errors
    assert b.is_element_present_by_css("#op-state-success")  # Op complete

    # View address
    b.find_by_css("#nav-op-address").click()
    assert b.is_element_present_by_css("#heading-address")  # Page renders without errors
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
Beispiel #3
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
Beispiel #4
0
def topped_up_user(dbsession, registry, mock_eth_service, user_id, eth_network_id, eth_asset_id):
    """User has some ETH on their account."""
    with transaction.manager:
        user = dbsession.query(User).get(user_id)
        setup_user_account(user)

    mock_create_addresses(mock_eth_service, dbsession)

    with transaction.manager:
        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")
def test_create_eth_account(dbsession, eth_network_id, eth_service):
    """Create Ethereum account on Ethereum node."""

    with transaction.manager:
        network = dbsession.query(AssetNetwork).get(eth_network_id)

        address = CryptoAddress(network=network)

        dbsession.flush()

        # Generate address on the account
        op = CryptoAddressCreation(address)
        dbsession.add(op)
        dbsession.flush()

        op_id = op.id

    success_op_count, failed_op_count = mock_create_addresses(eth_service, dbsession)

    assert success_op_count == 1
    assert failed_op_count == 0

    with transaction.manager:
        op = dbsession.query(CryptoOperation).get(op_id)
        assert op.completed_at

        address = dbsession.query(CryptoAddress).first()
        assert address.address
Beispiel #6
0
def topped_up_user(dbsession, registry, mock_eth_service, user_id,
                   eth_network_id, eth_asset_id):
    """User has some ETH on their account."""
    with transaction.manager:
        user = dbsession.query(User).get(user_id)
        setup_user_account(user, do_mainnet=True)

    mock_create_addresses(mock_eth_service, dbsession)

    with transaction.manager:
        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")
Beispiel #7
0
def test_create_eth_account(dbsession, eth_network_id, eth_service):
    """Create Ethereum account on Ethereum node."""

    with transaction.manager:
        network = dbsession.query(AssetNetwork).get(eth_network_id)

        address = CryptoAddress(network=network)

        dbsession.flush()

        # Generate address on the account
        op = CryptoAddressCreation(address)
        dbsession.add(op)
        dbsession.flush()

        op_id = op.id

    success_op_count, failed_op_count = mock_create_addresses(
        eth_service, dbsession)

    assert success_op_count == 1
    assert failed_op_count == 0

    with transaction.manager:
        op = dbsession.query(CryptoOperation).get(op_id)
        assert op.completed_at

        address = dbsession.query(CryptoAddress).first()
        assert address.address
Beispiel #8
0
def wallet_user(dbsession, registry, mock_eth_service) -> dict:
    """Create a user having a wallet in place with some faux tokens."""

    details = {
        "email": "*****@*****.**",
        "password": "******"
    }

    with transaction.manager:
        user = create_user(dbsession, registry, email=details["email"], password=details["password"])
        setup_user_account(user)
        details["user_id"] = user.id

    success_op_count, failed_op_count = mock_create_addresses(mock_eth_service, dbsession)

    assert success_op_count == 1
    assert failed_op_count == 0

    return details
Beispiel #9
0
def wallet_user(dbsession, registry, mock_eth_service) -> dict:
    """Create a user having a wallet in place with some faux tokens."""

    details = {
        "email": "*****@*****.**",
        "password": "******"
    }

    with transaction.manager:
        user = create_user(dbsession, registry, email=details["email"], password=details["password"])
        setup_user_account(user, do_mainnet=True)
        details["user_id"] = user.id

    success_op_count, failed_op_count = mock_create_addresses(mock_eth_service, dbsession)

    assert success_op_count == 1
    assert failed_op_count == 0

    return details