From 1f8a4fd304d1240d114be0b2e83e2471b9bdb56c Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 25 Jun 2023 17:32:22 -0300 Subject: [PATCH] use uint32 for Permissions' backing integer prevents negative values from wrapping around to values that are over the limit of postgresql bigint --- litecord/permissions.py | 2 +- tests/test_guild.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/litecord/permissions.py b/litecord/permissions.py index 3825fe3..205e5be 100644 --- a/litecord/permissions.py +++ b/litecord/permissions.py @@ -75,7 +75,7 @@ class Permissions(ctypes.Union): The permissions value as an integer. """ - _fields_ = [("bits", _RawPermsBits), ("binary", ctypes.c_uint64)] + _fields_ = [("bits", _RawPermsBits), ("binary", ctypes.c_uint32)] def __init__(self, val: Union[str, int]): # always coerce to int, even when the user gives us a str, because diff --git a/tests/test_guild.py b/tests/test_guild.py index dd4a4f3..0a17666 100644 --- a/tests/test_guild.py +++ b/tests/test_guild.py @@ -150,3 +150,17 @@ async def test_prune_guild(test_cli_user): pruned_member_guild = await guild.refetch() assert pruned_member_guild.member_count == 1 + + +@pytest.mark.asyncio +async def test_guild_roles(test_cli_user): + guild = await test_cli_user.create_guild() + + resp = await test_cli_user.post( + f"/api/v6/guilds/{guild.id}/roles", + json={"name": "myrole", "permissions": -2043163063}, + ) + + assert resp.status_code == 200 + rjson = await resp.json + assert rjson["name"] == "myrole"