From d8adfce4658490bb4a556b39e21f0fdd2588837d Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Wed, 4 Sep 2019 10:45:43 +0200 Subject: [PATCH] Tests for unapplied builtins --- src/aeso_code_errors.erl | 4 ++ test/aeso_compiler_tests.erl | 6 +- .../unapplied_named_arg_builtin.aes | 5 ++ test/contracts/unapplied_builtins.aes | 63 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/contracts/code_errors/unapplied_named_arg_builtin.aes create mode 100644 test/contracts/unapplied_builtins.aes diff --git a/src/aeso_code_errors.erl b/src/aeso_code_errors.erl index 9a4d8b2..b178637 100644 --- a/src/aeso_code_errors.erl +++ b/src/aeso_code_errors.erl @@ -66,6 +66,10 @@ format({unapplied_contract_call, Contract}) -> "~s\n", [pp_expr(2, Contract)]), Cxt = "Use FATE if you need this.\n", mk_err(pos(Contract), Msg, Cxt); +format({unapplied_builtin, Id}) -> + Msg = io_lib:format("The AEVM does not support unapplied use of ~s.\n", [pp_expr(0, Id)]), + Cxt = "Use FATE if you need this.\n", + mk_err(pos(Id), Msg, Cxt); format({invalid_map_key_type, Why, Ann, Type}) -> Msg = io_lib:format("Invalid map key type\n~s\n", [pp_type(2, Type)]), Cxt = case Why of diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index ddad533..22b5275 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -144,7 +144,8 @@ compilable_contracts() -> "double_include", "manual_stdlib_include", "list_comp", - "payable" + "payable", + "unapplied_builtins" ]. not_yet_compilable(fate) -> []; @@ -577,6 +578,9 @@ failing_code_gen_contracts() -> "The AEVM does not support unapplied contract call to\n" " r : Remote\n" "Use FATE if you need this.") + , ?AEVM(unapplied_named_arg_builtin, 4, 15, + "The AEVM does not support unapplied use of Oracle.register.\n" + "Use FATE if you need this.") , ?AEVM(polymorphic_map_keys, 4, 34, "Invalid map key type\n" " 'a\n" diff --git a/test/contracts/code_errors/unapplied_named_arg_builtin.aes b/test/contracts/code_errors/unapplied_named_arg_builtin.aes new file mode 100644 index 0000000..9b0a5ce --- /dev/null +++ b/test/contracts/code_errors/unapplied_named_arg_builtin.aes @@ -0,0 +1,5 @@ +contract UnappliedNamedArgBuiltin = + // Allowed in FATE, but not AEVM + stateful entrypoint main(s) = + let reg = Oracle.register + reg(signature = s, Contract.address, 100, RelativeTTL(100)) : oracle(int, int) diff --git a/test/contracts/unapplied_builtins.aes b/test/contracts/unapplied_builtins.aes new file mode 100644 index 0000000..6055a87 --- /dev/null +++ b/test/contracts/unapplied_builtins.aes @@ -0,0 +1,63 @@ +// Builtins without named arguments can appear unapplied in both AEVM and FATE. +// Named argument builtins are: +// Oracle.register +// Oracle.respond +// AENS.preclaim +// AENS.claim +// AENS.transfer +// AENS.revoke +// Oracle.extend +contract UnappliedBuiltins = + entrypoint main() = () + type o = oracle(int, int) + type t = list(int * string) + type m = map(int, int) + datatype event = Event(int) + stateful function chain_spend() = Chain.spend + function chain_event() = Chain.event + function chain_balance() = Chain.balance + function chain_block_hash() = Chain.block_hash + function call_gas_left() = Call.gas_left + function b_abort() = abort + function b_require() = require + function oracle_query_fee() = Oracle.query_fee + stateful function oracle_query() = Oracle.query : (o, _, _, _, _) => _ + function oracle_get_question() = Oracle.get_question : (o, _) => _ + function oracle_get_answer() = Oracle.get_answer : (o, _) => _ + function oracle_check() = Oracle.check : o => _ + function oracle_check_query() = Oracle.check_query : (o, _) => _ + function aens_resolve() = AENS.resolve : (_, _) => option(string) + function map_lookup() = Map.lookup : (_, m) => _ + function map_lookup_default() = Map.lookup_default : (_, m, _) => _ + function map_member() = Map.member : (_, m) => _ + function map_size() = Map.size : m => _ + function map_delete() = Map.delete : (_, m) => _ + function map_from_list() = Map.from_list : _ => m + function map_to_list() = Map.to_list : m => _ + function crypto_verify_sig() = Crypto.verify_sig + function crypto_verify_sig_secp256k1() = Crypto.verify_sig_secp256k1 + function crypto_ecverify_secp256k1() = Crypto.ecverify_secp256k1 + function crypto_ecrecover_secp256k1() = Crypto.ecrecover_secp256k1 + function crypto_sha3() = Crypto.sha3 : t => _ + function crypto_sha256() = Crypto.sha256 : t => _ + function crypto_blake2b() = Crypto.blake2b : t => _ + function string_sha256() = String.sha256 + function string_blake2b() = String.blake2b + function string_length() = String.length + function string_concat() = String.concat + function string_sha3() = String.sha3 + function bits_test() = Bits.test + function bits_set() = Bits.set + function bits_clear() = Bits.clear + function bits_union() = Bits.union + function bits_intersection() = Bits.intersection + function bits_difference() = Bits.difference + function bits_sum() = Bits.sum + function int_to_str() = Int.to_str + function address_to_str() = Address.to_str + function address_is_oracle() = Address.is_oracle + function address_is_contract() = Address.is_contract + function address_is_payable() = Address.is_payable + function bytes_to_int() = Bytes.to_int : bytes(10) => int + function bytes_to_str() = Bytes.to_str : bytes(99) => string +