I have created a simulator of the Ethereum C-Like Language Contracts. The intention of this simulator is to help contract coders develop and test their work using test driven best practises and in full isolation, without the need to connect to the Ethereum Test Net.
Contracts from the whitepaper are slightly modified to make them Python syntax compatible and contained within a Contract class. Automated testing scenarios are also written in a Simulator DSL (similar to unit tests) which can run, inspect and verify the outcome of contract runs.
Source Code:
https://github.com/jorisbontje/cll-simLet me know what you think!
Joris Bontje /
@mids106 / mids on IRC #ethereum
Example Run:
./run.py examples/subcurrency.py
This will execute several simulation scenarios on the Sub-Currency example from the Ethereum whitepaper.
Example Output
sim INFO RUN test_insufficient_fee:
sim WARNING Stopped: Insufficient basefee
sim INFO --------------------
sim INFO RUN test_creation:
sim DEBUG Accessing storage 1000
subcurrency INFO Initializing storage for creator alice
sim DEBUG Setting storage alice to 1000000000000000000
sim DEBUG Setting storage 1000 to 1
sim INFO --------------------
sim INFO RUN test_alice_to_bob:
sim DEBUG Accessing storage 1000
sim DEBUG Accessing storage alice
subcurrency INFO Transfering 1000 from alice to bob
sim DEBUG Accessing storage alice
sim DEBUG Setting storage alice to 999999999999999000
sim DEBUG Accessing storage bob
sim DEBUG Setting storage bob to 1000
sim INFO --------------------
sim INFO RUN test_bob_to_charlie_invalid:
sim DEBUG Accessing storage 1000
sim DEBUG Accessing storage bob
sim DEBUG Accessing storage bob
sim WARNING Stopped: Insufficient funds, bob has 1000 needs 1001
sim INFO --------------------
sim INFO RUN test_bob_to_charlie_valid:
sim DEBUG Accessing storage 1000
sim DEBUG Accessing storage bob
subcurrency INFO Transfering 1000 from bob to charlie
sim DEBUG Accessing storage bob
sim DEBUG Setting storage bob to 0
sim DEBUG Accessing storage charlie
sim DEBUG Setting storage charlie to 1000
sim INFO --------------------
subcurrency INFO , {1000: 1, 'charlie': 1000, 'bob': 0, 'alice': 999999999999999000})>
Comments
It'd be nice if there was a cleaner way to auto create the Contract class based directly on the cll
James Levy contributed the simulation for the datafeed example. We have added `mktx` and `block.contract_storage` support which now also allows the financial derivative example to run. During the implementation I discovered a couple bugs in the whitepaper reference code, this emphasises that proper contract simulation is so essential to Ethereum.
Take a look at the contract with simulation runs:
https://github.com/jorisbontje/cll-sim/blob/master/examples/hedging.py
Can someone explain the or tx.data[0] < 100:
in namecoin.py?
Comparisions between string and numeric: In python the numeric types comes first.
So it seems this will allow all non-occupied strings and also all non-occupied numericals below 100
Why is this? Are there some differences to CLL that I am unaware of?
The check that the argument tx.data[0] is above 100 (the contract will stop otherwise), is so that you won't accidentally overwrite the contract etherscript code by storing a low value key.
block.account_balance
pseudo function as requested by @caktuxSmall code sample:
https://github.com/jorisbontje/cll-sim/blob/master/examples/fountain.py