Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions blockapi/test/v2/api/debank/test_debank.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,28 @@ def test_debank_parse_chains(
assert parsed_items[0] == debank_chain_eth


def test_debank_parse_unknown_chain(debank_api, requests_mock):
requests_mock.get(
"https://pro-openapi.debank.com/v1/chain/list",
json=[
{
"id": "new-chain",
"community_id": 1234,
"name": "New Chain",
"native_token_id": "new-chain",
"logo_url": "https://example.com/new-chain.png",
"wrapped_token_id": "new-chain",
"is_support_pre_exec": False,
}
],
)

chain = debank_api.get_chains()[0]

assert chain.chain == "new-chain"
assert chain.name == "New Chain"


def test_get_balance_fetches_protocols(
debank_api,
yflink_protocol_response_raw,
Expand Down
11 changes: 3 additions & 8 deletions blockapi/v2/api/debank.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class DebankModelChain(BaseModel):


class DebankChain(BaseModel):
chain: Blockchain
chain: Union[Blockchain, str]
community_id: int
name: str
logo_url: str
Expand Down Expand Up @@ -204,13 +204,8 @@ def parse(self, response: List) -> list[DebankChain]:
return list(sorted(chains, key=lambda x: x.name))

@staticmethod
def parse_item(item: DebankModelChain) -> Optional[DebankChain]:
blockchain = get_blockchain_from_debank_chain(item.id)
if not blockchain:
logger.warning(
f'No blockchain found for debank chain {item.id} ({item.name}, {item.community_id}). Skipping.'
)
return None
def parse_item(item: DebankModelChain) -> DebankChain:
blockchain = get_blockchain_from_debank_chain(item.id) or item.id

return DebankChain(
chain=blockchain,
Expand Down
Loading