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.14.0 #629

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions backend/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SAFE_API_SEPOLIA = "https://safe-transaction-sepolia.safe.global/api/v1"

DEFAULT_MAINNET_PROJECT_CIDS = "QmSQEFD35gKxdPEmngNt1CWe3kSwiiGqBn1Z3FZvWb8mvK,Qmds9N5y2vkMuPTD6M4EBxNXnf3bjTDmzWBGnCkQGsMMGe,QmSXcT18anMXKACTueom8GXw8zrxTBbHGB71atitf6gZ9V,QmXomSdCCwt4FtBp3pidqSz3PtaiV2EyQikU6zRGWeCAsf,QmdtFLK3sB7EwQTNaqtmBnZqnN2pYZcu6GmUSTrpvb9wcq"
DEFAULT_PROJECTS_CONTRACT_ADDRESS = "0xB259fe6EC190cffF893b247AE688eFBF4261D2fc"

EPOCH0_SYBILS = [
"0xde19a6ce83cc934e5d4c4573f0f026c02c984fb2",
Expand Down
4 changes: 2 additions & 2 deletions backend/app/infrastructure/contracts/erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def glm_fund(self, to_address, nonce):
return self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)

def transfer(self, sender, receiver: str, amount: int):
nonce = self.w3.eth.get_transaction_count(sender.address)
nonce = self.w3.eth.get_transaction_count(sender.address, "pending")
transaction = self.contract.functions.transfer(
receiver, amount
).build_transaction({"from": sender.address, "nonce": nonce})
Expand All @@ -26,7 +26,7 @@ def approve(self, owner, benefactor, wad: int):
print("owner address: ", owner.address)
print("owner key: ", owner.key)
print("benefactor of lock: ", benefactor)
nonce = self.w3.eth.get_transaction_count(owner.address)
nonce = self.w3.eth.get_transaction_count(owner.address, "pending")
transaction = self.contract.functions.approve(
benefactor, wad
).build_transaction({"from": owner.address, "nonce": nonce})
Expand Down
6 changes: 3 additions & 3 deletions backend/app/modules/projects/details/controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Dict
from typing import List

from app.context.manager import epoch_context
from app.modules.registry import get_services
Expand All @@ -7,7 +7,7 @@

