Arguments are in the body of the call, use term_to_fate before serializing them

This commit is contained in:
Thomas Arts 2019-06-13 12:20:41 +02:00
parent 95c41b8eee
commit a34558412d
3 changed files with 58 additions and 24 deletions

View File

@ -217,7 +217,7 @@ check_call1(ContractString0, FunName, Args, Options) ->
lists:seq($1, $9) ++ lists:seq($A, $Z) ++ lists:seq($a, $z)), lists:seq($1, $9) ++ lists:seq($A, $Z) ++ lists:seq($a, $z)),
ContractString = insert_call_function(ContractString0, CallName, FunName, Args, Options), ContractString = insert_call_function(ContractString0, CallName, FunName, Args, Options),
#{fcode := Fcode} = string_to_fcode(ContractString, Options), #{fcode := Fcode} = string_to_fcode(ContractString, Options),
#{args := CallArgs} = maps:get({entrypoint, list_to_binary(CallName)}, maps:get(functions, Fcode)), CallArgs = arguments_of_body(CallName, FunName, Fcode),
{ok, FunName, CallArgs} {ok, FunName, CallArgs}
end end
catch catch
@ -233,7 +233,13 @@ check_call1(ContractString0, FunName, Args, Options) ->
fun (E) -> io_lib:format("~p", [E]) end)} fun (E) -> io_lib:format("~p", [E]) end)}
end. end.
first_none_match(CallName, Hashes, []) -> arguments_of_body(CallName, _FunName, Fcode) ->
#{body := Body} = maps:get({entrypoint, list_to_binary(CallName)}, maps:get(functions, Fcode)),
{def, _FName, Args} = Body,
%% FName is either {entrypoint, list_to_binary(FunName)} or 'init'
[ aeso_fcode_to_fate:term_to_fate(A) || A <- Args ].
first_none_match(_CallName, _Hashes, []) ->
error(unable_to_find_unique_call_name); error(unable_to_find_unique_call_name);
first_none_match(CallName, Hashes, [Char|Chars]) -> first_none_match(CallName, Hashes, [Char|Chars]) ->
case not lists:member(aeb_fate_code:symbol_identifier(list_to_binary(CallName)), Hashes) of case not lists:member(aeb_fate_code:symbol_identifier(list_to_binary(CallName)), Hashes) of

View File

