Skip to content

Commit

Permalink
Merge pull request #159 from DanielSchiavini/value-overload
Browse files Browse the repository at this point in the history
fix: Allow special args in overloaded ABI methods
  • Loading branch information
charles-cooper authored Feb 15, 2024
2 parents 969816f + 1ab0ef9 commit 8a36e29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions boa/contracts/abi/abi_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ def __init__(self, functions: list[ABIFunction]):
def name(self) -> str:
return self.functions[0].name

def __call__(self, *args, disambiguate_signature=None, **kwargs):
def __call__(
self,
*args,
value=0,
gas=None,
sender=None,
disambiguate_signature=None,
**kwargs,
):
"""
Call the function that matches the given arguments.
:raises Exception: if a single function is not found
Expand All @@ -166,7 +174,7 @@ def __call__(self, *args, disambiguate_signature=None, **kwargs):

match matches:
case [function]:
return function(*args, **kwargs)
return function(*args, value=value, gas=gas, sender=sender, **kwargs)
case []:
raise Exception(
f"Could not find matching {self.name} function for given arguments."
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/fork/test_abi_contract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hypothesis.strategies as st
import pytest
from hypothesis import given, example
from hypothesis import given

import boa
from boa import BoaError
Expand Down Expand Up @@ -108,6 +108,7 @@ def test_stableswap_factory_ng(stableswap_factory_ng):
def test_balances(addr, balance, crvusd):
assert crvusd.balanceOf(addr) == balance


# test write 0 to fresh fork state
def test_fork_write0(crvusd):
n = balances[account_a]
Expand Down
1 change: 1 addition & 0 deletions tests/unitary/test_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test(a: uint128 = 0, b: uint128 = 0) -> uint128:
assert c.test(a=1) == 1
assert c.test(1, 2) == 3
assert c.test(a=1, b=2) == 3
assert c.test(a=1, b=2, value=0, gas=None) == 3

with pytest.raises(Exception) as exc_info:
c.test(1, 2, 3)
Expand Down

0 comments on commit 8a36e29

Please sign in to comment.