Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clean up tests
Browse files Browse the repository at this point in the history
pik694 committed Mar 27, 2024
1 parent 6c617af commit 8e0ac04
Showing 14 changed files with 104 additions and 292 deletions.
23 changes: 1 addition & 22 deletions backend/app/infrastructure/database/allocations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import defaultdict
from datetime import datetime
from typing import List, Optional
from typing import List

from eth_utils import to_checksum_address
from sqlalchemy.orm import Query
@@ -197,27 +197,6 @@ def add_all(epoch: int, user_id: int, nonce: int, allocations):
db.session.add_all(new_allocations)


@deprecated("Alloc rework")
def add_allocation_request(
user_address: str,
epoch: int,
nonce: int,
signature: str,
is_manually_edited: Optional[bool] = None,
):
user: User = get_by_address(user_address)

allocation_request = AllocationRequest(
user=user,
epoch=epoch,
nonce=nonce,
signature=signature,
is_manually_edited=is_manually_edited,
)

db.session.add(allocation_request)


def get_allocation_request_by_user_nonce(
user_address: str, nonce: int
) -> AllocationRequest | None:
10 changes: 3 additions & 7 deletions backend/app/infrastructure/routes/allocations.py
Original file line number Diff line number Diff line change
@@ -3,8 +3,6 @@
from flask import current_app as app
from flask_restx import Namespace, fields

