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

[RELEASE] 0.12.0 #557

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions backend/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ MAINNET_PROPOSAL_CIDS=

SABLIER_MAINNET_SUBGRAPH_URL=
SABLIER_SEPOLIA_SUBGRAPH_URL=

CACHE_REDIS_HOST=
CACHE_REDIS_PORT=
CACHE_REDIS_PASSWORD=
CACHE_REDIS_DB=
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests

from app.extensions import cache
from app.constants import GC_PASSPORT_SCORER_API
from app.exceptions import ExternalApiException
from app.infrastructure.exception_handler import ExceptionHandler
Expand Down Expand Up @@ -29,6 +30,7 @@ def _get_issue_address_for_scoring_url() -> str:
return f"{GC_PASSPORT_SCORER_API}/registry/submit-passport"


@cache.memoize(timeout=1)
def issue_address_for_scoring(address: str) -> dict:
try:
response = requests.post(
Expand All @@ -48,6 +50,7 @@ def _get_fetch_score_url(scorer_id: str, address: str) -> str:
return f"{GC_PASSPORT_SCORER_API}/registry/score/{scorer_id}/{address}"


@cache.memoize(timeout=1)
def fetch_score(address: str) -> dict:
try:
response = requests.get(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http import HTTPStatus
import requests

import app as app_module
Expand All @@ -13,7 +14,8 @@ def get_message_details(message_hash: str, is_mainnet: bool) -> dict:
response.raise_for_status()
json_response = response.json()
except requests.exceptions.RequestException as e:
app_module.ExceptionHandler.print_stacktrace(e)
if response.status_code != HTTPStatus.NOT_FOUND:
app_module.ExceptionHandler.print_stacktrace(e)
raise ExternalApiException(e)

return json_response
Expand Down
28 changes: 15 additions & 13 deletions backend/app/infrastructure/graphql/epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

from app.extensions import gql_octant_factory

from app import exceptions
from app import exceptions, cache


@cache.memoize(timeout=15)
def get_epoch_by_number(epoch_number):
query = gql(
"""
Expand Down Expand Up @@ -39,21 +40,22 @@ def get_epoch_by_number(epoch_number):
raise exceptions.EpochNotIndexed(epoch_number)


@cache.memoize(timeout=15)
def get_epochs():
query = gql(
"""
query {
epoches(first: 1000) {
epoch
fromTs
toTs
}
_meta {
block {
number
}
}
}
query {
epoches(first: 1000) {
epoch
fromTs
toTs
}
_meta {
block {
number
}
}
}
"""
)

Expand Down
4 changes: 3 additions & 1 deletion backend/app/infrastructure/graphql/withdrawals.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from flask import current_app as app
from gql import gql

from app.extensions import gql_octant_factory
from app.extensions import gql_octant_factory, cache


@cache.memoize(timeout=60)
def get_user_withdrawals_history(user_address: str, from_timestamp: int, limit: int):
query = gql(
"""
Expand Down Expand Up @@ -52,6 +53,7 @@ def get_user_withdrawals_history(user_address: str, from_timestamp: int, limit:
return result


@cache.memoize(timeout=60)
def get_withdrawals_by_address_and_timestamp_range(
user_address: str, from_timestamp: int, to_timestamp: int
):
Expand Down
10 changes: 8 additions & 2 deletions backend/app/legacy/crypto/eth_sign/patron_mode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from app.legacy.crypto.eth_sign.signature import verify_signed_message
from app.modules.common.crypto.signature import (
encode_for_signing,
EncodingStandardFor,
verify_signed_message,
)


def build_patron_mode_msg(user_address: str, toggle: bool) -> str:
Expand All @@ -9,4 +13,6 @@ def build_patron_mode_msg(user_address: str, toggle: bool) -> str:
def verify(user_address: str, toggle: bool, signature: str) -> bool:
msg_text = build_patron_mode_msg(user_address, toggle)

return verify_signed_message(user_address, msg_text, signature)
encoded_msg = encode_for_signing(EncodingStandardFor.TEXT, msg_text)

return verify_signed_message(user_address, encoded_msg, signature)
36 changes: 0 additions & 36 deletions backend/app/legacy/crypto/eth_sign/signature.py

This file was deleted.

3 changes: 2 additions & 1 deletion backend/app/modules/user/antisybil/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def _has_guest_stamp_applied_by_gp(score: GPStamps) -> bool:


def _apply_gtc_staking_stamp_nullification(score: int, stamps: GPStamps) -> int:
"Take score and stamps as returned by Passport and remove score associated with GTC staking"
"""Take score and stamps as returned by Passport and remove score associated with GTC staking"""

delta = 0
all_stamps = json.loads(stamps.stamps)
providers = [_get_provider(stamp) for stamp in all_stamps]
Expand Down
24 changes: 12 additions & 12 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -656,18 +656,12 @@ def get_rewards_budget(self, address: str, epoch: int):

def get_user_rewards_in_upcoming_epoch(self, address: str):
rv = self._flask_client.get(f"/rewards/budget/{address}/upcoming")
current_app.logger.debug(
"get_user_rewards_in_upcoming_epoch :",
self._flask_client.get(f"/rewards/budget/{address}/upcoming").request,
)
current_app.logger.debug("get_user_rewards_in_upcoming_epoch :", rv.text)
return json.loads(rv.text)

def get_user_rewards_in_epoch(self, address: str, epoch: int):
rv = self._flask_client.get(f"/rewards/budget/{address}/epoch/{epoch}")
current_app.logger.debug(
"get_rewards_budget :",
self._flask_client.get(f"/rewards/budget/{address}/epoch/{epoch}").request,
)
current_app.logger.debug("get_rewards_budget :", rv.text)
return json.loads(rv.text)

def get_total_users_rewards_in_epoch(self, epoch):
Expand Down Expand Up @@ -1036,9 +1030,6 @@ def patch_vault(monkeypatch):

@pytest.fixture(scope="function")
def patch_is_contract(monkeypatch):
monkeypatch.setattr(
"app.legacy.crypto.eth_sign.signature.is_contract", MOCK_IS_CONTRACT
)
monkeypatch.setattr(
"app.modules.common.crypto.signature.is_contract", MOCK_IS_CONTRACT
)
Expand Down Expand Up @@ -1136,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(
Expand Down
76 changes: 38 additions & 38 deletions backend/tests/modules/user/antisybil/test_antisybil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions ci/argocd/contracts/uat.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
BLOCK_NUMBER=6982586
BLOCK_NUMBER=7156082
GLM_CONTRACT_ADDRESS=0x71432DD1ae7DB41706ee6a22148446087BdD0906
AUTH_CONTRACT_ADDRESS=0xDBf4afCC7c4394C3679b0A9E53d736294D63C886
DEPOSITS_CONTRACT_ADDRESS=0x2524b5FA6Ae221a540A52744661277796aF36791
EPOCHS_CONTRACT_ADDRESS=0xC3E155B1b382F6766bA22f949D996EA10E342Cd3
PROPOSALS_CONTRACT_ADDRESS=0xF4ffF4D6061A44097222B1C2176627F84F7696C9
WITHDRAWALS_TARGET_CONTRACT_ADDRESS=0xcE997E5e2114dD32B89dA78802f29748EABfC9f5
VAULT_CONTRACT_ADDRESS=0x83aCd40D6f3fA6f8927A7ABc34a56DD58C2B518A
AUTH_CONTRACT_ADDRESS=0xC09CddcF90F5aF074D9670682c980345D04a5b07
DEPOSITS_CONTRACT_ADDRESS=0x53BF7aB7d5130c2f085990f32b3975fFC724123d
EPOCHS_CONTRACT_ADDRESS=0x983d3c467d46b85858b65C4Fa72394Cc96F04762
PROPOSALS_CONTRACT_ADDRESS=0xA9361e7258Ee22B006dCB90Bf2A06D0edACdF31F
WITHDRAWALS_TARGET_CONTRACT_ADDRESS=0x6013d2240B7Ff82D7781786273ec6B73CfB90d79
VAULT_CONTRACT_ADDRESS=0x0f9D1aba589792B3a12F8e8823581c257C237B52
11 changes: 11 additions & 0 deletions localenv/localenv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ services:
- octant


backend-redis:
image: redis:7
ports:
- '6379:6379'
networks:
- octant


backend:
image: octant/backend:latest
platform: linux/amd64
Expand All @@ -50,6 +58,9 @@ services:

SABLIER_SEPOLIA_SUBGRAPH_URL: "${SABLIER_SEPOLIA_SUBGRAPH_URL}"

CACHE_REDIS_HOST: backend-redis
CACHE_REDIS_PORT: 6379

depends_on:
- backend-postgres
- anvil
Expand Down
Loading