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

OCT-2095: Improve test #562

Merged
merged 1 commit into from
Nov 28, 2024
Merged
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
OCT-2095: Improve test
kgarbacinski committed Nov 22, 2024
commit 8a175ac96dcfad72647cda7afec967d2adb24621
11 changes: 10 additions & 1 deletion backend/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ def mock_gitcoin_passport_fetch_score(*args, **kwargs):


def mock_gitcoin_passport_fetch_stamps(*args, **kwargs):
"Returns structure resembling GP stamps, but only with relevant fields"
"""Returns structure resembling GP stamps, but only with relevant fields"""
if args[0] == "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266":
return {
"items": [
@@ -1127,6 +1127,15 @@ def patch_gitcoin_passport_fetch_stamps(monkeypatch):
)


@pytest.fixture(scope="function")
def patch_guest_list_for_scoring(monkeypatch, alice):
MOCK_GUEST_LIST = [alice.address.lower()]
monkeypatch.setattr(
"app.modules.user.antisybil.core.GUEST_LIST",
MOCK_GUEST_LIST,
)


@pytest.fixture(scope="function")
def patch_etherscan_transactions_api(monkeypatch):
monkeypatch.setattr(
76 changes: 38 additions & 38 deletions backend/tests/modules/user/antisybil/test_antisybil.py
Original file line number Diff line number Diff line change
@@ -64,44 +64,44 @@ def test_gtc_staking_stamp_nullification(
assert result.score == 0.5


# TODO - OCT-2095: Fix this test as not to rely on the GP API but mock the response
# def test_guest_stamp_score_bump_for_both_gp_and_octant_side_application(
# patch_gitcoin_passport_issue_address_for_scoring,
# patch_gitcoin_passport_fetch_score,
# patch_gitcoin_passport_fetch_stamps,
# mock_users_db,
# ):
# context = get_context(4)
#
# service = GitcoinPassportAntisybil(timeout_list=TIMEOUT_LIST)
# alice, _, _ = mock_users_db
#
# score, expires_at, stamps = service.fetch_antisybil_status(context, alice.address)
# service.update_antisybil_status(context, alice.address, score, expires_at, stamps)
# result = service.get_antisybil_status(context, alice.address)
# score = result.score
# assert score == 2.572 # guest list score bonus not applied
#
# guest_address = "0xe6ed9c681967a4ea7cef4486942b800139dfb000"
# database.user.add_user(guest_address)
# score, expires_at, stamps = service.fetch_antisybil_status(context, guest_address)
# print("YYY", score, expires_at, stamps)
# service.update_antisybil_status(context, guest_address, score, expires_at, stamps)
# result = service.get_antisybil_status(context, guest_address)
# score = result.score
# assert (not stamps) and (
# score == 21.0
# ) # is on guest list, no stamps, applying 21 score bonus manually
#
# stamp_address = "0xBc6d82D8d6632938394905Bb0217Ad9c673015d1"
# database.user.add_user(stamp_address)
# score, expires_at, stamps = service.fetch_antisybil_status(context, stamp_address)
# service.update_antisybil_status(context, stamp_address, score, expires_at, stamps)
# result = service.get_antisybil_status(context, stamp_address)
# score = result.score
# assert (stamps) and (
# score == 22.0
# ) # is on guest list, HAS GUEST LIST STAMP, score is from fetch
def test_guest_stamp_score_bump_for_both_gp_and_octant_side_application(
patch_gitcoin_passport_issue_address_for_scoring,
patch_gitcoin_passport_fetch_score,
patch_gitcoin_passport_fetch_stamps,
patch_guest_list_for_scoring,
mock_users_db,
):
context = get_context(4)

service = GitcoinPassportAntisybil(timeout_list=TIMEOUT_LIST)
alice, bob, _ = mock_users_db

score, expires_at, stamps = service.fetch_antisybil_status(context, bob.address)

service.update_antisybil_status(context, bob.address, score, expires_at, stamps)
result = service.get_antisybil_status(context, bob.address)
score = result.score
assert score == 0.0 # nullified score, address is not on the GUEST_LIST

guest_address = alice.address
score, expires_at, stamps = service.fetch_antisybil_status(context, guest_address)
service.update_antisybil_status(context, guest_address, score, expires_at, stamps)
result = service.get_antisybil_status(context, guest_address)
score = result.score

assert len(stamps) > 0 # has stamps from the mock
assert (
score == 2.572 + 21.0
) # is on guest list, applying additional 21 score bonus manually

stamp_address = "0xBc6d82D8d6632938394905Bb0217Ad9c673015d1"
database.user.add_user(stamp_address)
score, expires_at, stamps = service.fetch_antisybil_status(context, stamp_address)
service.update_antisybil_status(context, stamp_address, score, expires_at, stamps)
result = service.get_antisybil_status(context, stamp_address)
score = result.score
assert len(stamps) > 0
assert score == 22.0 # is on guest list, HAS GUEST LIST STAMP, score is from fetch


def test_antisybil_cant_be_update_when_address_is_delegated(alice, bob):