From 56f70fea6ca77e127d3ce70dd7c330cca6c7b41e Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Fri, 1 Mar 2019 09:36:43 +0100 Subject: [PATCH] test oracle calldata fixes --- src/aeso_compiler.erl | 2 +- test/aeso_abi_tests.erl | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index 59e5638..d0fe602 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -117,7 +117,7 @@ join_errors(Prefix, Errors, Pfun) -> %% terms for the arguments. %% NOTE: Special treatment for "init" since it might be implicit and has %% a special return type (typerep, T) --spec check_call(string(), string(), [string()], options()) -> {ok, string(), {[Type], Type | any}, [term()]} | {error, term()} +-spec check_call(string(), string(), [string()], options()) -> {ok, string(), {[Type], Type}, [term()]} | {error, term()} when Type :: term(). check_call(Source, "init" = FunName, Args, Options) -> PatchFun = fun(T) -> {tuple, [typerep, T]} end, diff --git a/test/aeso_abi_tests.erl b/test/aeso_abi_tests.erl index dee8317..706d7af 100644 --- a/test/aeso_abi_tests.erl +++ b/test/aeso_abi_tests.erl @@ -107,12 +107,30 @@ calldata_init_test() -> parameterized_contract(FunName, Types) -> lists:flatten( - ["contract Dummy =\n", + ["contract Dummy =\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" " function ", FunName, " : (", string:join(Types, ", "), ") => int\n" ]). +oracle_test() -> + Contract = + "contract OracleTest =\n" + " function question(o, q : oracle_query(list(string), option(int))) =\n" + " Oracle.get_question(o, q)\n", + {ok, _, {[word, word], {list, string}}, [16#123, 16#456]} = + aeso_compiler:check_call(Contract, "question", ["#123", "#456"], []), + ok. + +permissive_literals_fail_test() -> + Contract = + "contract OracleTest =\n" + " function haxx(o : oracle(list(string), option(int))) =\n" + " Chain.spend(o, 1000000)\n", + {error, <<"Type errors\nCannot unify address\n and oracle", _/binary>>} = + aeso_compiler:check_call(Contract, "haxx", ["#123"], []), + ok. + encode_decode_calldata(FunName, Types, Args) -> encode_decode_calldata(FunName, Types, Args, word).