Skip to content

Commit

Permalink
add error handle for decoding type name from qdata
Browse files Browse the repository at this point in the history
  • Loading branch information
akremstudy committed Feb 12, 2024
1 parent 2d99868 commit 5164869
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/telliot_feeds/utils/query_search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

from clamfig.base import Registry
from eth_abi import decode_single
from eth_abi.exceptions import NonEmptyPaddingBytes
from web3 import Web3 as w3

from telliot_feeds.feeds import CATALOG_FEEDS
from telliot_feeds.feeds import DataFeed
from telliot_feeds.feeds import DATAFEED_BUILDER_MAPPING
from telliot_feeds.queries.query import OracleQuery
from telliot_feeds.queries.query_catalog import query_catalog
from telliot_feeds.utils.log import get_logger

logger = get_logger(__name__)


def decode_typ_name(qdata: bytes) -> str:
Expand All @@ -27,6 +31,12 @@ def decode_typ_name(qdata: bytes) -> str:
except OverflowError:
# string query for some reason encoding isn't the same as the others
qtype_name = ast.literal_eval(qdata.decode("utf-8"))["type"]
except NonEmptyPaddingBytes:
logger.error(f"NonEmptyPaddingBytes error for query data: {qdata.hex()}")
return ""
except Exception as e:
logger.error(f"Error decoding query type name for query data: {qdata.hex()}; error: {e}")
return ""
return qtype_name


Expand Down
8 changes: 8 additions & 0 deletions tests/utils/test_decode_qtype_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest
from telliot_feeds.utils.query_search_utils import decode_typ_name


def test_decode_qtype_name():
# query data with non empty bytes error
querydata = "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000745564d43616c6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe840000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000002470a082310000000000000000000000004e518e2b4e1649974d29e0697818d6e030e328cf00000000000000000000000000000000000000000000000000000000"
assert decode_typ_name(bytes.fromhex(querydata[2:])) == ""

0 comments on commit 5164869

Please sign in to comment.