Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4522 #4552

Merged
merged 13 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/dashboard/tests/test_dashboard_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
from django.conf import settings
from django.test.client import RequestFactory

import ipfshttpclient
import pytest
from dashboard.utils import (
clean_bounty_url, create_user_action, get_bounty, get_ordinal_repr, get_web3, getBountyContract,
humanize_event_name,
IPFSCantConnectException, clean_bounty_url, create_user_action, get_bounty, get_ipfs, get_ordinal_repr, get_web3,
getBountyContract, humanize_event_name, ipfs_cat_ipfsapi,
)
from test_plus.test import TestCase
from web3.main import Web3
Expand Down Expand Up @@ -114,3 +116,20 @@ def test_create_user_action_with_partial_cookie(mockUserAction):
create_user_action(None, 'Login', request)
mockUserAction.create.assert_called_once_with(action='Login', metadata={}, user=None,
utm={'utm_campaign': 'test campaign'})

@staticmethod
def test_get_ipfs():
"""Test that IPFS connectivity to gateway defined in settings succeeds."""
ipfs = get_ipfs()
assert type(ipfs) is ipfshttpclient.client.Client

@staticmethod
def test_get_ipfs_with_bad_host():
"""Test that IPFS connectivity to gateway fails when bad host is passed."""
with pytest.raises(IPFSCantConnectException):
assert get_ipfs('nohost.com')

@staticmethod
def test_ipfs_cat_ipfsapi():
"""Test that ipfs_cat_ipfsapi method returns IPFS object."""
assert "security-notes" in str(ipfs_cat_ipfsapi('/ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme'))
16 changes: 9 additions & 7 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

from django.conf import settings

import ipfsapi
import ipfshttpclient
import requests
from app.utils import sync_profile
from dashboard.helpers import UnsupportedSchemaException, normalize_url, process_bounty_changes, process_bounty_details
from dashboard.models import Activity, BlockedUser, Bounty, Profile, UserAction
from eth_utils import to_checksum_address
from gas.utils import conf_time_spread, eth_usd_conv_rate, gas_advisories, recommend_min_gas_price_to_confirm_in_time
from hexbytes import HexBytes
from ipfsapi.exceptions import CommunicationError
from ipfshttpclient.exceptions import CommunicationError
from web3 import HTTPProvider, Web3, WebsocketProvider
from web3.exceptions import BadFunctionCallOutput
from web3.middleware import geth_poa_middleware
Expand Down Expand Up @@ -187,7 +187,8 @@ def get_ipfs(host=None, port=settings.IPFS_API_PORT):

Args:
host (str): The IPFS host to connect to.
Defaults to environment variable: IPFS_HOST.
Defaults to environment variable: IPFS_HOST. The host name should be of the form 'ipfs.infura.io' and not
acolytec3 marked this conversation as resolved.
Show resolved Hide resolved
include 'https://'.
port (int): The IPFS port to connect to.
Defaults to environment variable: env IPFS_API_PORT.

Expand All @@ -196,14 +197,15 @@ def get_ipfs(host=None, port=settings.IPFS_API_PORT):
communication error with IPFS.

Returns:
ipfsapi.client.Client: The IPFS connection client.
ipfshttpclient.client.Client: The IPFS connection client.

"""
if host is None:
host = f'https://{settings.IPFS_HOST}'

clientConnectString = f'/dns/{settings.IPFS_HOST}/tcp/{settings.IPFS_API_PORT}/{settings.IPFS_API_SCHEME}'
else:
clientConnectString = f'/dns/{host}/tcp/{settings.IPFS_API_PORT}/https'
try:
return ipfsapi.connect(host, port)
return ipfshttpclient.connect(clientConnectString)
except CommunicationError as e:
logger.exception(e)
raise IPFSCantConnectException('Failed while attempt to connect to IPFS')
Expand Down
2 changes: 1 addition & 1 deletion app/healthcheck/healthchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def check_status(self):
"""Define the functionality of the health check."""
from dashboard.utils import get_ipfs
try:
ipfs_connection = get_ipfs(host='https://ipfs.infura.io', port=5001)
ipfs_connection = get_ipfs(host='ipfs.infura.io', port=5001)
except IPFSCantConnectException:
ipfs_connection = None

Expand Down
6 changes: 3 additions & 3 deletions app/kudos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from django.conf import settings

import ipfsapi
import ipfshttpclient
from dashboard.utils import get_web3
from eth_utils import to_checksum_address
from git.utils import get_emails_master
Expand Down Expand Up @@ -160,8 +160,8 @@ def __init__(self, network='localhost', sockets=False):

self._w3 = get_web3(self.network, sockets=sockets)

host = f'{settings.IPFS_API_SCHEME}://{settings.IPFS_HOST}'
self._ipfs = ipfsapi.connect(host=host, port=settings.IPFS_API_PORT)
ipfsConnectionString = f'/dns/{settings.IPFS_HOST}/tcp/{settings.IPFS_API_PORT}/{settings.IPFS_API_SCHEME}'
self._ipfs = ipfshttpclient.connect(ipfsConnectionString)
self._contract = self._get_contract()

self.address = self._get_contract_address()
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cytoolz==0.9.0
boto==2.49.0
google-api-python-client
django-environ==0.4.5
ipfsapi
ipfshttpclient
eth-utils==1.4.1
jsondiff==1.1.1
social-auth-app-django==2.1.0
Expand Down