diff --git a/src/aeso_aci.erl b/src/aeso_aci.erl index 5a629cd..422fb77 100644 --- a/src/aeso_aci.erl +++ b/src/aeso_aci.erl @@ -356,6 +356,9 @@ typedef_vars(#type_def{vars=Vars}) -> Vars. typedef_def(#type_def{typedef=Def}) -> Def. +%% parse(ContractString, Options) -> {ok,AST}. +%% Signal errors, the sophia compiler way. Sigh! + parse(Text, Options) -> %% Try and return something sensible here! case aeso_parser:string(Text, Options) of diff --git a/test/aeso_aci_tests.erl b/test/aeso_aci_tests.erl index fd6ab0c..8b5e1d7 100644 --- a/test/aeso_aci_tests.erl +++ b/test/aeso_aci_tests.erl @@ -5,17 +5,19 @@ do_test() -> test_contract(1), - test_contract(2). + test_contract(2), + test_contract(3). test_contract(N) -> - {Contract,DecACI} = test_cases(N), - {ok,Enc} = aeso_aci:encode(Contract), - ?assertEqual(DecACI, jsx:decode(Enc, [return_maps])). + {Contract,MapACI,DecACI} = test_cases(N), + {ok,JSON} = aeso_aci:encode(Contract), + ?assertEqual(MapACI, jsx:decode(JSON, [return_maps])), + ?assertEqual(DecACI, aeso_aci:decode(JSON)). test_cases(1) -> Contract = <<"contract C =\n" " function a(i : int) = i+1\n">>, - DecodedACI = #{<<"contract">> => + MapACI = #{<<"contract">> => #{<<"name">> => <<"C">>, <<"type_defs">> => [], <<"functions">> => @@ -25,13 +27,15 @@ test_cases(1) -> <<"type">> => [<<"int">>]}], <<"returns">> => <<"int">>, <<"stateful">> => false}]}}, - {Contract,DecodedACI}; + DecACI = <<"contract C =\n" + " function a : (int) => int\n">>, + {Contract,MapACI,DecACI}; test_cases(2) -> Contract = <<"contract C =\n" " type allan = int\n" " function a(i : allan) = i+1\n">>, - DecodedACI = #{<<"contract">> => + MapACI = #{<<"contract">> => #{<<"name">> => <<"C">>, <<"type_defs">> => [#{<<"name">> => <<"allan">>, @@ -44,4 +48,29 @@ test_cases(2) -> <<"name">> => <<"a">>, <<"returns">> => <<"int">>, <<"stateful">> => false}]}}, - {Contract,DecodedACI}. + DecACI = <<"contract C =\n" + " function a : (int) => int\n">>, + {Contract,MapACI,DecACI}; +test_cases(3) -> + Contract = <<"contract C =\n" + " datatype bert('a) = Bin('a)\n" + " function a(i : bert(string)) = 1\n">>, + MapACI = #{<<"contract">> => + #{<<"functions">> => + [#{<<"arguments">> => + [#{<<"name">> => <<"i">>, + <<"type">> => + [#{<<"C.bert">> => [<<"string">>]}]}], + <<"name">> => <<"a">>,<<"returns">> => <<"int">>, + <<"stateful">> => false}], + <<"name">> => <<"C">>, + <<"type_defs">> => + [#{<<"name">> => <<"bert">>, + <<"typedef">> => + #{<<"variant">> => + [#{<<"Bin">> => [<<"'a">>]}]}, + <<"vars">> => [#{<<"name">> => <<"'a">>}]}]}}, + DecACI = <<"contract C =\n" + " datatype bert('a) = Bin('a)\n" + " function a : (C.bert(string)) => int\n">>, + {Contract,MapACI,DecACI}.