Skip to content

Commit

Permalink
OCT-1714 API Tests: Implement tests for epoch4 with capped QF (alloca…
Browse files Browse the repository at this point in the history
…tions) (#395)

## Description

## Definition of Done

1. [ ] Acceptance criteria are met.
2. [ ] PR is manually tested before the merge by developer(s).
    - [ ] Happy path is manually checked.
3. [ ] PR is manually tested by QA when their assistance is required
(1).
- [ ] Octant Areas & Test Cases are checked for impact and updated if
required (2).
4. [ ] Unit tests are added unless there is a reason to omit them.
5. [ ] Automated tests are added when required.
6. [ ] The code is merged.
7. [ ] Tech documentation is added / updated, reviewed and approved
(including mandatory approval by a code owner, should such exist for
changed files).
    - [ ] BE: Swagger documentation is updated.
8. [ ] When required by QA:
    - [ ] Deployed to the relevant environment.
    - [ ] Passed system tests.

---

(1) Developer(s) in coordination with QA decide whether it's required.
For small tickets introducing small changes QA assistance is most
probably not required.

(2) [Octant Areas & Test
Cases](https://docs.google.com/spreadsheets/d/1cRe6dxuKJV3a4ZskAwWEPvrFkQm6rEfyUCYwLTYw_Cc).

---------

Co-authored-by: Michał Kluczek <michal@wildland.io>
  • Loading branch information
kgarbacinski and mike-code authored Sep 2, 2024
1 parent 143eabd commit bceb433
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
61 changes: 43 additions & 18 deletions backend/tests/api-e2e/test_api_allocations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from flask import current_app as app

from app.legacy.core.projects import get_projects_addresses
from tests.conftest import Client, UserAccount
from tests.helpers.constants import STARTING_EPOCH
from tests.helpers.constants import STARTING_EPOCH, LOW_UQ_SCORE


@pytest.mark.api
Expand Down Expand Up @@ -49,24 +49,21 @@ def test_allocations(
assert len(unique_proposals) == 3


@pytest.mark.api
def test_allocations_basics(
client: Client,
deployer: UserAccount,
ua_alice: UserAccount,
ua_bob: UserAccount,
setup_funds,
def _check_allocations_logic(
client: Client, ua_alice: UserAccount, target_pending_epoch: int
):
alice_proposals = get_projects_addresses(1)[:3]

# lock GLM from one account
ua_alice.lock(10000)
i = 0
for i in range(0, target_pending_epoch + 1):
if i > 0:
client.move_to_next_epoch(STARTING_EPOCH + i)

# forward time to the beginning of the epoch 2
client.move_to_next_epoch(STARTING_EPOCH + 1)
if STARTING_EPOCH + i == target_pending_epoch:
ua_alice.lock(10000)

# wait for indexer to catch up
epoch_no = client.wait_for_sync(STARTING_EPOCH + 1)
epoch_no = client.wait_for_sync(STARTING_EPOCH + i)
app.logger.debug(f"indexed epoch: {epoch_no}")

# make a snapshot
Expand All @@ -84,7 +81,7 @@ def test_allocations_basics(
allocation_response_code == 201
), "Allocation status code is different than 201"

epoch_allocations, status_code = client.get_epoch_allocations(STARTING_EPOCH)
epoch_allocations, status_code = client.get_epoch_allocations(target_pending_epoch)
assert len(epoch_allocations["allocations"]) == len(alice_proposals)

for allocation in epoch_allocations["allocations"]:
Expand All @@ -97,14 +94,14 @@ def test_allocations_basics(

# Check user donations
user_allocations, status_code = client.get_user_allocations(
STARTING_EPOCH, ua_alice.address
target_pending_epoch, ua_alice.address
)
app.logger.debug(f"User allocations: {user_allocations}")
assert user_allocations["allocations"], "User allocations for given epoch are empty"
assert status_code == 200, "Status code is different than 200"

# Check donors
donors, status_code = client.get_donors(STARTING_EPOCH)
donors, status_code = client.get_donors(target_pending_epoch)
app.logger.debug(f"Donors: {donors}")
for donor in donors["donors"]:
assert donor == ua_alice.address, "Donor address is wrong"
Expand All @@ -113,7 +110,7 @@ def test_allocations_basics(
proposal_address = alice_proposals[0]
# Check donors of particular proposal
proposal_donors, status_code = client.get_proposal_donors(
STARTING_EPOCH, proposal_address
target_pending_epoch, proposal_address
)
app.logger.debug(f"Proposal donors: {proposal_donors}")
for proposal_donor in proposal_donors:
Expand All @@ -133,3 +130,31 @@ def test_allocations_basics(
assert matched["value"], "Leverage value is empty"

assert status_code == 200, "Status code is different than 200"


@pytest.mark.api
def test_allocations_basics(
client: Client,
deployer: UserAccount,
ua_alice: UserAccount,
ua_bob: UserAccount,
setup_funds,
):
_check_allocations_logic(client, ua_alice, target_pending_epoch=1)


@pytest.mark.api
def test_qf_and_uq_allocations(client: Client, ua_alice: UserAccount):
"""
Test for QF and UQ allocations.
This test checks if we use the QF alongside with UQ functionality properly.
Introduced in E4.
"""
PENDING_EPOCH = STARTING_EPOCH + 3

_check_allocations_logic(client, ua_alice, target_pending_epoch=PENDING_EPOCH)

# Check if UQ is saved in the database after the allocation properly
res, code = client.get_user_uq(ua_alice.address, 4)
assert code == 200
assert res["uniquenessQuotient"] == str(LOW_UQ_SCORE)
1 change: 0 additions & 1 deletion backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ def wait_for_sync(self, target, timeout_s=20, check_interval=0.5):
timeout = datetime.timedelta(seconds=timeout_s)
start = datetime.datetime.now()
while True:
res = {}
try:
res, status_code = self.sync_status()
current_app.logger.debug(f"sync_status returns {res}")
Expand Down

0 comments on commit bceb433

Please sign in to comment.