Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support bytes array argument in solidity and vyper contracts #2255

17 changes: 16 additions & 1 deletion src/ape/managers/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ def convert(self, value: Any) -> int:
return to_int(HexBytes(value))


class HexListConverter(ConverterAPI):
"""
Convert list of hex values to single concatenated hex value.
bitwise-constructs marked this conversation as resolved.
Show resolved Hide resolved
"""

def is_convertible(self, value: Any) -> bool:
return isinstance(value, list) and all(is_hex(v) or isinstance(v, bytes) for v in value)
antazoey marked this conversation as resolved.
Show resolved Hide resolved

def convert(self, value: Any) -> bytes:
return HexBytes(b"".join([HexBytes(v) for v in value]))
bitwise-constructs marked this conversation as resolved.
Show resolved Hide resolved


class StringIntConverter(ConverterAPI):
def is_convertible(self, value: Any) -> bool:
return isinstance(value, str) and not is_0x_prefixed(value) and value.isnumeric()
Expand Down Expand Up @@ -263,7 +275,10 @@ def _converters(self) -> dict[type, list[ConverterAPI]]:
HexAddressConverter(),
IntAddressConverter(),
],
bytes: [HexConverter()],
bytes: [
HexConverter(),
HexListConverter(),
],
int: [
TimestampConverter(),
HexIntConverter(),
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/functional/data/sources/SolidityContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ contract SolidityContract {

}

function functionWithCalldata(bytes calldata data) public {

}

function setStruct(MyStruct memory _my_struct) public pure {

}
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/data/sources/VyperContract.vy
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ def functionWithUniqueAmountOfArguments(
):
pass

@external
def functionWithCalldata(data: Bytes[1_024]=b""):
pass

@pure
@external
def setStruct(_my_struct: MyStruct):
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/test_contract_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,9 @@ def test_sending_funds_to_non_payable_constructor_by_accountDeploy(
def test_as_transaction(tx_type, vyper_contract_instance, owner, eth_tester_provider):
tx = vyper_contract_instance.setNumber.as_transaction(987, sender=owner, type=tx_type.value)
assert tx.gas_limit == eth_tester_provider.max_gas


@pytest.mark.parametrize("calldata", ("0x123456", ["0x123456", "0xabcd"]))
def test_calldata_arg(calldata, contract_instance, owner):
tx = contract_instance.functionWithCalldata(calldata, sender=owner)
assert not tx.failed
antazoey marked this conversation as resolved.
Show resolved Hide resolved
Loading