from app.legacy.controllers import allocations
from app.legacy.core.allocations import AllocationRequest
from app.extensions import api
from app.infrastructure import OctantResource
from app.modules.user.allocations import controller
@@ -165,14 +163,12 @@ class Allocation(OctantResource):
@ns.expect(user_allocation_request)
@ns.response(201, "User allocated successfully")
def post(self):
payload, signature = ns.payload["payload"], ns.payload["signature"]
app.logger.info(f"User allocation: {ns.payload}")
is_manually_edited = (
ns.payload["isManuallyEdited"] if "isManuallyEdited" in ns.payload else None
)
app.logger.info(f"User allocation payload: {payload}, signature: {signature}")
user_address = allocations.allocate(
AllocationRequest(payload, signature, override_existing_allocations=True),
is_manually_edited,
user_address = controller.allocate(
ns.payload, is_manually_edited=is_manually_edited
)
app.logger.info(f"User: {user_address} allocated successfully")

102 changes: 1 addition & 101 deletions backend/app/legacy/core/allocations.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
from typing_extensions import deprecated
from dataclasses import dataclass
from typing import List, Dict, Tuple, Optional
from typing import Dict

from dataclass_wizard import JSONWizard
from eth_utils import to_checksum_address

from app import exceptions
from app.extensions import proposals
from app.infrastructure import database
from app.legacy.core.epochs.epoch_snapshots import has_pending_epoch_snapshot
from app.legacy.core.user.budget import get_budget
from app.legacy.core.user.patron_mode import get_patron_mode_status


@dataclass(frozen=True)
@@ -24,94 +15,3 @@ class AllocationRequest(JSONWizard):
payload: Dict
signature: str
override_existing_allocations: bool


def add_allocations_to_db(
epoch: int,
user_address: str,
nonce: int,
allocations: List[Allocation],
delete_existing_user_epoch_allocations: bool,
):
user = database.user.get_by_address(user_address)
if not user:
user = database.user.add_user(user_address)

if delete_existing_user_epoch_allocations:
revoke_previous_allocation(user.address, epoch)

database.allocations.add_all(epoch, user.id, nonce, allocations)


def deserialize_payload(payload) -> Tuple[int, List[Allocation]]:
allocations = [
Allocation.from_dict(allocation_data)
for allocation_data in payload["allocations"]
]
return payload["nonce"], allocations


@deprecated("ALLOCATIONS REWORK")
def verify_allocations(
epoch: Optional[int], user_address: str, allocations: List[Allocation]
):
if epoch is None:
raise exceptions.NotInDecisionWindow

if not has_pending_epoch_snapshot(epoch):
raise exceptions.MissingSnapshot

patron_mode_enabled = get_patron_mode_status(
user_address=to_checksum_address(user_address)
)
if patron_mode_enabled:
raise exceptions.NotAllowedInPatronMode(user_address)

# Check if allocations list is empty
if len(allocations) == 0:
raise exceptions.EmptyAllocations()

# Check if the list of proposal addresses is a subset of
# proposal addresses in the Proposals contract
proposal_addresses = [a.proposal_address for a in allocations]
valid_proposals = proposals.get_proposal_addresses(epoch)
invalid_proposals = list(set(proposal_addresses) - set(valid_proposals))

if invalid_proposals:
raise exceptions.InvalidProjects(invalid_proposals)

# Check if any allocation address has been duplicated in the payload
[proposal_addresses.remove(p) for p in set(proposal_addresses)]

if proposal_addresses:
raise exceptions.DuplicatedProposals(proposal_addresses)

# Check if user address is not in one of the allocations
for allocation in allocations:
if allocation.proposal_address == user_address:
raise exceptions.ProposalAllocateToItself

# Check if user didn't exceed his budget
user_budget = get_budget(user_address, epoch)
proposals_sum = sum([a.amount for a in allocations])

if proposals_sum > user_budget:
raise exceptions.RewardsBudgetExceeded


@deprecated("ALLOCATIONS REWORK")
def revoke_previous_allocation(user_address: str, epoch: int):
user = database.user.get_by_address(user_address)
if user is None:
raise exceptions.UserNotFound

database.allocations.soft_delete_all_by_epoch_and_user_id(epoch, user.id)


def has_user_allocated_rewards(user_address: str, epoch: int) -> List[str]:
allocation_signature = (
database.allocations.get_allocation_request_by_user_and_epoch(
user_address, epoch
)
)
return allocation_signature is not None
7 changes: 4 additions & 3 deletions backend/app/modules/user/allocations/controller.py
Original file line number Diff line number Diff line change
@@ -103,9 +103,10 @@ def revoke_previous_allocation(user_address: str):


def _deserialize_payload(payload: Dict) -> UserAllocationRequestPayload:
allocation_items = _deserialize_items(payload.payload)
nonce = int(payload.payload["nonce"])
signature = payload.signature
allocation_payload = payload["payload"]
allocation_items = _deserialize_items(allocation_payload)
nonce = int(allocation_payload["nonce"])
signature = payload["signature"]

return UserAllocationRequestPayload(
payload=UserAllocationPayload(allocation_items, nonce), signature=signature
8 changes: 0 additions & 8 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -437,7 +437,6 @@ def patch_epochs(monkeypatch):

@pytest.fixture(scope="function")
def patch_proposals(monkeypatch, proposal_accounts):
monkeypatch.setattr("app.legacy.core.allocations.proposals", MOCK_PROPOSALS)
monkeypatch.setattr("app.legacy.core.proposals.proposals", MOCK_PROPOSALS)
monkeypatch.setattr("app.context.projects.proposals", MOCK_PROPOSALS)

@@ -492,12 +491,6 @@ def patch_eth_get_balance(monkeypatch):

@pytest.fixture(scope="function")
def patch_has_pending_epoch_snapshot(monkeypatch):
(
monkeypatch.setattr(
"app.legacy.core.allocations.has_pending_epoch_snapshot",
MOCK_HAS_PENDING_SNAPSHOT,
)
)
(
monkeypatch.setattr(
"app.context.epoch_state._has_pending_epoch_snapshot",
@@ -520,7 +513,6 @@ def patch_last_finalized_snapshot(monkeypatch):

@pytest.fixture(scope="function")
def patch_user_budget(monkeypatch):
monkeypatch.setattr("app.legacy.core.allocations.get_budget", MOCK_GET_USER_BUDGET)
monkeypatch.setattr(
"app.modules.user.budgets.service.saved.SavedUserBudgets.get_budget",
MOCK_GET_USER_BUDGET,
1 change: 1 addition & 0 deletions backend/tests/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .allocations import make_user_allocation # noqa
from .subgraph.events import ( # noqa
create_epoch_event,
generate_epoch_events,
31 changes: 31 additions & 0 deletions backend/tests/helpers/allocations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from app.modules.dto import (
AllocationItem,
UserAllocationPayload,
UserAllocationRequestPayload,
)
from app.infrastructure import database


def make_user_allocation(context, user, allocations=1, nonce=0, **kwargs):
projects = context.projects_details.projects
database.allocations.soft_delete_all_by_epoch_and_user_id(
context.epoch_details.epoch_num, user.id
)

allocation_items = [
AllocationItem(projects[i], (i + 1) * 100) for i in range(allocations)
]

if kwargs.get("allocation_items"):
allocation_items = kwargs.get("allocation_items")

request = UserAllocationRequestPayload(
payload=UserAllocationPayload(allocations=allocation_items, nonce=nonce),
signature="0xdeadbeef",
)

database.allocations.store_allocation_request(
user.address, context.epoch_details.epoch_num, request, **kwargs
)

return allocation_items
82 changes: 19 additions & 63 deletions backend/tests/legacy/test_allocations.py
Original file line number Diff line number Diff line change
@@ -2,12 +2,7 @@

from app import exceptions
from app.infrastructure import database
from app.legacy.controllers.allocations import (
allocate,
)
from app.legacy.core.allocations import (
AllocationRequest,
)
from app.modules.user.allocations.controller import allocate
from app.legacy.crypto.eip712 import sign, build_allocations_eip712_data
from tests.conftest import (
create_payload,
@@ -57,7 +52,7 @@ def test_user_allocates_for_the_first_time(tos_users, proposal_accounts):
signature = sign(tos_users[0], build_allocations_eip712_data(payload))

# Call allocate method
allocate(AllocationRequest(payload, signature, override_existing_allocations=True))
allocate({"payload": payload, "signature": signature})

# Check if allocations were created
check_allocations(tos_users[0].address, payload, 2)
@@ -75,12 +70,8 @@ def test_multiple_users_allocate_for_the_first_time(tos_users, proposal_accounts
signature2 = sign(tos_users[1], build_allocations_eip712_data(payload2))

# Call allocate method for both users
allocate(
AllocationRequest(payload1, signature1, override_existing_allocations=True)
)
allocate(
AllocationRequest(payload2, signature2, override_existing_allocations=True)
)
allocate({"payload": payload1, "signature": signature1})
allocate({"payload": payload2, "signature": signature2})

# Check if allocations were created for both users
check_allocations(tos_users[0].address, payload1, 2)
@@ -98,11 +89,7 @@ def test_allocate_updates_with_more_proposals(tos_users, proposal_accounts):
)

# Call allocate method
allocate(
AllocationRequest(
initial_payload, initial_signature, override_existing_allocations=True
)
)
allocate({"payload": initial_payload, "signature": initial_signature})

# Create a new payload with more proposals
updated_payload = create_payload(proposal_accounts[0:3], None, 1)
@@ -111,11 +98,7 @@ def test_allocate_updates_with_more_proposals(tos_users, proposal_accounts):
)

# Call allocate method with updated_payload
allocate(
AllocationRequest(
updated_payload, updated_signature, override_existing_allocations=True
)
)
allocate({"payload": updated_payload, "signature": updated_signature})

# Check if allocations were updated
check_allocations(tos_users[0].address, updated_payload, 3)
@@ -132,11 +115,7 @@ def test_allocate_updates_with_less_proposals(tos_users, proposal_accounts):
)

# Call allocate method
allocate(
AllocationRequest(
initial_payload, initial_signature, override_existing_allocations=True
)
)
allocate({"payload": initial_payload, "signature": initial_signature})

# Create a new payload with fewer proposals
updated_payload = create_payload(proposal_accounts[0:2], None, 1)
@@ -145,11 +124,7 @@ def test_allocate_updates_with_less_proposals(tos_users, proposal_accounts):
)

# Call allocate method with updated_payload
allocate(
AllocationRequest(
updated_payload, updated_signature, override_existing_allocations=True
)
)
allocate({"payload": updated_payload, "signature": updated_signature})

# Check if allocations were updated
check_allocations(tos_users[0].address, updated_payload, 2)
@@ -170,16 +145,8 @@ def test_multiple_users_change_their_allocations(tos_users, proposal_accounts):
)

# Call allocate method with initial payloads for both users
allocate(
AllocationRequest(
initial_payload1, initial_signature1, override_existing_allocations=True
)
)
allocate(
AllocationRequest(
initial_payload2, initial_signature2, override_existing_allocations=True
)
)
allocate({"payload": initial_payload1, "signature": initial_signature1})
allocate({"payload": initial_payload2, "signature": initial_signature2})

# Create updated payloads for both users
updated_payload1 = create_payload(proposal_accounts[0:4], None, 1)
@@ -192,16 +159,8 @@ def test_multiple_users_change_their_allocations(tos_users, proposal_accounts):
)

# Call allocate method with updated payloads for both users
allocate(
AllocationRequest(
updated_payload1, updated_signature1, override_existing_allocations=True
)
)
allocate(
AllocationRequest(
updated_payload2, updated_signature2, override_existing_allocations=True
)
)
allocate({"payload": updated_payload1, "signature": updated_signature1})
allocate({"payload": updated_payload2, "signature": updated_signature2})

# Check if allocations were updated for both users
check_allocations(tos_users[0].address, updated_payload1, 4)
@@ -222,16 +181,14 @@ def test_user_exceeded_rewards_budget_in_allocations(app, proposal_accounts, tos
signature = sign(tos_users[0], build_allocations_eip712_data(payload))

with pytest.raises(exceptions.RewardsBudgetExceeded):
allocate(
AllocationRequest(payload, signature, override_existing_allocations=True)
)
allocate({"payload": payload, "signature": signature})

# Lower it to 100 total (should pass)
payload = create_payload(
proposal_accounts[0:3], [10 * 10**18, 40 * 10**18, 50 * 10**18]
)
signature = sign(tos_users[0], build_allocations_eip712_data(payload))
allocate(AllocationRequest(payload, signature, override_existing_allocations=True))
allocate({"payload": payload, "signature": signature})


def test_nonces(tos_users, proposal_accounts):
@@ -240,14 +197,15 @@ def test_nonces(tos_users, proposal_accounts):
proposal_accounts[0:2], [10 * 10**18, 20 * 10**18], nonce0
)
signature = sign(tos_users[0], build_allocations_eip712_data(payload))
allocate(AllocationRequest(payload, signature, override_existing_allocations=True))
allocate({"payload": payload, "signature": signature})
nonce1 = get_allocation_nonce(tos_users[0].address)
assert nonce0 != nonce1
payload = create_payload(
proposal_accounts[0:2], [10 * 10**18, 30 * 10**18], nonce1
)
signature = sign(tos_users[0], build_allocations_eip712_data(payload))
allocate(AllocationRequest(payload, signature, override_existing_allocations=True))
allocate({"payload": payload, "signature": signature})

nonce2 = get_allocation_nonce(tos_users[0].address)
assert nonce1 != nonce2

@@ -256,9 +214,7 @@ def test_nonces(tos_users, proposal_accounts):
)
signature = sign(tos_users[0], build_allocations_eip712_data(payload))
with pytest.raises(exceptions.WrongAllocationsNonce):
allocate(
AllocationRequest(payload, signature, override_existing_allocations=True)
)
allocate({"payload": payload, "signature": signature})


def test_stores_allocation_request_signature(tos_users, proposal_accounts):
@@ -268,7 +224,7 @@ def test_stores_allocation_request_signature(tos_users, proposal_accounts):
)
signature = sign(tos_users[0], build_allocations_eip712_data(payload))

