Skip to content

Commit

Permalink
basic api tests for history endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Stolecki <mateusz@golem.foundation>

Signed-off-by: Mateusz Stolecki <mateusz@golem.foundation>
  • Loading branch information
MateuszStoleckiGLM committed Jul 30, 2024
1 parent 69aad73 commit 52c3972
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions backend/tests/api-e2e/test_api_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest

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


@pytest.mark.api
def test_history_basics(
client: Client,
deployer: UserAccount,
ua_alice: UserAccount,
):
# Check user history before allocation
user_history, status_code = client.get_user_history(ua_alice.address)
assert len(user_history["history"]) == 0, "User history should be empty"
assert status_code == 200

# Get alice proposals
alice_proposals = get_projects_addresses(1)[:3]

# lock GLM for one account
ua_alice.lock(10000)

# forward time to the beginning of the epoch 2
client.move_to_next_epoch(STARTING_EPOCH + 1)

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

# make a snapshot
res = client.pending_snapshot()
assert res["epoch"] > STARTING_EPOCH - 1

allocation_response_code = ua_alice.allocate(1000, alice_proposals)
assert (
allocation_response_code == 201
), "Allocation status code is different than 201"

# Check user history after allocation
user_history, status_code = client.get_user_history(ua_alice.address)
assert (
user_history["history"][0]["type"] == "allocation"
), "Type of history record should be 'allocation'"
assert (
len(user_history["history"][0]["eventData"]["allocations"]) == 3
), "Number of allocations should be 3"
assert status_code == 200
4 changes: 4 additions & 0 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,10 @@ def accept_tos(self, user_address, signature):
)
return json.loads(rv.text), rv.status_code

def get_user_history(self, user_address) -> tuple[dict, int]:
rv = self._flask_client.get(f"/history/{user_address}")
return json.loads(rv.text), rv.status_code

def get_antisybil_score(self, user_address: str) -> (any, int):
rv = self._flask_client.get(f"/user/{user_address}/antisybil-status")
return json.loads(rv.text), rv.status_code
Expand Down

0 comments on commit 52c3972

Please sign in to comment.