Check that init doesn't read or write the state

This commit is contained in:
Ulf Norell
2019-05-13 17:51:47 +02:00
parent 6bd2b7c483
commit 74d4048d9f
3 changed files with 75 additions and 0 deletions
+13
View File
@@ -316,4 +316,17 @@ failing_contracts() ->
<<"Cannot pass non-zero value argument 1000 (at line 48, column 55)\nin the definition of non-stateful function fail6.">>,
<<"Cannot pass non-zero value argument 1000 (at line 49, column 54)\nin the definition of non-stateful function fail7.">>,
<<"Cannot pass non-zero value argument 1000 (at line 52, column 17)\nin the definition of non-stateful function fail8.">>]}
, {"bad_init_state_access",
[<<"The init function should return the initial state as its result and cannot write the state,\n"
"but it calls\n"
" - set_state (at line 11, column 5), which calls\n"
" - roundabout (at line 8, column 36), which calls\n"
" - put (at line 7, column 37)">>,
<<"The init function should return the initial state as its result and cannot read the state,\n"
"but it calls\n"
" - new_state (at line 12, column 5), which calls\n"
" - state (at line 5, column 27)">>,
<<"The init function should return the initial state as its result and cannot read the state,\n"
"but it calls\n"
" - state (at line 13, column 13)">>]}
].
+13
View File
@@ -0,0 +1,13 @@
contract BadInit =
type state = int
function new_state(n) = state + n
stateful function roundabout(n) = put(n)
stateful function set_state(n) = roundabout(n)
stateful function init() =
set_state(4)
new_state(0)
state + state