From 021ba6f465c910cf9f1248a13777a58b843d493a Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Fri, 5 May 2023 13:06:07 +0200 Subject: [PATCH] Add tests --- test/aeso_compiler_tests.erl | 35 ++++++++++++++++++++++++++++++- test/contracts/bad_bytes_to_x.aes | 5 +++++ test/contracts/bytes_misc.aes | 27 ++++++++++++++++++++++++ test/contracts/bytes_to_x.aes | 2 ++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 test/contracts/bad_bytes_to_x.aes create mode 100644 test/contracts/bytes_misc.aes diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index 5d2c417..8c0b1da 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -170,6 +170,7 @@ compilable_contracts() -> "namespace_bug", "bytes_to_x", "bytes_concat", + "bytes_misc", "aens", "aens_update", "tuple_match", @@ -448,6 +449,10 @@ failing_contracts() -> [<>, + <>]) , ?TYPE_ERROR(not_toplevel_include, [< [<>]) + , ?TYPE_ERROR(bad_bytes_to_x, + [<>, + < option('a)`\n" + "to arguments\n" + " `b : bytes(4)`">>, + <>, + <>]) , ?TYPE_ERROR(bad_bytes_concat, [< "and result type\n" " - 'c (at line 16, column 39)">>, <>]) + "Cannot resolve type of byte array in\n" + " the first argument of a call to Bytes.to_str">>]) , ?TYPE_ERROR(bad_bytes_split, [< < Cat) => dt_inv(Cat)`\nto arguments\n `f_c_to_a : (Cat) => Animal`">>, + <>, <>, @@ -977,6 +1001,9 @@ failing_contracts() -> <>, + <>, <>, @@ -1020,6 +1047,9 @@ failing_contracts() -> <>, + <>, <>, @@ -1044,6 +1074,9 @@ failing_contracts() -> <>, + <>, <>, diff --git a/test/contracts/bad_bytes_to_x.aes b/test/contracts/bad_bytes_to_x.aes new file mode 100644 index 0000000..4e3db65 --- /dev/null +++ b/test/contracts/bad_bytes_to_x.aes @@ -0,0 +1,5 @@ +// include "String.aes" +contract BytesToX = + entrypoint fail1(b : bytes()) = Bytes.to_fixed_size(b) + entrypoint fail2(b : bytes(4)) = Bytes.to_fixed_size(b) + entrypoint fail3(b : bytes()) = Bytes.to_any_size(b) diff --git a/test/contracts/bytes_misc.aes b/test/contracts/bytes_misc.aes new file mode 100644 index 0000000..13e7fb4 --- /dev/null +++ b/test/contracts/bytes_misc.aes @@ -0,0 +1,27 @@ +include "String.aes" +contract BytesMisc = + entrypoint sizeFixed(b : bytes(4)) : int = Bytes.size(b) + entrypoint sizeAny(b : bytes()) : int = Bytes.size(b) + entrypoint int_to_bytes(i : int) : bytes() = Int.to_bytes(i, 16) + + entrypoint test(b3 : bytes(3), b7 : bytes(7), bX : bytes, i : int, s : string) = + let bi = Int.to_bytes(i, 8) + let bs = String.to_bytes(s) + + let b10 = Bytes.concat(b3, b7) + + let (b4, b6 : bytes(6)) = Bytes.split(b10) + + let Some((b8, b2)) = Bytes.split_any(bX, 8) + + let bX7 = Bytes.concat(bX, b7) + + let Some((b5, bX2)) = Bytes.split_any(bX7, 5) + + let Some((b7b, b0)) = Bytes.split_any(bX, Bytes.size(b7)) + + let Some(b5b : bytes(5)) = Bytes.to_fixed_size(b5) + + let (b1 : bytes(1), _) = Bytes.split(b5b) + + [bi, bs, b0, Bytes.to_any_size(b1), b2, Bytes.to_any_size(b4), Bytes.to_any_size(b6), b7b, b8, bX2] diff --git a/test/contracts/bytes_to_x.aes b/test/contracts/bytes_to_x.aes index 6ab4852..14e150d 100644 --- a/test/contracts/bytes_to_x.aes +++ b/test/contracts/bytes_to_x.aes @@ -6,3 +6,5 @@ contract BytesToX = String.concat(Bytes.to_str(b), Bytes.to_str(#ffff)) entrypoint to_str_big(b : bytes(65)) : string = Bytes.to_str(b) + entrypoint to_fixed(b : bytes()) : option(bytes(4)) = Bytes.to_fixed_size(b) + entrypoint to_any(b : bytes(4)) = Bytes.to_any_size(b)