From a77261c1d6667dd3d57320618f3f9788c58e9259 Mon Sep 17 00:00:00 2001 From: radrow Date: Tue, 11 May 2021 14:19:59 +0200 Subject: [PATCH] Cleanup --- src/aeso_ast_to_fcode.erl | 5 +++-- test/aeso_compiler_tests.erl | 4 ++-- test/contracts/create.aes | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 test/contracts/create.aes diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 9d596d4..c51cce5 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -327,12 +327,12 @@ to_fcode(Env, [{Contract, Attrs, Con = {con, _, Name}, Decls}|Rest]) when ?IS_CONTRACT_HEAD(Contract) -> case Contract =:= contract_interface of false -> - #{ builtins := Builtins } = Env, ConEnv = Env#{ context => {main_contract, Name}, builtins => Builtins#{[Name, "state"] => {get_state, none}, [Name, "put"] => {set_state, 1}, [Name, "Chain", "event"] => {chain_event, 1}} }, + #{ functions := PrevFuns } = ConEnv, #{ functions := Funs } = Env1 = decls_to_fcode(ConEnv, Decls), StateType = lookup_type(Env1, [Name, "state"], [], {tuple, []}), @@ -350,7 +350,8 @@ to_fcode(Env, [{Contract, Attrs, Con = {con, _, Name}, Decls}|Rest]) contract_main -> Rest = [], {Env1, ConFcode}; contract_child -> Env2 = add_child_con(Env1, Name, ConFcode), - to_fcode(Env2, Rest) + Env3 = Env2#{ functions := PrevFuns }, + to_fcode(Env3, Rest) end; true -> Env1 = decls_to_fcode(Env#{ context => {abstract_contract, Con} }, Decls), diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index d51be87..2691b03 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -26,14 +26,14 @@ run_test(Test) -> simple_compile_test_() -> [ {"Testing the " ++ ContractName ++ " contract with the " ++ atom_to_list(Backend) ++ " backend", fun() -> - case compile(Backend, ContractName, [pp_assembler]) of + case compile(Backend, ContractName) of #{byte_code := ByteCode, contract_source := _, type_info := _} when Backend == aevm -> ?assertMatch(Code when is_binary(Code), ByteCode); #{fate_code := Code} when Backend == fate -> Code1 = aeb_fate_code:deserialize(aeb_fate_code:serialize(Code)), - ?assertMatch({X, X}, {Code1, Code}), error(xd); + ?assertMatch({X, X}, {Code1, Code}); ErrBin -> io:format("\n~s", [ErrBin]), error(ErrBin) diff --git a/test/contracts/create.aes b/test/contracts/create.aes new file mode 100644 index 0000000..5886b20 --- /dev/null +++ b/test/contracts/create.aes @@ -0,0 +1,28 @@ +contract IntegerAdder = + entrypoint init() = () + entrypoint addIntegers(x, y) = x + y + +contract IntegerAdderHolder = + type state = IntegerAdder + stateful entrypoint init() = Chain.create() : IntegerAdder + entrypoint get() = state + +contract IntegerAdderFactory = + entrypoint init() = () + stateful entrypoint new() = + let i = Chain.create() : IntegerAdderHolder + i.get() + +payable contract ValueAdder = + entrypoint init() = () + stateful entrypoint addValue(x) = + let integerAdderFactory = Chain.create() + let adder = integerAdderFactory.new() + adder.addIntegers(x, Contract.balance) + +main contract EnterpriseContract = + entrypoint init() = () + stateful payable entrypoint increaseByThree(x) = + require(Call.value >= 3, "Price for addition = 3AEtto, insufficient funds") + let threeAdder = Chain.create(value = 3) + threeAdder.addValue(x)