Updated tests

This commit is contained in:
radrow
2019-07-22 13:56:45 +02:00
parent 4c72045a86
commit 5ff983b0b3
25 changed files with 78 additions and 57 deletions
+4 -4
View File
@@ -66,7 +66,7 @@ encode_decode_sophia_test() ->
ok = Check("bool", "true"),
ok = Check("bool", "false"),
ok = Check("string", "\"Hello\""),
ok = Check("(string, list(int), option(bool))",
ok = Check("string * list(int) * option(bool)",
"(\"Hello\", [1, 2, 3], Some(true))"),
ok = Check("variant", "Blue({[\"x\"] = 1})"),
ok = Check("r", "{x = (\"foo\", 0), y = Red}"),
@@ -76,7 +76,7 @@ encode_decode_sophia_string(SophiaType, String) ->
io:format("String ~p~n", [String]),
Code = [ "contract MakeCall =\n"
, " type arg_type = ", SophiaType, "\n"
, " type an_alias('a) = (string, 'a)\n"
, " type an_alias('a) = string * 'a\n"
, " record r = {x : an_alias(int), y : variant}\n"
, " datatype variant = Red | Blue(map(string, int))\n"
, " entrypoint foo : arg_type => arg_type\n" ],
@@ -137,10 +137,10 @@ parameterized_contract(FunName, Types) ->
parameterized_contract(ExtraCode, FunName, Types) ->
lists:flatten(
["contract Remote =\n"
" entrypoint bla : () => ()\n\n"
" entrypoint bla : () => unit\n\n"
"contract Dummy =\n",
ExtraCode, "\n",
" type an_alias('a) = (string, 'a)\n"
" type an_alias('a) = string * 'a\n"
" record r = {x : an_alias(int), y : variant}\n"
" datatype variant = Red | Blue(map(string, int))\n"
" entrypoint ", FunName, " : (", string:join(Types, ", "), ") => int\n" ]).
+3 -3
View File
@@ -53,7 +53,7 @@ test_cases(2) ->
{Contract,MapACI,DecACI};
test_cases(3) ->
Contract = <<"contract C =\n"
" type state = ()\n"
" type state = unit\n"
" datatype event = SingleEventDefined\n"
" datatype bert('a) = Bin('a)\n"
" entrypoint a(i : bert(string)) = 1\n">>,
@@ -67,7 +67,7 @@ test_cases(3) ->
stateful => false}],
name => <<"C">>,
event => #{variant => [#{<<"SingleEventDefined">> => []}]},
state => #{tuple => []},
state => <<"unit">>,
type_defs =>
[#{name => <<"bert">>,
typedef =>
@@ -75,7 +75,7 @@ test_cases(3) ->
[#{<<"Bin">> => [<<"'a">>]}]},
vars => [#{name => <<"'a">>}]}]}},
DecACI = <<"contract C =\n"
" type state = ()\n"
" type state = unit\n"
" datatype event = SingleEventDefined\n"
" datatype bert('a) = Bin('a)\n"
" entrypoint a : (C.bert(string)) => int\n">>,
+4 -4
View File
@@ -220,7 +220,7 @@ failing_contracts() ->
"when checking that 'init' returns a value of type 'state' at line 7, column 3">>]}
, {"missing_state_type",
[<<"Cannot unify string\n"
" and ()\n"
" and unit\n"
"when checking that 'init' returns a value of type 'state' at line 5, column 3">>]}
, {"missing_fields_in_record_expression",
[<<"The field x is missing when constructing an element of type r('a) (at line 7, column 42)">>,
@@ -325,7 +325,7 @@ failing_contracts() ->
<<"Cannot reference stateful function local_spend (at line 14, column 35)\nin the definition of non-stateful function fail2.">>,
<<"Cannot reference stateful function Chain.spend (at line 16, column 15)\nin the definition of non-stateful function fail3.">>,
<<"Cannot reference stateful function Chain.spend (at line 20, column 31)\nin the definition of non-stateful function fail4.">>,
<<"Cannot reference stateful function Chain.spend (at line 35, column 45)\nin the definition of non-stateful function fail5.">>,
<<"Cannot reference stateful function Chain.spend (at line 35, column 47)\nin the definition of non-stateful function fail5.">>,
<<"Cannot pass non-zero value argument 1000 (at line 48, column 57)\nin the definition of non-stateful function fail6.">>,
<<"Cannot pass non-zero value argument 1000 (at line 49, column 56)\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.">>]}
@@ -350,7 +350,7 @@ failing_contracts() ->
<<"Namespaces cannot contain entrypoints (at line 3, column 3). Use 'function' instead.">>,
<<"The contract Remote (at line 5, column 10) has no entrypoints. Since Sophia version 3.2, public\ncontract functions must be declared with the 'entrypoint' keyword instead of\n'function'.">>,
<<"The entrypoint wha (at line 12, column 3) cannot be private. Use 'function' instead.">>,
<<"Use 'entrypoint' for declaration of foo (at line 6, column 3):\n entrypoint foo : () => ()">>,
<<"Use 'entrypoint' for declaration of foo (at line 6, column 3):\n entrypoint foo : () => unit">>,
<<"Use 'entrypoint' instead of 'function' for public function foo (at line 10, column 3):\n entrypoint foo() = ()">>,
<<"Use 'entrypoint' instead of 'function' for public function foo (at line 6, column 3):\n entrypoint foo : () => ()">>]}
<<"Use 'entrypoint' instead of 'function' for public function foo (at line 6, column 3):\n entrypoint foo : () => unit">>]}
].
+1 -1
View File
@@ -8,7 +8,7 @@ contract AbortTest =
{ value = v }
// Aborting
public function do_abort(v : int, s : string) : () =
public function do_abort(v : int, s : string) : unit =
put_value(v)
revert_abort(s)
+3 -3
View File
@@ -1,9 +1,9 @@
contract Interface =
function do_abort : (int, string) => ()
function do_abort : (int, string) => unit
function get_value : () => int
function put_value : (int) => ()
function put_value : (int) => unit
function get_values : () => list(int)
function put_values : (int) => ()
function put_values : (int) => unit
contract AbortTestInt =
+1 -1
View File
@@ -1,5 +1,5 @@
contract Remote =
entrypoint main : (int) => ()
entrypoint main : (int) => unit
contract AddrChain =
type o_type = oracle(string, map(string, int))
+1 -1
View File
@@ -1,6 +1,6 @@
contract Remote =
entrypoint foo : () => ()
entrypoint foo : () => unit
contract AddressLiterals =
entrypoint addr() : address =
+8 -8
View File
@@ -12,44 +12,44 @@ contract AENSTest =
// Transactions
stateful entrypoint preclaim(addr : address, // Claim on behalf of this account (can be Contract.address)
chash : hash) : () = // Commitment hash
chash : hash) : unit = // Commitment hash
AENS.preclaim(addr, chash)
stateful entrypoint signedPreclaim(addr : address, // Claim on behalf of this account (can be Contract.address)
chash : hash, // Commitment hash
sign : signature) : () = // Signed by addr (if not Contract.address)
sign : signature) : unit = // Signed by addr (if not Contract.address)
AENS.preclaim(addr, chash, signature = sign)
stateful entrypoint claim(addr : address,
name : string,
salt : int) : () =
salt : int) : unit =
AENS.claim(addr, name, salt)
stateful entrypoint signedClaim(addr : address,
name : string,
salt : int,
sign : signature) : () =
sign : signature) : unit =
AENS.claim(addr, name, salt, signature = sign)
// TODO: update() -- how to handle pointers?
stateful entrypoint transfer(owner : address,
new_owner : address,
name : string) : () =
name : string) : unit =
AENS.transfer(owner, new_owner, name)
stateful entrypoint signedTransfer(owner : address,
new_owner : address,
name : string,
sign : signature) : () =
sign : signature) : unit =
AENS.transfer(owner, new_owner, name, signature = sign)
stateful entrypoint revoke(owner : address,
name : string) : () =
name : string) : unit =
AENS.revoke(owner, name)
stateful entrypoint signedRevoke(owner : address,
name : string,
sign : signature) : () =
sign : signature) : unit =
AENS.revoke(owner, name, signature = sign)
+1 -1
View File
@@ -24,7 +24,7 @@ contract AllSyntax =
if(valWithType(Map.empty) == None)
print(42 mod 10 * 5 / 3)
function funWithType(x : int, y) : (int, list(int)) = (x, 0 :: [y] ++ [])
function funWithType(x : int, y) : int * list(int) = (x, 0 :: [y] ++ [])
function funNoType() =
let foo = (x, y : bool) =>
if (! (y && x =< 0x0b || true)) [x]
+1 -1
View File
@@ -1,6 +1,6 @@
contract Remote =
entrypoint foo : () => ()
entrypoint foo : () => unit
contract AddressLiterals =
entrypoint addr1() : bytes(32) =
+4 -4
View File
@@ -3,8 +3,8 @@ contract Remote =
entrypoint up_to : (int) => list(int)
entrypoint sum : (list(int)) => int
entrypoint some_string : () => string
entrypoint pair : (int, string) => (int, string)
entrypoint squares : (int) => list((int, int))
entrypoint pair : (int, string) => int * string
entrypoint squares : (int) => list(int * int)
entrypoint filter_some : (list(option(int))) => list(int)
entrypoint all_some : (list(option(int))) => option(list(int))
@@ -47,7 +47,7 @@ contract ComplexTypes =
entrypoint pair(x : int, y : string) = (x, y)
entrypoint remote_pair(n : int, s : string) : (int, string) =
entrypoint remote_pair(n : int, s : string) : int * string =
state.worker.pair(gas = 10000, n, s)
entrypoint map(f, xs) =
@@ -58,7 +58,7 @@ contract ComplexTypes =
entrypoint squares(n) =
map((i) => (i, i * i), up_to(n))
entrypoint remote_squares(n) : list((int, int)) =
entrypoint remote_squares(n) : list(int * int) =
state.worker.squares(n)
// option types
+1 -1
View File
@@ -1,5 +1,5 @@
contract Remote =
entrypoint dummy : () => ()
entrypoint dummy : () => unit
contract Events =
+1 -1
View File
@@ -40,7 +40,7 @@ contract FunctionArguments =
entrypoint traffic_light(c : colour) =
Red
entrypoint tuples(t : ()) =
entrypoint tuples(t : unit) =
t
entrypoint due(t : Chain.ttl) =
+2 -2
View File
@@ -93,8 +93,8 @@ contract Maps =
entrypoint tolist_state_s() = tolist_s(state.map_s)
// Map.from_list
entrypoint fromlist_i(xs : list((int, pt))) = Map.from_list(xs)
entrypoint fromlist_s(xs : list((string, pt))) = Map.from_list(xs)
entrypoint fromlist_i(xs : list(int * pt)) = Map.from_list(xs)
entrypoint fromlist_s(xs : list(string * pt)) = Map.from_list(xs)
stateful entrypoint fromlist_state_i(xs) = put(state{ map_i = fromlist_i(xs) })
stateful entrypoint fromlist_state_s(xs) = put(state{ map_s = fromlist_s(xs) })
+1 -1
View File
@@ -3,7 +3,7 @@ namespace Lib =
entrypoint foo() = ()
contract Remote =
public function foo : () => ()
public function foo : () => unit
function bla() = ()
contract Contract =
+4 -4
View File
@@ -60,23 +60,23 @@ contract Oracles =
res
stateful entrypoint extendOracle(o : oracle_id,
ttl : ttl) : () =
ttl : ttl) : unit =
Oracle.extend(o, ttl)
stateful entrypoint signedExtendOracle(o : oracle_id,
sign : signature, // Signed oracle address
ttl : ttl) : () =
ttl : ttl) : unit =
Oracle.extend(o, signature = sign, ttl)
stateful entrypoint respond(o : oracle_id,
q : query_id,
r : answer_t) : () =
r : answer_t) : unit =
Oracle.respond(o, q, r)
stateful entrypoint signedRespond(o : oracle_id,
q : query_id,
sign : signature,
r : answer_t) : () =
r : answer_t) : unit =
Oracle.respond(o, q, signature = sign, r)
entrypoint getQuestion(o : oracle_id,
+1 -1
View File
@@ -21,7 +21,7 @@ contract Oracles =
function respond(o : oracle_id,
q : query_id,
sign : signature,
r : answer_t) : () =
r : answer_t) : unit =
Oracle.respond(o, q, signature = sign, r)
+1 -1
View File
@@ -7,7 +7,7 @@ contract Remote2 =
contract Remote3 =
entrypoint get : () => int
entrypoint tick : () => ()
entrypoint tick : () => unit
contract RemoteCall =
+1 -1
View File
@@ -1,7 +1,7 @@
contract Remote =
record rstate = { i : int, s : string, m : map(int, int) }
entrypoint look_at : (rstate) => ()
entrypoint look_at : (rstate) => unit
entrypoint return_s : (bool) => string
entrypoint return_m : (bool) => map(int, int)
entrypoint get : (rstate) => rstate
+2 -2
View File
@@ -1,6 +1,6 @@
contract Remote =
stateful entrypoint remote_spend : (address, int) => ()
stateful entrypoint remote_spend : (address, int) => unit
entrypoint remote_pure : int => int
contract Stateful =
@@ -32,7 +32,7 @@ contract Stateful =
entrypoint ok4(a : address) = fail4(a)
// Lamdbas are checked at the construction site
function fail5() : address => () = (a) => Chain.spend(a, 1000)
function fail5() : address => unit = (a) => Chain.spend(a, 1000)
// .. so you can pass a stateful lambda to a non-stateful higher-order
// function:
+1 -1
View File
@@ -8,7 +8,7 @@ contract VotingType =
function delegate : address => unit
function vote : int => unit
function winnerName : unit => string
function currentTally : unit => list((string, int))
function currentTally : unit => list(string * int)
/* Contract implementation */
contract Voting =