From 8619f47ee6ff2041ca9229dc0b9d2f54d783fb27 Mon Sep 17 00:00:00 2001 From: Robert Virding Date: Thu, 28 Feb 2019 16:09:59 +0100 Subject: [PATCH] Add very basic ACI testing These should be extended and expanded. --- test/aeso_aci_tests.erl | 45 +++++++++++++++++++++++++++++++++++++++ test/aeso_eunit_SUITE.erl | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 test/aeso_aci_tests.erl diff --git a/test/aeso_aci_tests.erl b/test/aeso_aci_tests.erl new file mode 100644 index 0000000..be9cf0f --- /dev/null +++ b/test/aeso_aci_tests.erl @@ -0,0 +1,45 @@ +-module(aeso_aci_tests). + +-include_lib("eunit/include/eunit.hrl"). + + +do_test() -> + test_contract(1), + test_contract(2). + +test_contract(N) -> + {Contract,DecACI} = test_cases(N), + {ok,Enc} = aeso_aci:encode(Contract), + ?assertEqual(DecACI, jsx:decode(Enc)). + +test_cases(1) -> + Contract = <<"contract C =\n" + " function a(i : int) = i+1\n">>, + DecodedACI = [{<<"contract">>, + [{<<"name">>,<<"C">>}, + {<<"type_defs">>,[]}, + {<<"functions">>, + [[{<<"name">>,<<"a">>}, + {<<"arguments">>, + [[{<<"name">>,<<"i">>},{<<"type">>,<<"int">>}]]}, + {<<"type">>,<<"int">>}, + {<<"stateful">>,false}]]}]}], + {Contract,DecodedACI}; + +test_cases(2) -> + Contract = <<"contract C =\n" + " type allan = int\n" + " function a(i : allan) = i+1\n">>, + DecodedACI = [{<<"contract">>, + [{<<"name">>,<<"C">>}, + {<<"type_defs">>, + [[{<<"name">>,<<"allan">>}, + {<<"vars">>,[]}, + {<<"typedef">>,<<"int">>}]]}, + {<<"functions">>, + [[{<<"name">>,<<"a">>}, + {<<"arguments">>, + [[{<<"name">>,<<"i">>},{<<"type">>,<<"int">>}]]}, + {<<"type">>,<<"int">>}, + {<<"stateful">>,false}]]}]}], + {Contract,DecodedACI}. diff --git a/test/aeso_eunit_SUITE.erl b/test/aeso_eunit_SUITE.erl index ed19643..695f354 100644 --- a/test/aeso_eunit_SUITE.erl +++ b/test/aeso_eunit_SUITE.erl @@ -12,9 +12,11 @@ groups() -> , aeso_parser_tests , aeso_compiler_tests , aeso_abi_tests + , aeso_aci_tests ]}]. aeso_scan_tests(_Config) -> ok = eunit:test(aeso_scan_tests). aeso_parser_tests(_Config) -> ok = eunit:test(aeso_parser_tests). aeso_compiler_tests(_Config) -> ok = eunit:test(aeso_compiler_tests). aeso_abi_tests(_Config) -> ok = eunit:test(aeso_abi_tests). +aeso_aci_tests(_Config) -> ok = eunit:test(aeso_aci_tests).