jorisbontje / cll-sim Goto Github PK
View Code? Open in Web Editor NEWEthereum CLL Contract Simulator
Ethereum CLL Contract Simulator
Having to refer all the way down assert self.contract.storage[index] ==
is a bit tiresome, and also we dont check all the things that shouldnt change. I propose we want ability to easily:
With the latter i mean, now we check simulation.stopped
, we could instead have .cll
(heard name .hll
floating around too?) files scan for comments besides those on stop
, and make a list. Then you could check that entire flow.
jorisbontje mentioned testing libraries. (pytest
, nosetest
or unittest
) To be honest i am not familiar about them, or how they fit in.
I already added for my own purposes(serving-and-viewing data PoC) block.number
and block.parenthash
just by setting self.thing
. Dont see contract.balance or something.. (well, block.account_balance(contract.address)
i suppose)
Required for examples/hedging.py
For example: when I am trying to ./run.py examples/escrow.py
there are some errors:
sim INFO RUN Test insufficient fee:
sim WARNING Stopped: Insufficient fee
Traceback (most recent call last):
File "./run.py", line 44, in
main(args.script)
File "./run.py", line 38, in main
simulation.run_all()
File "./lib/sim.py", line 218, in run_all
method()
File "examples/escrow.py", line 87, in test_insufficient_fee
self.run(tx, contract)
File "./lib/sim.py", line 244, in run
totalgas = gas.calculate_gas(contract)
File "./lib/sim.py", line 387, in calculate_gas
code_lines = contract.closure.split('\n')
AttributeError: 'Escrow' object has no attribute 'closure'
Looks like I miss some libraries?
Traceback (most recent call last):
File "cllcompiler.py", line 208, in
print ' '.join([str(k) for k in compile(open(sys.argv[1]).read())])
File "cllcompiler.py", line 201, in compile
p = parse_lines(lines)
File "/Users/hhalfordthompson/ethereum/compiler/cllparser.py", line 38, in parse_lines
out.append(parse_lines(child_block))
File "/Users/hhalfordthompson/ethereum/compiler/cllparser.py", line 32, in parse_lines
out = parse_line(main)
File "/Users/hhalfordthompson/ethereum/compiler/cllparser.py", line 217, in parse_line
return [ 'set', shunting_yard(tokens[:eqplace]), shunting_yard(tokens[eqplace+1:]) ]
File "/Users/hhalfordthompson/ethereum/compiler/cllparser.py", line 162, in shunting_yard
typ = toktype(tok)
File "/Users/hhalfordthompson/ethereum/compiler/cllparser.py", line 126, in toktype
else: raise Exception("Invalid token: "+token)
Exception: Invalid token: MYCREATOR
Contracts have 'discrete states modulo parameters' i.e with the lockin-escrow case you have a Idle(balance)
state and and a Customer(balance, address, incentive, total, paid)
state.
If those are vertexes of graphs, transactions sent to a contract go through one of the edges depending on parameter circumstance, changing parameters as function of the earlier parameters, including those of the attempted edge. I.e. attempted edges are functions. allow(value,address, incentive, total)
, refund(value)
, accept(value)
, send(value)
each of those returns a function i.e:
allow(value,address,incentive,total)(Idle(balance)) ==
Customer(balance+value-fee,address,incentive,total,0)
If we figure out those functions we can try parameters all we want. Contracts need to be robust against anything you throw at it, now we can throw 'noise' at it. The 'noise' could be focussed on edge cases to improve it. Of course you cant only rely on black-box testing entirely.
Note: but dont mind either way if i'll do it later or if someone else does. (just wanted to note it down)
Probably you didnt do this because it doesnt simulate fees? I reckon it could do balances could be added.. As for adding fees, kindah against making attempts to simulate.. Not sure, i reckon having the actual ethereum script interpreter behind there might be a better approach?
Fees could be constant, or maybe random. ..Kindah might want an easy way to get the random seed of the cases where the test failed.
Required for examples/hedging.py
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.