Skip to content

Commit 449220d

Browse files
committed
remove public key as params from getBalance and added negative testcases.
1 parent 3b46244 commit 449220d

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/lighthouseweb3/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ def uploadBlob(self, source: io.BufferedReader, filename: str, tag: str = ''):
4545
except Exception as e:
4646
raise e
4747

48-
def getBalance(self, publicKey: str):
48+
def getBalance(self):
4949
"""
5050
Retrieve the balance information of a user from the Lighthouse.
5151
5252
:param publicKey: str, The public key of the user.
5353
:return: dict[str, any], A dictionary containing the data usage and data limit details.
5454
"""
5555
try:
56-
return getBalance.get_balance(self.token, publicKey)
56+
return getBalance.get_balance(self.token)
5757
except Exception as e:
5858
raise e
5959

src/lighthouseweb3/functions/get_balance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from .config import Config
22
import requests as req
33

4-
def get_balance(token:str, publicKey: str):
4+
def get_balance(token:str):
55
headers = {
66
"Authorization": f"Bearer {token}",
77
}
8-
url = f"{Config.lighthouse_api}/api/user/user_data_usage?publicKey={publicKey}"
8+
url = f"{Config.lighthouse_api}/api/user/user_data_usage"
99
try:
1010
response = req.get(url, headers=headers)
1111
except Exception as e:

tests/test_get_balance.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ def test_get_balance(self):
1111
"""test get_balance function"""
1212
parse_env()
1313
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
14-
res = l.getBalance("0x1FB9Be96d228De94F4C57962675433Ae55a6c4a5")
14+
res = l.getBalance()
1515
self.assertIsInstance(res, dict, "data is a dict")
1616
self.assertIsInstance(res.get("dataLimit"), int, "data limit is a integer")
17-
self.assertIsInstance(res.get("dataUsed"), int, "data used is a integer")
17+
self.assertIsInstance(res.get("dataUsed"), int, "data used is a integer")
18+
19+
def test_get_balance_invalid_token(self):
20+
"""test get_balance function with invalid token"""
21+
parse_env()
22+
l = Lighthouse('invalid_token')
23+
res = l.getBalance()
24+
self.assertIsInstance(res, dict, "res is a dict")
25+
self.assertIn("authentication failed", str(res).lower())
26+

0 commit comments

Comments
 (0)