Skip to content

Commit

Permalink
feat: updating test for the APIs returning the GTC stakes - the block… (
Browse files Browse the repository at this point in the history
#608)

* feat: updating test for the APIs returning the GTC stakes - the blockNumber is now also included

* feat: adding test for the banner API changes
  • Loading branch information
nutrina authored May 31, 2024
1 parent d7d349b commit ac626f3
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 21 deletions.
46 changes: 44 additions & 2 deletions api/passport_admin/tests/test_passport_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,55 @@ def test_get_address(self):
== "0xc79abb54e4824cdb65c71f2eeb2d7f2db5da1fb8"
)

def test_get_banners(self, sample_token):
def test_get_banners_default(self, sample_token):
banner = PassportBanner.objects.create(content="test", link="test")
response = client.get(
"/passport-admin/banners",
HTTP_AUTHORIZATION=f"Bearer {sample_token}",
content_type="application/json",
)
assert response.json() == []
assert response.json() == [
{
"application": "passport",
"banner_id": banner.id,
"content": "test",
"link": "test",
}
]

def test_get_banners_filtered(self, sample_token):
banner_passport = PassportBanner.objects.create(content="test", link="test")
banner_staking = PassportBanner.objects.create(
content="test_staking", link="test_staking_link", application="staking"
)
# Test getting passport banners
response = client.get(
"/passport-admin/banners?application=passport",
HTTP_AUTHORIZATION=f"Bearer {sample_token}",
content_type="application/json",
)
assert response.json() == [
{
"application": "passport",
"banner_id": banner_passport.id,
"content": "test",
"link": "test",
}
]
# Test getting staking banners
response = client.get(
"/passport-admin/banners?application=staking",
HTTP_AUTHORIZATION=f"Bearer {sample_token}",
content_type="application/json",
)
assert response.json() == [
{
"application": "staking",
"banner_id": banner_staking.id,
"content": "test_staking",
"link": "test_staking_link",
}
]

def test_dismiss_banner(self, sample_token, sample_address):
banner = PassportBanner.objects.create(content="test", link="test")
Expand Down
112 changes: 93 additions & 19 deletions api/stake/test/test_get_stake.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from decimal import Decimal

import pytest
Expand All @@ -11,6 +11,16 @@
other_user_address = "0x976EA74026E726554dB657fA54763abd0C3a0aa9"
twelve_weeks = 7257600

now = datetime.now(tz=timezone.utc)
unlock_time_0 = now + timedelta(days=90)
lock_time_0 = now + timedelta(days=90)
unlock_time_1 = now + timedelta(days=91)
lock_time_1 = now + timedelta(days=90)
unlock_time_2 = now + timedelta(days=92)
lock_time_2 = now + timedelta(days=90)
unlock_time_3 = now + timedelta(days=92)
lock_time_3 = now + timedelta(days=90)


@pytest.fixture
def mock_stakes(sample_address):
Expand All @@ -20,35 +30,35 @@ def mock_stakes(sample_address):
stakee=sample_address,
current_amount=Decimal("100000000000000000000"),
last_updated_in_block=Decimal("10000000"),
unlock_time=datetime.now() + timedelta(days=90),
lock_time=datetime.now() - timedelta(days=90),
unlock_time=unlock_time_0,
lock_time=lock_time_0,
)
Stake.objects.create(
chain="11155420",
staker=sample_address,
stakee=other_user_address,
current_amount=Decimal("200000000000000000000"),
last_updated_in_block=Decimal("10000001"),
unlock_time=datetime.now() + timedelta(days=91),
lock_time=datetime.now() - timedelta(days=90),
unlock_time=unlock_time_1,
lock_time=lock_time_1,
)
Stake.objects.create(
chain="11155420",
staker=other_user_address,
stakee=sample_address,
current_amount=Decimal("350000000000000000000"),
last_updated_in_block=Decimal("10000002"),
unlock_time=datetime.now() + timedelta(days=92),
lock_time=datetime.now() - timedelta(days=90),
unlock_time=unlock_time_2,
lock_time=lock_time_2,
)
Stake.objects.create(
chain="1",
staker=other_user_address,
stakee=sample_address,
current_amount=Decimal("475000000000000000000"),
last_updated_in_block=Decimal("10000002"),
unlock_time=datetime.now() + timedelta(days=92),
lock_time=datetime.now() - timedelta(days=90),
unlock_time=unlock_time_3,
lock_time=lock_time_3,
)


