From 7c291158c2c48052467816fd5f2b563c214ac9df Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Wed, 6 Nov 2019 11:08:18 -0800 Subject: [PATCH] Finish balance operator and add test for CameLIGO --- src/passes/operators/operators.ml | 2 ++ src/test/contracts/balance_constant.mligo | 17 +++++++++++++++++ src/test/integration_tests.ml | 7 +++++++ 3 files changed, 26 insertions(+) create mode 100644 src/test/contracts/balance_constant.mligo diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 04db39706..ac4d68bfc 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -751,6 +751,7 @@ module Typer = struct sender ; source ; unit ; + balance ; amount ; transaction ; get_contract ; @@ -827,6 +828,7 @@ module Compiler = struct ("ABS" , simple_unary @@ prim I_ABS) ; ("CONS" , simple_binary @@ prim I_CONS) ; ("UNIT" , simple_constant @@ prim I_UNIT) ; + ("BALANCE" , simple_constant @@ prim I_BALANCE) ; ("AMOUNT" , simple_constant @@ prim I_AMOUNT) ; ("ADDRESS" , simple_constant @@ prim I_ADDRESS) ; ("NOW" , simple_constant @@ prim I_NOW) ; diff --git a/src/test/contracts/balance_constant.mligo b/src/test/contracts/balance_constant.mligo new file mode 100644 index 000000000..8ac584a40 --- /dev/null +++ b/src/test/contracts/balance_constant.mligo @@ -0,0 +1,17 @@ +(** + +This test makes sure that the balance is accessible in CameLIGO. +It's there to detect a regression of: https://gitlab.com/ligolang/ligo/issues/61 + +Which results in this error when you attempt to compile this contract: + +generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} + + +*) + +type storage = tez + +let main (p : unit) storage = + ([] : operation list), balance + diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index f670f11c6..a971527aa 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1150,6 +1150,12 @@ let website2_mligo () : unit result = e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in expect_eq_n program "main" make_input make_expected +let balance_constant () : unit result = + let%bind program = mtype_file "./contracts/balance_constant.mligo" in + let input = e_tuple [e_unit () ; e_mutez 0] in + let expected = e_tuple [e_list []; e_mutez 4000000000000] in + expect_eq program "main" input expected + let main = test_suite "Integration (End to End)" [ test "type alias" type_alias ; test "function" function_ ; @@ -1230,4 +1236,5 @@ let main = test_suite "Integration (End to End)" [ test "website1 ligo" website1_ligo ; test "website2 ligo" website2_ligo ; test "website2 (mligo)" website2_mligo ; + test "balance constant (mligo)" balance_constant ; ]