@ -9,7 +9,7 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(aeso_fcode_to_fate). -module(aeso_fcode_to_fate).
-export([compile/2]). -export([compile/2, term_to_fate/1]).
%% -- Preamble --------------------------------------------------------------- %% -- Preamble ---------------------------------------------------------------
@ -231,7 +231,32 @@ lookup_var(#env{vars = Vars}, X) ->
%% -- The compiler -- %% -- The compiler --
term_to_fate({lit, L}) ->
case L of
{int, N} -> aeb_fate_data:make_integer(N);
{string, S} -> aeb_fate_data:make_string(S);
{bool, B} -> aeb_fate_data:make_boolean(B);
{account_pubkey, K} -> aeb_fate_data:make_address(K);
{contract_pubkey, K} -> aeb_fate_data:make_contract(K);
{oracle_pubkey, K} -> aeb_fate_data:make_oracle(K);
{oracle_query_id, _} -> ?TODO(fate_oracle_query_id_value)
end;
%% negative literals are parsed as 0 - N
term_to_fate({op, '-', [{lit, {int, 0}}, {lit, {int, N}}]}) ->
aeb_fate_data:make_integer(-N);
term_to_fate(nil) ->
aeb_fate_data:make_list([]);
term_to_fate({op, '::', [Hd | Tl]}) ->
aeb_fate_data:make_list([term_to_fate(Hd) | [ term_to_fate(E) || E<-Tl]]);
term_to_fate({tuple, As}) ->
aeb_fate_data:make_tuple(list_to_tuple([ term_to_fate(A) || A<-As]));
term_to_fate({con, Ar, I, As}) ->
FateAs = [ term_to_fate(A) || A <- As ],
aeb_fate_data:make_variant(Ar, I, list_to_tuple(FateAs)).
to_scode(_Env, {lit, L}) -> to_scode(_Env, {lit, L}) ->
%% use term_to_fate here
case L of case L of
{int, N} -> [push(?i(N))]; {int, N} -> [push(?i(N))];
{string, S} -> [push(?i(aeb_fate_data:make_string(S)))]; {string, S} -> [push(?i(aeb_fate_data:make_string(S)))];

View File

@ -19,14 +19,14 @@ calldata_test_() ->
[ {"Testing the " ++ ContractName ++ " contract with the " ++ atom_to_list(Backend) ++ " backend", [ {"Testing the " ++ ContractName ++ " contract with the " ++ atom_to_list(Backend) ++ " backend",
fun() -> fun() ->
ContractString = aeso_test_utils:read_contract(ContractName), ContractString = aeso_test_utils:read_contract(ContractName),
Res = aeso_compiler:create_calldata(ContractString, "init", [], [{backend, Backend}]), Res = aeso_compiler:create_calldata(ContractString, Fun, Args, [{backend, Backend}]),
case Backend of case Backend of
aevm -> aevm ->
?assertMatch({ok, _, _, _}, Res); ?assertMatch({ok, _, _, _}, Res);
fate -> fate ->
?assertMatch({ok, _}, Res) ?assertMatch({ok, _}, Res)
end end
end} || ContractName <- compilable_contracts(), Backend <- [aevm, fate], end} || {ContractName, Fun, Args} <- compilable_contracts(), Backend <- [aevm, fate],
not lists:member(ContractName, not_yet_compilable(Backend))]. not lists:member(ContractName, not_yet_compilable(Backend))].
check_errors(Expect, ErrorString) -> check_errors(Expect, ErrorString) ->
@ -43,31 +43,34 @@ check_errors(Expect, ErrorString) ->
compilable_contracts() -> compilable_contracts() ->
[ [
"functions", {"identity", "init", []},
"identity", {"maps", "init", []},
"maps", {"oracles", "init", []},
"oracles", {"variant_types", "init", []},
"remote_call", {"basic_auth", "init", []},
"simple", {"address_literals", "init", []},
"spend_test", {"bytes_equality", "init", []},
"test", {"address_chain", "init", []},
"builtin_bug", {"counter", "init",
"builtin_map_get_bug", ["-3334353637383940202122232425262728293031323334353637"]},
"nodeadcode", {"dutch_auction", "init",
"deadcode", ["ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt", "200000", "1000"]},
"variant_types", {"maps", "fromlist_i",
"events", ["[(1, {x = 1, y = 2}), (2, {x = 3, y = 4}), (3, {x = 4, y = 4})]"]},
"basic_auth", {"strings", "str_concat", ["\"test\"","\"me\""]},
"address_literals", {"complex_types", "filter_some", ["[Some(1), Some(2), None]"]},
"bytes_equality", {"complex_types", "init", ["ct_Ez6MyeTMm17YnTnDdHTSrzMEBKmy7Uz2sXu347bTDPgVH2ifJ"]},
"address_chain", {"__call" "init", []},
"__call" {"bitcoin_auth", "init",
["#0102030405060708090a0b0c0d0e0f1017181920212223242526272829303132"
"33343536373839401a1b1c1d1e1f202122232425262728293031323334353637"]}
]. ].
not_yet_compilable(fate) -> not_yet_compilable(fate) ->
["oracles", %% Oracle.register ["oracles", %% Oracle.register
"events", "events",
"basic_auth", %% auth_tx_hash instruction "basic_auth", %% auth_tx_hash instruction
"bitcoin_auth", %% fate_auth_tx_hash_instruction
"address_literals", %% oracle_query_id literals "address_literals", %% oracle_query_id literals
"address_chain" %% Oracle.check_query "address_chain" %% Oracle.check_query
]; ];