Skip to content

Commit

Permalink
fix: _DankMethod.call (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Apr 15, 2024
1 parent 646c0bf commit 7fd2be2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions dank_mids/brownie_patch/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _make_hashable(obj: Any) -> Any:

class _DankMethod(Generic[_EVMType]):
"""A mixin class that gives brownie objects async support and reduces memory usage"""
__slots__ = "_address", "_abi", "_name", "_owner", "natspec", "encode_input", "decode_input"
__slots__ = "_address", "_abi", "_name", "_owner", "natspec", "_encode_input", "_decode_input"
def __await__(self):
"""Asynchronously call the contract method without arguments at the latest block and await the result."""
return self.coroutine().__await__()
Expand All @@ -61,11 +61,11 @@ async def coroutine( # type: ignore [empty-body]
if override:
raise ValueError("Cannot use state override with `coroutine`.")
async with ENVS.BROWNIE_ENCODER_SEMAPHORE[block_identifier]:
data = await self.encode_input(self, self._len_inputs, self._prep_request_data, *args)
data = await self._encode_input(self, self._len_inputs, self._prep_request_data, *args)
async with ENVS.BROWNIE_CALL_SEMAPHORE[block_identifier]:
output = await self._web3.eth.call({"to": self._address, "data": data}, block_identifier)
try:
decoded = await self.decode_output(self, output)
decoded = await self._decode_output(self, output)
except InsufficientDataBytes as e:
raise InsufficientDataBytes(str(e), self, self._address, output) from e
return decoded if decimals is None else decoded / 10 ** Decimal(decimals)
Expand All @@ -91,8 +91,8 @@ def __init__(
self.natspec = natspec or {}
# TODO: refactor this
from dank_mids.brownie_patch import call
self.encode_input = call.encode_input
self.decode_output = call.decode_output
self._encode_input = call.encode_input
self._decode_output = call.decode_output
@property
def abi(self) -> dict:
return self._abi.abi
Expand Down
4 changes: 4 additions & 0 deletions tests/test_brownie_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async def test_dank_contract_call():
dank_weth = get_dank_contract('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2')
assert isinstance(dank_weth, dank_mids.Contract)
assert isinstance(dank_weth.totalSupply, dank_mids.DankContractCall)
assert dank_weth.totalSupply(block_identifier=13_000_000) == 6620041514474872981393155
assert await dank_weth.totalSupply.coroutine(block_identifier=13_000_000) == 6620041514474872981393155
assert await dank_weth.totalSupply.coroutine(block_identifier=13_000_000, decimals=18) == Decimal("6620041.514474872981393155")
assert await dank_weth.totalSupply
Expand All @@ -70,6 +71,9 @@ async def test_dank_contract_tx():
assert isinstance(uni_v3_quoter, dank_mids.Contract)
assert isinstance(uni_v3_quoter.quoteExactInput, dank_mids.DankContractTx)
assert hasattr(uni_v3_quoter.quoteExactInput, 'coroutine')
assert (
uni_v3_quoter.quoteExactInput.call(b"\xc0*\xaa9\xb2#\xfe\x8d\n\x0e\\O'\xea\xd9\x08<ul\xc2\x00\x01\xf4\xa0\xb8i\x91\xc6!\x8b6\xc1\xd1\x9dJ.\x9e\xb0\xce6\x06\xebH", 1e18, block_identifier=13_000_000)
) == 3169438072
assert await (
uni_v3_quoter.quoteExactInput.coroutine(b"\xc0*\xaa9\xb2#\xfe\x8d\n\x0e\\O'\xea\xd9\x08<ul\xc2\x00\x01\xf4\xa0\xb8i\x91\xc6!\x8b6\xc1\xd1\x9dJ.\x9e\xb0\xce6\x06\xebH", 1e18, block_identifier=13_000_000)
) == 3169438072
Expand Down

0 comments on commit 7fd2be2

Please sign in to comment.