diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 517cc9c544..a5f89f772b 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -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( diff --git a/backend/tests/modules/user/antisybil/test_antisybil.py b/backend/tests/modules/user/antisybil/test_antisybil.py index 0d624a0ee9..63fa84998c 100644 --- a/backend/tests/modules/user/antisybil/test_antisybil.py +++ b/backend/tests/modules/user/antisybil/test_antisybil.py @@ -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):