diff --git a/genlayer_py/abi/calldata/decoder.py b/genlayer_py/abi/calldata/decoder.py index c993ac8..6d9bb64 100644 --- a/genlayer_py/abi/calldata/decoder.py +++ b/genlayer_py/abi/calldata/decoder.py @@ -45,7 +45,7 @@ def impl() -> CalldataEncodable: elif typ == consts.TYPE_BYTES: ret_bytes = mem[:code] mem = mem[code:] - return ret_bytes + return bytes(ret_bytes) elif typ == consts.TYPE_STR: ret_str = mem[:code] mem = mem[code:] diff --git a/tests/unit/abi/test_calldata.py b/tests/unit/abi/test_calldata.py new file mode 100644 index 0000000..78c4d90 --- /dev/null +++ b/tests/unit/abi/test_calldata.py @@ -0,0 +1,15 @@ +from genlayer_py.abi import calldata + + +def test_decode_bytes_returns_bytes(): + decoded = calldata.decode(calldata.encode(b"hello")) + + assert isinstance(decoded, bytes) + assert decoded == b"hello" + + +def test_decoded_bytes_round_trip_through_to_str(): + value = b"hello" + decoded = calldata.decode(calldata.encode(value)) + + assert calldata.to_str(decoded) == calldata.to_str(value)