From 4c79f7b9f2b73005550812cb200d311308d59be7 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Tue, 26 Feb 2019 17:41:04 +0100 Subject: [PATCH] tests for calldata creation --- test/aeso_abi_tests.erl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/aeso_abi_tests.erl b/test/aeso_abi_tests.erl index 8557975..f061a83 100644 --- a/test/aeso_abi_tests.erl +++ b/test/aeso_abi_tests.erl @@ -92,6 +92,24 @@ encode_decode_sophia_string(SophiaType, String) -> {error, Err} end. +calldata_test() -> + [42, <<"foobar">>] = encode_decode_calldata(["int", "string"], ["42", "\"foobar\""]), + Map = #{ <<"a">> => 4 }, + [{variant, 1, [Map]}, {{<<"b">>, 5}, {variant, 0, []}}] = + encode_decode_calldata(["variant", "r"], ["Blue({[\"a\"] = 4})", "{x = (\"b\", 5), y = Red}"]), + ok. + +encode_decode_calldata(Types, Args) -> + Code = lists:flatten( + ["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 foo : (", string:join(Types, ", "), ") => int\n" ]), + {ok, Calldata, CalldataType, word} = aeso_compiler:create_calldata(Code, "foo", Args), + {ok, {_Hash, ArgTuple}} = aeso_heap:from_binary(CalldataType, Calldata), + tuple_to_list(ArgTuple). + encode_decode(T, D) -> ?assertEqual(D, decode(T, encode(D))), D.