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

OCT-1862: Cover /check in delegation with API Tests #392

Merged
merged 4 commits into from
Aug 28, 2024
Merged
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
36 changes: 34 additions & 2 deletions backend/tests/api-e2e/test_api_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,37 @@ def test_delegation(client: Client, payload: ScoreDelegationPayload):


@pytest.mark.api
def test_check_in_delegation():
pass
def test_check_delegation(client: Client, payload: ScoreDelegationPayload):
client.move_to_next_epoch(STARTING_EPOCH + 1)
client.move_to_next_epoch(STARTING_EPOCH + 2)
client.move_to_next_epoch(STARTING_EPOCH + 3)

epoch_no = client.wait_for_sync(STARTING_EPOCH + 3)
app.logger.debug(f"indexed epoch: {epoch_no}")

database.user.add_user(USER1_ADDRESS)
database.user.add_user(USER2_ADDRESS)

# check if invalid request is handled correctly
addresses = [payload.primary_addr] * 12
_, status = client.check_delegation(*addresses)
assert status == 400

# check that obfuscated delegation does not exist
_, status = client.check_delegation(payload.primary_addr, payload.secondary_addr)
assert status == 400

# conduct a delegation
_, status = client.delegate(
primary_address=payload.primary_addr,
secondary_address=payload.secondary_addr,
primary_address_signature=payload.primary_addr_signature,
secondary_address_signature=payload.secondary_addr_signature,
)
assert status == 201

# check if given addresses are used for delegation
resp, status = client.check_delegation(payload.primary_addr, payload.secondary_addr)
assert status == 200
assert resp["primary"] == payload.primary_addr
assert resp["secondary"] == payload.secondary_addr
5 changes: 5 additions & 0 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,11 @@ def get_healthcheck(self) -> tuple[dict, int]:
rv = self._flask_client.get("/info/healthcheck")
return json.loads(rv.text), rv.status_code

def check_delegation(self, *addresses) -> tuple[dict, int]:
addresses = ",".join(addresses)
rv = self._flask_client.get(f"/delegation/check/{addresses}")
return json.loads(rv.text), rv.status_code

def delegate(
self,
primary_address: str,
Expand Down
Loading