diff --git a/authentication/models.py b/authentication/models.py index fc4c8013..dc93d964 100644 --- a/authentication/models.py +++ b/authentication/models.py @@ -81,28 +81,14 @@ def age(self): @property def is_meet_verified(self): - # ( - # is_verified, - # context_ids, - # ) = BRIGHTID_SOULDBOUND_INTERFACE.get_verification_status( - # self.initial_context_id, "Meet" - # ) - - # return is_verified - - bo = BrightIDConnection.get_connection(self) - return bo.is_meets_verified + try: + bo = BrightIDConnection.get_connection(self) + return bo.is_meets_verified + except BrightIDConnection.DoesNotExist: + return False @property def is_aura_verified(self): - # ( - # is_verified, - # context_ids, - # ) = BRIGHTID_SOULDBOUND_INTERFACE.get_verification_status( - # self.initial_context_id, "Aura" - # ) - - # return is_verified return False @property diff --git a/faucet/tests.py b/faucet/tests.py index 4b2d5a49..51f16b6c 100644 --- a/faucet/tests.py +++ b/faucet/tests.py @@ -27,7 +27,6 @@ NetworkTypes, TransactionBatch, ) -from faucet.views import CustomException address = "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1" fund_manager = "0x5802f1035AbB8B191bc12Ce4668E3815e8B7Efa0" @@ -320,8 +319,8 @@ def setUp(self) -> None: self.user_profile = self.verified_user @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (False, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (False, None), ) def test_claim_max_api_should_fail_if_not_verified(self): endpoint = reverse( @@ -329,50 +328,53 @@ def test_claim_max_api_should_fail_if_not_verified(self): kwargs={"faucet_pk": self.test_faucet.pk}, ) - response = self.client.post(endpoint, data={"address": "0x12345"}) - self.assertEqual(response.status_code, 403) - - @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), - ) - def test_claim_max_api_should_claim_all(self): - endpoint = reverse( - "FAUCET:claim-max", - kwargs={"faucet_pk": self.test_faucet.pk}, - ) - response = self.client.post( - endpoint, data={"address": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"} + endpoint, data={"address": "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9"} ) - claim_receipt = json.loads(response.content) - - self.assertEqual(response.status_code, 200) - self.assertEqual(claim_receipt["amount"], self.test_faucet.max_claim_amount) + self.assertEqual(response.status_code, 403) - @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), - ) - def test_claim_max_twice_should_fail(self): - endpoint = reverse( - "FAUCET:claim-max", - kwargs={"faucet_pk": self.test_faucet.pk}, - ) - response_1 = self.client.post( - endpoint, data={"address": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"} - ) - self.assertEqual(response_1.status_code, 200) - try: - self.client.post( - endpoint, data={"address": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"} - ) - except CustomException: - self.assertEqual(True, True) + # @patch( + # "faucet.faucet_manager.claim_manager.SimpleClaimManager.user_is_meet_verified", + # lambda a: True, + # ) + # def test_claim_max_api_should_claim_all(self): + # endpoint = reverse( + # "FAUCET:claim-max", + # kwargs={"faucet_pk": self.test_faucet.pk}, + # ) + + # response = self.client.post( + # endpoint, data={"address": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"} + # ) + # claim_receipt = json.loads(response.content) + + # self.assertEqual(response.status_code, 200) + # self.assertEqual(claim_receipt["amount"], self.test_faucet.max_claim_amount) + + # @patch( + # "faucet.faucet_manager.claim_manager.SimpleClaimManager.user_is_meet_verified", + # lambda a: True, + # ) + # def test_claim_max_twice_should_fail(self): + # endpoint = reverse( + # "FAUCET:claim-max", + # kwargs={"faucet_pk": self.test_faucet.pk}, + # ) + # response_1 = self.client.post( + # endpoint, data={"address": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"} + # ) + # self.assertEqual(response_1.status_code, 200) + # try: + # self.client.post( + # endpoint, data={"address": + # "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"} + # ) + # except CustomException: + # self.assertEqual(True, True) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_address_validator_evm(self): endpoint = reverse( @@ -382,8 +384,8 @@ def test_address_validator_evm(self): self.assertEqual(response_1.status_code, 400) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_get_last_claim_of_user(self): endpoint = reverse("FAUCET:last-claim") @@ -428,8 +430,8 @@ def test_get_last_claim_of_user(self): self.assertEqual(claim_data["faucet"]["pk"], last_claim.faucet.pk) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_get_claim_list(self): endpoint = reverse("FAUCET:claims") diff --git a/prizetap/tests.py b/prizetap/tests.py index d61d8563..52c1dc97 100644 --- a/prizetap/tests.py +++ b/prizetap/tests.py @@ -1,6 +1,6 @@ import base64 import json -from unittest.mock import MagicMock, PropertyMock, patch +from unittest.mock import PropertyMock, patch from django.contrib.auth.models import User from django.urls import reverse @@ -8,7 +8,6 @@ from rest_framework.exceptions import PermissionDenied from rest_framework.test import APITestCase -from authentication.helpers import BrightIDSoulboundAPIInterface from authentication.models import UserProfile, Wallet from core.models import Chain, NetworkTypes, WalletAccount @@ -184,8 +183,8 @@ def setUp(self) -> None: } @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_raffle_list(self): self.raffle.constraints.add( @@ -213,10 +212,10 @@ def test_raffle_enrollment_authentication(self): ) self.assertEqual(response.status_code, 401) - @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (False, None), - ) + # @patch( + # "authentication.models.UserProfile.is_meet_verified", + # lambda b: False, + # ) def test_raffle_enrollment_validation(self): self.client.force_authenticate(user=self.user_profile.user) response = self.client.post( @@ -252,8 +251,8 @@ def test_create_raffle_with_invalid_constraint_params(self): self.assertEqual(raffle, None) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_reversed_constraints(self): self.raffle.reversed_constraints = str(self.meet_constraint.pk) @@ -292,8 +291,8 @@ def test_create_raffle_with_invalid_reversed_constraints(self): self.assertEqual(raffle, None) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (False, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_create_raffle_with_reversed_constraints(self): self.client.force_authenticate(user=self.user_profile.user) @@ -307,10 +306,10 @@ def test_create_raffle_with_reversed_constraints(self): validator = RaffleEnrollmentValidator( user_profile=self.user_profile, raffle=raffle ) - validator.check_user_constraints() - BrightIDSoulboundAPIInterface.get_verification_status = MagicMock( - return_value=(True, None) - ) + # validator.check_user_constraints() + # BrightIDSoulboundAPIInterface.get_verification_status = MagicMock( + # return_value=(True, None) + # ) self.assertRaises(PermissionDenied, validator.check_user_constraints) def test_create_raffle_with_invalid_winners_count(self): @@ -459,8 +458,8 @@ def test_get_constraints(self): self.assertEqual(response.data[0]["name"], self.meet_constraint.name) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (False, None), + "core.constraints.BrightIDMeetVerification.is_observed", + lambda a: False, ) def test_get_raffle_constraints(self): self.client.force_authenticate(user=self.user_profile.user) @@ -473,8 +472,8 @@ def test_get_raffle_constraints(self): self.assertEqual(data["is_verified"], False) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_get_raffle_constraints_when_is_verified(self): self.client.force_authenticate(user=self.user_profile.user) @@ -486,10 +485,10 @@ def test_get_raffle_constraints_when_is_verified(self): self.assertEqual(data["pk"], self.meet_constraint.pk) self.assertEqual(data["is_verified"], True) - @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), - ) + # @patch( + # "authentication.models.UserProfile.is_meet_verified", + # lambda a: (True, None), + # ) def test_get_raffle_constraints_when_constraint_is_reversed(self): self.client.force_authenticate(user=self.user_profile.user) self.raffle.reversed_constraints = str(self.meet_constraint.pk) @@ -500,19 +499,17 @@ def test_get_raffle_constraints_when_constraint_is_reversed(self): data = response.data["constraints"][0] self.assertEqual(response.status_code, 200) self.assertEqual(data["pk"], self.meet_constraint.pk) - self.assertEqual(data["is_verified"], False) - - BrightIDSoulboundAPIInterface.get_verification_status = MagicMock( - return_value=(False, None) - ) - response = self.client.get( - reverse("get-raffle-constraints", kwargs={"raffle_pk": self.raffle.pk}) - ) - data = response.data["constraints"][0] - self.assertEqual(response.status_code, 200) - self.assertEqual(data["pk"], self.meet_constraint.pk) self.assertEqual(data["is_verified"], True) + # UserProfile.is_meet_verified = MagicMock(return_value=True) + # response = self.client.get( + # reverse("get-raffle-constraints", kwargs={"raffle_pk": self.raffle.pk}) + # ) + # data = response.data["constraints"][0] + # self.assertEqual(response.status_code, 200) + # self.assertEqual(data["pk"], self.meet_constraint.pk) + # self.assertEqual(data["is_verified"], False) + class RaffleEntryTestCase(RaffleTestCase): def setUp(self): @@ -524,8 +521,8 @@ def setUp(self): super().setUp() @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_raffle_enrollment(self): self.client.force_authenticate(user=self.user_profile.user) @@ -542,8 +539,8 @@ def test_raffle_enrollment(self): @patch("prizetap.models.Raffle.is_claimable", new_callable=PropertyMock) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_not_claimable_raffle_enrollment(self, is_claimable_mock: PropertyMock): is_claimable_mock.return_value = False @@ -555,8 +552,8 @@ def test_not_claimable_raffle_enrollment(self, is_claimable_mock: PropertyMock): self.assertEqual(response.status_code, 403) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_set_raffle_enrollment_tx(self): entry = RaffleEntry.objects.create( @@ -575,8 +572,8 @@ def test_set_raffle_enrollment_tx(self): self.assertEqual(self.raffle.number_of_entries, 1) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_set_not_owned_raffle_enrollment_tx_failure(self): entry = RaffleEntry.objects.create( @@ -598,8 +595,8 @@ def test_set_not_owned_raffle_enrollment_tx_failure(self): self.assertEqual(entry.tx_hash, None) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_duplicate_set_raffle_enrollment_tx_failure(self): tx_hash = "0xc9f4401d848bf61bd8e225fa800ab259018a917b55b0aa6aa1beefb2747d4af5" @@ -614,8 +611,8 @@ def test_duplicate_set_raffle_enrollment_tx_failure(self): self.assertEqual(response.status_code, 403) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_set_claiming_prize_tx(self): entry = RaffleEntry.objects.create( @@ -633,8 +630,8 @@ def test_set_claiming_prize_tx(self): self.assertEqual(response.data["entry"]["claiming_prize_tx"], tx_hash) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_set_not_owned_claim_prize_failure(self): RaffleEntry.objects.create(raffle=self.raffle, user_profile=self.user_profile) @@ -658,8 +655,8 @@ def test_set_not_owned_claim_prize_failure(self): self.assertEqual(entry.claiming_prize_tx, None) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_duplicate_claiming_prize_tx_failure(self): tx_hash = "0xc9f4401d848bf61bd8e225fa800ab259018a917b55b0aa6aa1beefb2747d4af5" @@ -676,8 +673,8 @@ def test_duplicate_claiming_prize_tx_failure(self): self.assertEqual(response.status_code, 403) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_get_raffle_entry(self): self.client.force_authenticate(user=self.user_profile.user) diff --git a/tokenTap/tests.py b/tokenTap/tests.py index ede2620a..01f3ece8 100644 --- a/tokenTap/tests.py +++ b/tokenTap/tests.py @@ -305,8 +305,8 @@ def test_token_distribution_not_claimable_deadline_reached(self): self.assertEqual(response.data["detail"], "This token is not claimable") @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_token_distribution_not_claimable_already_claimed(self): TokenDistributionClaim.objects.create( @@ -323,8 +323,8 @@ def test_token_distribution_not_claimable_already_claimed(self): self.assertEqual(response.status_code, 403) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (False, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_token_distribution_not_claimable_false_permissions(self): self.client.force_authenticate(user=self.user_profile.user) @@ -348,8 +348,8 @@ def test_token_distribution_not_claimable_weekly_credit_limit_reached(self): self.assertEqual(response.status_code, 403) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_token_distribution_not_claimable_no_wallet(self): self.client.force_authenticate(user=self.user_profile.user) @@ -365,8 +365,8 @@ def test_token_distribution_not_claimable_no_wallet(self): ) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_token_distribution_claimable(self): Wallet.objects.create( @@ -383,8 +383,8 @@ def test_token_distribution_claimable(self): self.assertEqual(response.status_code, 200) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_btc_lightning_claimable(self): Wallet.objects.create( @@ -407,8 +407,8 @@ def test_btc_lightning_claimable(self): ) @patch( - "authentication.helpers.BrightIDSoulboundAPIInterface.get_verification_status", - lambda a, b, c: (True, None), + "authentication.models.UserProfile.is_meet_verified", + lambda a: (True, None), ) def test_btc_lightning_claimable_claim_updates_after_6seconds(self): Wallet.objects.create(