[fix] bandit assert warnings (#3243)

Co-authored-by: dni  <office@dnilabs.com>
This commit is contained in:
Vlad Stan
2025-07-15 11:14:23 +02:00
committed by dni ⚡
co-authored by dni ⚡
parent 76ecf113c3
commit fa89313e6f
28 changed files with 196 additions and 220 deletions
+6 -5
View File
@@ -252,7 +252,8 @@ class BlinkWallet(Wallet):
response = await self._graphql_query(data)
response_data = response.get("data")
assert response_data is not None
if response_data is None:
raise ValueError("No data found in response.")
txs_data = (
response_data.get("me", {})
.get("defaultAccount", {})
@@ -260,7 +261,8 @@ class BlinkWallet(Wallet):
.get("transactionsByPaymentHash", [])
)
tx_data = next((t for t in txs_data if t.get("direction") == "SEND"), None)
assert tx_data, "No SEND data found."
if not tx_data:
raise ValueError("No SEND data found.")
fee = tx_data.get("settlementFee")
preimage = tx_data.get("settlementVia", {}).get("preImage")
status = tx_data.get("status")
@@ -284,9 +286,8 @@ class BlinkWallet(Wallet):
await ws.send(json.dumps(self.ws_auth))
confirmation = await ws.recv()
ack = json.loads(confirmation)
assert (
ack.get("type") == "connection_ack"
), "Websocket connection not acknowledged."
if ack.get("type") != "connection_ack":
raise ValueError("Websocket connection not acknowledged.")
logger.info("Websocket connection acknowledged.")
subscription_req = {
+2 -1
View File
@@ -142,7 +142,8 @@ class BoltzWallet(Wallet):
pair_info = await self.rpc.GetPairInfo(pair_request, metadata=self.metadata)
invoice = decode(bolt11)
assert invoice.amount_msat, "amountless invoice"
if not invoice.amount_msat:
raise ValueError("amountless invoice")
service_fee: float = invoice.amount_msat * pair_info.fees.percentage / 100
estimate = service_fee + pair_info.fees.miner_fees * 1000
if estimate > fee_limit_msat:
+6 -5
View File
@@ -314,11 +314,12 @@ class CoreLightningRestWallet(Wallet):
)
paid_invoice = r.json()
logger.trace(f"paid invoice: {paid_invoice}")
assert self.statuses[
paid_invoice["invoices"][0]["status"]
], "streamed invoice not paid"
assert "invoices" in paid_invoice, "no invoices in response"
assert len(paid_invoice["invoices"]), "no invoices in response"
if not self.statuses[paid_invoice["invoices"][0]["status"]]:
raise ValueError("streamed invoice not paid")
if "invoices" not in paid_invoice:
raise ValueError("no invoices in response")
if not len(paid_invoice["invoices"]):
raise ValueError("no invoices in response")
yield paid_invoice["invoices"][0]["payment_hash"]
except Exception as exc:
+2 -1
View File
@@ -22,7 +22,8 @@ def load_macaroon(
aes = AESCipher(key.encode())
return aes.decrypt(encrypted_macaroon)
assert macaroon, "macaroon must be set here"
if not macaroon:
raise ValueError("macaroon must be set here")
# if the macaroon is a file path, load it and return hex version
if macaroon.split(".")[-1] == "macaroon":
+2 -1
View File
@@ -309,7 +309,8 @@ class NWCConnection:
self.account_private_key = secp256k1.PrivateKey(bytes.fromhex(secret))
self.account_private_key_hex = secret
self.account_public_key = self.account_private_key.pubkey
assert self.account_public_key
if not self.account_public_key:
raise ValueError("Missing account public key")
self.account_public_key_hex = self.account_public_key.serialize().hex()[2:]
# Extract service key (used for encryption to identify the nwc service provider)