From 3a6337d8cac58be2d5a227361d499893a87cbad7 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Wed, 12 Jun 2019 16:33:26 +0200 Subject: [PATCH] Testing that fate calldata is immune to existing __call in contract --- test/aeso_calldata_tests.erl | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/aeso_calldata_tests.erl diff --git a/test/aeso_calldata_tests.erl b/test/aeso_calldata_tests.erl new file mode 100644 index 0000000..a92785a --- /dev/null +++ b/test/aeso_calldata_tests.erl @@ -0,0 +1,75 @@ +%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*- +%%%------------------------------------------------------------------- +%%% @copyright (C) 2019, Aeternity Anstalt +%%% @doc Test Sophia language compiler. +%%% +%%% @end +%%%------------------------------------------------------------------- + +-module(aeso_calldata_tests). + +-compile([export_all, nowarn_export_all]). + +-include_lib("eunit/include/eunit.hrl"). + +%% Very simply test compile the given contracts. Only basic checks +%% are made on the output, just that it is a binary which indicates +%% that the compilation worked. +calldata_test_() -> + [ {"Testing the " ++ ContractName ++ " contract with the " ++ atom_to_list(Backend) ++ " backend", + fun() -> + ContractString = aeso_test_utils:read_contract(ContractName), + Res = aeso_compiler:create_calldata(ContractString, "init", [], [{backend, Backend}]), + case Backend of + aevm -> + ?assertMatch({ok, _, _, _}, Res); + fate -> + ?assertMatch({ok, _}, Res) + end + end} || ContractName <- compilable_contracts(), Backend <- [aevm, fate], + not lists:member(ContractName, not_yet_compilable(Backend))]. + +check_errors(Expect, ErrorString) -> + %% This removes the final single \n as well. + Actual = binary:split(<>, <<"\n\n">>, [global,trim]), + case {Expect -- Actual, Actual -- Expect} of + {[], Extra} -> ?assertMatch({unexpected, []}, {unexpected, Extra}); + {Missing, []} -> ?assertMatch({missing, []}, {missing, Missing}); + {Missing, Extra} -> ?assertEqual(Missing, Extra) + end. + +%% compilable_contracts() -> [ContractName]. +%% The currently compilable contracts. + +compilable_contracts() -> + [ + "functions", + "identity", + "maps", + "oracles", + "remote_call", + "simple", + "spend_test", + "test", + "builtin_bug", + "builtin_map_get_bug", + "nodeadcode", + "deadcode", + "variant_types", + "events", + "basic_auth", + "address_literals", + "bytes_equality", + "address_chain", + "__call" + ]. + +not_yet_compilable(fate) -> + ["oracles", %% Oracle.register + "events", + "basic_auth", %% auth_tx_hash instruction + "address_literals", %% oracle_query_id literals + "address_chain" %% Oracle.check_query + ]; +not_yet_compilable(aevm) -> + ["__call"].