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

Unable to import Solidity contract from a file using compile_files #43

Open
ltfschoen opened this issue Dec 30, 2017 · 2 comments
Open

Comments

@ltfschoen
Copy link

  • py-solc Version: 2.1.0 (shown when I run pip3 list)
  • solc Version: 0.4.17+commit.bdeb9e52.Linux.g++
  • Python Version: 3.6.3
  • OS: Docker VM on macOS 10.12.6 - Linux version 4.9.49-moby (gcc version 6.2.1 20160822 (Alpine 6.2.1) )
  • Solc v0.4.17 (see where I load Solc dependency in my Dockerfile)
  • Source Code: https://github.com/ltfschoen/pyethfinality/blob/master/main.py

What was wrong?

How to reproduce the issue

Follow steps in the "Quickstart Guide" of my Github repo https://github.com/ltfschoen/pyethfinality#chapter-0

  • Run the Python script in the 1st Bash Terminal tab's Docker shell
python3 main.py

What was the result of the issue. What the expected behaviour is

In the web3.py Quick Start example code https://github.com/pipermerriam/web3.py, they load the Solidity contract "inline" and store it in variable contract_source_code and then compile the source code with compiled_sol = compile_source(contract_source_code), which is then assigned to the contract_interface = compiled_sol['<stdin>:Greeter'].

But I want to load the Solidity contract from a "file", so I added compile_files to the list of imports from solc import install_solc, compile_source, compile_files and compiled the source code with compiled_sol = compile_files([“./Greeter.sol”]), but I get the following error on the above mentioned line of code that assigns to the contract_interface variable.

Traceback (most recent call last):
  File "main.py", line 42, in <module>
    contract_interface = compiled_sol['<stdin>:Greeter']
KeyError: '<stdin>:Greeter'

Note: I need to load the Solidity contract from a file so I can implement unit tests.

Cute Animal Picture

alt text

@KPrasch
Copy link

KPrasch commented Jun 21, 2018

Not exactly the same issue - but I noticed that any filepath containing a : character will be split incorrectly here: https://github.com/ethereum/py-solc/blob/v4.0.0/solc/main.py#L73

    for source, data in contracts.items():
        data['abi'] = json.loads(data['abi'])
        data['ast'] = sources[source.split(':')[0]]['AST']    # <<<<<

For example - if we use a standard windows filepath as an input (C:\path\to\contract\Greeter.sol:Greeter) a KeyError will be raised when C is used for the lookup. This issue is not unique to windows, and in fact will occur with any filepath containing a colon.

Anyone else experience this behaviour?

@tlatkdgus1
Copy link

I've experienced it, too. (Windows)

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

No branches or pull requests

3 participants