From bceb433f1ec6e55abcd6714aae172a73a97e79c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Garbaci=C5=84ski?= <57113816+kgarbacinski@users.noreply.github.com> Date: Mon, 2 Sep 2024 16:41:07 +0200 Subject: [PATCH] OCT-1714 API Tests: Implement tests for epoch4 with capped QF (allocations) (#395) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- backend/tests/api-e2e/test_api_allocations.py | 61 +++++++++++++------ backend/tests/conftest.py | 1 - 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/backend/tests/api-e2e/test_api_allocations.py b/backend/tests/api-e2e/test_api_allocations.py index 730912bab8..ceba1d6ba0 100644 --- a/backend/tests/api-e2e/test_api_allocations.py +++ b/backend/tests/api-e2e/test_api_allocations.py @@ -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 @@ -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 @@ -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"]: @@ -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" @@ -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: @@ -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) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index a6533926ce..4ff4c6bdef 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -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}")