/ test / contracts / abort_test.aes
abort_test.aes
 1  // A simple test of the abort built-in function.
 2  
 3  contract AbortTest =
 4  
 5    record state = { value : int }
 6  
 7    entrypoint init(v : int) =
 8      { value = v }
 9  
10    // Aborting
11    stateful entrypoint do_abort(v : int, s : string) : unit =
12      put_value(v)
13      revert_abort(s)
14  
15    // Accessing the value
16    entrypoint get_value() = state.value
17    stateful entrypoint put_value(v : int) = put(state{value = v})
18    entrypoint get_values() : list(int) = [state.value]
19    stateful entrypoint put_values(v : int) = put(state{value = v})
20  
21    // Some basic statistics
22    entrypoint get_stats(acct : address) =
23      ( Contract.balance, Chain.balance(acct) )
24  
25    // Abort functions.
26    function revert_abort(s : string) =
27      abort(s)
28  
29    // This is still legal but will be stripped out.
30    // TODO: This function confuses the type inference, so it cannot be present.
31    //private function abort(s : string) = 42