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

Jeremy/GITC-460/inaccurate payout amount bug #9645

Merged
merged 3 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion app/dashboard/sync/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dashboard.helpers import bounty_activity_event_adapter, get_bounty_data_for_activity
from dashboard.models import Activity, BountyEvent, BountyFulfillment
from decimal import Decimal

logger = logging.getLogger(__name__)

Expand All @@ -26,7 +27,7 @@ def record_payout_activity(fulfillment):
kwargs['profile'] = fulfillment.funder_profile
kwargs['metadata']['from'] = fulfillment.funder_profile.handle
kwargs['metadata']['to'] = fulfillment.profile.handle
kwargs['metadata']['payout_amount'] = str(fulfillment.payout_amount)
kwargs['metadata']['payout_amount'] = str(Decimal(fulfillment.payout_amount).normalize())
kwargs['metadata']['token_name'] = fulfillment.token_name

try:
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/templates/bounty/details2.html
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ <h5 class="font-body font-weight-semibold">ALL ACTIVITY</h5>
>
[[ activity.metadata.to ]]
</a>
<span class="tag token">[[ activity.metadata.token_value ]] [[ activity.metadata.token_name ]]</span>
<span class="tag token">[[ activity.metadata.payout_amount ]] [[ activity.metadata.token_name ]]</span>
</template>
<template v-if="activity.activity_type === 'increased_bounty'">
to <span class="tag token">[[ activity.metadata.token_value ]] [[ activity.metadata.token_name ]]</span>
Expand Down
15 changes: 15 additions & 0 deletions app/dashboard/tests/factories/bounty_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from datetime import datetime, timedelta

import factory
from dashboard.models import Bounty


class BountyFactory(factory.django.DjangoModelFactory):
class Meta:
model = Bounty

web3_created = datetime.now()
is_open = True
expires_date = datetime.now() + timedelta(days=365)
raw_data = {}
bounty_owner_github_username = 'gitcoin'
13 changes: 13 additions & 0 deletions app/dashboard/tests/factories/fulfillment_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import factory

from dashboard.models import BountyFulfillment
from .bounty_factory import BountyFactory
from .profile_factory import ProfileFactory


class FulfillmentFactory(factory.django.DjangoModelFactory):
class Meta:
model = BountyFulfillment

bounty = factory.SubFactory(BountyFactory)
profile = factory.SubFactory(ProfileFactory)
16 changes: 16 additions & 0 deletions app/dashboard/tests/views/test_bounty_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from dashboard.tests.factories.bounty_factory import BountyFactory
from rest_framework.test import APIClient


class TestBountyAPI:
def test_retrieves_activities(self, django_user_model):
github_url = {'github_url': 'https://github.com/gitcoinco/web/issues/1'}
BountyFactory(**github_url)
user = django_user_model.objects.create(username="gitcoin", password="password123")
client = APIClient()

client.force_login(user)
response = client.get('/actions/api/v0.1/bounty/', github_url, format='json')

assert response.status_code == 200
34 changes: 34 additions & 0 deletions app/dashboard/tests/views/test_bounty_payout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from dashboard.tests.factories.profile_factory import ProfileFactory
from dashboard.tests.factories.bounty_factory import BountyFactory
from dashboard.tests.factories.fulfillment_factory import FulfillmentFactory
from rest_framework.test import APIClient


@pytest.mark.django_db
class TestBountyPayout:
def test_pays_out_bounty(self, django_user_model):
github_url = {'github_url': 'https://github.com/gitcoinco/web/issues/1'}
BountyFactory(**github_url)
user = django_user_model.objects.create(username="gitcoin", password="password123")
ProfileFactory(user=user)
fulfillment = FulfillmentFactory()

client = APIClient()

client.force_login(user)

payload = {
'payout_type': 'fiat',
'tenant': 'testtenant',
'amount': '1',
'token_name': 'ETH',
'funder_address': '0x0',
'payout_status': 'pending',
'funder_identifier': 'test_funder_identifier',
'payout_tx_id': '0x0',
}

response = client.post(f'/api/v1/bounty/payout/{fulfillment.id}', payload)

assert response.status_code == 200