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

Store trusta labs scores to Event table #354

Merged
merged 3 commits into from
Aug 15, 2023
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
1 change: 1 addition & 0 deletions api/registry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Event(models.Model):
class Action(models.TextChoices):
FIFO_DEDUPLICATION = "FDP"
LIFO_DEDUPLICATION = "LDP"
TRUSTALAB_SCORE = "TLS"

action = models.CharField(
max_length=3,
Expand Down
3 changes: 0 additions & 3 deletions api/scorer/settings/gitcoin_passport_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
"twitterAccountAgeGte#180": "1.21",
"twitterAccountAgeGte#365": "1.21",
"twitterAccountAgeGte#730": "1.21",
"twitterTweetDaysGte#30": "1.21",
"twitterTweetDaysGte#60": "1.21",
"twitterTweetDaysGte#120": "1.21",
"ZkSync": "0.400",
"ZkSyncEra": "0.400",
"CyberProfilePremium": "1.21",
Expand Down
12 changes: 0 additions & 12 deletions api/trusta_labs/admin.py

This file was deleted.

8 changes: 5 additions & 3 deletions api/trusta_labs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ninja.security import APIKeyHeader
from ninja_extra import NinjaExtraAPI, status
from ninja_extra.exceptions import APIException
from trusta_labs.models import TrustaLabsScore
from registry.models import Event

api = NinjaExtraAPI(urls_namespace="trusta_labs")

Expand Down Expand Up @@ -55,6 +55,8 @@ def create_trusta_labs_score_db(request, payload: TrustaLabsScorePayload):
if payload.score == None:
raise TrustaLabsScoreHasNoScore()

TrustaLabsScore.objects.update_or_create(
address=payload.address, sybil_risk_score=payload.score
Event.objects.create(
action=Event.Action.TRUSTALAB_SCORE,
address=payload.address.lower(),
data={"score": payload.score},
)
36 changes: 0 additions & 36 deletions api/trusta_labs/migrations/0001_initial.py

This file was deleted.

12 changes: 0 additions & 12 deletions api/trusta_labs/models.py

This file was deleted.

45 changes: 38 additions & 7 deletions api/trusta_labs/test/test_trusta_labs_score.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import json
from datetime import datetime, timezone
from typing import cast

from django.conf import settings
from django.test import Client, TestCase
from trusta_labs.models import TrustaLabsScore
from registry.models import Event

mock_trusta_labs_score_body = {
"address": "0x8u3eu3ydh3rydh3irydhu",
Expand All @@ -14,8 +12,8 @@

class TrustaLabsScoreTestCase(TestCase):
def test_create_trusta_labs_score(self):
self.headers = {"HTTP_AUTHORIZATION": settings.CGRANTS_API_TOKEN}
"""Test that creation of a trusta lab score works and saved correctly"""
self.headers = {"HTTP_AUTHORIZATION": settings.CGRANTS_API_TOKEN}
client = Client()
trusta_labs_response = client.post(
"/trusta_labs/trusta-labs-score",
Expand All @@ -26,11 +24,44 @@ def test_create_trusta_labs_score(self):
self.assertEqual(trusta_labs_response.status_code, 200)

# Check that the trusta lab score was created
all_trusta_labs_scores = list(TrustaLabsScore.objects.all())
all_trusta_labs_scores = list(
Event.objects.filter(action=Event.Action.TRUSTALAB_SCORE)
)
self.assertEqual(len(all_trusta_labs_scores), 1)
score = all_trusta_labs_scores[0]
self.assertEqual(score.address, mock_trusta_labs_score_body["address"])
self.assertEqual(score.sybil_risk_score, mock_trusta_labs_score_body["score"])
self.assertEqual(score.data["score"], mock_trusta_labs_score_body["score"])

def test_error_creating_trusta_lab_score(self):
pass
self.headers = {"HTTP_AUTHORIZATION": settings.CGRANTS_API_TOKEN}
client = Client()
trusta_labs_response = client.post(
"/trusta_labs/trusta-labs-score",
"{}",
content_type="application/json",
**self.headers
)
self.assertEqual(trusta_labs_response.status_code, 422)

# Check that the trusta lab score was not created
all_trusta_labs_scores = list(
Event.objects.filter(action=Event.Action.TRUSTALAB_SCORE)
)
self.assertEqual(len(all_trusta_labs_scores), 0)

def test_bad_auth(self):
self.headers = {"HTTP_AUTHORIZATION": "bad_auth"}
client = Client()
trusta_labs_response = client.post(
"/trusta_labs/trusta-labs-score",
"{}",
content_type="application/json",
**self.headers
)
self.assertEqual(trusta_labs_response.status_code, 401)

# Check that the trusta lab score was not created
all_trusta_labs_scores = list(
Event.objects.filter(action=Event.Action.TRUSTALAB_SCORE)
)
self.assertEqual(len(all_trusta_labs_scores), 0)