Skip to content

Commit

Permalink
feat: helpful exc when user passes block as string type (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Oct 31, 2023
1 parent 1633505 commit 78da409
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dank_mids/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ async def get_response(self) -> None:
try:
await self.spoof_response(await self.controller.make_request(self.method, self.params, request_id=self.uid))
except internal_err_types.__args__ as e:
raise DankMidsInternalError(e)
raise e if 'invalid argument' in str(e) else DankMidsInternalError(e) from e
except ClientResponseError as e:
if e.message == "Payload Too Large":
logger.info("Payload too large. response headers: %s", e.headers)
Expand Down Expand Up @@ -645,7 +645,7 @@ async def get_response(self) -> None:
await self.spoof_response(await self.post())
# I want to see these asap when working on the lib.
except internal_err_types.__args__ as e:
raise DankMidsInternalError(e) from e
raise e if 'invalid argument' in str(e) else DankMidsInternalError(e) from e
except EmptyBatch as e:
logger.warning("These EmptyBatch exceptions shouldn't actually happen and this except clause can probably be removed soon.")
except ExceedsMaxBatchSize as e:
Expand Down
1 change: 1 addition & 0 deletions dank_mids/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def exception(self) -> BadResponse:
return (
PayloadTooLarge(self) if self.payload_too_large
else ExceedsMaxBatchSize(self) if re.search(r'batch limit (\d+) exceeded', self.error.message)
else TypeError(self.error.message, "You're probably passing what should be an integer type as a string type. The usual culprit is a block number.") if self.error.message == 'invalid argument 1: hex string without 0x prefix'
else BadResponse(self)
)

Expand Down
7 changes: 6 additions & 1 deletion tests/test_dank_mids.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@


import pytest
from brownie import chain
from dank_mids import instances
from multicall import Call
from multicall.utils import await_awaitable, gather
from web3._utils.rpc_abi import RPC

from dank_mids import instances
from tests.fixtures import dank_w3

CHAI = '0x06AF07097C9Eeb7fD685c692751D5C66dB49c215'
Expand Down Expand Up @@ -64,3 +65,7 @@ def test_AttributeDict():
block = await_awaitable(dank_w3.eth.get_block("0xe25822"))
assert block['timestamp']
assert block.timestamp

def test_string_block():
with pytest.raises(TypeError):
await_awaitable(Call(CHAI, 'totalSupply()(uint)', block_id="14000000").coroutine())

0 comments on commit 78da409

Please sign in to comment.