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

Viper contract deploy and testing #459

Closed
temanmd opened this issue Nov 11, 2017 · 8 comments
Closed

Viper contract deploy and testing #459

temanmd opened this issue Nov 11, 2017 · 8 comments

Comments

@temanmd
Copy link

temanmd commented Nov 11, 2017

What's your issue about?

I see many tutorials about solidity contracts deploying and testing (without using real ETH transactions), but there is not the same for viper
I wanna learn/test/debug my contract, wanna see how it works (in local blockchain if is it possible)
Where can I find this information?

Cute Animal Picture

ccc

@fubuloubu
Copy link
Member

Because what happens when you deploy a smart contract (in any language) is that you are deploying the bytecode generated by the compiler, the tools used are actually somewhat agnostic to which language you end up using (Solidity, Viper, LLL, etc.) Personally, I like using pyethereum for testing purposes because it's written in python, which is the same module we use for the majority of our testing here.

If you install pyethereum (pip install ethereum>=2.1.0), you can use the tester module for testing against a very simple blockchain via the following:

from viper import compiler
from ethereum.tools import tester
# Get a new chain
chain = tester.Chain()
# Set the viper compiler to run when the viper language is requested
tester.languages['viper'] = compiler.Compiler() 
# Compile and apply __init__ method (using init_args
contract = chain.contract(source_code, language="viper", init_args, sender=..., value=..., etc.)
contract.myMethod() # Executes myMethod on the tester "chain"
chain.mine() # Mines the above transaction (and any before it) into a block

Now for deployment against a "real" blockchain, you have several options: you can use a tool that can deploy the bytecode for you (which doesn't get pretty), or you can create your own process via py-testrpc and web3.py (which is what I am doing) to connect to a running instance of geth, deploy your bytecode, and interact with your deployed contracts. This is definitely a much more advanced step, but realistically using the ethereum.tester module above can let you do most of what you want to do (see how it works on a chain) without going through these steps of seeing how it works out there in the wild. If you're just getting into contract programming, getting very familiar with testing is a great first step and you can probably learn enough there to make you dangerous when you actually want to go deploy some code on testnet (or mainnet shivers lol).

You're right we need to actually come up with real tools and examples of how to do this eventually, especially the testing aspect. Let us know if you need some further answers on gitter and we'll keep this issue for us to create documentation on how to setup your own test suite for contracts (using the same tools we use to test our own e.g. here)

@temanmd
Copy link
Author

temanmd commented Nov 11, 2017

@fubuloubu awesome detailed answer. Thank you, I'll try it soon and text further answers on gitter

@jacqueswww
Copy link
Contributor

@fubuloubu Would be good to have the above information as a section 'Testing your contract' (or similar) in the docs, could just copy paste most of your answer ;)

@fubuloubu
Copy link
Member

Sure, if I get time tomorrow I might do that. For my personal development work I've been working on a set of compilation and deployment modules I would love to make into more of a general development utility module for Ethereum. I know there is Populus but it's based on an older pyethereum and I don't really get the way it searches for contracts.

@fubuloubu
Copy link
Member

Plus it's not extendable to viper

@fubuloubu
Copy link
Member

@DavidKnott assign me to this so I don't forget the above

@DavidKnott
Copy link
Contributor

@fubuloubu Assigning to someone who's not a collaborator doesn't work on github. But I can remind you 👍

@DavidKnott
Copy link
Contributor

@fubuloubu Thanks for creating some docs for this, I'm closing this issue.

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

4 participants