Skip to content

Commit

Permalink
add service unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulperegud committed Aug 28, 2024
1 parent 108d356 commit a33a0fc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
15 changes: 15 additions & 0 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
MOCK_IS_CONTRACT = Mock()


def mock_holonym_check(*args, **kwargs):
if args[0] == "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266":
return (True, ["phone"])
else:
return (False, [])


def mock_gitcoin_passport_issue_address_for_scoring(*args, **kwargs):
if args[0] == "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266":
return {
Expand Down Expand Up @@ -1187,6 +1194,14 @@ def patch_user_budget(monkeypatch):
MOCK_GET_USER_BUDGET.return_value = USER_MOCKED_BUDGET


@pytest.fixture(scope="function")
def patch_holonym_check(monkeypatch):
monkeypatch.setattr(
"app.modules.user.antisybil.service.holonym.check",
mock_holonym_check,
)


@pytest.fixture(scope="function")
def patch_gitcoin_passport_issue_address_for_scoring(monkeypatch):
monkeypatch.setattr(
Expand Down
38 changes: 36 additions & 2 deletions backend/tests/modules/user/antisybil/test_antisybil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.infrastructure import database
from app.modules.common.delegation import get_hashed_addresses
from app.modules.user.antisybil.service.passport import GitcoinPassportAntisybil
from app.modules.user.antisybil.service.holonym import HolonymAntisybil
from tests.helpers.context import get_context


Expand All @@ -13,7 +14,40 @@ def before(app):
pass


def test_antisybil_service(
def test_holonym_antisybil_service(
mock_users_db,
patch_holonym_check,
):
context = get_context(4)
service = HolonymAntisybil()

# check unknown user
unknown_address = "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
try:
service.get_sbt_status(context, unknown_address)
except UserNotFound:
pass # expected

alice, _, _ = mock_users_db

# SBT not yet cached
assert service.get_sbt_status(context, alice.address) is None

# SBT fetching for known owner returns expected data
entry = service.fetch_sbt_status(context, alice.address)
assert entry.has_sbt is True
assert entry.sbt_details == ["phone"]

# Lets cache the result
service.update_sbt_status(context, alice.address, entry.has_sbt, entry.sbt_details)

# Check cache state
entry = service.get_sbt_status(context, alice.address)
assert entry.has_sbt is True
assert entry.sbt_details == ["phone"]


def test_passport_antisybil_service(
patch_gitcoin_passport_issue_address_for_scoring,
patch_gitcoin_passport_fetch_score,
patch_gitcoin_passport_fetch_stamps,
Expand Down Expand Up @@ -88,7 +122,7 @@ def test_guest_stamp_score_bump_for_both_gp_and_octant_side_application(
) # is on guest list, HAS GUEST LIST STAMP, score is from fetch


def test_antisybil_cant_be_update_when_address_is_delegated(alice, bob):
def test_passport_antisybil_cant_be_update_when_address_is_delegated(alice, bob):
context = get_context(4)
score = 2.572
primary, secondary, both = get_hashed_addresses(alice.address, bob.address)
Expand Down

0 comments on commit a33a0fc

Please sign in to comment.