Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jan 22, 2025
1 parent 994375c commit 58a9a94
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions cashu/wallet/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ async def with_db(cls, *args, **kwargs) -> "WalletAuth":
raise Exception("Wallet db location is required.")
wallet_db = Database(name, db)

# the wallet db could not have been created yet
# run migrations etc
kwargs.update(dict(skip_db_read=True))
await super().with_db(*args, **kwargs)

# the wallet might not have been created yet
# if it was though, we load the username, password,
# access token and refresh token from the database
try:
mint_db = await get_mint_by_url(wallet_db, url)
if mint_db:
Expand All @@ -94,10 +100,6 @@ async def with_db(cls, *args, **kwargs) -> "WalletAuth":
except Exception:
pass

# run migrations etc
kwargs.update(dict(skip_db_read=True))
await super().with_db(*args, **kwargs)

return cls(*args, **kwargs)

async def init_wallet(self, mint_info: MintInfo) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions cashu/wallet/auth/openid_connect/openid_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ async def authenticate_with_password(self) -> None:
"""Authenticate using the resource owner password credentials flow."""
if not self.username or not self.password:
raise ValueError(
"Username and password must be provided for password flow."
'Username and password must be provided. To set a password use: "cashu auth -p"'
)
data = {
"grant_type": "password",
Expand All @@ -334,8 +334,8 @@ async def authenticate_with_password(self) -> None:
token_data = response.json()
self.update_token_data(token_data)
logger.info("Authentication successful!")
logger.info("Token response:")
logger.info(self.token_response)
# logger.info("Token response:")
# logger.info(self.token_response)
except httpx.HTTPError as e:
logger.error(f"Failed to obtain token: {e}")
raise
Expand Down
9 changes: 5 additions & 4 deletions cashu/wallet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ async def wrapper(*args, **kwargs):
wallet: Wallet = ctx.obj["WALLET"]
db_location = wallet.db.db_location
wallet_db_name = wallet.db.name
MIN_BALANCE = wallet.mint_info.bat_max_mint

auth_wallet = await WalletAuth.with_db(
ctx.obj["HOST"],
db_location,
"auth",
url=ctx.obj["HOST"],
db=db_location,
name="auth",
unit=Unit.auth.name,
wallet_db=wallet_db_name,
)
Expand All @@ -111,6 +110,8 @@ async def wrapper(*args, **kwargs):
logger.debug("Mint does not require clear auth.")
return await func(*args, **kwargs)

MIN_BALANCE = wallet.mint_info.bat_max_mint

# Check balance and mint new auth proofs if necessary
if auth_wallet.available_balance < MIN_BALANCE:
logger.debug(
Expand Down

0 comments on commit 58a9a94

Please sign in to comment.