def get_projects_details_for_multiple_params(
epochs: List[int], search_phrases: List[str]
) -> List[Dict[str, str]]:
) -> list[dict[str, str]]:
searched_projects = []
for epoch in epochs:
for search_phrase in search_phrases:
Expand All @@ -16,7 +16,7 @@ def get_projects_details_for_multiple_params(
return searched_projects


def get_projects_details(epoch: int, search_phrase: str) -> List[Dict[str, str]]:
def get_projects_details(epoch: int, search_phrase: str) -> list[dict[str, str]]:
context = epoch_context(epoch)

service = get_services(context.epoch_state).projects_details_service
Expand Down
7 changes: 5 additions & 2 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,11 @@ def snapshot_status(self, epoch):
return json.loads(rv.text), rv.status_code

def pending_snapshot(self):
rv = self._flask_client.post("/snapshots/pending").text
return json.loads(rv)
rv = self._flask_client.post("/snapshots/pending")
current_app.logger.debug(
f"Request to /snapshots/pending [{rv.status_code}] returned text {rv.text}"
)
return json.loads(rv.text)

def pending_snapshot_simulate(self):
rv = self._flask_client.get("/snapshots/pending/simulate")
Expand Down
3 changes: 3 additions & 0 deletions backend/tests/v2/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from tests.v2.factories.allocation_requests import AllocationRequestFactorySet
from tests.v2.factories.allocations import AllocationFactorySet
from tests.v2.factories.projects_details import ProjectsDetailsFactorySet
from tests.v2.factories.users import UserFactorySet
from dataclasses import dataclass

Expand All @@ -21,6 +22,7 @@ class FactoriesAggregator:
users: UserFactorySet
allocation_requests: AllocationRequestFactorySet
allocations: AllocationFactorySet
projects_details: ProjectsDetailsFactorySet

def __init__(self, fast_session: AsyncSession):
"""
Expand All @@ -29,3 +31,4 @@ def __init__(self, fast_session: AsyncSession):
self.users = UserFactorySet(fast_session)
self.allocation_requests = AllocationRequestFactorySet(fast_session)
self.allocations = AllocationFactorySet(fast_session)
self.projects_details = ProjectsDetailsFactorySet(fast_session)
40 changes: 40 additions & 0 deletions backend/tests/v2/factories/projects_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from async_factory_boy.factory.sqlalchemy import AsyncSQLAlchemyFactory
from factory import LazyAttribute

from app.infrastructure.database.models import ProjectsDetails
from tests.v2.factories.base import FactorySetBase
from tests.v2.factories.helpers import generate_random_eip55_address
from v2.core.types import Address


class ProjectsDetailsFactory(AsyncSQLAlchemyFactory):
class Meta:
model = ProjectsDetails
sqlalchemy_session_persistence = "commit"

address = LazyAttribute(lambda _: generate_random_eip55_address())
name = None
epoch = None


class ProjectsDetailsFactorySet(FactorySetBase):
_factories = {"projects_details": ProjectsDetailsFactory}

async def create(
self,
name: str,
epoch: int,
address: Address | None = None,
) -> ProjectsDetails:
factory_kwargs = {
"address": address,
"name": name,
"epoch": epoch,
}

if address is not None:
factory_kwargs["address"] = address

projects_details = await ProjectsDetailsFactory.create(**factory_kwargs)

return projects_details
26 changes: 25 additions & 1 deletion backend/tests/v2/fake_contracts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
from fastapi import FastAPI

from tests.v2.fake_contracts.epochs import FakeEpochsContract
from tests.v2.fake_contracts.helpers import FakeEpochsContractDetails
from tests.v2.fake_contracts.helpers import (
FakeEpochsContractDetails,
FakeProjectsContractDetails,
)
from tests.v2.fake_contracts.projects import FakeProjectsContract
from v2.epochs.dependencies import get_epochs_contracts
from v2.projects.dependencies import get_projects_contracts


@pytest.fixture(scope="function")
Expand All @@ -26,6 +31,25 @@ def _create_fake_epochs_contract(
return _create_fake_epochs_contract


@pytest.fixture(scope="function")
def fake_projects_contract_factory(fast_app: FastAPI) -> FakeProjectsContractCallable:
def _create_fake_projects_contract(
projects_details_for_contract: FakeProjectsContractDetails | None = None,
):
fake_projects_contract = FakeProjectsContract(projects_details_for_contract)

fast_app.dependency_overrides[
get_projects_contracts
] = lambda: fake_projects_contract

return fake_projects_contract

return _create_fake_projects_contract


FakeEpochsContractCallable = Callable[
[FakeEpochsContractDetails | None], FakeEpochsContract
]
FakeProjectsContractCallable = Callable[
[FakeProjectsContractDetails | None], FakeProjectsContract
]
14 changes: 14 additions & 0 deletions backend/tests/v2/fake_contracts/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from dataclasses import dataclass

from v2.core.types import Address


@dataclass
class FakeEpochsContractDetails:
Expand All @@ -13,3 +15,15 @@ class FakeEpochsContractDetails:
future_epoch_props: dict = None
is_started: bool = False
started: int = 0


@dataclass
class FakeProjectDetails:
address: Address
epoch_number: int


@dataclass
class FakeProjectsContractDetails:
projects_cid: str
projects_details: list[FakeProjectDetails]
23 changes: 23 additions & 0 deletions backend/tests/v2/fake_contracts/projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from tests.v2.fake_contracts.helpers import FakeProjectsContractDetails


class FakeProjectsContract:
def __init__(self, projects_details_for_contract: FakeProjectsContractDetails):
self.projects_details_for_contract = projects_details_for_contract

async def get_project_addresses(self, epoch_number: int) -> list[str]:
filtered_projects_details = list(
filter(
lambda project_details: project_details.epoch_number == epoch_number,
self.projects_details_for_contract.projects_details,
)
)
return list(
map(
lambda project_details: project_details.address,
filtered_projects_details,
)
)

async def get_project_cid(self) -> str:
return self.projects_details_for_contract.projects_cid
52 changes: 52 additions & 0 deletions backend/tests/v2/projects/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest

from tests.v2.fake_contracts.conftest import ( # noqa: F401
fake_projects_contract_factory,
)

from tests.v2.factories.helpers import generate_random_eip55_address


@pytest.fixture(scope="module")
def multiple_project_details_simple() -> list:
details = [
{
"name": "test_project1",
"epoch": 3,
"address": generate_random_eip55_address(),
},
{
"name": "test_project2",
"epoch": 2,
"address": generate_random_eip55_address(),
},
{
"name": "test_project3",
"epoch": 1,
"address": generate_random_eip55_address(),
},
]

return details


@pytest.fixture(scope="module")
def multiple_project_details_various() -> list:
details = [
{
"name": "test_project1",
"epoch": 3,
"address": generate_random_eip55_address(),
},
{
"name": "octant_project2",
"epoch": 2,
"address": generate_random_eip55_address(),
},
{
"name": "great_project3",
"epoch": 1,
"address": generate_random_eip55_address(),
},
]
return details
Loading