Expand All @@ -59,16 +69,48 @@ def test_successful_get_staking_results(self, mock_stakes, sample_address):
f"/stake/gtc/{sample_address.lower()}",
HTTP_AUTHORIZATION=settings.CGRANTS_API_TOKEN,
)
response_data = response.json()['items']
response_data = response.json()["items"]
print(response_data)
assert response.status_code == 200

# an extra stake event was added that is below the filtered amount, hence the minus 1
assert len(response_data) == 4
assert response_data[0]["staker"] == sample_address.lower()
assert response_data[0]["chain"] == 11155420
assert response_data[3]["staker"] == other_user_address.lower()
assert response_data[3]["chain"] == 1
assert response_data[0] == {
"staker": sample_address.lower(),
"chain": 11155420,
"amount": "100000000000000000000.000000000000000000",
"last_updated_in_block": "10000000",
"lock_time": lock_time_0.isoformat(),
"unlock_time": unlock_time_0.isoformat(),
"stakee": sample_address.lower(),
}
assert response_data[1] == {
"staker": sample_address.lower(),
"chain": 11155420,
"amount": "200000000000000000000.000000000000000000",
"last_updated_in_block": "10000001",
"lock_time": lock_time_1.isoformat(),
"unlock_time": unlock_time_1.isoformat(),
"stakee": other_user_address.lower(),
}
assert response_data[2] == {
"staker": other_user_address.lower(),
"chain": 11155420,
"amount": "350000000000000000000.000000000000000000",
"last_updated_in_block": "10000002",
"lock_time": lock_time_2.isoformat(),
"unlock_time": unlock_time_2.isoformat(),
"stakee": sample_address.lower(),
}
assert response_data[3] == {
"staker": other_user_address.lower(),
"chain": 1,
"amount": "475000000000000000000.000000000000000000",
"last_updated_in_block": "10000002",
"lock_time": lock_time_3.isoformat(),
"unlock_time": unlock_time_3.isoformat(),
"stakee": sample_address.lower(),
}

def test_failed_auth(self, mock_stakes, sample_address):
client = Client()
Expand All @@ -85,15 +127,47 @@ def test_ceramic_cache_endpoint_success(
HTTP_AUTHORIZATION="Bearer " + sample_token,
)

response_data = response.json()['items']
response_data = response.json()["items"]
assert response.status_code == 200

# an extra stake event was added that is below the filtered amount, hence the minus 1
assert len(response_data) == 4
assert response_data[0]["staker"] == sample_address.lower()
assert response_data[0]["chain"] == 11155420
assert response_data[3]["staker"] == other_user_address.lower()
assert response_data[3]["chain"] == 1
assert response_data[0] == {
"staker": sample_address.lower(),
"chain": 11155420,
"amount": "100000000000000000000.000000000000000000",
"last_updated_in_block": "10000000",
"lock_time": lock_time_0.isoformat(),
"unlock_time": unlock_time_0.isoformat(),
"stakee": sample_address.lower(),
}
assert response_data[1] == {
"staker": sample_address.lower(),
"chain": 11155420,
"amount": "200000000000000000000.000000000000000000",
"last_updated_in_block": "10000001",
"lock_time": lock_time_1.isoformat(),
"unlock_time": unlock_time_1.isoformat(),
"stakee": other_user_address.lower(),
}
assert response_data[2] == {
"staker": other_user_address.lower(),
"chain": 11155420,
"amount": "350000000000000000000.000000000000000000",
"last_updated_in_block": "10000002",
"lock_time": lock_time_2.isoformat(),
"unlock_time": unlock_time_2.isoformat(),
"stakee": sample_address.lower(),
}
assert response_data[3] == {
"staker": other_user_address.lower(),
"chain": 1,
"amount": "475000000000000000000.000000000000000000",
"last_updated_in_block": "10000002",
"lock_time": lock_time_3.isoformat(),
"unlock_time": unlock_time_3.isoformat(),
"stakee": sample_address.lower(),
}

def test_ceramic_cache_endpoint_failed_auth(self, mock_stakes):
client = Client()
Expand Down

0 comments on commit ac626f3

Please sign in to comment.