allocate(AllocationRequest(payload, signature, override_existing_allocations=True))
allocate({"payload": payload, "signature": signature})

alloc_signature = database.allocations.get_allocation_request_by_user_nonce(
tos_users[0].address, nonce0
12 changes: 4 additions & 8 deletions backend/tests/legacy/test_rewards.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest

from app import exceptions
from app.legacy.controllers.allocations import allocate
from app.modules.user.allocations.controller import allocate

from app.legacy.controllers.rewards import (
get_allocation_threshold,
)
from app.legacy.core.allocations import AllocationRequest
from tests.conftest import (
MOCK_EPOCHS,
deserialize_allocations,
@@ -64,12 +64,8 @@ def _allocate_random_individual_rewards(user_accounts, proposal_accounts) -> int
signature2 = sign(user_accounts[1], build_allocations_eip712_data(payload2))

# Call allocate method for both users
allocate(
AllocationRequest(payload1, signature1, override_existing_allocations=True)
)
allocate(
AllocationRequest(payload2, signature2, override_existing_allocations=True)
)
allocate({"payload": payload1, "signature": signature1})
allocate({"payload": payload2, "signature": signature2})

allocations1 = sum([int(a.amount) for a in deserialize_allocations(payload1)])
allocations2 = sum([int(a.amount) for a in deserialize_allocations(payload2)])
6 changes: 4 additions & 2 deletions backend/tests/modules/modules_factory/test_modules_factory.py
Original file line number Diff line number Diff line change
@@ -102,13 +102,15 @@ def test_pending_services_factory():
result = PendingServices.create()

events_based_patron_mode = EventsBasedUserPatronMode()
saved_user_budgets = SavedUserBudgets()
octant_rewards = PendingOctantRewards(patrons_mode=events_based_patron_mode)
user_allocations = PendingUserAllocations(
octant_rewards=octant_rewards,
user_budgets=saved_user_budgets,
patrons_mode=events_based_patron_mode,
octant_rewards=octant_rewards,
)
user_rewards = CalculatedUserRewards(
user_budgets=SavedUserBudgets(),
user_budgets=saved_user_budgets,
patrons_mode=events_based_patron_mode,
allocations=user_allocations,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from app.infrastructure import database
from app.modules.dto import AllocationDTO
from app.modules.dto import AllocationItem
from app.modules.octant_rewards.service.finalized import FinalizedOctantRewards

from tests.helpers import make_user_allocation
from tests.helpers.constants import (
USER1_BUDGET,
COMMUNITY_FUND,
@@ -59,13 +60,13 @@ def test_finalized_get_leverage(
proposal_accounts, mock_users_db, mock_finalized_epoch_snapshot_db
):
user, _, _ = mock_users_db
database.allocations.add_all(
1,
user.id,
0,
[AllocationDTO(proposal_accounts[0].address, USER1_BUDGET)],
)
context = get_context()
make_user_allocation(
context,
user,
allocation_items=[AllocationItem(proposal_accounts[0].address, USER1_BUDGET)],
)

service = FinalizedOctantRewards()

result = service.get_leverage(context)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest

from app.infrastructure import database
from app.modules.dto import AccountFundsDTO, AllocationDTO, ProjectAccountFundsDTO
from app.modules.dto import AccountFundsDTO, ProjectAccountFundsDTO
from app.modules.snapshots.finalized.service.simulated import (
SimulatedFinalizedSnapshots,
)
from tests.helpers.constants import MATCHED_REWARDS
from tests.helpers.context import get_context
from tests.helpers import make_user_allocation


@pytest.fixture(autouse=True)
@@ -19,9 +19,7 @@ def test_simulate_finalized_snapshots(
):
context = get_context(1)
projects = context.projects_details.projects
database.allocations.add_all(
1, mock_users_db[2].id, 0, [AllocationDTO(projects[0], 100)]
)
make_user_allocation(context, mock_users_db[2])

service = SimulatedFinalizedSnapshots(
patrons_mode=mock_patron_mode,
19 changes: 7 additions & 12 deletions backend/tests/modules/user/allocations/test_pending_allocations.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest

from app.engine.projects.rewards import ProjectRewardDTO
from app.infrastructure import database
from app.context.epoch_state import EpochState
from app.modules.dto import AllocationDTO
from app.modules.user.allocations.service.pending import PendingUserAllocations
from tests.helpers.constants import MATCHED_REWARDS
from tests.helpers.context import get_context
from tests.helpers import make_user_allocation


@pytest.fixture(autouse=True)
@@ -27,10 +27,7 @@ def test_simulate_allocation(service, mock_users_db):
user1, _, _ = mock_users_db
context = get_context()
projects = context.projects_details.projects
prev_allocation = [
AllocationDTO(projects[0], 100_000000000),
]
database.allocations.add_all(1, user1.id, 0, prev_allocation)
make_user_allocation(context, user1)

next_allocations = [
AllocationDTO(projects[1], 200_000000000),
@@ -56,17 +53,15 @@ def test_simulate_allocation(service, mock_users_db):
ProjectRewardDTO(sorted_projects[9], 0, 0),
]

# but the allocation didn't change
assert service.get_user_allocation_sum(context, user1.address) == 100


def test_revoke_previous_allocation(service, mock_users_db):
user1, _, _ = mock_users_db
context = get_context(epoch_state=EpochState.PENDING)
make_user_allocation(context, user1)

projects = context.projects_details.projects
prev_allocation = [
AllocationDTO(projects[0], 100_000000000),
]
database.allocations.add_all(1, user1.id, 0, prev_allocation)

assert service.get_user_allocation_sum(context, user1.address) == 100_000000000
assert service.get_user_allocation_sum(context, user1.address) == 100
service.revoke_previous_allocation(context, user1.address)
assert service.get_user_allocation_sum(context, user1.address) == 0
70 changes: 17 additions & 53 deletions backend/tests/modules/user/allocations/test_saved_allocations.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
from app.modules.history.dto import AllocationItem as HistoryAllocationItem

from tests.helpers.context import get_context
from tests.helpers import make_user_allocation


@pytest.fixture(autouse=True)
@@ -25,35 +26,6 @@ def service():
return SavedUserAllocations()


@pytest.fixture()
def make_user_allocation(proposal_accounts):
def _make_user_allocation(context, user, allocations=1, nonce=0, **kwargs):
database.allocations.soft_delete_all_by_epoch_and_user_id(
context.epoch_details.epoch_num, user.id
)

allocation_items = [
AllocationItem(proposal_accounts[i].address, (i + 1) * 100)
for i in range(allocations)
]

if kwargs.get("allocation_items"):
allocation_items = kwargs.get("allocation_items")

request = UserAllocationRequestPayload(
payload=UserAllocationPayload(allocations=allocation_items, nonce=nonce),
signature="0xdeadbeef",
)

database.allocations.store_allocation_request(
user.address, context.epoch_details.epoch_num, request, **kwargs
)

return allocation_items

return _make_user_allocation


def _alloc_item_to_donation(item, user):
return ProposalDonationDTO(user.address, item.amount, item.proposal_address)

@@ -152,7 +124,7 @@ def test_user_nonce_is_continuous_despite_epoch_changes(service, mock_users_db):
assert new_nonce == 3


def test_get_all_donors_addresses(service, mock_users_db, make_user_allocation):
def test_get_all_donors_addresses(service, mock_users_db):
user1, user2, user3 = mock_users_db
context_epoch_1 = get_context(1)
context_epoch_2 = get_context(2)
@@ -168,9 +140,7 @@ def test_get_all_donors_addresses(service, mock_users_db, make_user_allocation):
assert result_epoch_2 == [user3.address]


def test_return_only_not_removed_allocations(
service, mock_users_db, make_user_allocation
):
def test_return_only_not_removed_allocations(service, mock_users_db):
user1, user2, _ = mock_users_db

context = get_context(1)
@@ -183,7 +153,7 @@ def test_return_only_not_removed_allocations(
assert result == [user1.address]


def test_get_user_allocation_sum(service, context, mock_users_db, make_user_allocation):
def test_get_user_allocation_sum(service, context, mock_users_db):
user1, user2, _ = mock_users_db
make_user_allocation(context, user1, allocations=2)
make_user_allocation(context, user2, allocations=2)
@@ -193,9 +163,7 @@ def test_get_user_allocation_sum(service, context, mock_users_db, make_user_allo
assert result == 300


def test_has_user_allocated_rewards(
service, context, mock_users_db, make_user_allocation
):
def test_has_user_allocated_rewards(service, context, mock_users_db):
user1, _, _ = mock_users_db
make_user_allocation(context, user1)

@@ -204,9 +172,7 @@ def test_has_user_allocated_rewards(
assert result is True


def test_has_user_allocated_rewards_returns_false(
service, context, mock_users_db, make_user_allocation
):
def test_has_user_allocated_rewards_returns_false(service, context, mock_users_db):
user1, user2, _ = mock_users_db

make_user_allocation(context, user1) # other user makes an allocation
@@ -218,7 +184,7 @@ def test_has_user_allocated_rewards_returns_false(

@freeze_time("2024-03-18 00:00:00")
def test_user_allocations_by_timestamp(
service, context, mock_users_db, proposal_accounts, make_user_allocation
service, context, mock_users_db, proposal_accounts
):
user1, _, _ = mock_users_db
timestamp_before = from_timestamp_s(1710719999)
@@ -274,7 +240,7 @@ def test_get_all_allocations_returns_empty_list_when_no_allocations(


def test_get_all_allocations_returns_list_of_allocations(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, user2, _ = mock_users_db

@@ -292,7 +258,7 @@ def test_get_all_allocations_returns_list_of_allocations(


def test_get_all_allocations_does_not_include_revoked_allocations_in_returned_list(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, user2, _ = mock_users_db

@@ -312,7 +278,7 @@ def test_get_all_allocations_does_not_include_revoked_allocations_in_returned_li


def test_get_all_allocations_does_not_return_allocations_from_previous_and_future_epochs(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, _, _ = mock_users_db
context_epoch_1 = get_context(1)
@@ -326,7 +292,7 @@ def test_get_all_allocations_does_not_return_allocations_from_previous_and_futur


def test_get_all_with_allocation_amount_equal_0(
service, context, mock_users_db, proposal_accounts, make_user_allocation
service, context, mock_users_db, proposal_accounts
):
user1, _, _ = mock_users_db
allocation_items = [AllocationItem(proposal_accounts[0].address, 0)]
@@ -336,14 +302,12 @@ def test_get_all_with_allocation_amount_equal_0(
assert service.get_all_allocations(context) == expected_result


def test_get_last_user_allocation_when_no_allocation(
service, context, alice, make_user_allocation
):
def test_get_last_user_allocation_when_no_allocation(service, context, alice):
assert service.get_last_user_allocation(context, alice.address) == ([], None)


def test_get_last_user_allocation_returns_the_only_allocation(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, _, _ = mock_users_db
expected_result = make_user_allocation(context, user1)
@@ -355,7 +319,7 @@ def test_get_last_user_allocation_returns_the_only_allocation(


def test_get_last_user_allocation_returns_the_only_the_last_allocation(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, _, _ = mock_users_db
_ = make_user_allocation(context, user1)
@@ -368,7 +332,7 @@ def test_get_last_user_allocation_returns_the_only_the_last_allocation(


def test_get_last_user_allocation_returns_stored_metadata(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, _, _ = mock_users_db

@@ -395,7 +359,7 @@ def test_get_allocations_by_project_returns_empty_list_when_no_allocations(


def test_get_allocations_by_project_returns_list_of_donations_per_project(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, user2, _ = mock_users_db
project1, project2 = (
@@ -427,7 +391,7 @@ def test_get_allocations_by_project_returns_list_of_donations_per_project(


def test_get_allocations_by_project_with_allocation_amount_equal_0(
service, context, mock_users_db, make_user_allocation
service, context, mock_users_db
):
user1, _, _ = mock_users_db
project1 = context.projects_details.projects[0]

0 comments on commit 8e0ac04

Please sign in to comment.