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

"Given value is not a list" while the value is U256 #345

Open
ales-tsurko opened this issue Jun 12, 2023 · 3 comments
Open

"Given value is not a list" while the value is U256 #345

ales-tsurko opened this issue Jun 12, 2023 · 3 comments

Comments

@ales-tsurko
Copy link

ales-tsurko commented Jun 12, 2023

Hi!

I'm trying to compose a call for my frontier-based node:

    call = interface.compose_call(
        call_module="EVM",
        call_function="call",
        call_params={
            "source": "0x" + keypair.public_key.hex(),
            "target": contract_addr,
            "input": input.hex(),
            "value": 0,
            "gas_limit": 10000000,
            "max_fee_per_gas": 10000000,
            "max_priority_fee_per_gas": None,
            "nonce": None,
            "access_list": [],
        },
    )

But I'm getting an error:

  File "erc20_balances.py", line 85, in call_contract
    call = interface.compose_call(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/substrateinterface/base.py", line 1380, in compose_call
    call.encode({
  File ".venv/lib/python3.11/site-packages/scalecodec/base.py", line 925, in encode
    self.data = self.process_encode(self.value_serialized)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/scalecodec/types.py", line 1687, in process_encode
    data += arg_obj.encode(param_value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/scalecodec/base.py", line 925, in encode
    self.data = self.process_encode(self.value_serialized)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/scalecodec/types.py", line 672, in process_encode
    data += element_obj.encode(value[idx])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/scalecodec/base.py", line 925, in encode
    self.data = self.process_encode(self.value_serialized)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/scalecodec/types.py", line 1961, in process_encode
    raise ValueError('Given value is not a list')
ValueError: Given value is not a list

I don't know wether it's ok to expect a list in the place of U256, but here is the metadata for the function:

{'name': 'call', 'fields': [{'name': 'source', 'type': 43, 'typeName': 'H160', 'docs': []}, {'name': 'target', 'type': 43, 'typeName': 'H160', 'docs': []}, {'name': 'input', 'type': 13, 'typeName': 'Vec
<u8>', 'docs': []}, {'name': 'value', 'type': 56, 'typeName': 'U256', 'docs': []}, {'name': 'gas_limit', 'type': 10, 'typeName': 'u64', 'docs': []}, {'name': 'max_fee_per_gas', 'type': 56, 'typeName': '
U256', 'docs': []}, {'name': 'max_priority_fee_per_gas', 'type': 132, 'typeName': 'Option<U256>', 'docs': []}, {'name': 'nonce', 'type': 132, 'typeName': 'Option<U256>', 'docs': []}, {'name': 'access_li
st', 'type': 133, 'typeName': 'Vec<(H160, Vec<H256>)>', 'docs': []}], 'index': 1, 'docs': ['Issue an EVM call operation. This is similar to a message call transaction in Ethereum.']}

Could you tell me how can I properly specify the params? Or is it a bug?

@arjanz
Copy link
Member

arjanz commented Jun 21, 2023

I did some debugging and I found out that there are some unexpected SCALE encoding issues with the U256 types in this call like the value and max_fee_per_gas attributes.

In the metadata of the runtime, this type is defined as followed:

{'path': ['primitive_types', 'U256'], 'params': [], 'def': {'composite': {'fields': [{'name': None, 'type': 114, 'typeName': '[u64; 4]', 'docs': []}]}}, 'docs': []}

Somehow the metadata dictates that this U256 should be interpreted as a [u64; 4] and the library does accordingly, but this seems unwanted behaviour. So I'm not sure if this is a bug on the library end, or I'm totally missing something here.

Until this is figured out, as a workaround you can overwrite this type with:

substrate = SubstrateInterface(
    url=url,
    type_registry={"types": {"primitive_types::U256": "U256"}}
)

@arjanz
Copy link
Member

arjanz commented Jun 22, 2023

Path override included in new release of scalecodec, if you update to https://github.com/polkascan/py-substrate-interface/releases/tag/v1.7.3 this shouldn't be an issue anymore

@ales-tsurko
Copy link
Author

Thanks! I checked the workaround yesterday and I had the same error. But it might be related to Option<U256> instead of U256.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

No branches or pull requests

2 participants