ApeWorX / ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
https://apeworx.io
Apache License 2.0
889 stars 131 forks source link

Type error in empty DynArray of struct #1231

Closed milkyklim closed 1 year ago

milkyklim commented 1 year ago

Environment information

$ ape --version
0.5.9

$ ape plugins list
Installed Plugins:
  etherscan    0.1.0b3
  tokens       0.1.0b5.dev2+g9dc883e
  vyper        0.5.2
  solidity     0.5.4
  foundry      0.5.2
name: test
plugins:
  - name: vyper
  - name: solidity
  - name: tokens
  - name: ethereum
  - name: foundry

ethereum:
  default_network: mainnet-fork
  mainnet_fork:
    default_provider: foundry

foundry:
  port: auto
  fork:
    ethereum:
      mainnet:
        upstream_provider: geth

geth:
  ethereum:
    mainnet:
      uri: ${WEB3_PROVIDER_URI}

What went wrong?

This gets compiled:

# @version 0.3.7
MAX_NUM: public(constant(uint256)) = 10

struct MyStruct:
    one: uint256
    two: uint256
    there: uint256

@view
@external
def get_values() -> (DynArray[uint256, MAX_NUM], DynArray[MyStruct, MAX_NUM]):
    _ids: DynArray[uint256, MAX_NUM] = []
    _my_structs: DynArray[MyStruct, MAX_NUM] = []

    return _ids, _my_structs

When I try to call .get_values() in ape I get an error:

TypeError: __init__() missing 3 required positional arguments: 'one', 'two', and 'there'

How can it be fixed?

--

fubuloubu commented 1 year ago

Diving into this, it seems like for the second return type it is returning an empty tuple instead of an empty list from ape.utils.abi.StructParser.parse