diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 1e7b64778..d570c96ef 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -7,7 +7,7 @@ let bad_contract basename = let%expect_test _ = run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ; - [%expect {| 1747 bytes |}] ; + [%expect {| 1870 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ; [%expect {| 1324 bytes |}] ; @@ -16,7 +16,7 @@ let%expect_test _ = [%expect {| 3231 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ; - [%expect {| 642 bytes |}] ; + [%expect {| 589 bytes |}] ; run_ligo_good [ "compile-parameter" ; contract "coase.ligo" ; "main" ; "Buy_single (record card_to_buy = 1n end)" ] ; [%expect {| (Left (Left 1)) |}] ; @@ -86,7 +86,9 @@ let%expect_test _ = SWAP ; DIP { DUP ; CAR ; CAR } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "buy_single: No card pattern." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; CAR ; DIP { DUP ; CDR ; PUSH nat 1 ; ADD } ; @@ -159,7 +161,9 @@ let%expect_test _ = SWAP ; DIP { DUP ; CAR ; CDR } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "sell_single: No card." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; CAR ; SENDER ; @@ -173,7 +177,9 @@ let%expect_test _ = CDR ; DIP { DIP 2 { DUP } ; DIG 2 ; CAR ; CAR } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "sell_single: No card pattern." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; DIP { DUP } ; SWAP ; @@ -209,7 +215,9 @@ let%expect_test _ = MUL ; SENDER ; CONTRACT unit ; - IF_NONE { PUSH string "bad address for get_contract" ; FAILWITH } {} ; + IF_NONE + { PUSH string "sell_single: No contract." ; FAILWITH } + { DUP ; DIP { DROP } } ; DIP { DUP } ; SWAP ; DIP { DUP } ; @@ -246,7 +254,9 @@ let%expect_test _ = CAR ; DIP { DUP } ; GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_NONE + { PUSH string "transfer_single: No card." ; FAILWITH } + { DUP ; DIP { DROP } } ; DUP ; CAR ; SENDER ; @@ -938,40 +948,27 @@ let%expect_test _ = run_ligo_good [ "compile-contract" ; contract "vote.mligo" ; "main" ] ; [%expect {| { parameter - (or (pair %init - (pair (timestamp %beginning_time) (timestamp %finish_time)) - (string %title)) - (string %vote)) ; + (or (pair %reset (pair (timestamp %finish_time) (timestamp %start_time)) (string %title)) + (or %vote (unit %nay) (unit %yea))) ; storage - (pair (pair (pair (timestamp %beginning_time) (map %candidates string int)) - (pair (timestamp %finish_time) (string %title))) - (set %voters address)) ; + (pair (pair (pair (timestamp %finish_time) (nat %nay)) + (pair (timestamp %start_time) (string %title))) + (pair (set %voters address) (nat %yea))) ; code { DUP ; + DUP ; CAR ; IF_LEFT { DUP ; - DIP { DIP { DUP } ; SWAP ; CDR } ; - PAIR ; DUP ; CAR ; CAR ; - CAR ; - DIP { PUSH int 0 ; - SOME ; - DIP { PUSH int 0 ; - SOME ; - EMPTY_MAP string int ; - SWAP ; - PUSH string "Yes" ; - UPDATE } ; - PUSH string "No" ; - UPDATE } ; - PAIR ; - DIP { DUP ; CAR ; CAR ; CDR ; DIP { DUP ; CAR ; CDR } ; PAIR } ; - PAIR ; - EMPTY_SET address ; + PUSH nat 0 ; SWAP ; PAIR ; + DIP { DUP ; CAR ; CDR ; DIP { DUP ; CDR } ; PAIR } ; + PAIR ; + DIP { PUSH nat 0 ; EMPTY_SET address ; PAIR } ; + PAIR ; NIL operation ; PAIR ; DIP { DROP 2 } } @@ -979,41 +976,56 @@ let%expect_test _ = DIP { DIP { DUP } ; SWAP ; CDR } ; PAIR ; DUP ; + CDR ; + DIP { DUP } ; + SWAP ; CAR ; - DIP { DUP ; CDR ; CAR ; CAR ; CDR } ; - GET ; - IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; + IF_LEFT + { DIP { DUP } ; + SWAP ; + DIP 2 { DUP } ; + DIG 2 ; + CAR ; + CAR ; + CDR ; + PUSH nat 1 ; + ADD ; + DIP { DUP ; CDR ; SWAP ; CAR ; DUP ; CDR ; SWAP ; CAR ; CAR } ; + SWAP ; + PAIR ; + PAIR ; + PAIR ; + DIP { DROP } } + { DIP { DUP } ; + SWAP ; + DIP 2 { DUP } ; + DIG 2 ; + CDR ; + CDR ; + PUSH nat 1 ; + ADD ; + DIP { DUP ; CAR ; SWAP ; CDR ; CAR } ; + SWAP ; + PAIR ; + SWAP ; + PAIR ; + DIP { DROP } } ; + DUP ; DIP { DUP } ; SWAP ; CDR ; CAR ; - CAR ; - CAR ; - DIP { DIP { DUP } ; - SWAP ; - CAR ; - DIP { DUP ; - PUSH int 1 ; - ADD ; - SOME ; - DIP { DIP { DUP } ; SWAP ; CDR ; CAR ; CAR ; CDR } } ; - UPDATE } ; + PUSH bool True ; + SENDER ; + UPDATE ; + DIP { DUP ; CAR ; SWAP ; CDR ; CDR } ; PAIR ; - DIP { DIP { DUP } ; - SWAP ; - CDR ; - CAR ; - CDR ; - CAR ; - DIP { DIP { DUP } ; SWAP ; CDR ; CAR ; CDR ; CDR } ; - PAIR } ; - PAIR ; - DIP { DIP { DUP } ; SWAP ; CDR ; CDR ; PUSH bool True ; SENDER ; UPDATE } ; + SWAP ; PAIR ; NIL operation ; PAIR ; - DIP { DROP 3 } } ; - DIP { DROP } } } |}] + DIP { DROP 4 } } ; + DIP { DROP 2 } } } |}] let%expect_test _ = run_ligo_good [ "compile-contract" ; contract "implicit.mligo" ; "main" ] ; @@ -1054,7 +1066,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; contract "bad_address_format.religo" ; "main" ] ; [%expect {| - ligo: in file "bad_address_format.religo", line 2, characters 25-47. Badly formatted literal: @"KT1badaddr" {"location":"in file \"bad_address_format.religo\", line 2, characters 25-47"} + ligo: in file "bad_address_format.religo", line 2, characters 26-48. Badly formatted literal: @"KT1badaddr" {"location":"in file \"bad_address_format.religo\", line 2, characters 26-48"} If you're not sure how to fix this error, you can @@ -1149,29 +1161,29 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#756 = #P in let p = rhs#756.0 in let s = rhs#756.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} +ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * string ):Some(( nat * string ))) : None return let rhs#808 = #P in let p = rhs#808.0 in let s = rhs#808.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} - If you're not sure how to fix this error, you can - do one of the following: + If you're not sure how to fix this error, you can + do one of the following: - * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ - * Ask a question on our Discord: https://discord.gg/9rhYaEt - * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new - * Check the changelog by running 'ligo changelog' |}] ; +* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ +* Ask a question on our Discord: https://discord.gg/9rhYaEt +* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new +* Check the changelog by running 'ligo changelog' |}] ; run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ; [%expect {| - ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#759 = #P in let p = rhs#759.0 in let s = rhs#759.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} +ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P : ( nat * int ):Some(( nat * int ))) : None return let rhs#811 = #P in let p = rhs#811.0 in let s = rhs#811.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} - If you're not sure how to fix this error, you can - do one of the following: + If you're not sure how to fix this error, you can + do one of the following: - * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ - * Ask a question on our Discord: https://discord.gg/9rhYaEt - * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new - * Check the changelog by running 'ligo changelog' |}] ; +* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ +* Ask a question on our Discord: https://discord.gg/9rhYaEt +* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new +* Check the changelog by running 'ligo changelog' |}] ; run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_no_inline.mligo" ; "main" ] ; [%expect {| diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 3537e1d89..9fd521087 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -68,31 +68,30 @@ module Simplify = struct (* Tezos module (ex-Michelson) *) | "Tezos.chain_id" -> ok C_CHAIN_ID - | "chain_id" -> ok C_CHAIN_ID (* Deprecated *) - | "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *) + | "chain_id" -> ok C_CHAIN_ID (* Deprecated *) + | "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *) | "Tezos.balance" -> ok C_BALANCE - | "balance" -> ok C_BALANCE (* Deprecated *) + | "balance" -> ok C_BALANCE (* Deprecated *) | "Tezos.now" -> ok C_NOW - | "now" -> ok C_NOW (* Deprecated *) + | "now" -> ok C_NOW (* Deprecated *) | "Tezos.amount" -> ok C_AMOUNT - | "amount" -> ok C_AMOUNT (* Deprecated *) + | "amount" -> ok C_AMOUNT (* Deprecated *) | "Tezos.sender" -> ok C_SENDER - | "sender" -> ok C_SENDER (* Deprecated *) + | "sender" -> ok C_SENDER (* Deprecated *) | "Tezos.address" -> ok C_ADDRESS - | "address" -> ok C_ADDRESS (* Deprecated *) + | "address" -> ok C_ADDRESS (* Deprecated *) | "Tezos.self_address" -> ok C_SELF_ADDRESS - | "self_address" -> ok C_SELF_ADDRESS (* Deprecated *) + | "self_address" -> ok C_SELF_ADDRESS (* Deprecated *) | "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT - | "implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) + | "implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) | "Tezos.source" -> ok C_SOURCE - | "source" -> ok C_SOURCE (* Deprecated *) + | "source" -> ok C_SOURCE (* Deprecated *) | "Tezos.failwith" -> ok C_FAILWITH - | "failwith" -> ok C_FAILWITH + | "failwith" -> ok C_FAILWITH | "Tezos.create_contract" -> ok C_CREATE_CONTRACT - - | "Tezos.transaction" -> ok C_CALL + | "Tezos.transaction" -> ok C_CALL | "transaction" -> ok C_CALL (* Deprecated *) - | "Tezos.set_delegate" -> ok C_SET_DELEGATE + | "Tezos.set_delegate" -> ok C_SET_DELEGATE | "set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) | "get_contract" -> ok C_CONTRACT (* Deprecated *) | "Tezos.get_contract_opt" -> ok C_CONTRACT_OPT @@ -145,7 +144,7 @@ module Simplify = struct | "Bytes.unpack" -> ok C_BYTES_UNPACK | "bytes_unpack" -> ok C_BYTES_UNPACK (* Deprecated *) | "Bytes.length" -> ok C_SIZE - | "Bytes.size" -> ok C_SIZE + | "Bytes.size" -> ok C_SIZE (* Deprecated *) | "bytes_concat" -> ok C_CONCAT (* Deprecated *) | "Bytes.concat" -> ok C_CONCAT | "Bytes.slice" -> ok C_SLICE @@ -166,7 +165,8 @@ module Simplify = struct (* Set module *) - | "Set.size" -> ok C_SIZE + | "Set.cardinal" -> ok C_SIZE + | "Set.size" -> ok C_SIZE (* Deprecated *) | "set_size" -> ok C_SIZE (* Deprecated *) | "set_empty" -> ok C_SET_EMPTY (* Deprecated *) | "Set.mem" -> ok C_SET_MEM @@ -326,9 +326,9 @@ module Simplify = struct | "Bytes.pack" -> ok C_BYTES_PACK | "Bytes.unpack" -> ok C_BYTES_UNPACK | "Bytes.length" -> ok C_SIZE - | "Bytes.size" -> ok C_SIZE + | "Bytes.size" -> ok C_SIZE (* Deprecated *) | "Bytes.concat" -> ok C_CONCAT - | "Bytes.slice" -> ok C_SLICE + | "Bytes.slice" -> ok C_SLICE (* Deprecated *) | "Bytes.sub" -> ok C_SLICE (* List module *) @@ -341,14 +341,15 @@ module Simplify = struct (* Set module *) - | "Set.mem" -> ok C_SET_MEM - | "Set.iter" -> ok C_SET_ITER - | "Set.empty" -> ok C_SET_EMPTY - | "Set.literal" -> ok C_SET_LITERAL - | "Set.add" -> ok C_SET_ADD - | "Set.remove" -> ok C_SET_REMOVE - | "Set.fold" -> ok C_SET_FOLD - | "Set.size" -> ok C_SIZE + | "Set.mem" -> ok C_SET_MEM + | "Set.iter" -> ok C_SET_ITER + | "Set.empty" -> ok C_SET_EMPTY + | "Set.literal" -> ok C_SET_LITERAL + | "Set.add" -> ok C_SET_ADD + | "Set.remove" -> ok C_SET_REMOVE + | "Set.fold" -> ok C_SET_FOLD + | "Set.size" -> ok C_SIZE (* Deprecated *) + | "Set.cardinal" -> ok C_SIZE (* Map module *) diff --git a/src/test/contracts/address.ligo b/src/test/contracts/address.ligo index 59d5bff4c..ae863ac81 100644 --- a/src/test/contracts/address.ligo +++ b/src/test/contracts/address.ligo @@ -1,5 +1,3 @@ -// function main (const c : contract (unit)) : address is address (c) - function main (const p : key_hash) : address is block { - const c : contract (unit) = implicit_account (p); -} with address (c) \ No newline at end of file + const c : contract (unit) = Tezos.implicit_account (p); +} with Tezos.address (c) diff --git a/src/test/contracts/address.mligo b/src/test/contracts/address.mligo index 3651ea223..e4d873bbe 100644 --- a/src/test/contracts/address.mligo +++ b/src/test/contracts/address.mligo @@ -1,3 +1,3 @@ let main (p : key_hash) = - let c : unit contract = Current.implicit_account p in - Current.address c \ No newline at end of file + let c : unit contract = Tezos.implicit_account p + in Tezos.address c diff --git a/src/test/contracts/address.religo b/src/test/contracts/address.religo index df1742ce1..7a5222e04 100644 --- a/src/test/contracts/address.religo +++ b/src/test/contracts/address.religo @@ -1,4 +1,4 @@ let main = (p : key_hash) : address => { - let c : contract(unit) = Current.implicit_account(p) ; - Current.address(c) ; + let c : contract (unit) = Tezos.implicit_account (p); + Tezos.address(c); }; diff --git a/src/test/contracts/amount.ligo b/src/test/contracts/amount.ligo index 8d4961be8..0bad23a72 100644 --- a/src/test/contracts/amount.ligo +++ b/src/test/contracts/amount.ligo @@ -1,8 +1,5 @@ -function check (const p: unit) : int is - begin +function check (const p : unit) : int is + block { var result : int := 0; - if amount = 100tz then - result := 42 - else - result := 0 - end with result + if amount = 100tez then result := 42 else result := 0 + } with result diff --git a/src/test/contracts/amount.mligo b/src/test/contracts/amount.mligo index 8e31e2d0c..483436507 100644 --- a/src/test/contracts/amount.mligo +++ b/src/test/contracts/amount.mligo @@ -1 +1 @@ -let check_ (p: unit) : int = if Current.amount = 100tz then 42 else 0 +let check_ (p : unit) : int = if Tezos.amount = 100tez then 42 else 0 diff --git a/src/test/contracts/amount.religo b/src/test/contracts/amount.religo index 9d19491b8..f33527daa 100644 --- a/src/test/contracts/amount.religo +++ b/src/test/contracts/amount.religo @@ -1,7 +1,2 @@ -let check_ = (p: unit) : int => - if (Current.amount == 100tz) { - 42; - } - else { - 0; - }; +let check_ = (p : unit) : int => + if (Tezos.amount == 100tez) { 42; } else { 0; }; diff --git a/src/test/contracts/arithmetic.ligo b/src/test/contracts/arithmetic.ligo index de3dc14ae..b9bfca273 100644 --- a/src/test/contracts/arithmetic.ligo +++ b/src/test/contracts/arithmetic.ligo @@ -1,15 +1,7 @@ -// Test PascaLIGO arithmetic operators - -function mod_op (const n : int) : nat is n mod 42 - -function plus_op (const n : int) : int is n + 42 - +function mod_op (const n : int) : nat is n mod 42 +function plus_op (const n : int) : int is n + 42 function minus_op (const n : int) : int is n - 42 - function times_op (const n : int) : int is n * 42 - -function div_op (const n : int) : int is n / 2 - -function int_op (const n : nat) : int is int (n) - -function neg_op (const n : int) : int is -n +function div_op (const n : int) : int is n / 2 +function int_op (const n : nat) : int is int (n) +function neg_op (const n : int) : int is -n diff --git a/src/test/contracts/arithmetic.mligo b/src/test/contracts/arithmetic.mligo index e3bb8ba07..3225027ab 100644 --- a/src/test/contracts/arithmetic.mligo +++ b/src/test/contracts/arithmetic.mligo @@ -1,30 +1,8 @@ -// Test CameLIGO arithmetic operators - -let mod_op (n : int) : nat = - n mod 42 - -let plus_op (n : int) : int = - n + 42 - -let minus_op (n : int) : int = - n - 42 - -let times_op (n : int) : int = - n * 42 - -let div_op (n : int) : int = - n / 2 - -(* TODO (?): Support conversion from nat to int and back - -let int_op (n : nat) : int = - Int n - -*) - -let neg_op (n : int) : int = - -n - -let foo (n : int) : int = n + 10 - -let neg_op_2 (b: int) : int = -(foo b) +let mod_op (n : int) : nat = n mod 42 +let plus_op (n : int) : int = n + 42 +let minus_op (n : int) : int = n - 42 +let times_op (n : int) : int = n * 42 +let div_op (n : int) : int = n / 2 +let neg_op (n : int) : int = -n +let foo (n : int) : int = n + 10 +let neg_op_2 (b : int) : int = -(foo b) diff --git a/src/test/contracts/arithmetic.religo b/src/test/contracts/arithmetic.religo index 6d7fc5d29..c598e125d 100644 --- a/src/test/contracts/arithmetic.religo +++ b/src/test/contracts/arithmetic.religo @@ -1,24 +1,10 @@ /* Test ReasonLIGO arithmetic operators */ -let mod_op = (n: int): nat => n mod 42; - -let plus_op = (n: int): int => n + 42; - -let minus_op = (n: int): int => n - 42; - -let times_op = (n: int): int => n * 42; - -let div_op = (n: int): int => n / 2; - -/* TODO (?): Support conversion from nat to int and back - - let int_op (n : nat) : int = - Int n - - */ - -let neg_op = (n: int): int => - n; - -let foo = (n: int): int => n + 10; - -let neg_op_2 = (b: int): int => - foo(b); +let mod_op = (n : int) : nat => n mod 42; +let plus_op = (n : int) : int => n + 42; +let minus_op = (n : int) : int => n - 42; +let times_op = (n : int) : int => n * 42; +let div_op = (n : int) : int => n / 2; +let neg_op = (n : int): int => - n; +let foo = (n : int): int => n + 10; +let neg_op_2 = (b : int): int => -foo(b); diff --git a/src/test/contracts/assert.mligo b/src/test/contracts/assert.mligo index 143f7066f..41785c58d 100644 --- a/src/test/contracts/assert.mligo +++ b/src/test/contracts/assert.mligo @@ -1,3 +1,3 @@ -let main (p, s: bool * unit) = +let main (p, s : bool * unit) = let u : unit = assert p in ([] : operation list), s diff --git a/src/test/contracts/assert.religo b/src/test/contracts/assert.religo index 26b9f0775..d35ee11e2 100644 --- a/src/test/contracts/assert.religo +++ b/src/test/contracts/assert.religo @@ -1,4 +1,4 @@ -let main = (p: bool, s: unit) => { - let u: unit = assert(p); - ([]: list(operation), s); +let main = (p, s : bool, unit) => { + let u : unit = assert (p); + ([]: list (operation), s); }; diff --git a/src/test/contracts/assign.ligo b/src/test/contracts/assign.ligo index 6c6de5351..b5181e2fd 100644 --- a/src/test/contracts/assign.ligo +++ b/src/test/contracts/assign.ligo @@ -1,4 +1 @@ -function main (const i : int) : int is - block { - i := i + 1 - } with i +function main (const i : int) : int is block {i := i + 1} with i diff --git a/src/test/contracts/attributes.mligo b/src/test/contracts/attributes.mligo index 8f582a725..d87f4e8e7 100644 --- a/src/test/contracts/attributes.mligo +++ b/src/test/contracts/attributes.mligo @@ -1,10 +1,7 @@ let x = 1 [@@inline] - -let foo (a: int): int = +let foo (a : int): int = (let test = 2 + a [@@inline] in test) [@@inline] - let y = 1 [@@inline][@@other] - -let bar (b: int): int = - let test = fun (z: int) -> 2 + b + z [@@inline][@@foo][@@bar] +let bar (b : int): int = + let test = fun (z : int) -> 2 + b + z [@@inline][@@foo][@@bar] in test b diff --git a/src/test/contracts/attributes.religo b/src/test/contracts/attributes.religo index 33062220f..d79928769 100644 --- a/src/test/contracts/attributes.religo +++ b/src/test/contracts/attributes.religo @@ -2,7 +2,7 @@ let x = 1; [@inline] -let foo = (a: int): int => { +let foo = (a : int) : int => { [@inline] let test = 2 + a; test; @@ -11,8 +11,8 @@ let foo = (a: int): int => { [@inline][@other] let y = 1; -let bar = (b: int): int => { +let bar = (b : int) : int => { [@inline][@foo][@bar] - let test = (z: int) => 2 + b + z; - test(b); + let test = (z : int) => 2 + b + z; + test (b); }; diff --git a/src/test/contracts/bad_address_format.religo b/src/test/contracts/bad_address_format.religo index c8668bc45..81f4739b7 100644 --- a/src/test/contracts/bad_address_format.religo +++ b/src/test/contracts/bad_address_format.religo @@ -1,3 +1,2 @@ -let main = (parameter: int, storage: address) => { - ([]:list(operation), "KT1badaddr" : address); -}; +let main = (parameter : int, storage : address) => + ([] : list (operation), "KT1badaddr" : address); diff --git a/src/test/contracts/bad_timestamp.ligo b/src/test/contracts/bad_timestamp.ligo index 8be6968e2..dff8f6f24 100644 --- a/src/test/contracts/bad_timestamp.ligo +++ b/src/test/contracts/bad_timestamp.ligo @@ -6,4 +6,4 @@ function main (const p : parameter; const s : storage) : return is block { var stamp : timestamp := ("badtimestamp" : timestamp) } - with ((nil: list(operation)), stamp) + with ((nil : list (operation)), stamp) diff --git a/src/test/contracts/balance_constant.ligo b/src/test/contracts/balance_constant.ligo index 6a5af3fe4..b23ae23e6 100644 --- a/src/test/contracts/balance_constant.ligo +++ b/src/test/contracts/balance_constant.ligo @@ -9,4 +9,4 @@ type storage is tez type return is list (operation) * storage function main (const param : parameter; const store: storage) : return is - ((nil : list (operation)), balance) + ((nil : list (operation)), Tezos.balance) diff --git a/src/test/contracts/balance_constant.mligo b/src/test/contracts/balance_constant.mligo index c364d2bce..53cba0c29 100644 --- a/src/test/contracts/balance_constant.mligo +++ b/src/test/contracts/balance_constant.mligo @@ -1,17 +1,18 @@ -(** - +(* 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: +It is 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 parameter = unit type storage = tez +type return = operation list * storage -let main (p, s : unit * storage) = - ([] : operation list), balance - +let main (p, s : parameter * storage) : return = + ([] : operation list), Tezos.balance diff --git a/src/test/contracts/balance_constant.religo b/src/test/contracts/balance_constant.religo index 52373431f..1d136052b 100644 --- a/src/test/contracts/balance_constant.religo +++ b/src/test/contracts/balance_constant.religo @@ -12,6 +12,7 @@ generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} type storage = tez; -let main2 = (p: unit, s: storage) => ([]: list(operation), balance); +let main2 = (p : unit, storage) => + ([]: list (operation), Tezos.balance); -let main = (x: (unit, storage)) => main2(x[0],x[1]); +let main = (x : (unit, storage)) => main2 (x[0], x[1]); diff --git a/src/test/contracts/big_map.ligo b/src/test/contracts/big_map.ligo index 9b8364ac3..b89fb8f05 100644 --- a/src/test/contracts/big_map.ligo +++ b/src/test/contracts/big_map.ligo @@ -8,7 +8,7 @@ function main (const p : parameter; const s : storage) : return is toto := s.0[23]; s.0[2] := 444 } - with ((nil: list(operation)), s) + with ((nil : list (operation)), s) type foo is big_map (int, int) @@ -16,14 +16,12 @@ function set_ (var n : int; var m : foo) : foo is block { m[23] := n } with m -function add (var n : int ; var m : foo) : foo is set_(n,m) +function add (var n : int ; var m : foo) : foo is set_ (n,m) function rm (var m : foo) : foo is block { remove 42 from map m } with m -function gf (const m : foo) : int is get_force (23, m) - function get (const m : foo) : option (int) is m[42] const empty_big_map : big_map (int,int) = big_map [] diff --git a/src/test/contracts/big_map.mligo b/src/test/contracts/big_map.mligo index 35a173f82..270826e51 100644 --- a/src/test/contracts/big_map.mligo +++ b/src/test/contracts/big_map.mligo @@ -1,23 +1,18 @@ type foo = (int, int) big_map let set_ (n, m: int * foo) : foo = Big_map.update 23 (Some n) m - -let add (n,m : int * foo) : foo = Big_map.add 23 n m +let add (n, m : int * foo) : foo = Big_map.add 23 n m let rm (m : foo) : foo = Big_map.remove 42 m - let gf (m : foo) : int = Big_map.find 23 m -let get (m: foo): int option = Big_map.find_opt 42 m +let get (m : foo): int option = Big_map.find_opt 42 m let empty_map : foo = Big_map.empty -let map1 : foo = Big_map.literal - [ (23 , 0) ; (42, 0) ] - -let map1 : foo = Big_map.literal - [ (23 , 0) ; (42, 0) ] +let map1 : foo = Big_map.literal [(23,0); (42,0)] +let map1 : foo = Big_map.literal [(23,0); (42,0)] let mutimaps (m : foo) (n : foo) : foo = - let bar : foo = Big_map.update 42 (Some 0) m in - Big_map.update 42 (get bar) n + let bar : foo = Big_map.update 42 (Some 0) m + in Big_map.update 42 (get bar) n diff --git a/src/test/contracts/big_map.religo b/src/test/contracts/big_map.religo index 92f5431c8..44d64c92e 100644 --- a/src/test/contracts/big_map.religo +++ b/src/test/contracts/big_map.religo @@ -1,24 +1,22 @@ type foo = big_map(int, int); -let set2 = (n: int, m: foo): foo => Big_map.update(23, Some(n), m); +let set2 = (n : int, m : foo) : foo => Big_map.update (23, Some (n), m); -let set_ = (x: (int, foo)): foo => set2(x[0], x[1]); +let set_ = (x : (int, foo)) : foo => set2 (x[0], x[1]); -let add = ((n,m): (int, foo)): foo => Big_map.add(23, n, m); +let add = ((n,m) : (int, foo)) : foo => Big_map.add (23, n, m); -let rm = (m: foo): foo => Big_map.remove(42, m); +let rm = (m : foo) : foo => Big_map.remove (42, m); -let gf = (m: foo): int => Big_map.find(23, m); +let gf = (m : foo) : int => Big_map.find (23, m); -let get = (m: foo): option(int) => Big_map.find_opt(42, m); +let get = (m : foo) : option (int) => Big_map.find_opt (42, m); -let empty_map: foo = Big_map.empty; +let empty_map : foo = Big_map.empty; -let map1: foo = Big_map.literal([(23, 0), (42, 0)]); - -let map1: foo = Big_map.literal([(23, 0), (42, 0)]); +let map1 : foo = Big_map.literal ([(23,0), (42,0)]); let mutimaps = (m: foo, n: foo): foo => { - let bar: foo = Big_map.update(42, Some(0), m); - Big_map.update(42, get(bar), n); + let bar : foo = Big_map.update (42, Some (0), m); + Big_map.update (42, get (bar), n); }; diff --git a/src/test/contracts/bitwise_arithmetic.mligo b/src/test/contracts/bitwise_arithmetic.mligo index d79cbe348..7cb38f439 100644 --- a/src/test/contracts/bitwise_arithmetic.mligo +++ b/src/test/contracts/bitwise_arithmetic.mligo @@ -1,7 +1,7 @@ (* Test CameLIGO bitwise operators *) -let or_op (n: nat) : nat = Bitwise.or n 4n -let and_op (n: nat) : nat = Bitwise.and n 7n -let xor_op (n: nat) : nat = Bitwise.xor n 7n -let lsl_op (n: nat) : nat = Bitwise.shift_left n 7n -let lsr_op (n: nat) : nat = Bitwise.shift_right n 7n +let or_op (n : nat) : nat = Bitwise.or n 4n +let and_op (n : nat) : nat = Bitwise.and n 7n +let xor_op (n : nat) : nat = Bitwise.xor n 7n +let lsl_op (n : nat) : nat = Bitwise.shift_left n 7n +let lsr_op (n : nat) : nat = Bitwise.shift_right n 7n diff --git a/src/test/contracts/boolean_operators.ligo b/src/test/contracts/boolean_operators.ligo index 122894d25..d19e5ad72 100644 --- a/src/test/contracts/boolean_operators.ligo +++ b/src/test/contracts/boolean_operators.ligo @@ -1,11 +1,5 @@ -// Test PascaLIGO boolean operators - -function or_true (const b : bool) : bool is b or True - -function or_false (const b : bool) : bool is b or False - -function and_true (const b : bool) : bool is b and True - +function or_true (const b : bool) : bool is b or True +function or_false (const b : bool) : bool is b or False +function and_true (const b : bool) : bool is b and True function and_false (const b : bool) : bool is b and False - -function not_bool (const b : bool) : bool is not b +function not_bool (const b : bool) : bool is not b diff --git a/src/test/contracts/boolean_operators.mligo b/src/test/contracts/boolean_operators.mligo index 7eb3cfd69..1c5b46a00 100644 --- a/src/test/contracts/boolean_operators.mligo +++ b/src/test/contracts/boolean_operators.mligo @@ -1,16 +1,7 @@ // Test CameLIGO boolean operators -let or_true (b : bool) : bool = - b || true - -let or_false (b : bool) : bool = - b || false - -let and_true (b : bool) : bool = - b && true - -let and_false (b : bool) : bool = - b && false - -let not_bool (b: bool) : bool = - not b +let or_true (b : bool) : bool = b || true +let or_false (b : bool) : bool = b || false +let and_true (b : bool) : bool = b && true +let and_false (b : bool) : bool = b && false +let not_bool (b : bool) : bool = not b diff --git a/src/test/contracts/boolean_operators.religo b/src/test/contracts/boolean_operators.religo index 8603380a7..acacfb198 100644 --- a/src/test/contracts/boolean_operators.religo +++ b/src/test/contracts/boolean_operators.religo @@ -1,11 +1,7 @@ // Test ReasonLIGO boolean operators -let or_true = (b: bool): bool => b || true; - -let or_false = (b: bool): bool => b || false; - -let and_true = (b: bool): bool => b && true; - -let and_false = (b: bool): bool => b && false; - -let not_bool = (b: bool): bool => !b; +let or_true = (b : bool) : bool => b || true; +let or_false = (b : bool) : bool => b || false; +let and_true = (b : bool) : bool => b && true; +let and_false = (b : bool) : bool => b && false; +let not_bool = (b : bool) : bool => !b; diff --git a/src/test/contracts/bytes_arithmetic.ligo b/src/test/contracts/bytes_arithmetic.ligo index 6d39dd4c9..820cf6fdc 100644 --- a/src/test/contracts/bytes_arithmetic.ligo +++ b/src/test/contracts/bytes_arithmetic.ligo @@ -1,5 +1,3 @@ -function concat_op (const s : bytes) : bytes is bytes_concat (s, 0x7070) - -function slice_op (const s : bytes) : bytes is bytes_slice (1n, 2n, s) - -function hasherman (const s : bytes) : bytes is sha_256 (s) +function concat_op (const s : bytes) : bytes is Bytes.concat (s, 0x7070) +function slice_op (const s : bytes) : bytes is Bytes.sub (1n, 2n, s) +function hasherman (const s : bytes) : bytes is Crypto.sha256 (s) diff --git a/src/test/contracts/bytes_arithmetic.mligo b/src/test/contracts/bytes_arithmetic.mligo index 4d71994a2..dbdc2a147 100644 --- a/src/test/contracts/bytes_arithmetic.mligo +++ b/src/test/contracts/bytes_arithmetic.mligo @@ -1,8 +1,3 @@ -let concat_op (s : bytes) : bytes = - Bytes.concat s 0x7070 - -let slice_op (s : bytes) : bytes = - Bytes.slice 1n 2n s - -let hasherman (s : bytes) : bytes = - Crypto.sha256 s +let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070 +let slice_op (s : bytes) : bytes = Bytes.sub 1n 2n s +let hasherman (s : bytes) : bytes = Crypto.sha256 s diff --git a/src/test/contracts/bytes_unpack.ligo b/src/test/contracts/bytes_unpack.ligo index e57ace2ab..feb76f806 100644 --- a/src/test/contracts/bytes_unpack.ligo +++ b/src/test/contracts/bytes_unpack.ligo @@ -1,11 +1,11 @@ function id_string (const p : string) : option (string) is block { - const packed : bytes = bytes_pack (p) -} with (bytes_unpack (packed) : option (string)) + const packed : bytes = Bytes.pack (p) +} with (Bytes.unpack (packed) : option (string)) function id_int (const p : int) : option (int) is block { - const packed : bytes = bytes_pack (p) -} with (bytes_unpack (packed) : option (int)) + const packed : bytes = Bytes.pack (p) +} with (Bytes.unpack (packed) : option (int)) function id_address (const p : address) : option (address) is block { - const packed : bytes = bytes_pack (p) -} with (bytes_unpack (packed) : option (address)) + const packed : bytes = Bytes.pack (p) +} with (Bytes.unpack (packed) : option (address)) diff --git a/src/test/contracts/bytes_unpack.mligo b/src/test/contracts/bytes_unpack.mligo index e33f09b47..56028af77 100644 --- a/src/test/contracts/bytes_unpack.mligo +++ b/src/test/contracts/bytes_unpack.mligo @@ -1,11 +1,11 @@ -let id_string (p: string) : string option = - let packed: bytes = Bytes.pack p in - ((Bytes.unpack packed): string option) +let id_string (p : string) : string option = + let packed : bytes = Bytes.pack p in + (Bytes.unpack packed : string option) -let id_int (p: int) : int option = - let packed: bytes = Bytes.pack p in - ((Bytes.unpack packed): int option) +let id_int (p : int) : int option = + let packed : bytes = Bytes.pack p in + (Bytes.unpack packed : int option) -let id_address (p: address) : address option = - let packed: bytes = Bytes.pack p in - ((Bytes.unpack packed): address option) +let id_address (p : address) : address option = + let packed : bytes = Bytes.pack p in + (Bytes.unpack packed : address option) diff --git a/src/test/contracts/bytes_unpack.religo b/src/test/contracts/bytes_unpack.religo index 86b291ecc..f8119e564 100644 --- a/src/test/contracts/bytes_unpack.religo +++ b/src/test/contracts/bytes_unpack.religo @@ -1,14 +1,14 @@ -let id_string = (p: string) : option(string) => { - let packed : bytes = Bytes.pack(p); - ((Bytes.unpack(packed)): option(string)); +let id_string = (p : string) : option(string) => { + let packed : bytes = Bytes.pack (p); + ((Bytes.unpack (packed)) : option (string)); }; -let id_int = (p: int) : option(int) => { - let packed: bytes = Bytes.pack(p); - ((Bytes.unpack(packed)): option(int)); +let id_int = (p : int) : option (int) => { + let packed : bytes = Bytes.pack (p); + ((Bytes.unpack (packed)) : option (int)); }; -let id_address = (p: address) : option(address) => { - let packed: bytes = Bytes.pack(p); - ((Bytes.unpack(packed)): option(address)); +let id_address = (p : address) : option (address) => { + let packed : bytes = Bytes.pack (p); + ((Bytes.unpack (packed)) : option (address)); }; diff --git a/src/test/contracts/chain_id.ligo b/src/test/contracts/chain_id.ligo index 353ba4a45..ad9f17395 100644 --- a/src/test/contracts/chain_id.ligo +++ b/src/test/contracts/chain_id.ligo @@ -1 +1 @@ -function chain_id (const tt : chain_id) : chain_id is get_chain_id +function chain_id (const tt : chain_id) : chain_id is Tezos.chain_id diff --git a/src/test/contracts/check_signature.ligo b/src/test/contracts/check_signature.ligo index 97de04bd2..83554433e 100644 --- a/src/test/contracts/check_signature.ligo +++ b/src/test/contracts/check_signature.ligo @@ -1,4 +1,4 @@ -function check_signature (const pk : key; +function check_signature (const pk : key; const signed : signature; - const msg: bytes) : bool -is crypto_check (pk, signed, msg) + const msg : bytes) : bool +is Crypto.check (pk, signed, msg) diff --git a/src/test/contracts/check_signature.mligo b/src/test/contracts/check_signature.mligo index ecd56eb4b..93218ee0f 100644 --- a/src/test/contracts/check_signature.mligo +++ b/src/test/contracts/check_signature.mligo @@ -1,2 +1,2 @@ -let check_signature (pk, signed, msg: key * signature * bytes) : bool = +let check_signature (pk, signed, msg : key * signature * bytes) : bool = Crypto.check pk signed msg diff --git a/src/test/contracts/check_signature.religo b/src/test/contracts/check_signature.religo index 9d2f266ce..992e693fd 100644 --- a/src/test/contracts/check_signature.religo +++ b/src/test/contracts/check_signature.religo @@ -1,4 +1,4 @@ -let check_signature = (param: (key, signature, bytes)) : bool => { +let check_signature = (param : (key, signature, bytes)) : bool => { let pk, signed, msg = param; - Crypto.check(pk, signed, msg); + Crypto.check (pk, signed, msg); }; diff --git a/src/test/contracts/closure.mligo b/src/test/contracts/closure.mligo index ee5f616ae..d849db1f0 100644 --- a/src/test/contracts/closure.mligo +++ b/src/test/contracts/closure.mligo @@ -1,9 +1,7 @@ -(* Test whether closures retain values in CameLIGO *) +(* Test whether closures capture variables in CameLIGO *) -let test (k: int) : int = - let j: int = k + 5 in - let close: (int -> int) = - fun (i: int) -> i + j - in - let j: int = 20 in (* Shadow original variable to see if value close'd *) - close 20 +let test (k : int) : int = + let j : int = k + 5 in + let close : int -> int = fun (i : int) -> i + j in + let j : int = 20 (* Shadow original variable *) + in close 20 diff --git a/src/test/contracts/closure.religo b/src/test/contracts/closure.religo index a17ddb728..72eaac5da 100644 --- a/src/test/contracts/closure.religo +++ b/src/test/contracts/closure.religo @@ -1,9 +1,9 @@ /* Test whether closures retain values in ReasonLIGO */ -let test = (k: int): int => { - let j: int = k + 5; - let close: (int => int) = (i: int) => i + j; +let test = (k : int) : int => { + let j : int = k + 5; + let close : (int => int) = (i : int) => i + j; - let j: int = 20; /* Shadow original variable to see if value close'd */ - close(20); + let j : int = 20; /* Shadow original variable */ + close (20); }; diff --git a/src/test/contracts/coase.ligo b/src/test/contracts/coase.ligo index 5f5b00644..5897b8686 100644 --- a/src/test/contracts/coase.ligo +++ b/src/test/contracts/coase.ligo @@ -45,27 +45,38 @@ type parameter is | Transfer_single of action_transfer_single function transfer_single (const action : action_transfer_single; - const s : storage) : return is block { + const s : storage) : return is + block { const cards : cards = s.cards; - const card : card = get_force (action.card_to_transfer, cards); + const card : card = + case cards[action.card_to_transfer] of + Some (card) -> card + | None -> (failwith ("transfer_single: No card.") : card) + end; if card.card_owner =/= sender then failwith ("This card doesn't belong to you") else skip; card.card_owner := action.destination; cards[action.card_to_transfer] := card; - s.cards := cards; - const operations : list (operation) = nil - } with (operations, s) + s.cards := cards + } with ((nil : list (operation)), s) function sell_single (const action : action_sell_single; const s : storage) : return is block { - const card : card = get_force (action.card_to_sell, s.cards); + const card : card = + case s.cards[action.card_to_sell] of + Some (card) -> card + | None -> (failwith ("sell_single: No card.") : card) + end; if card.card_owner =/= sender then failwith ("This card doesn't belong to you") else skip; const card_pattern : card_pattern = - get_force (card.card_pattern, s.card_patterns); + case s.card_patterns[card.card_pattern] of + Some (pattern) -> pattern + | None -> (failwith ("sell_single: No card pattern.") : card_pattern) + end; card_pattern.quantity := abs (card_pattern.quantity - 1n); const card_patterns : card_patterns = s.card_patterns; card_patterns[card.card_pattern] := card_pattern; @@ -74,8 +85,12 @@ function sell_single (const action : action_sell_single; remove action.card_to_sell from map cards; s.cards := cards; const price : tez = card_pattern.coefficient * card_pattern.quantity; - const receiver : contract (unit) = get_contract (sender); - const op : operation = transaction (unit, price, receiver); + const receiver : contract (unit) = + case (Tezos.get_contract_opt (Tezos.sender) : option (contract (unit))) of + Some (contract) -> contract + | None -> (failwith ("sell_single: No contract.") : contract (unit)) + end; + const op : operation = Tezos.transaction (unit, price, receiver); const operations : list (operation) = list [op] } with (operations, s) @@ -84,12 +99,13 @@ function buy_single (const action : action_buy_single; block { // Check funds const card_pattern : card_pattern = - get_force (action.card_to_buy, s.card_patterns); + case s.card_patterns[action.card_to_buy] of + Some (pattern) -> pattern + | None -> (failwith ("buy_single: No card pattern.") : card_pattern) + end; const price : tez = card_pattern.coefficient * (card_pattern.quantity + 1n); if price > amount then failwith ("Not enough money") else skip; - // Administrative procedure - const operations : list(operation) = nil; // Increase quantity card_pattern.quantity := card_pattern.quantity + 1n; const card_patterns : card_patterns = s.card_patterns; @@ -103,7 +119,7 @@ function buy_single (const action : action_buy_single; ]; s.cards := cards; s.next_id := s.next_id + 1n - } with (operations, s) + } with ((nil : list (operation)), s) function main (const action : parameter; const s : storage) : return is case action of diff --git a/src/test/contracts/condition-annot.mligo b/src/test/contracts/condition-annot.mligo index 697329fcb..1eb1bf0f9 100644 --- a/src/test/contracts/condition-annot.mligo +++ b/src/test/contracts/condition-annot.mligo @@ -1,2 +1,4 @@ -let main (i: int) = - if (i=2 : bool) then (42: int) else (0: int) +type integer = int + +let main (i : int) = + if (i = 2 : bool) then (42 : int) else (0 : integer) diff --git a/src/test/contracts/condition-annot.religo b/src/test/contracts/condition-annot.religo index 97e14f489..792090326 100644 --- a/src/test/contracts/condition-annot.religo +++ b/src/test/contracts/condition-annot.religo @@ -1,6 +1,2 @@ -let main = (i: int) => - if (((i == 2): bool)) { - (42: int); - } else { - (0: int); - }; +let main = (i : int) => + if (((i == 2) : bool)) { (42 : int); } else { (0 : int); }; diff --git a/src/test/contracts/condition-shadowing.mligo b/src/test/contracts/condition-shadowing.mligo index c4dbbbb7b..577d3f4b5 100644 --- a/src/test/contracts/condition-shadowing.mligo +++ b/src/test/contracts/condition-shadowing.mligo @@ -1,8 +1,5 @@ -(* TODO : make a test using mutation, not shadowing *) - -let main (i: int) = +let main (i : int) = let result = 0 in - if i = 2 then - let result = 42 in result - else - let result = 0 in result + if i = 2 + then let result = 42 in result + else let result = 0 in result diff --git a/src/test/contracts/condition.mligo b/src/test/contracts/condition.mligo index 31568e353..4807f36c1 100644 --- a/src/test/contracts/condition.mligo +++ b/src/test/contracts/condition.mligo @@ -1,3 +1,3 @@ // Test conditional in CameLIGO -let main (i: int) = if i = 2 then 42 else 0 +let main (i : int) = if i = 2 then 42 else 0 diff --git a/src/test/contracts/condition.religo b/src/test/contracts/condition.religo index e44e93d7f..231fbe3fe 100644 --- a/src/test/contracts/condition.religo +++ b/src/test/contracts/condition.religo @@ -1,8 +1,3 @@ /* Test conditional in ReasonLIGO */ -let main = (i: int) => - if (i == 2) { - 42; - } else { - 0; - }; +let main = (i : int) => if (i == 2) { 42; } else { 0; }; diff --git a/src/test/contracts/counter.ligo b/src/test/contracts/counter.ligo index 295c540ee..70bd7ed30 100644 --- a/src/test/contracts/counter.ligo +++ b/src/test/contracts/counter.ligo @@ -1,7 +1,7 @@ type t is int -function main (const p : int ; const s : t) : list (operation) * int is +function main (const p : int; const s : t) : list (operation) * int is block { skip } // skip is a do nothing instruction, needed for empty blocks - with ((nil : list(operation)), p + s) + with ((nil : list (operation)), p+s) diff --git a/src/test/contracts/counter.mligo b/src/test/contracts/counter.mligo index 615dfa62a..c16620367 100644 --- a/src/test/contracts/counter.mligo +++ b/src/test/contracts/counter.mligo @@ -1,4 +1,3 @@ type storage = int -let main (ps: int * storage) = - (([] : operation list) , ps.0 + ps.1) +let main (p, s : int * storage) = ([] : operation list), p + s diff --git a/src/test/contracts/counter.religo b/src/test/contracts/counter.religo index 773c94deb..a2c27966f 100644 --- a/src/test/contracts/counter.religo +++ b/src/test/contracts/counter.religo @@ -1,6 +1,4 @@ - type storage = int; -let main2 = (p: int, s: storage): string => ([]: list(operation), p + s); - -let main = (x: (int, storage)) : string => main2(x[0],x[1]); +let main = ((p, s) : (int, storage)) : (list (operation), storage) => + ([] : list (operation), p + s); diff --git a/src/test/contracts/crypto.ligo b/src/test/contracts/crypto.ligo index 08d417241..5c963fe6e 100644 --- a/src/test/contracts/crypto.ligo +++ b/src/test/contracts/crypto.ligo @@ -1,3 +1,2 @@ -function hasherman512 (const s: bytes) : bytes is sha_512 (s) - -function hasherman_blake (const s: bytes) : bytes is blake2b (s) +function hasherman512 (const s : bytes) : bytes is Crypto.sha512 (s) +function hasherman_blake (const s : bytes) : bytes is Crypto.blake2b (s) diff --git a/src/test/contracts/crypto.mligo b/src/test/contracts/crypto.mligo index 9fa7e99e8..902cd088e 100644 --- a/src/test/contracts/crypto.mligo +++ b/src/test/contracts/crypto.mligo @@ -1,2 +1,2 @@ -let hasherman512 (s: bytes) : bytes = Crypto.sha512 s -let hasherman_blake (s: bytes) : bytes = Crypto.blake2b s +let hasherman512 (s : bytes) : bytes = Crypto.sha512 s +let hasherman_blake (s : bytes) : bytes = Crypto.blake2b s diff --git a/src/test/contracts/crypto.religo b/src/test/contracts/crypto.religo index c5b17ce8e..befe63391 100644 --- a/src/test/contracts/crypto.religo +++ b/src/test/contracts/crypto.religo @@ -1,2 +1,2 @@ -let hasherman512 = (s: bytes) => Crypto.sha512(s); -let hasherman_blake = (s: bytes) => Crypto.blake2b(s); +let hasherman512 = (s : bytes) => Crypto.sha512 (s); +let hasherman_blake = (s : bytes) => Crypto.blake2b (s); diff --git a/src/test/contracts/curry.mligo b/src/test/contracts/curry.mligo index eee47985a..9584cf7b1 100644 --- a/src/test/contracts/curry.mligo +++ b/src/test/contracts/curry.mligo @@ -1,9 +1,5 @@ -let conv_test (j: int) (k: int) = j + k - -let main (i: int) : int = conv_test i 10 - -let partial (a: int) (b: int) : int = a + b - -let mk_partial (j: int) : (int -> int) = partial j - -let partial_apply (i: int) : int = (mk_partial 10) i +let conv_test (j : int) (k : int) = j + k +let main (i : int) : int = conv_test i 10 +let partial (a : int) (b : int) : int = a + b +let mk_partial (j : int) : int -> int = partial j +let partial_apply (i : int) : int = mk_partial 10 i diff --git a/src/test/contracts/declarations.ligo b/src/test/contracts/declarations.ligo index d6cc5dfb5..b41c36819 100644 --- a/src/test/contracts/declarations.ligo +++ b/src/test/contracts/declarations.ligo @@ -1,5 +1,3 @@ -// Test PascaLIGO top-level declarations - const foo : int = 42 function main (const i : int) : int is i + foo diff --git a/src/test/contracts/deep_access.ligo b/src/test/contracts/deep_access.ligo index 2d9ad32d4..4c4159111 100644 --- a/src/test/contracts/deep_access.ligo +++ b/src/test/contracts/deep_access.ligo @@ -21,9 +21,12 @@ function asymetric_tuple_access (const foo : unit) : int is } with tuple.0 + tuple.1.0 + tuple.1.1.0 + tuple.1.1.1 type nested_record_t is - record [nesty : record [mymap : map (int,string)]] + record [nesty : record [mymap : map (int, string)]] function nested_record (var nee : nested_record_t) : string is block { nee.nesty.mymap[1] := "one" - } with get_force (1, nee.nesty.mymap) + } with case nee.nesty.mymap[1] of + Some (s) -> s + | None -> (failwith ("Should not happen.") : string) + end diff --git a/src/test/contracts/dispatch-counter.ligo b/src/test/contracts/dispatch-counter.ligo index c513381ae..0ef19ab75 100644 --- a/src/test/contracts/dispatch-counter.ligo +++ b/src/test/contracts/dispatch-counter.ligo @@ -7,7 +7,6 @@ type storage is int type return is list (operation) * storage function increment (const i : int; const n : int) : int is i+n - function decrement (const i : int; const n : int) : int is i-n const nop : list (operation) = nil diff --git a/src/test/contracts/empty_case.mligo b/src/test/contracts/empty_case.mligo index 844897f01..4d08d9c3c 100644 --- a/src/test/contracts/empty_case.mligo +++ b/src/test/contracts/empty_case.mligo @@ -1,8 +1,8 @@ type foo = - | Bar of int - | Baz + Bar of int +| Baz -let main (f: foo): int = - match f with - | Bar i -> i - | Baz -> -1 \ No newline at end of file +let main (f : foo) : int = + match f with + Bar i -> i + | Baz -> -1 diff --git a/src/test/contracts/empty_case.religo b/src/test/contracts/empty_case.religo index c5d6bdc5a..68d179140 100644 --- a/src/test/contracts/empty_case.religo +++ b/src/test/contracts/empty_case.religo @@ -1,9 +1,9 @@ type foo = - | Bar(int) - | Baz; +| Bar (int) +| Baz; -let main = (f: foo): int => +let main = (f : foo) : int => switch (f) { - | Bar(i) => i - | Baz => (-1) + | Bar (i) => i + | Baz => (-1) }; diff --git a/src/test/contracts/entrypoints.ligo b/src/test/contracts/entrypoints.ligo index d1945ac8d..8775e7314 100644 --- a/src/test/contracts/entrypoints.ligo +++ b/src/test/contracts/entrypoints.ligo @@ -5,8 +5,7 @@ type return is list (operation) * storage function cb (const a : address; const s : storage) : return is block { const c : contract (unit) = get_entrypoint ("%cb", a) - } - with (list [transaction (unit, 0mutez, c)], s) + } with (list [Tezos.transaction (unit, 0tez, c)], s) function cbo (const a : address; const s : storage) : return is @@ -14,6 +13,6 @@ function cbo (const a : address; const s : storage) : return is const c : contract (unit) = case (get_entrypoint_opt ("%cbo", a) : option (contract (unit))) of Some (c) -> c - | None -> (failwith ("entrypoint not found") : contract (unit)) + | None -> (failwith ("cbo: Entrypoint not found.") : contract (unit)) end - } with (list [transaction(unit, 0mutez, c)], s) + } with (list [Tezos.transaction (unit, 0tez, c)], s) diff --git a/src/test/contracts/eq_bool.mligo b/src/test/contracts/eq_bool.mligo index 6869d5dfd..ef2aefe55 100644 --- a/src/test/contracts/eq_bool.mligo +++ b/src/test/contracts/eq_bool.mligo @@ -1,3 +1,3 @@ // Test conditional in CameLIGO -let main (a , b : bool * bool) = if a = b then 999 else 1 +let main (a, b : bool * bool) = if a = b then 999 else 1 diff --git a/src/test/contracts/eq_bool.religo b/src/test/contracts/eq_bool.religo index 5674d49b5..85e52ae7c 100644 --- a/src/test/contracts/eq_bool.religo +++ b/src/test/contracts/eq_bool.religo @@ -1,8 +1,4 @@ /* Test boolean comparison in ReasonLIGO */ -let main = ((a , b) : (bool , bool)) => - if (a == b) { - 999; - } else { - 1; - }; +let main = ((a, b) : (bool, bool)) => + if (a == b) { 999; } else { 1; }; diff --git a/src/test/contracts/failwith.mligo b/src/test/contracts/failwith.mligo index b2f7411da..c4b052102 100644 --- a/src/test/contracts/failwith.mligo +++ b/src/test/contracts/failwith.mligo @@ -1,4 +1,4 @@ type storage = unit -let main (p: unit) (s:storage) = - if true then failwith "This contract always fails" else () +let main (p, store : unit * storage) : operation list * storage = + (failwith "This contract always fails" : operation list * storage) diff --git a/src/test/contracts/failwith.religo b/src/test/contracts/failwith.religo index c7b028c3e..24317a106 100644 --- a/src/test/contracts/failwith.religo +++ b/src/test/contracts/failwith.religo @@ -1,8 +1,4 @@ type storage = unit; let main = (p: unit, storage) => - if (true) { - failwith("This contract always fails"); - } else { - (); - }; + if (true) { failwith("This contract always fails"); }; diff --git a/src/test/contracts/fibo.mligo b/src/test/contracts/fibo.mligo index fa345f653..73886ccce 100644 --- a/src/test/contracts/fibo.mligo +++ b/src/test/contracts/fibo.mligo @@ -1,7 +1,9 @@ type storage = unit -let main (p: unit) storage = - (fun (f: (int * int) -> int) (x: int) (y: int) -> f (y,x)) - (fun (x: int) (y: int) -> x + y) - 0 - 1 +let main (p, store : unit * storage) : operation list * storage = + let n = + (fun (f : int * int -> int) (x : int) (y : int) -> f (y,x)) + (fun (x : int) (y : int) -> x + y) + 0 + 1 + in ([] : operation list), store diff --git a/src/test/contracts/fibo2.mligo b/src/test/contracts/fibo2.mligo index 0b12826fc..f41ee0e3d 100644 --- a/src/test/contracts/fibo2.mligo +++ b/src/test/contracts/fibo2.mligo @@ -1,7 +1,9 @@ type storage = unit -let main (p: unit) storage = - (fun (f: int -> int) (_: int) (y: int) -> f y) - (fun (x: int) -> x) - 0 - 1 +let main (p : unit; store : storage) : operation list * storage = + let n = + (fun (f : int -> int) (z : int) (y : int) -> f y) + (fun (x : int) -> x) + 0 + 1 + in ([] : operation list), store diff --git a/src/test/contracts/fibo3.mligo b/src/test/contracts/fibo3.mligo index 1310bfa10..bfa5a5dd3 100644 --- a/src/test/contracts/fibo3.mligo +++ b/src/test/contracts/fibo3.mligo @@ -1,7 +1,9 @@ type storage = unit -let main (p: unit) storage = - (fun (f: int -> int -> int) (x: int) (y: int) -> f y (x+y)) - (fun (x: int) (y: int) -> x + y) - 0 - 1 +let main (p, s : unit * storage) : operation list * storage = + let n = + (fun (f : int -> int -> int) (x : int) (y : int) -> f y (x+y)) + (fun (x : int) (y : int) -> x + y) + 0 + 1 + in ([] : operation list), store diff --git a/src/test/contracts/fibo4.mligo b/src/test/contracts/fibo4.mligo index ccb3e5451..9806eabee 100644 --- a/src/test/contracts/fibo4.mligo +++ b/src/test/contracts/fibo4.mligo @@ -1,6 +1,6 @@ type storage = unit -let main (p: unit) storage = - (fun (f: int -> int) (x: int) -> f x) - (fun (x: int) -> x) +let main (p, s : unit * storage) = + (fun (f : int -> int) (x : int) -> f x) + (fun (x : int) -> x) 1 diff --git a/src/test/contracts/for_fail.ligo b/src/test/contracts/for_fail.ligo index a8c870843..682c5e295 100644 --- a/src/test/contracts/for_fail.ligo +++ b/src/test/contracts/for_fail.ligo @@ -1,2 +1,2 @@ -function main (const a: int) : int is +function main (const a : int) : int is block { for i := 0 to 100 block { skip } } with i diff --git a/src/test/contracts/function-shared.mligo b/src/test/contracts/function-shared.mligo index 3568f0b3a..044af0d32 100644 --- a/src/test/contracts/function-shared.mligo +++ b/src/test/contracts/function-shared.mligo @@ -1,7 +1,5 @@ (* Test use of multiple subroutines in a CameLIGO function *) -let foo (i: int) : int = i + 20 - -let bar (i: int) : int = i + 50 - -let foobar (i: int) : int = (foo i) + (bar i) +let foo (i : int) : int = i + 20 +let bar (i : int) : int = i + 50 +let foobar (i : int) : int = foo i + bar i diff --git a/src/test/contracts/function-shared.religo b/src/test/contracts/function-shared.religo index 94cc6b337..0e6c9dc47 100644 --- a/src/test/contracts/function-shared.religo +++ b/src/test/contracts/function-shared.religo @@ -1,7 +1,5 @@ /* Test use of multiple subroutines in a ReasonLIGO function */ -let foo = (i: int): int => i + 20; - -let bar = (i: int): int => i + 50; - -let foobar = (i: int): int => foo(i) + bar(i); +let foo = (i : int) : int => i + 20; +let bar = (i : int) : int => i + 50; +let foobar = (i : int) : int => foo (i) + bar (i); diff --git a/src/test/contracts/get_contract.ligo b/src/test/contracts/get_contract.ligo index 8ace2277d..13d325cba 100644 --- a/src/test/contracts/get_contract.ligo +++ b/src/test/contracts/get_contract.ligo @@ -1,19 +1,16 @@ type storage is unit type return is list (operation) * storage -function cb (const s : storage) : return is - block { - const c : contract(unit) = get_contract(sender) - } - with (list [transaction(unit, 0mutez, c)], s) +function cb (const s : storage) : return is block { + const c : contract (unit) = get_contract (Tezos.sender) +} with (list [Tezos.transaction (unit, 0tez, c)], s) function cbo (const s : unit) : return is block { const c : contract (unit) = - case (get_contract_opt(sender) : option(contract(unit))) of - Some (c) -> c + case (Tezos.get_contract_opt (Tezos.sender) : option (contract (unit))) of + Some (contract) -> contract | None -> (failwith ("contract not found") : contract (unit)) end - } - with (list [transaction(unit, 0mutez, c)], s) + } with (list [Tezos.transaction (unit, 0tez, c)], s) diff --git a/src/test/contracts/guess_string.mligo b/src/test/contracts/guess_string.mligo index 3921d4108..0b2395180 100644 --- a/src/test/contracts/guess_string.mligo +++ b/src/test/contracts/guess_string.mligo @@ -1,20 +1,22 @@ type storage = { - challenge : string; + challenge : string } type param = { new_challenge : string; - attempt : string; + attempt : string } -let attempt (p: param) storage = - (* if p.attempt <> storage.challenge then failwith "Failed challenge" else *) +type return = operation list * storage + +let attempt (p, store : param * storage) : return = + (* if p.attempt <> store.challenge then failwith "Failed challenge" else *) let contract : unit contract = - Operation.get_contract sender in + match (Tezos.get_contract_opt Tezos.sender : unit contract option) with + Some contract -> contract + | None -> (failwith "No contract" : unit contract) + in let transfer : operation = - Operation.transaction (unit , contract , 10.00tz) in - (* TODO: no syntax for functional updates yet *) - (* let storage : storage = { storage with challenge = p.new_challenge } in *) - (* for now, rebuild the record by hand. *) - let storage : storage = { challenge = p.new_challenge } - in ([] : operation list), storage + Tezos.transaction (unit, contract, 10.00tez) in + let store : storage = {challenge = p.new_challenge} + in ([] : operation list), store diff --git a/src/test/contracts/hashlock.mligo b/src/test/contracts/hashlock.mligo index 1f6fa02a1..c354bdfc2 100644 --- a/src/test/contracts/hashlock.mligo +++ b/src/test/contracts/hashlock.mligo @@ -1,56 +1,67 @@ type commit = { - date: timestamp; - salted_hash: bytes; + date : timestamp; + salted_hash : bytes; } type commit_set = (address, commit) big_map type storage = { - hashed: bytes; - unused: bool; - commits: commit_set; + hashed : bytes; + unused : bool; + commits : commit_set } type reveal = { - hashable: bytes; - message: unit -> operation list; + hashable : bytes; + message : unit -> operation list } type parameter = -| Commit of bytes + Commit of bytes | Reveal of reveal -(* We use hash-commit so that a baker can't steal *) -let commit ((p,s): bytes * storage) : operation list * storage = - let commit: commit = {date = Current.time + 86400; salted_hash = p;} in - let updated_map: commit_set = Big_map.update sender (Some commit) s.commits in - let s = {hashed = s.hashed; unused = s.unused; commits = updated_map} in - (([]: operation list), s) +type return = operation list * storage -let reveal ((p,s): reveal * storage) : operation list * storage = +(* We use hash-commit so that a baker can not steal *) + +let commit (p, s : bytes * storage) : return = + let commit : commit = + {date = Tezos.now + 86_400; salted_hash = p} in + let updated_map: commit_set = + Big_map.update Tezos.sender (Some commit) s.commits in + let s = {s with commits = updated_map} + in ([] : operation list), s + +let reveal (p, s : reveal * storage) : return = if not s.unused - then (failwith "This contract has already been used.": operation list * storage) - else - let commit: commit = - match (Big_map.find_opt sender s.commits) with - | Some c -> c - | None -> (failwith "You haven't made a commitment to hash against yet.": commit) - in - if Current.time < commit.date - then (failwith "It hasn't been 24 hours since your commit yet.": operation list * storage) - else - let salted = Crypto.sha256 (Bytes.concat p.hashable (Bytes.pack sender)) in - if (salted <> commit.salted_hash) - then (failwith "This reveal doesn't match your commitment.": operation list * storage) - else - if (s.hashed = Crypto.sha256 p.hashable) then - let s: storage = {hashed = s.hashed; unused = false; commits = s.commits} in - ((p.message ()), s) - else (failwith "Your commitment did not match the storage hash.": - operation list * storage) + (failwith "This contract has already been used." : return) + else + let commit : commit = + match Big_map.find_opt sender s.commits with + | Some c -> c + | None -> + (failwith "You have not made a commitment to hash against yet." + : commit) + in + if Tezos.now < commit.date + then + (failwith "It has not been 24 hours since your commit yet.": return) + else + let salted = + Crypto.sha256 (Bytes.concat p.hashable (Bytes.pack sender)) in + if salted <> commit.salted_hash + then + (failwith "This reveal does not match your commitment.": return) + else + if s.hashed = Crypto.sha256 p.hashable + then + let s : storage = {s with unused = false} + in p.message (), s + else (failwith "Your commitment did not match the storage hash." + : return) -let main ((p,s): parameter * storage) : operation list * storage = +let main (p, s : parameter * storage) : return = match p with - | Commit c -> commit (c, s) - | Reveal r -> reveal (r, s) + | Commit c -> commit (c,s) + | Reveal r -> reveal (r,s) diff --git a/src/test/contracts/heap.ligo b/src/test/contracts/heap.ligo index 66c7747b6..9ff8f8154 100644 --- a/src/test/contracts/heap.ligo +++ b/src/test/contracts/heap.ligo @@ -10,8 +10,12 @@ function get_top (const h : heap) : heap_elt is get_force (1n, h) function pop_switch (const h : heap) : heap is block { const result : heap_elt = get_top (h); - const s : nat = size (h); - const last : heap_elt = get_force (s, h); + const s : nat = Map.size (h); + const last : heap_elt = + case h[s] of + Some (e) -> e + | None -> (failwith ("No element.") : heap_elt) + end; remove 1n from map h; h[1n] := last } with h @@ -19,8 +23,12 @@ function pop_switch (const h : heap) : heap is function pop_ (const h : heap) : nat is block { const result : heap_elt = get_top (h); - const s : nat = size (h); - var current : heap_elt := get_force (s, h); + const s : nat = Map.size (h); + var current : heap_elt := + case h[s] of + Some (e) -> e + | None -> (failwith ("No element.") : heap_elt) + end; const i : nat = 1n; const left : nat = 2n * i; const right : nat = left + 1n; diff --git a/src/test/contracts/high-order.mligo b/src/test/contracts/high-order.mligo index 4bba30eb3..41d50f67a 100644 --- a/src/test/contracts/high-order.mligo +++ b/src/test/contracts/high-order.mligo @@ -1,30 +1,24 @@ (* Test a function which takes another function as an argument *) + let foobar (i : int) : int = - let foo: (int -> int) = - fun (i : int) -> i - in - let bar: ((int -> int) -> int) = - fun (f : int -> int) -> f i - in - bar foo + let foo: (int -> int) = fun (i : int) -> i in + let bar: ((int -> int) -> int) = fun (f : int -> int) -> f i + in bar foo (* higher order function with more than one argument *) -let higher2 (i: int) (f: int -> int): int = + +let higher2 (i : int) (f : int -> int): int = let ii: int = f i in ii let foobar2 (i : int) : int = - let foo2: (int -> int) = - fun (i : int) -> i - in - higher2 i foo2 + let foo2 : (int -> int) = fun (i : int) -> i + in higher2 i foo2 let a : int = 0 let foobar3 (i : int) : int = - let foo2: (int -> int) = - fun (i : int) -> a + i - in - higher2 i foo2 + let foo2 : (int -> int) = fun (i : int) -> a + i + in higher2 i foo2 let f (i : int) : int = i @@ -32,15 +26,11 @@ let g (i : int) : int = f i let foobar4 (i : int) : int = g (g i) -let higher3 (i: int) (f: int -> int) (g: int -> int) : int = - let ii: int = f (g i) in ii +let higher3 (i : int) (f : int -> int) (g : int -> int) : int = + let ii : int = f (g i) in ii let foobar5 (i : int) : int = let a : int = 0 in - let foo: (int -> int) = - fun (i : int) -> a + i - in - let goo: (int -> int) = - fun (i : int) -> foo i - in - higher3 i foo goo + let foo : (int -> int) = fun (i : int) -> a + i in + let goo : (int -> int) = fun (i : int) -> foo i + in higher3 i foo goo diff --git a/src/test/contracts/high-order.religo b/src/test/contracts/high-order.religo index 9e8e5cd17..0ec28a689 100644 --- a/src/test/contracts/high-order.religo +++ b/src/test/contracts/high-order.religo @@ -1,48 +1,44 @@ /* Test a function which takes another function as an argument */ -let foobar = (i: int): int => { + +let foobar = (i : int): int => { let foo: int => int = (i: int) => i; - - let bar: ((int => int) => int) = (f: (int => int)) => f(i); - - bar(foo); + let bar: ((int => int) => int) = (f : (int => int)) => f (i); + bar (foo); }; /* higher order function with more than one argument */ -let higher2 = (i: int, f: (int => int)): int => { - let ii: int = f(i); + +let higher2 = (i : int, f : (int => int)) : int => { + let ii : int = f (i); ii; }; -let foobar2 = (i: int): int => { - let foo2: int => int = (i: int) => i; - - higher2(i, foo2); +let foobar2 = (i : int) : int => { + let foo2 : int => int = (i : int) => i; + higher2 (i, foo2); }; -let a: int = 0; +let a : int = 0; -let foobar3 = (i: int): int => { - let foo2: int => int = (i: int) => a + i; - - higher2(i, foo2); +let foobar3 = (i : int) : int => { + let foo2: int => int = (i : int) => a + i; + higher2 (i, foo2); }; -let f = (i: int): int => i; +let f = (i : int) : int => i; -let g = (i: int): int => f(i); +let g = (i : int) : int => f (i); -let foobar4 = (i: int): int => g(g(i)); +let foobar4 = (i : int) : int => g (g (i)); -let higher3 = (i: int, f: (int => int), g: (int => int)): int => { - let ii: int = f(g(i)); +let higher3 = (i : int, f : (int => int), g : (int => int)) : int => { + let ii : int = f (g (i)); ii; }; -let foobar5 = (i: int): int => { - let a: int = 0; - let foo: int => int = (i: int) => a + i; - - let goo: int => int = (i: int) => foo(i); - - higher3(i, foo, goo); +let foobar5 = (i : int) : int => { + let a : int = 0; + let foo : int => int = (i : int) => a + i; + let goo : int => int = (i : int) => foo (i); + higher3 (i, foo, goo); }; diff --git a/src/test/contracts/id.mligo b/src/test/contracts/id.mligo index fd7b7c424..e23f8d841 100644 --- a/src/test/contracts/id.mligo +++ b/src/test/contracts/id.mligo @@ -3,7 +3,7 @@ type id = int type id_details = { owner: address; controller: address; - profile: bytes; + profile: bytes } type buy = bytes * address option @@ -14,126 +14,118 @@ type action = | Buy of buy | Update_owner of update_owner | Update_details of update_details -| Skip of unit +| Skip + +(* The prices kept in storage can be changed by bakers, though they + should only be adjusted down over time, not up. *) -(* The prices kept in storage can be changed by bakers, though they should only be - adjusted down over time, not up. *) type storage = (id, id_details) big_map * int * (tez * tez) -(** Preliminary thoughts on ids: +type return = operation list * storage -I very much like the simplicity of http://gurno.com/adam/mne/. -5 three letter words means you have a 15 character identity, not actually more -annoying than an IP address and a lot more memorable than the raw digits. This -can be stored as a single integer which is then translated into the corresponding -series of 5 words. +(* Preliminary thoughts on ids: -I in general like the idea of having a 'skip' mechanism, but it does need to cost -something so people don't eat up the address space. 256 ^ 5 means you have a lot -of address space, but if people troll by skipping a lot that could be eaten up. -Should probably do some napkin calculations for how expensive skipping needs to -be to deter people from doing it just to chew up address space. -*) +I very much like the simplicity of http://gurno.com/adam/mne/. 5 three +letter words means you have a 15 character identity, not actually more +annoying than an IP address and a lot more memorable than the raw +digits. This can be stored as a single integer which is then +translated into the corresponding series of 5 words. + +I in general like the idea of having a 'skip' mechanism, but it does +need to cost something so people don't eat up the address space. 256^5 +means you have a lot of address space, but if people troll by skipping +a lot that could be eaten up. Should probably do some napkin +calculations for how expensive skipping needs to be to deter people +from doing it just to chew up address space. *) let buy (parameter, storage: (bytes * address option) * storage) = - let void: unit = - if amount = storage.2.0 - then () - else (failwith "Incorrect amount paid.": unit) - in + let void : unit = + if Tezos.amount <> storage.2.0 + then (failwith "Incorrect amount paid.": unit) in let profile, initial_controller = parameter in let identities, new_id, prices = storage in - let controller: address = + let controller : address = match initial_controller with | Some addr -> addr - | None -> sender - in + | None -> sender in let new_id_details: id_details = { - owner = sender ; - controller = controller ; - profile = profile ; - } - in - let updated_identities: (id, id_details) big_map = + owner = sender; + controller = controller; + profile = profile} in + let updated_identities : (id, id_details) big_map = Big_map.update new_id (Some new_id_details) identities - in - ([]: operation list), (updated_identities, new_id + 1, prices) + in ([]: operation list), (updated_identities, new_id + 1, prices) -let update_owner (parameter, storage: (id * address) * storage) = - if (amount <> 0mutez) - then (failwith "Updating owner doesn't cost anything.": (operation list) * storage) +let update_owner (parameter, storage : (id * address) * storage) = + if amount <> 0tez + then (failwith "Updating owner doesn't cost anything.": return) else - let id, new_owner = parameter in - let identities, last_id, prices = storage in - let current_id_details: id_details = - match Big_map.find_opt id identities with - | Some id_details -> id_details - | None -> (failwith "This ID does not exist.": id_details) - in - let is_allowed: bool = - if sender = current_id_details.owner - then true - else (failwith "You are not the owner of this ID.": bool) - in - let updated_id_details: id_details = { + let id, new_owner = parameter in + let identities, last_id, prices = storage in + let current_id_details : id_details = + match Big_map.find_opt id identities with + | Some id_details -> id_details + | None -> (failwith "This ID does not exist." : id_details) in + let is_allowed : bool = + if Tezos.sender = current_id_details.owner + then true + else (failwith "You are not the owner of this ID." : bool) in + let updated_id_details : id_details = { owner = new_owner; controller = current_id_details.controller; - profile = current_id_details.profile; - } - in - let updated_identities = Big_map.update id (Some updated_id_details) identities in - ([]: operation list), (updated_identities, last_id, prices) + profile = current_id_details.profile} in + let updated_identities = + Big_map.update id (Some updated_id_details) identities + in ([]: operation list), (updated_identities, last_id, prices) let update_details (parameter, storage: (id * bytes option * address option) * storage) = - if (amount <> 0mutez) - then (failwith "Updating details doesn't cost anything.": (operation list) * storage) + if Tezos.amount <> 0tez + then + (failwith "Updating details doesn't cost anything." : return) else - let id, new_profile, new_controller = parameter in - let identities, last_id, prices = storage in - let current_id_details: id_details = - match Big_map.find_opt id identities with - | Some id_details -> id_details - | None -> (failwith "This ID does not exist.": id_details) - in - let is_allowed: bool = - if (sender = current_id_details.controller) || (sender = current_id_details.owner) - then true - else (failwith ("You are not the owner or controller of this ID."): bool) - in - let owner: address = current_id_details.owner in - let profile: bytes = - match new_profile with - | None -> (* Default *) current_id_details.profile - | Some new_profile -> new_profile - in - let controller: address = - match new_controller with - | None -> (* Default *) current_id_details.controller - | Some new_controller -> new_controller - in - let updated_id_details: id_details = { - owner = owner; - controller = controller; - profile = profile; - } - in + let id, new_profile, new_controller = parameter in + let identities, last_id, prices = storage in + let current_id_details: id_details = + match Big_map.find_opt id identities with + | Some id_details -> id_details + | None -> (failwith "This ID does not exist.": id_details) in + let is_allowed : bool = + if Tezos.sender = current_id_details.controller + || Tezos.sender = current_id_details.owner + then true + else + (failwith ("You are not the owner or controller of this ID.") + : bool) in + let owner : address = current_id_details.owner in + let profile : bytes = + match new_profile with + | None -> (* Default *) current_id_details.profile + | Some new_profile -> new_profile in + let controller : address = + match new_controller with + | None -> (* Default *) current_id_details.controller + | Some new_controller -> new_controller in + let updated_id_details: id_details = { + owner = owner; + controller = controller; + profile = profile} in let updated_identities: (id, id_details) big_map = - Big_map.update id (Some updated_id_details) identities in - ([]: operation list), (updated_identities, last_id, prices) + Big_map.update id (Some updated_id_details) identities + in ([]: operation list), (updated_identities, last_id, prices) -(* Let someone skip the next identity so nobody has to take one that's undesirable *) -let skip (p,storage: unit * storage) = - let void: unit = - if amount = storage.2.1 - then () - else (failwith "Incorrect amount paid.": unit) - in +(* Let someone skip the next identity so nobody has to take one that's +undesirable *) + +let skip (p, storage: unit * storage) = + let void : unit = + if Tezos.amount <> storage.2.1 + then (failwith "Incorrect amount paid." : unit) in let identities, last_id, prices = storage in ([]: operation list), (identities, last_id + 1, prices) -let main (action, storage: action * storage) : operation list * storage = +let main (action, storage : action * storage) : return = match action with | Buy b -> buy (b, storage) | Update_owner uo -> update_owner (uo, storage) | Update_details ud -> update_details (ud, storage) - | Skip s -> skip ((), storage) + | Skip -> skip ((), storage) diff --git a/src/test/contracts/implicit.mligo b/src/test/contracts/implicit.mligo index 443ef8710..9b4ba9068 100644 --- a/src/test/contracts/implicit.mligo +++ b/src/test/contracts/implicit.mligo @@ -1,5 +1,5 @@ let main2 (p : key_hash) (s : unit) = - let c : unit contract = Current.implicit_account p in - (([] : operation list), unit) + let c : unit contract = Tezos.implicit_account p + in ([] : operation list), unit -let main (t: key_hash * unit) = main2 t.0 t.1 +let main (p,s : key_hash * unit) = main2 p s diff --git a/src/test/contracts/implicit_account.ligo b/src/test/contracts/implicit_account.ligo index ad0a6c54b..c1f8b3649 100644 --- a/src/test/contracts/implicit_account.ligo +++ b/src/test/contracts/implicit_account.ligo @@ -1 +1,2 @@ -function main (const kh: key_hash) : contract (unit) is implicit_account (kh) +function main (const kh: key_hash) : contract (unit) is + Tezos.implicit_account (kh) diff --git a/src/test/contracts/implicit_account.mligo b/src/test/contracts/implicit_account.mligo index bf3c89dcc..0b52bf0b8 100644 --- a/src/test/contracts/implicit_account.mligo +++ b/src/test/contracts/implicit_account.mligo @@ -1 +1 @@ -let main (kh: key_hash) : unit contract = Current.implicit_account kh +let main (kh : key_hash) : unit contract = Tezos.implicit_account kh diff --git a/src/test/contracts/implicit_account.religo b/src/test/contracts/implicit_account.religo index dba1656ec..1c22b5e0e 100644 --- a/src/test/contracts/implicit_account.religo +++ b/src/test/contracts/implicit_account.religo @@ -1 +1,2 @@ -let main = (kh: key_hash): contract(unit) => Current.implicit_account(kh); +let main = (kh : key_hash) : contract (unit) => + Tezos.implicit_account (kh); diff --git a/src/test/contracts/incr_decr.mligo b/src/test/contracts/incr_decr.mligo index bceb88af3..f7f3e3e83 100644 --- a/src/test/contracts/incr_decr.mligo +++ b/src/test/contracts/incr_decr.mligo @@ -1,19 +1,17 @@ type storage = int -(* variant defining pseudo multi-entrypoint actions *) - -type action = +type parameter = Increment of int | Decrement of int -let add (a: int) (b: int) : int = a + b -let sub (a: int) (b: int) : int = a - b +type return = operation list * storage -(* real entrypoint that re-routes the flow based on the action provided *) +let add (a : int) (b : int) : int = a + b +let sub (a : int) (b : int) : int = a - b -let main (p: action) storage = - let storage = - match p with +let main (action, store : parameter * storage) : return = + let store = + match action with Increment n -> add s n | Decrement n -> sub s n - in ([] : operation list), storage + in ([] : operation list), store diff --git a/src/test/contracts/interpret_test.mligo b/src/test/contracts/interpret_test.mligo index 90fe2bcbf..c06113589 100644 --- a/src/test/contracts/interpret_test.mligo +++ b/src/test/contracts/interpret_test.mligo @@ -1,87 +1,87 @@ let lambda_call = let a = 3 in - let foo = fun (i : int) -> i * i in - foo (a + 1) + let foo = fun (i : int) -> i * i + in foo (a + 1) let higher_order1 = let a = 2 in - let foo = fun (i:int) (j:int) (k:int) -> - a + i + j + 0 in - let bar = (foo 1 2) in - bar 3 + let foo = fun (i : int) (j : int) (k : int) -> a + i + j + 0 in + let bar = (foo 1 2) + in bar 3 let higher_order2 = let a = 2 in - let foo = fun (i:int) -> - let b = 2 in - let bar = fun (i:int) -> i + a + b - in bar i + let foo = fun (i : int) -> + let b = 2 in + let bar = fun (i : int) -> i + a + b + in bar i in foo 1 let higher_order3 = - let foo = fun (i:int) -> i + 1 in - let bar = fun (f:int->int) (i:int) -> (f i) + 1 in - let baz : (int -> int ) = bar foo in - baz 3 + let foo = fun (i : int) -> i + 1 in + let bar = fun (f : int -> int) (i : int) -> f i + 1 in + let baz : int -> int = bar foo + in baz 3 let higher_order4 = let a = 3 in let foo = fun (i : int) -> a + i in - let bar: (int -> int) = fun (i : int) -> foo i in - bar 2 - -let concats = - 0x70 ^ 0x70 + let bar : int -> int = fun (i : int) -> foo i + in bar 2 + +let concats = 0x70 ^ 0x70 type foo_record = { - a : string ; - b : string ; + a : string; + b : string } + let record_concat = - let ab : foo_record = { a = "a" ; b = "b" } in - ab.a ^ ab.b + let ab : foo_record = {a="a"; b="b"} + in ab.a ^ ab.b let record_patch = - let ab : foo_record = { a = "a" ; b = "b" } in - {ab with b = "c"} + let ab : foo_record = {a="a"; b="b"} + in {ab with b = "c"} type bar_record = { - f : int -> int ; - arg : int ; + f : int -> int; + arg : int } + let record_lambda = let a = 1 in - let foo : (int -> int) = fun (i:int) -> a+(i*2) in - let farg : bar_record = { f = foo ; arg = 2 } in - farg.f farg.arg + let foo : int -> int = fun (i : int) -> a + i*2 in + let farg : bar_record = {f = foo; arg = 2} + in farg.f farg.arg type foo_variant = | Foo | Bar of int | Baz of string -let variant_exp = - (Foo, Bar 1, Baz "b") +let variant_exp = Foo, Bar 1, Baz "b" let variant_match = let a = Bar 1 in match a with - | Foo -> 1 - | Bar(i) -> 2 - | Baz(s) -> 3 + | Foo -> 1 + | Bar i -> 2 + | Baz s -> 3 -/* UNSUPPORTED +(* UNSUPPORTED: No deep patterns yet. type bar_variant = | Baz | Buz of int * int | Biz of int * int * string + let long_variant_match = let a = Biz (1,2,"Biz") in match a with | Baz -> "Baz" - | Buz(a,b) -> "Buz" - | Biz(a,b,c) -> c -*/ + | Buz (a,b) -> "Buz" + | Biz (a,b,c) -> c + *) let bool_match = let b = true in @@ -90,149 +90,145 @@ let bool_match = | false -> 2 let list_match = - let a = [ 1 ; 2 ; 3 ; 4 ] in + let a = [1; 2; 3; 4] in match a with - | hd :: tl -> hd::a + | hd::tl -> hd::a | [] -> a let tuple_proj = - let (a,b) = (true,false) in - a or b + let a, b = true, false + in a or b let list_const = - let a = [1 ; 2 ; 3 ; 4] in - 0 :: a + let a = [1; 2; 3; 4] + in 0::a type foobar = int option let options_match_some = let a = Some 0 in match a with - | Some(i) -> i + | Some i -> i | None -> 1 let options_match_none = let a : foobar = None in match a with - | Some(i) -> i + | Some i -> i | None -> 0 let is_nat_nat = let i : int = 1 in - let j : int = -1 in - (Michelson.is_nat i, Michelson.is_nat j) + let j : int = -1 + in is_nat i, is_nat j let abs_int = abs (-5) -let nat_int = int (5n) +let nat_int = int 5n let map_list = - let a = [1 ; 2 ; 3 ; 4] in - let add_one: (int -> int) = fun (i : int) -> i + 1 in - List.map add_one a + let a = [1; 2; 3; 4] in + let add_one : (int -> int) = fun (i : int) -> i + 1 + in List.map add_one a let fail_alone = failwith "you failed" let iter_list_fail = - let a = [1 ; 2 ; 3 ; 4] in - let check_something: (int -> unit) = fun (i : int) -> - if i = 2 then failwith "you failed" - else () - in - List.iter check_something a + let a = [1; 2; 3; 4] in + let check_something : int -> unit = + fun (i : int) -> + if i = 2 then failwith "you failed" + in List.iter check_something a let fold_list = - let a = [1 ; 2 ; 3 ; 4] in - let acc : (int * int -> int) = - fun (prev, el : int * int) -> prev + el in - List.fold acc a 0 + let a = [1; 2; 3; 4] in + let acc : int * int -> int = + fun (prev, el : int * int) -> prev + el + in List.fold acc a 0 -let comparison_int = - (1 > 2, 2 > 1, 1 >=2 , 2 >= 1) +let comparison_int = 1 > 2, 2 > 1, 1 >=2, 2 >= 1 -let comparison_string = - ("foo" = "bar", "baz" = "baz") +let comparison_string = "foo"="bar", "baz"="baz" -let divs : (int * nat * tez * nat) = - (1/2 , 1n/2n , 1tz/2n , 1tz/2tz) +let divs : int * nat * tez * nat = 1/2, 1n/2n, 1tez/2n, 1tez/2tez let var_neg = - let a = 2 in - -a + let a = 2 in -a let sizes = - let a = [ 1 ; 2 ; 3 ; 4 ; 5 ] in + let a = [1; 2; 3; 4; 5] in let b = "12345" in - let c = Set.literal [ 1 ; 2 ; 3 ; 4 ; 5 ] in - let d = Map.literal [ (1,1) ; (2,2) ; (3,3) ] in + let c = Set.literal [1; 2; 3; 4; 5] in + let d = Map.literal [(1,1); (2,2); (3,3)] in let e = 0xFFFF in - (List.size a, String.size b, Set.size c, Map.size d, Bytes.size e) + List.length a, + String.length b, + Set.cardinal c, + Map.size d, + Bytes.length e let modi = 3 mod 2 let fold_while = - let aux : int -> bool * int = fun (i:int) -> - if i < 10 then continue (i + 1) else stop i in - (Loop.fold_while aux 20, Loop.fold_while aux 0) + let aux : int -> bool * int = + fun (i : int) -> + if i < 10 then Loop.resume (i + 1) else Loop.stop i + in (Loop.fold_while aux 20, Loop.fold_while aux 0) -let assertion_pass = - assert (1=1) +let assertion_pass = assert (1=1) -let assertion_fail = - assert (1=2) +let assertion_fail = assert (1=2) let lit_address = ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" : address) let map_finds = - let m = Map.literal [ ("one" , 1) ; ("two" , 2) ; ("three" , 3) ] in - Map.find_opt "two" m + let m = Map.literal [("one", 1); ("two", 2); ("three", 3)] + in Map.find_opt "two" m let map_finds_fail = - let m = Map.literal [ ("one" , 1) ; ("two" , 2) ; ("three" , 3) ] in - Map.find "four" m + let m = Map.literal [("one", 1); ("two", 2); ("three", 3)] + in Map.find "four" m let map_empty = - ((Map.empty : (int,int) map) , (Map.literal [] : (int,int) map)) + ((Map.empty : (int, int) map), (Map.literal [] : (int, int) map)) -let m = Map.literal [ ("one" , 1) ; ("two" , 2) ; ("three" , 3) ] +let m = Map.literal [("one", 1); ("two", 2); ("three", 3)] let map_fold = - let aux = fun (i: int * (string * int)) -> i.0 + i.1.1 in - Map.fold aux m (-2) + let aux = fun (i : int * (string * int)) -> i.0 + i.1.1 + in Map.fold aux m (-2) let map_iter = - let aux = fun (i: string * int) -> if (i.1=12) then failwith "never" else () in - Map.iter aux m + let aux = + fun (i : string * int) -> if i.1 = 12 then failwith "never" + in Map.iter aux m let map_map = - let aux = fun (i: string * int) -> i.1 + (String.size i.0) in - Map.map aux m + let aux = fun (i : string * int) -> i.1 + String.length i.0 + in Map.map aux m -let map_mem = (Map.mem "one" m , Map.mem "four" m) +let map_mem = Map.mem "one" m, Map.mem "four" m -let map_remove = (Map.remove "one" m, Map.remove "four" m) +let map_remove = Map.remove "one" m, Map.remove "four" m -let map_update = ( - Map.update "one" (Some(1)) (Map.literal [ "one", 2 ]), - Map.update "one" (None : int option) (Map.literal [ "one", 1]), - Map.update "one" (None : int option) (Map.literal []:(string,int) map), - Map.update "one" (Some(1)) (Map.literal []:(string,int) map) -) +let map_update = + Map.update "one" (Some 1) (Map.literal ["one", 2]), + Map.update "one" (None : int option) (Map.literal ["one", 1]), + Map.update "one" (None : int option) (Map.empty : (string, int) map), + Map.update "one" (Some 1) (Map.literal [] : (string, int) map) -let s = Set.literal [ 1 ; 2 ; 3 ] +let s = Set.literal [1; 2; 3] -let set_add = ( +let set_add = Set.add 1 s, Set.add 4 s, - Set.add 1 (Set.literal [] : int set) -) + Set.add 1 (Set.empty : int set) let set_iter_fail = - let aux = fun (i:int) -> if i = 1 then failwith "set_iter_fail" else () in - Set.iter aux (Set.literal [1 ; 2 ; 3]) + let aux = fun (i : int) -> if i = 1 then failwith "set_iter_fail" + in Set.iter aux (Set.literal [1; 2; 3]) -let set_mem = ( +let set_mem = Set.mem 1 s, Set.mem 4 s, - Set.mem 1 (Set.literal [] : int set) -) + Set.mem 1 (Set.empty : int set) diff --git a/src/test/contracts/isnat.mligo b/src/test/contracts/isnat.mligo index c5bea0294..7440ea85e 100644 --- a/src/test/contracts/isnat.mligo +++ b/src/test/contracts/isnat.mligo @@ -1 +1 @@ -let main (i: int) : nat option = Michelson.is_nat i +let main (i : int) : nat option = is_nat i diff --git a/src/test/contracts/isnat.religo b/src/test/contracts/isnat.religo index b6b5921b7..be81913c0 100644 --- a/src/test/contracts/isnat.religo +++ b/src/test/contracts/isnat.religo @@ -1 +1 @@ -let main = (i: int): option(nat) => Michelson.is_nat(i); +let main = (i : int): option (nat) => is_nat (i); diff --git a/src/test/contracts/key_hash.ligo b/src/test/contracts/key_hash.ligo index 865abfbb8..41c7fe56b 100644 --- a/src/test/contracts/key_hash.ligo +++ b/src/test/contracts/key_hash.ligo @@ -1,7 +1,5 @@ function check_hash_key (const kh1 : key_hash; const k2 : key) : bool * key_hash is block { - var ret : bool := False; - var kh2 : key_hash := crypto_hash_key (k2); - if kh1 = kh2 then ret := True else skip - } with (ret, kh2) + var kh2 : key_hash := Crypto.hash_key (k2); + } with ((kh1 = kh2), kh2) diff --git a/src/test/contracts/key_hash.mligo b/src/test/contracts/key_hash.mligo index 0eba14d9b..d42dcc8f1 100644 --- a/src/test/contracts/key_hash.mligo +++ b/src/test/contracts/key_hash.mligo @@ -1,5 +1,3 @@ -let check_hash_key (kh1, k2: key_hash * key) : bool * key_hash = - let kh2 : key_hash = Crypto.hash_key k2 in - if kh1 = kh2 - then (true, kh2) - else (false, kh2) +let check_hash_key (kh1, k2 : key_hash * key) : bool * key_hash = + let kh2 : key_hash = Crypto.hash_key k2 + in kh1 = kh2, kh2 diff --git a/src/test/contracts/key_hash.religo b/src/test/contracts/key_hash.religo index f3b8e8976..e434cfb50 100644 --- a/src/test/contracts/key_hash.religo +++ b/src/test/contracts/key_hash.religo @@ -1,10 +1,5 @@ -let check_hash_key = (kh1_k2: (key_hash, key)) : (bool, key_hash) => { +let check_hash_key = (kh1_k2 : (key_hash, key)) : (bool, key_hash) => { let kh1, k2 = kh1_k2; - let kh2 : key_hash = Crypto.hash_key(k2); - if (kh1 == kh2) { - (true, kh2); - } - else { - (false, kh2); - } + let kh2 : key_hash = Crypto.hash_key (k2); + ((kh1 == kh2), kh2) }; diff --git a/src/test/contracts/key_hash_comparable.ligo b/src/test/contracts/key_hash_comparable.ligo index 02003b927..7c5a60613 100644 --- a/src/test/contracts/key_hash_comparable.ligo +++ b/src/test/contracts/key_hash_comparable.ligo @@ -1,8 +1,9 @@ -type storage is record - one: map(key_hash, nat); - two: big_map(key_hash, bool); -end +type storage is record [ + one : map (key_hash, nat); + two : big_map (key_hash, bool) +] type return is list (operation) * storage -function main (const a : int; const store : storage) : return is ((nil: list(operation)), store) \ No newline at end of file +function main (const a : int; const store : storage) : return is + ((nil : list (operation)), store) diff --git a/src/test/contracts/lambda.mligo b/src/test/contracts/lambda.mligo index fc32e0334..f7d21eeb1 100644 --- a/src/test/contracts/lambda.mligo +++ b/src/test/contracts/lambda.mligo @@ -1,8 +1,7 @@ type storage = unit (* not supported yet -let main (p:unit) storage = - (fun x -> ()) () +let main (p, s : unit * storage) = (fun x -> ()) () *) -let main (ps: unit * storage) = (fun (_: unit) -> ()) () +let main (p, s : unit * storage) = (fun (_ : unit) -> ()) () diff --git a/src/test/contracts/lambda.religo b/src/test/contracts/lambda.religo index 6a997e826..aa9f53845 100644 --- a/src/test/contracts/lambda.religo +++ b/src/test/contracts/lambda.religo @@ -5,6 +5,5 @@ type storage = unit; (fun x -> ()) () */ -let main2 = ((p: unit), s: storage) => (((xxx: unit)) => ())(); - -let main = (x: (unit, storage)) => main2(x[0], x[1]); +let main = ((p,s) : (unit, storage)) : unit => + (((useless : unit)) => ()) (); diff --git a/src/test/contracts/lambda2.mligo b/src/test/contracts/lambda2.mligo index 840761bb2..6608f87e8 100644 --- a/src/test/contracts/lambda2.mligo +++ b/src/test/contracts/lambda2.mligo @@ -1,8 +1,8 @@ type storage = unit (* Not supported yet: -let main (p:unit) storage = (fun x -> ()) () +let main (a, s : unit * storage) = (fun x -> ()) () *) -let main (_: unit * storage) = - (fun (f: unit -> unit) -> f ()) (fun (_: unit) -> unit) +let main (a, s : unit * storage) = + (fun (f : unit -> unit) -> f ()) (fun (_ : unit) -> unit) diff --git a/src/test/contracts/lambda2.religo b/src/test/contracts/lambda2.religo index 4be943b06..4c505fa0b 100644 --- a/src/test/contracts/lambda2.religo +++ b/src/test/contracts/lambda2.religo @@ -4,7 +4,5 @@ type storage = unit; let main (p:unit) storage = (fun x -> ()) () */ -let main2 = (z: unit, s: storage) => - ((f: (unit => unit)) => f())((z: unit) => unit); - -let main = (x: (unit, storage)) => main2(x[0],x[1]); +let main = ((a, s) : (unit, storage)) : unit => + ((f : (unit => unit)) => f ()) ((useless : unit) => unit); diff --git a/src/test/contracts/let_in_multi_bind.mligo b/src/test/contracts/let_in_multi_bind.mligo index f6e11b035..9da2f4c31 100644 --- a/src/test/contracts/let_in_multi_bind.mligo +++ b/src/test/contracts/let_in_multi_bind.mligo @@ -1,4 +1,4 @@ -let sum (p: int * int) : int = +let sum (p : int * int) : int = let i, result = p in i + result let sum2 (p: string * string * string * string) : string = diff --git a/src/test/contracts/let_multiple.mligo b/src/test/contracts/let_multiple.mligo index 08cb6dc3c..1ef5fbfa3 100644 --- a/src/test/contracts/let_multiple.mligo +++ b/src/test/contracts/let_multiple.mligo @@ -1,38 +1,36 @@ (* Simple test of binding multiple values *) -let (x: int), (y: int) = 1,2 +let (x : int), (y : int) = 1,2 -let main (p: unit) : int = x + y +let main (p : unit) : int = x + y -let ((x : int) , (y :int)) = 3,3 +let ((x : int) , (y : int)) = 3,3 -let main_paren (p: unit) : int = x + y +let main_paren (p : unit) : int = x + y let foobar : (int * int) = (23 , 42) let (foo : int) , (bar : int) = foobar (* Here to prevent a regression of https://gitlab.com/ligolang/ligo/issues/63#note_254106580 *) -let correct_values_bound (p: unit) : int * int = - foo, bar +let correct_values_bound (p : unit) : int * int = foo, bar -let non_tuple_rhs (p: unit) : int = - bar - foo +let non_tuple_rhs (p : unit) : int = bar - foo (* Here to prevent a regression of https://gitlab.com/ligolang/ligo/issues/63#note_254106580 *) -let big_tuple : (int * int * int * int * int) = (10, 20, 30, 40, 50) +let big_tuple : int * int * int * int * int = 10, 20, 30, 40, 50 let (a: int), (b: int), (c: int), (d: int), (e: int) = big_tuple -let correct_values_big_tuple (p: unit) : int * int * int * int * int = +let correct_values_big_tuple (p : unit) : int * int * int * int * int = a, b, c, d, e (* Here to prevent a regression of https://gitlab.com/ligolang/ligo/issues/63#note_254106580 *) -let different_types: (int * string) = 10, "hello" +let different_types : int * string = 10, "hello" -let (greet_num: int), (greeting: string) = different_types +let (greet_num : int), (greeting : string) = different_types -let correct_values_different_types (p: unit) : int * string = +let correct_values_different_types (p : unit) : int * string = greet_num, greeting diff --git a/src/test/contracts/let_multiple.religo b/src/test/contracts/let_multiple.religo index 0e5934027..b55df0d1d 100644 --- a/src/test/contracts/let_multiple.religo +++ b/src/test/contracts/let_multiple.religo @@ -1,14 +1,15 @@ /* Simple test of binding multiple values */ -let ((x: int), (y: int)) = (1, 2); +let ((x : int), (y : int)) = (1,2); -let main = (p: unit): int => x + y; +let main = (p : unit): int => x + y; -let ((x: int), (y: int)) = (3, 3); +let ((x : int), (y : int)) = (3,3); -let main_paren = (p: unit): int => x + y; +let main_paren = (p : unit): int => x + y; -let foobar: (int, int) = (23, 42); -let ((foo: int), (bar: int)) = foobar; +let foobar : (int, int) = (23, 42); -let non_tuple_rhs = (p: unit): int => foo + bar; +let ((foo : int), (bar : int)) = foobar; + +let non_tuple_rhs = (p : unit) : int => foo + bar; diff --git a/src/test/contracts/letin.mligo b/src/test/contracts/letin.mligo index 37b89aa3f..8ee8912c7 100644 --- a/src/test/contracts/letin.mligo +++ b/src/test/contracts/letin.mligo @@ -1,6 +1,6 @@ type storage = int * int -let main (n: int * storage) = +let main (n : int * storage) : operation list * storage = let x : int * int = let x : int = 7 in x + n.0, n.1.0 + n.1.1 diff --git a/src/test/contracts/letin.religo b/src/test/contracts/letin.religo index 22b08bda9..8956133e3 100644 --- a/src/test/contracts/letin.religo +++ b/src/test/contracts/letin.religo @@ -1,11 +1,9 @@ type storage = (int, int); -let main2 = ((n : int), s: storage) => { - let x: (int, int) = { - let x: int = 7; - (x + n, s[0] + s[1]); +let main = (n : (int, storage)) : (list (operation), storage) => { + let x : (int, int) = { + let x : int = 7; + (x + n[0], n[1][0] + n[1][1]); }; - ([]: list(operation), x); + ([]: list (operation), x); }; - -let main = (x: (int, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/list.ligo b/src/test/contracts/list.ligo index 155b80ac5..ae01f1559 100644 --- a/src/test/contracts/list.ligo +++ b/src/test/contracts/list.ligo @@ -17,17 +17,17 @@ const bl : foobar = list [144; 51; 42; 120; 421] function fold_op (const s : list (int)) : int is block { function aggregate (const prec: int; const cur: int) : int is prec+cur - } with list_fold (aggregate, s, 10) + } with List.fold (aggregate, s, 10) function iter_op (const s : list (int)) : int is block { var r : int := 0; function aggregate (const i : int) : unit is block { r := r + i } with unit; - list_iter (aggregate, s) + List.iter (aggregate, s) } with r function map_op (const s : list (int)) : list (int) is block { function increment (const i : int) : int is i+1 - } with list_map (increment, s) + } with List.map (increment, s) diff --git a/src/test/contracts/list.mligo b/src/test/contracts/list.mligo index 06a914514..26383f27b 100644 --- a/src/test/contracts/list.mligo +++ b/src/test/contracts/list.mligo @@ -1,27 +1,29 @@ type storage = int * int list -type param = int list +type parameter = int list + +type return = operation list * storage let x : int list = [] let y : int list = [3; 4; 5] let z : int list = 2::y -let main (p, s: param * storage) = +let main (p, s: parameter * storage) : return = let storage = match p with [] -> s | hd::tl -> s.0 + hd, tl in ([] : operation list), storage -let size_ (s: int list) : nat = List.size s +let size_ (s : int list) : nat = List.length s -let fold_op (s: int list) : int = - let aggregate = fun (t: int * int) -> t.0 + t.1 +let fold_op (s : int list) : int = + let aggregate = fun (t : int * int) -> t.0 + t.1 in List.fold aggregate s 10 -let map_op (s: int list) : int list = - List.map (fun (cur: int) -> cur + 1) s +let map_op (s : int list) : int list = + List.map (fun (cur : int) -> cur + 1) s let iter_op (s : int list) : unit = - let do_nothing = fun (_: int) -> unit + let do_nothing = fun (_ : int) -> unit in List.iter do_nothing s diff --git a/src/test/contracts/list.religo b/src/test/contracts/list.religo index 5dc8f17d2..433894a47 100644 --- a/src/test/contracts/list.religo +++ b/src/test/contracts/list.religo @@ -1,33 +1,33 @@ -type storage = (int, list(int)); +type storage = (int, list (int)); -type param = list(int); +type parameter = list (int); -let x: list(int) = []; -let y: list(int) = [3, 4, 5]; -let z: list(int) = [2, ...y]; +type return = (list (operation), storage); -let main2 = (p: param, storage : storage) => { +let x : list (int) = []; +let y : list (int) = [3, 4, 5]; +let z : list (int) = [2, ...y]; + +let main = ((action, s) : (parameter, storage)) : return => { let storage = - switch (p) { - | [] => storage - | [hd, ...tl] => (storage[0] + hd, tl) + switch (action) { + | [] => s + | [hd, ...tl] => (s[0] + hd, tl) }; ([]: list(operation), storage); }; -let main = (x: (param, storage)) => main2(x[0],x[1]); +let size_ = (s : list (int)) : nat => List.length (s); -let size_ = (s: list(int)): nat => List.size(s); - -let fold_op = (s: list(int)): int => { - let aggregate = (prec_cur: (int, int)) => prec_cur[0] + prec_cur[1]; - List.fold(aggregate, s, 10); +let fold_op = (s : list (int)) : int => { + let aggregate = (t: (int, int)) => t[0] + t[1]; + List.fold (aggregate, s, 10); }; -let map_op = (s: list(int)): list(int) => - List.map((cur: int) => cur + 1, s); +let map_op = (s : list (int)) : list (int) => + List.map ((cur : int) => cur + 1, s); -let iter_op = (s: list(int)): unit => { - let do_nothing = (z: int) => unit; - List.iter(do_nothing, s); +let iter_op = (s : list (int)) : unit => { + let do_nothing = (useless : int) => unit; + List.iter (do_nothing, s); }; diff --git a/src/test/contracts/loop.mligo b/src/test/contracts/loop.mligo index 215aa6c41..82da7268e 100644 --- a/src/test/contracts/loop.mligo +++ b/src/test/contracts/loop.mligo @@ -1,33 +1,37 @@ -(* Test loops in CameLIGO *) +(* Test functional iterators in CameLIGO *) -let aux_simple (i: int) : bool * int = - if i < 100 then continue (i + 1) else stop i +let aux_simple (i : int) : bool * int = + if i < 100 then Loop.resume (i + 1) else Loop.stop i -let counter_simple (n: int) : int = +let counter_simple (n : int) : int = Loop.fold_while aux_simple n type sum_aggregator = { - counter : int ; - sum : int ; + counter : int; + sum : int } let counter (n : int) : int = - let initial : sum_aggregator = { counter = 0 ; sum = 0 } in - let out : sum_aggregator = Loop.fold_while (fun (prev: sum_aggregator) -> + let initial : sum_aggregator = {counter=0; sum=0} in + let aggregate = fun (prev : sum_aggregator) -> if prev.counter <= n then - continue ({ counter = prev.counter + 1 ; sum = prev.counter + prev.sum }) + Loop.resume {counter = prev.counter + 1; + sum = prev.counter + prev.sum} else - stop ({ counter = prev.counter ; sum = prev.sum }) ) - initial in out.sum + Loop.stop {counter = prev.counter; sum = prev.sum} in + let out : sum_aggregator = + Loop.fold_while aggregate initial + in out.sum -let aux_nest (prev: sum_aggregator) : bool * sum_aggregator = +let aux_nest (prev : sum_aggregator) : bool * sum_aggregator = if prev.counter < 100 then - continue ({ counter = prev.counter + 1 ; - sum = prev.sum + Loop.fold_while aux_simple prev.counter}) + let sum : int = + prev.sum + Loop.fold_while aux_simple prev.counter + in Loop.resume {counter = prev.counter + 1; sum = sum} else - stop ({ counter = prev.counter ; sum = prev.sum }) + Loop.stop {counter = prev.counter; sum = prev.sum} -let counter_nest (n: int) : int = - let initial : sum_aggregator = { counter = 0 ; sum = 0 } in +let counter_nest (n : int) : int = + let initial : sum_aggregator = {counter=0; sum=0} in let out : sum_aggregator = Loop.fold_while aux_nest initial in out.sum diff --git a/src/test/contracts/loop.religo b/src/test/contracts/loop.religo index 60bba7d17..a1d8b6e44 100644 --- a/src/test/contracts/loop.religo +++ b/src/test/contracts/loop.religo @@ -1,46 +1,41 @@ /* Test loops in ReasonLIGO */ -let aux_simple = (i: int): (bool, int) => - if (i < 100) { - continue(i + 1); - } else { - stop(i); - }; +let aux_simple = (i : int) : (bool, int) => + if (i < 100) { Loop.resume (i + 1); } else { Loop.stop (i); }; -let counter_simple = (n: int): int => Loop.fold_while(aux_simple, n); +let counter_simple = (n : int) : int => Loop.fold_while (aux_simple, n); type sum_aggregator = { - counter: int, - sum: int, + counter : int, + sum : int, }; -let counter = (n: int): int => { - let initial: sum_aggregator = {counter: 0, sum: 0}; - let out: sum_aggregator = - Loop.fold_while( - (prev: sum_aggregator) => - if (prev.counter <= n) { - continue({counter: prev.counter + 1, sum: prev.counter + prev.sum}); - } else { - stop({counter: prev.counter, sum: prev.sum}); - }, - initial - ); +let counter = (n : int) : int => { + let initial : sum_aggregator = {counter: 0, sum: 0}; + let aggregate = (prev : sum_aggregator) => + if (prev.counter <= n) { + Loop.resume ({counter : prev.counter + 1, + sum : prev.counter + prev.sum}); + } else { + Loop.stop ({counter: prev.counter, sum: prev.sum}); + }; + let out : sum_aggregator = + Loop.fold_while (aggregate, initial); out.sum; }; -let aux_nest = (prev: sum_aggregator): (bool, sum_aggregator) => +let aux_nest = (prev : sum_aggregator) : (bool, sum_aggregator) => if (prev.counter < 100) { - continue({ - counter: prev.counter + 1, - sum: prev.sum + Loop.fold_while(aux_simple, prev.counter), - }); + let sum : int = + prev.sum + Loop.fold_while (aux_simple, prev.counter); + Loop.resume ({counter: prev.counter + 1, + sum: sum}); } else { - stop({counter: prev.counter, sum: prev.sum}); + Loop.stop ({counter: prev.counter, sum: prev.sum}); }; -let counter_nest = (n: int): int => { - let initial: sum_aggregator = {counter: 0, sum: 0}; - let out: sum_aggregator = Loop.fold_while(aux_nest, initial); +let counter_nest = (n : int) : int => { + let initial : sum_aggregator = {counter: 0, sum: 0}; + let out : sum_aggregator = Loop.fold_while (aux_nest, initial); out.sum; }; diff --git a/src/test/contracts/loop_bugs.ligo b/src/test/contracts/loop_bugs.ligo index 1a18a6758..55b443352 100644 --- a/src/test/contracts/loop_bugs.ligo +++ b/src/test/contracts/loop_bugs.ligo @@ -1,6 +1,6 @@ function shadowing_in_body (var nee : unit) : string is block { var st : string := ""; - var list1 : list(string) := list "to"; "to" end; + var list1 : list (string) := list ["to"; "to"]; for x in list list1 block { const x : string = "ta"; st := st ^ x; @@ -10,7 +10,7 @@ function shadowing_in_body (var nee : unit) : string is block { function shadowing_assigned_in_body (var nee : unit) : string is block { var st : string := ""; - var list1 : list(string) := list "to"; "to" end; + var list1 : list (string) := list ["to"; "to"]; for x in list list1 block { st := st ^ x; var st : string := "ta"; diff --git a/src/test/contracts/map.ligo b/src/test/contracts/map.ligo index eabd8edc7..51339ada4 100644 --- a/src/test/contracts/map.ligo +++ b/src/test/contracts/map.ligo @@ -30,32 +30,28 @@ function patch_ (var m : foobar) : foobar is block { function patch_deep (var m : foobar * nat) : foobar * nat is block { patch m.0 with map [1 -> 9] } with m -function size_ (const m : foobar) : nat is size (m) - -function gf (const m : foobar) : int is get_force (23, m) +function size_ (const m : foobar) : nat is Map.size (m) function get (const m : foobar) : option (int) is m[42] -function get_ (const m : foobar) : option (int) is map_get (42, m) - -function mem (const k: int; const m: foobar) : bool is map_mem (k, m) +function mem (const k: int; const m: foobar) : bool is Map.mem (k, m) function iter_op (const m : foobar) : unit is block { function aggregate (const i : int; const j : int) : unit is block { if i=j then skip else failwith ("fail") } with unit - } with map_iter (aggregate, m) + } with Map.iter (aggregate, m) function map_op (const m : foobar) : foobar is block { function increment (const i : int; const j : int) : int is j+1 - } with map_map (increment, m) + } with Map.map (increment, m) function fold_op (const m : foobar) : int is block { function aggregate (const i : int; const j : int * int) : int is i + j.0 + j.1 - } with map_fold(aggregate, m, 10) + } with Map.fold (aggregate, m, 10) function deep_op (var m : foobar) : foobar is block { diff --git a/src/test/contracts/map.mligo b/src/test/contracts/map.mligo index 5ad4246f7..dfc4a84ee 100644 --- a/src/test/contracts/map.mligo +++ b/src/test/contracts/map.mligo @@ -7,47 +7,48 @@ let map1 : foobar = let map2 : foobar = Map.literal [(23,0); (42,0)] -let set_2 (n: int) (m: foobar) : foobar = Map.update 23 (Some n) m +let set_2 (n : int) (m : foobar) : foobar = Map.update 23 (Some n) m -let set_ (t: int * foobar) : foobar = set_2 t.0 t.1 +let set_ (t : int * foobar) : foobar = set_2 t.0 t.1 -let add (n,m: int * foobar) : foobar = Map.add 23 n m +let add (n,m : int * foobar) : foobar = Map.add 23 n m -let rm (m: foobar) : foobar = Map.remove 42 m +let rm (m : foobar) : foobar = Map.remove 42 m (* Dummy test so that we can add the same test for PascaLIGO *) -let patch_ (m: foobar) : foobar = Map.literal [(0,5); (1,6); (2,7)] + +let patch_ (m : foobar) : foobar = Map.literal [(0,5); (1,6); (2,7)] (* Second dummy test, see above *) -let patch_empty (m: foobar) : foobar = Map.literal [(0,0); (1,1); (2,2)] + +let patch_empty (m : foobar) : foobar = Map.literal [(0,0); (1,1); (2,2)] (* Third dummy test, see above *) -let patch_deep (m: foobar * nat) : foobar * nat = + +let patch_deep (m : foobar * nat) : foobar * nat = Map.literal [(0,0); (1,9); (2,2)], 10n -let size_ (m: foobar) : nat = Map.size m +let size_ (m : foobar) : nat = Map.size m -let gf (m: foobar) : int = Map.find 23 m +let get (m : foobar) : int option = Map.find_opt 42 m +let get_ (m : foobar) : int option = Map.find_opt 42 m -let get (m: foobar) : int option = Map.find_opt 42 m -let get_ (m: foobar) : int option = Map.find_opt 42 m - -let mem (k,m: int * foobar) : bool = Map.mem k m +let mem (k,m : int * foobar) : bool = Map.mem k m let iter_op (m : foobar) : unit = - let assert_eq = fun (i: int * int) -> assert (i.0 = i.1) + let assert_eq = fun (a, b : int * int) -> assert (a = b) in Map.iter assert_eq m let map_op (m : foobar) : foobar = - let increment = fun (i: int * int) -> i.1 + 1 + let increment = fun (i : int * int) -> i.1 + 1 in Map.map increment m let fold_op (m : foobar) : int = - let aggregate = fun (i,m: int * (int * int)) -> i + m.0 + m.1 + let aggregate = fun (i, m : int * (int * int)) -> i + m.0 + m.1 in Map.fold aggregate m 10 let deep_op (m: foobar) : foobar = - let coco = 0,m in + let coco = 0, m in let coco = 0, Map.remove 42 coco.1 in let coco = 0, Map.update 32 (Some 16) coco.1 in coco.1 diff --git a/src/test/contracts/map.religo b/src/test/contracts/map.religo index 74ec39dcf..a88ea1ad7 100644 --- a/src/test/contracts/map.religo +++ b/src/test/contracts/map.religo @@ -1,59 +1,60 @@ - -type foobar = map(int, int); +type foobar = map (int, int); let empty_map: foobar = Map.empty; -let map1: foobar = - Map.literal([(144, 23), (51, 23), (42, 23), (120, 23), (421, 23)]); +let map1 : foobar = + Map.literal ([(144, 23), (51, 23), (42, 23), (120, 23), (421, 23)]); -let map2: foobar = Map.literal([(23, 0), (42, 0)]); +let map2 : foobar = Map.literal ([(23, 0), (42, 0)]); -let set_ = (n: int, m: foobar): foobar => Map.update(23, Some(n), m); +let set_ = (n: int, m: foobar) : foobar => Map.update (23, Some (n), m); -let add = (n: int, m: foobar) : foobar => Map.add(23, n, m); +let add = (n: int, m: foobar) : foobar => Map.add (23, n, m); -let rm = (m: foobar): foobar => Map.remove(42, m); +let rm = (m: foobar) : foobar => Map.remove (42, m); /* Dummy test so that we can add the same test for PascaLIGO */ -let patch_ = (m: foobar): foobar => Map.literal([(0, 5), (1, 6), (2, 7)]); + +let patch_ = (m : foobar) : foobar => + Map.literal ([(0, 5), (1, 6), (2, 7)]); /* Second dummy test, see above */ -let patch_empty = (m: foobar): foobar => - Map.literal([(0, 0), (1, 1), (2, 2)]); + +let patch_empty = (m : foobar) : foobar => + Map.literal ([(0, 0), (1, 1), (2, 2)]); /* Third dummy test, see above */ -let patch_deep = (m: (foobar, nat)): (foobar, nat) => ( + +let patch_deep = (m : (foobar, nat)) : (foobar, nat) => ( Map.literal([(0, 0), (1, 9), (2, 2)]), 10n ); -let size_ = (m: foobar): nat => Map.size(m); +let size_ = (m : foobar) : nat => Map.size (m); -let gf = (m: foobar): int => Map.find(23, m); - -let get = (m: foobar): option(int) => Map.find_opt(42, m); +let get = (m: foobar): option(int) => Map.find_opt (42, m); let get_ = (m: foobar): option(int) => Map.find_opt(42, m); -let mem = (km: (int, foobar)): bool => Map.mem(km[0], km[1]); +let mem = (km: (int, foobar)): bool => Map.mem (km[0], km[1]); let iter_op = (m: foobar): unit => { - let assert_eq = (i: int, j: int) => assert(i == j); - Map.iter(assert_eq, m); + let assert_eq = (i: int, j: int) => assert (i == j); + Map.iter (assert_eq, m); }; -let map_op = (m: foobar): foobar => { +let map_op = (m: foobar) : foobar => { let increment = (z: int, j: int) => j + 1; - Map.map(increment, m); + Map.map (increment, m); }; let fold_op = (m: foobar): foobar => { let aggregate = (i: int, j: (int, int)) => i + j[0] + j[1]; - Map.fold(aggregate, m, 10); + Map.fold (aggregate, m, 10); }; -let deep_op = (m: foobar): foobar => { +let deep_op = (m: foobar) : foobar => { let coco = (0, m); - let coco = (0, Map.remove(42, coco[1])); - let coco = (0, Map.update(32, Some(16), coco[1])); + let coco = (0, Map.remove (42, coco[1])); + let coco = (0, Map.update (32, Some (16), coco[1])); coco[1]; }; diff --git a/src/test/contracts/match.mligo b/src/test/contracts/match.mligo index 36d3f4b9b..d3e9d8d52 100644 --- a/src/test/contracts/match.mligo +++ b/src/test/contracts/match.mligo @@ -1,28 +1,30 @@ type storage = int -type param = +type parameter = Add of int | Sub of int -let main (p, s: param * storage) = - let storage = - s + - (match p with - Add n -> n - | Sub n -> 0-n) - in ([] : operation list), storage +type return = operation list * storage -let match_bool (b: bool) : int = +let main (action, store : parameter * storage) = + let store = + store + + (match action with + Add n -> n + | Sub n -> -n) + in ([] : operation list), store + +let match_bool (b : bool) : int = match b with true -> 10 | false -> 0 -let match_list (l: int list) : int = +let match_list (l : int list) : int = match l with - hd :: tl -> hd + hd::tl -> hd | [] -> 10 -let match_option (i: int option) : int = +let match_option (i : int option) : int = match i with Some n -> n | None -> 0 diff --git a/src/test/contracts/match.religo b/src/test/contracts/match.religo index 361443089..09e6836f7 100644 --- a/src/test/contracts/match.religo +++ b/src/test/contracts/match.religo @@ -1,19 +1,17 @@ type storage = int; -type param = - | Add(int) - | Sub(int); +type parameter = +| Add (int) +| Sub (int); -let main2 = ((p: param), s: storage) => { - let storage = - s - + ( - switch (p) { - | Add(n) => n - | Sub(n) => 0 - n - } - ); - (([]: list(operation)), storage); +type return = (list (operation), storage); + +let main = ((action, store): (parameter, storage)) => { + let store = + store + + (switch (action) { + | Add (n) => n + | Sub (n) => -n + }); + (([]: list (operation)), store); }; - -let main = (x: (param, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/match_bis.mligo b/src/test/contracts/match_bis.mligo index dcbc155e9..145e1bcf6 100644 --- a/src/test/contracts/match_bis.mligo +++ b/src/test/contracts/match_bis.mligo @@ -1,19 +1,17 @@ type storage = int -(* variant defining pseudo multi-entrypoint actions *) - -type action = +type parameter = Increment of int | Decrement of int -let add (a: int) (b: int) : int = a + b -let sub (a: int) (b: int) : int = a - b +type return = operation list * storage -(* real entrypoint that re-routes the flow based on the action provided *) +let add (a : int) (b : int) : int = a + b +let sub (a : int) (b : int) : int = a - b -let main (p, s: action * storage) = - let storage = - match p with - Increment n -> add s n - | Decrement n -> sub s n - in ([] : operation list), storage +let main (action, store : parameter * storage) : return = + let store = + match action with + Increment n -> add store n + | Decrement n -> sub store n + in ([] : operation list), store diff --git a/src/test/contracts/match_bis.religo b/src/test/contracts/match_bis.religo index ece959639..0ba4d8d95 100644 --- a/src/test/contracts/match_bis.religo +++ b/src/test/contracts/match_bis.religo @@ -1,24 +1,17 @@ type storage = int; -/* variant defining pseudo multi-entrypoint actions */ - -type action = - Increment(int) - | Decrement(int); +type parameter = + Increment (int) +| Decrement (int); let add = ((a: int), (b: int)) => a + b; +let sub = ((a: int), (b: int)) => a - b; -let subtract = ((a: int), (b: int)) => a - b; - -/* real entrypoint that re-routes the flow based on the action provided */ - -let main2 = ((p: action), storage : storage) => { - let storage = - switch (p) { - | Increment(n) => add(storage, n) - | Decrement(n) => subtract(storage, n) +let main = ((action, store) : (parameter, storage)) => { + let store = + switch (action) { + | Increment (n) => add (store, n) + | Decrement (n) => sub (store, n) }; - (([]: list(operation)), storage); + (([] : list (operation)), store); }; - -let main = (x: (action, storage)) => main2(x[0],x[1]); diff --git a/src/test/contracts/multiple-parameters.mligo b/src/test/contracts/multiple-parameters.mligo index 8b6d442f7..745b421cf 100644 --- a/src/test/contracts/multiple-parameters.mligo +++ b/src/test/contracts/multiple-parameters.mligo @@ -1,7 +1,7 @@ (* Test function with several parameters *) let abcde_curried (a : int) (b : int) (c : int) (d : int) (e : int) : int = - (c + e + 3) + c + e + 3 let abcde (x : int * int * int * int * int) : int = abcde_curried x.0 x.1 x.2 x.3 x.4 diff --git a/src/test/contracts/multiple-parameters.religo b/src/test/contracts/multiple-parameters.religo index 09af4152b..bececfa8f 100644 --- a/src/test/contracts/multiple-parameters.religo +++ b/src/test/contracts/multiple-parameters.religo @@ -1,6 +1,7 @@ /* Test function with several parameters */ -let abcde_curried = (a: int, b: int, c: int, d: int, e: int): int => c + e + 3; - -let abcde = (x: (int , int , int , int , int)): int => abcde_curried(x[0], x[1], x[2], x[3], x[4]); +let abcde_curried = + (a: int, b: int, c: int, d: int, e: int): int => c + e + 3; +let abcde = (x: (int , int , int , int , int)) : int => + abcde_curried (x[0], x[1], x[2], x[3], x[4]); diff --git a/src/test/contracts/multisig-v2.ligo b/src/test/contracts/multisig-v2.ligo index cb3292d18..002379827 100644 --- a/src/test/contracts/multisig-v2.ligo +++ b/src/test/contracts/multisig-v2.ligo @@ -37,22 +37,22 @@ function send (const param : send_pt; const s : storage) : return is block { // check sender against the authorized addresses - if not set_mem (sender, s.authorized_addresses) + if not Set.mem (Tezos.sender, s.authorized_addresses) then failwith("Unauthorized address") else skip; // check message size against the stored limit var message : message := param; - const packed_msg : bytes = bytes_pack (message); - if size (packed_msg) > s.max_message_size + const packed_msg : bytes = Bytes.pack (message); + if Bytes.length (packed_msg) > s.max_message_size then failwith ("Message size exceed maximum limit") else skip; (* compute the new set of addresses associated with the message and update counters *) - var new_store : addr_set := set_empty; + var new_store : addr_set := set []; case map_get (packed_msg, s.message_store) of Some (voters) -> @@ -60,26 +60,25 @@ function send (const param : send_pt; const s : storage) : return is (* The message is already stored. Increment the counter only if the sender is not already associated with the message. *) - if set_mem (sender, voters) + if Set.mem (Tezos.sender, voters) then skip - else s.proposal_counters[sender] := - get_force (sender, s.proposal_counters) + 1n; - - new_store := set_add(sender,voters) + else s.proposal_counters[Tezos.sender] := + get_force (Tezos.sender, s.proposal_counters) + 1n; + new_store := Set.add (Tezos.sender,voters) } | None -> block { // the message has never been received before s.proposal_counters[sender] := - get_force (sender, s.proposal_counters) + 1n; - new_store := set [sender] + get_force (Tezos.sender, s.proposal_counters) + 1n; + new_store := set [Tezos.sender] } end; // check sender counters against the maximum number of proposal var sender_proposal_counter : nat := - get_force (sender, s.proposal_counters); + get_force (Tezos.sender, s.proposal_counters); if sender_proposal_counter > s.max_proposal then failwith ("Maximum number of proposal reached") @@ -89,14 +88,14 @@ function send (const param : send_pt; const s : storage) : return is var ret_ops : list (operation) := nil; - if size (new_store) >= s.threshold then { + if Set.cardinal (new_store) >= s.threshold then { remove packed_msg from map s.message_store; ret_ops := message (s.state_hash); // update the state hash - s.state_hash := sha_256 (bytes_concat (s.state_hash, packed_msg)); + s.state_hash := Crypto.sha256 (Bytes.concat (s.state_hash, packed_msg)); // decrement the counters for addr -> ctr in map s.proposal_counters block { - if set_mem(addr,new_store) then + if Set.mem (addr, new_store) then s.proposal_counters[addr] := abs (ctr - 1n) else skip } @@ -106,26 +105,26 @@ function send (const param : send_pt; const s : storage) : return is function withdraw (const param : withdraw_pt; const s : storage) : return is block { var message : message := param; - const packed_msg : bytes = bytes_pack (message); + const packed_msg : bytes = Bytes.pack (message); - case map_get(packed_msg, s.message_store) of + case s.message_store[packed_msg] of Some (voters) -> block { // The message is stored - const new_set : addr_set = set_remove (sender, voters); + const new_set : addr_set = Set.remove (Tezos.sender, voters); (* Decrement the counter only if the sender was already associated with the message *) - if size (voters) =/= size (new_set) - then s.proposal_counters[sender] := - abs (get_force (sender, s.proposal_counters) - 1n) - else skip ; + if Set.cardinal (voters) =/= Set.cardinal (new_set) + then s.proposal_counters[Tezos.sender] := + abs (get_force (Tezos.sender, s.proposal_counters) - 1n) + else skip; (* If the message is left without any associated addresses, remove the corresponding message_store field *) - if size (new_set) = 0n + if Set.cardinal (new_set) = 0n then remove packed_msg from map s.message_store else s.message_store[packed_msg] := new_set } diff --git a/src/test/contracts/multisig.ligo b/src/test/contracts/multisig.ligo index f0cdb636c..19c8fc3c4 100644 --- a/src/test/contracts/multisig.ligo +++ b/src/test/contracts/multisig.ligo @@ -38,7 +38,7 @@ function check_message (const param : check_message_pt; failwith ("Counters does not match") else { const packed_payload : bytes = - bytes_pack ((message, param.counter, s.id, get_chain_id)); + Bytes.pack ((message, param.counter, s.id, Tezos.chain_id)); var valid : nat := 0n; var keys : authorized_keys := s.auth; @@ -47,12 +47,12 @@ function check_message (const param : check_message_pt; nil -> skip | key # tl -> block { keys := tl; - if pkh_sig.0 = crypto_hash_key (key) then - if crypto_check (key, pkh_sig.1, packed_payload) + if pkh_sig.0 = Crypto.hash_key (key) then + if Crypto.check (key, pkh_sig.1, packed_payload) then valid := valid + 1n else failwith ("Invalid signature") else skip - } + } end }; diff --git a/src/test/contracts/multisig.mligo b/src/test/contracts/multisig.mligo index 2a7753cc6..4d81e158a 100644 --- a/src/test/contracts/multisig.mligo +++ b/src/test/contracts/multisig.mligo @@ -2,65 +2,63 @@ type counter = nat type threshold = nat -type authorized_keys = (key) list +type authorized_keys = key list type id = string type storage = { - id : id; - counter : counter; - threshold : threshold; - auth : authorized_keys + id : id; + counter : counter; + threshold : threshold; + auth : authorized_keys } // I/O types -type message = unit -> (operation) list +type message = unit -> operation list + +type signatures = (key_hash * signature) list -type signatures = (key_hash*signature) list type check_message_pt = { - counter : counter; - message : message; - signatures : signatures + counter : counter; + message : message; + signatures : signatures } -type return = (operation) list * storage +type return = operation list * storage type parameter = CheckMessage of check_message_pt -let check_message (param,s : check_message_pt * storage) : return = +let check_message (param, s : check_message_pt * storage) : return = let message : message = param.message in let s = - if (param.counter <> s.counter) then - let coco = failwith ("Counters does not match") in s - else ( - let packed_payload : bytes = Bytes.pack ((message, param.counter, s.id, chain_id)) in - let valid : nat = 0n in - let keys : authorized_keys = s.auth in - let aux = fun (vk, pkh_sig: (nat* authorized_keys) * (key_hash*signature)) -> - let (valid,keys) = vk in - match (keys) with - | [] -> (valid,keys) - | key::tl -> ( - let keys = tl in - if (pkh_sig.0 = Crypto.hash_key (key)) then - let valid = - if (Crypto.check key pkh_sig.1 packed_payload) then valid + 1n - else let coco = failwith ("Invalid signature") in valid - in - (valid,keys) - else (valid,keys) - ) - in - let (valid,keys) = List.fold aux param.signatures (valid,keys) in - if (valid < s.threshold) then - let coco = failwith ("Not enough signatures passed the check") in - s - else - {s with counter = s.counter + 1n} - ) - in - (message(unit),s) + if param.counter <> s.counter then + (failwith "Counters does not match" : storage) + else + let packed_payload : bytes = + Bytes.pack (message, param.counter, s.id, chain_id) in + let valid : nat = 0n in + let keys : authorized_keys = s.auth in + let aux = + fun (vk, pkh_sig: (nat * authorized_keys)*(key_hash * signature)) -> + let valid, keys = vk in + match keys with + | [] -> vk + | key::keys -> + if pkh_sig.0 = Crypto.hash_key key + then + let valid = + if Crypto.check key pkh_sig.1 packed_payload + then valid + 1n + else (failwith "Invalid signature" : nat) + in valid, keys + else valid, keys in + let valid, keys = + List.fold aux param.signatures (valid, keys) in + if valid < s.threshold then + (failwith ("Not enough signatures passed the check") : storage) + else {s with counter = s.counter + 1n} + in message unit, s -let main (param, s: parameter * storage) : return = - match (param) with - | CheckMessage (p) -> check_message (p,s) +let main (action, store : parameter * storage) : return = + match action with + CheckMessage (p) -> check_message (p, store) diff --git a/src/test/contracts/multisig.religo b/src/test/contracts/multisig.religo index a2d709ab9..82b44d861 100644 --- a/src/test/contracts/multisig.religo +++ b/src/test/contracts/multisig.religo @@ -6,75 +6,72 @@ type authorized_keys = list (key); type id = string; type storage = { - id : id, - counter : counter, - threshold : threshold, - auth : authorized_keys + id : id, + counter : counter, + threshold : threshold, + auth : authorized_keys }; // I/O types type message = unit => list (operation); + type dummy = (key_hash,signature); -type signatures = list (dummy); + +type signatures = list (dummy); /* Waiting to be fixed */ type check_message_pt = { - counter : counter, - message : message, - signatures : signatures + counter : counter, + message : message, + signatures : signatures }; -type return = (list (operation),storage); +type return = (list (operation),storage); type parameter = CheckMessage (check_message_pt); -let check_message = ((param,s) : (check_message_pt, storage)) : return => { +let check_message = ((param, s): (check_message_pt, storage)) : return => +{ let message : message = param.message; let s = - if (param.counter != s.counter) { - let coco = failwith ("Counters does not match"); - s; - } - else { - let packed_payload : bytes = Bytes.pack ((message, param.counter, s.id, chain_id)); - let valid : nat = 0n; - let keys : authorized_keys = s.auth; - let aux = ((vk,pkh_sig) : ((nat, authorized_keys),(key_hash,signature))):(nat,authorized_keys) => { - let (valid,keys) = vk; - switch(keys) { - | [] => (valid,keys); - | [key, ...tl] => { - let keys = tl; - if (pkh_sig[0] == Crypto.hash_key (key)){ - let valid = - if (Crypto.check (key, pkh_sig[1], packed_payload)){ - valid + 1n ; - } - else { - let coco = failwith ("Invalid signature"); - valid; - }; - (valid,keys); - } - else { - (valid,keys); - }; + if (param.counter != s.counter) { + (failwith ("Counters does not match") : storage); + } else { + let packed_payload : bytes = + Bytes.pack ((message, param.counter, s.id, chain_id)); + let valid : nat = 0n; + let keys : authorized_keys = s.auth; + let aux = ((vk, pkh_sig) : + ((nat, authorized_keys), (key_hash, signature))) + : (nat, authorized_keys) => { + let (valid, keys) = vk; + switch (keys) { + | [] => vk; + | [key, ...keys] => + if (pkh_sig[0] == Crypto.hash_key (key)) { + let valid = + if (Crypto.check (key, pkh_sig[1], packed_payload)) { + valid + 1n; + } + else { (failwith ("Invalid signature") : nat) }; + (valid, keys); + } + else { (valid, keys); }; }; }; - }; - let (valid,keys) = List.fold (aux, param.signatures, (valid,keys)); + let (valid, keys) = + List.fold (aux, param.signatures, (valid, keys)); if (valid < s.threshold) { - let coco = failwith ("Not enough signatures passed the check"); - s; + (failwith ("Not enough signatures passed the check") : storage); } else { {...s,counter : s.counter + 1n}; }; }; - (message(unit),s) + (message (unit),s) }; -let main = ((param, s) : (parameter,storage)) : return => - switch(param) { - | CheckMessage (p) => check_message ((p,s)) +let main = ((action, store) : (parameter,storage)) : return => + switch (action) { + | CheckMessage (p) => check_message ((p, store)) } diff --git a/src/test/contracts/negative/self_in_lambda.mligo b/src/test/contracts/negative/self_in_lambda.mligo index 982973973..4c497e268 100644 --- a/src/test/contracts/negative/self_in_lambda.mligo +++ b/src/test/contracts/negative/self_in_lambda.mligo @@ -1,6 +1,5 @@ -let foo (u: unit) : address = - Current.self_address +let foo (u : unit) : address = Tezos.self_address -let main (ps: unit * address): (operation list * address) = - let dummy = foo() in - ( ([] : operation list) , foo()) +let main (ps : unit * address) : (operation list * address) = + let dummy = foo () in + ([] : operation list), foo () diff --git a/src/test/contracts/option.ligo b/src/test/contracts/option.ligo index 424171c93..39614435d 100644 --- a/src/test/contracts/option.ligo +++ b/src/test/contracts/option.ligo @@ -1,13 +1,13 @@ // Test the option type in PascaLIGO -type foobar is option(int) +type foobar is option (int) -const s : foobar = Some(42) +const s : foobar = Some (42) const n : foobar = None function assign (var m : int) : foobar is block { var coco : foobar := None; - coco := Some(m); + coco := Some (m); coco := (None : foobar); //temporary annotation added until type inference } with coco diff --git a/src/test/contracts/option.religo b/src/test/contracts/option.religo index 75dacb697..e416a034e 100644 --- a/src/test/contracts/option.religo +++ b/src/test/contracts/option.religo @@ -1,4 +1,4 @@ -type foobar = option(int); +type foobar = option (int); -let s: foobar = Some(42); -let n: foobar = None; +let s : foobar = Some (42); +let n : foobar = None; diff --git a/src/test/contracts/parser-bad-reported-term.ligo b/src/test/contracts/parser-bad-reported-term.ligo deleted file mode 100644 index 05dc69e3e..000000000 --- a/src/test/contracts/parser-bad-reported-term.ligo +++ /dev/null @@ -1,6 +0,0 @@ -function f (const x : unit) : unit is - begin skip end with unit - -function main (const p : unit ; const s : unit) : unit is - behin skip end with f unit -// the srcloc is correct but the reported term is "skip" instead of "behin". diff --git a/src/test/contracts/procedure.ligo b/src/test/contracts/procedure.ligo deleted file mode 100644 index a0f6664c6..000000000 --- a/src/test/contracts/procedure.ligo +++ /dev/null @@ -1,11 +0,0 @@ -// Test a trivial PascaLIGO procedure - -procedure sub (const j: int) is - begin - i := i + 1 - end - -function main (const i: int) : int is - begin - sub(i) - end with i diff --git a/src/test/contracts/quote-declaration.ligo b/src/test/contracts/quote-declaration.ligo index 4c5547d4c..d11fa919b 100644 --- a/src/test/contracts/quote-declaration.ligo +++ b/src/test/contracts/quote-declaration.ligo @@ -1,8 +1,3 @@ -function foo (const input : int) : int is begin - skip -end with (input + 42) +function foo (const input : int) : int is input + 42 -function main (const i : int) : int is - begin - skip - end with i + foo (i) +function main (const i : int) : int is i + foo (i) diff --git a/src/test/contracts/quote-declarations.ligo b/src/test/contracts/quote-declarations.ligo index 1b783066d..d98fbe15a 100644 --- a/src/test/contracts/quote-declarations.ligo +++ b/src/test/contracts/quote-declarations.ligo @@ -1,13 +1,5 @@ -function foo (const input : int) : int is begin - skip -end with (input + 23) +function foo (const input : int) : int is input + 23 -function bar (const input : int) : int is begin - skip -end with (input + 51) +function bar (const input : int) : int is input + 51 - -function main (const i : int) : int is - begin - skip - end with foo (i) + bar (i) +function main (const i : int) : int is foo (i) + bar (i) diff --git a/src/test/contracts/record.ligo b/src/test/contracts/record.ligo index 94b49d9fc..1cc6ad2a2 100644 --- a/src/test/contracts/record.ligo +++ b/src/test/contracts/record.ligo @@ -1,68 +1,38 @@ // Test record type in PascaLIGO -type foobar is record - foo : int ; - bar : int ; -end +type foobar is record [foo : int; bar : int] -const fb : foobar = record - foo = 0 ; - bar = 0 ; -end +const fb : foobar = record [foo = 0; bar = 0] -type abc is record - a : int ; - b : int ; - c : int ; -end +type abc is record [a : int; b : int; c : int] -const abc : abc = record - a = 42 ; - b = 142 ; - c = 242 ; -end +const abc : abc = record [a = 42; b = 142; c = 242] -const a : int = abc.a ; -const b : int = abc.b ; -const c : int = abc.c ; +const a : int = abc.a +const b : int = abc.b +const c : int = abc.c -function projection (const r : foobar) : int is - begin - skip - end with r.foo + r.bar +function projection (const r : foobar) : int is r.foo + r.bar -function modify (const r : foobar) : foobar is +function modify (var r : foobar) : foobar is block { - r.foo := 256 ; + r.foo := 256 } with r function modify_abc (const r : abc) : abc is block { const c : int = 42; - r := r with record b = 2048; c = c; end; + r := r with record [b=2048; c=c] } with r -type big_record is record - a : int ; - b : int ; - c : int ; - d : int ; - e : int ; -end +type big_record is record [a : int; b : int; c : int; d : int; e : int] -const br : big_record = record - a = 23 ; - b = 23 ; - c = 23 ; - d = 23 ; - e = 23 ; -end +const br : big_record = + record [a = 23; b = 23; c = 23; d = 23; e = 23] -type double_record is record - inner : abc; -end +type double_record is record [inner : abc] function modify_inner (const r : double_record) : double_record is block { - r := r with record inner.b = 2048; end; + r := r with record [inner.b = 2048] } with r diff --git a/src/test/contracts/record.mligo b/src/test/contracts/record.mligo index 4863cdf6c..96cb99a33 100644 --- a/src/test/contracts/record.mligo +++ b/src/test/contracts/record.mligo @@ -1,24 +1,10 @@ -type foobar = { - foo : int ; - bar : int ; -} +type foobar = {foo : int; bar : int} -let fb : foobar = { - foo = 0 ; - bar = 0 ; -} +let fb : foobar = {foo=0; bar=0} -type abc = { - a : int ; - b : int ; - c : int -} +type abc = {a : int; b : int; c : int} -let abc : abc = { - a = 42 ; - b = 142 ; - c = 242 -} +let abc : abc = {a=42; b=142; c=242} let a : int = abc.a let b : int = abc.b @@ -28,26 +14,25 @@ let projection (r : foobar) : int = r.foo + r.bar let modify (r : foobar) : foobar = {foo = 256; bar = r.bar} -let modify_abc (r : abc) : abc = let c = 42 in {r with b = 2048; c = c} +let modify_abc (r : abc) : abc = let c = 42 in {r with b=2048; c=c} type big_record = { - a : int ; - b : int ; - c : int ; - d : int ; - e : int ; + a : int; + b : int; + c : int; + d : int; + e : int } let br : big_record = { - a = 23 ; - b = 23 ; - c = 23 ; - d = 23 ; - e = 23 ; + a = 23; + b = 23; + c = 23; + d = 23; + e = 23 } -type double_record = { - inner : abc; -} +type double_record = {inner : abc} -let modify_inner (r : double_record) : double_record = {r with inner.b = 2048 } +let modify_inner (r : double_record) : double_record = + {r with inner.b = 2048} diff --git a/src/test/contracts/record.religo b/src/test/contracts/record.religo index c82801324..793d01640 100644 --- a/src/test/contracts/record.religo +++ b/src/test/contracts/record.religo @@ -1,22 +1,22 @@ type foobar = { - foo : int , - bar : int , + foo : int, + bar : int }; let fb : foobar = { - foo : 0 , - bar : 0 , + foo : 0, + bar : 0 }; type abc = { - a : int , - b : int , + a : int, + b : int, c : int }; let abc : abc = { - a : 42 , - b : 142 , + a : 42, + b : 142, c : 242 }; @@ -24,30 +24,31 @@ let a : int = abc.a; let b : int = abc.b; let c : int = abc.c; -let projection = (r : foobar) : int => r.foo + r.bar; +let projection = (r: foobar) : int => r.foo + r.bar; -let modify = (r : foobar) : foobar => {foo : 256, bar : r.bar}; +let modify = (r: foobar) : foobar => {foo: 256, bar: r.bar}; -let modify_abc = (r : abc) : abc => {...r,b : 2048 , c:42}; +let modify_abc = (r: abc) : abc => {...r, b: 2048, c: 42}; type big_record = { - a : int , - b : int , - c : int , - d : int , - e : int , + a : int, + b : int, + c : int, + d : int, + e : int }; let br : big_record = { - a : 23 , - b : 23 , - c : 23 , - d : 23 , - e : 23 , + a : 23, + b : 23, + c : 23, + d : 23, + e : 23 }; type double_record = { inner : abc, }; -let modify_inner = (r : double_record) : double_record => {...r,inner.b : 2048 }; +let modify_inner = + (r: double_record) : double_record => {...r, inner.b : 2048}; diff --git a/src/test/contracts/redeclaration.ligo b/src/test/contracts/redeclaration.ligo index c74594ad3..b8bcecbc2 100644 --- a/src/test/contracts/redeclaration.ligo +++ b/src/test/contracts/redeclaration.ligo @@ -1,6 +1,6 @@ -function foo(const p : unit) : int is 0 +function foo (const p : unit) : int is 0 -function main(const p : unit; const s : int) : list(operation) * int is - ((list end : list(operation)), foo(unit)) +function main (const p : unit; const s : int) : list (operation) * int is + ((nil : list (operation)), foo (unit)) -function foo(const p : unit) : int is 1 \ No newline at end of file +function foo (const p : unit) : int is 1 diff --git a/src/test/contracts/replaceable_id.ligo b/src/test/contracts/replaceable_id.ligo index 3b116e69b..8e46cde84 100644 --- a/src/test/contracts/replaceable_id.ligo +++ b/src/test/contracts/replaceable_id.ligo @@ -1,35 +1,35 @@ // storage type -type storage_t is address; +type storage_t is address // entry points parameter types type change_addr_pt is address -type message_t is list (operation) ; -type pass_message_pt is (unit -> message_t) +type message_t is list (operation) +type pass_message_pt is unit -> message_t -type contract_return_t is (list(operation) * storage_t) +type contract_return_t is list (operation) * storage_t type entry_point_t is -| Change_address of change_addr_pt -| Pass_message of pass_message_pt + Change_address of change_addr_pt +| Pass_message of pass_message_pt function change_address (const param : change_addr_pt; const s : storage_t) : contract_return_t is - begin - if sender =/= s then failwith("Unauthorized sender") + block { + if sender =/= s then failwith ("Unauthorized sender") else skip -end with ((nil : list(operation)), param) + } with ((nil : list (operation)), param) -function pass_message ( const param: pass_message_pt; - const s : storage_t ) : contract_return_t is - begin - if sender =/= s then failwith("Unauthorized sender") else skip ; - var message : pass_message_pt := param ; -end with (param(unit),s) +function pass_message (const param: pass_message_pt; + const s : storage_t ) : contract_return_t is + block { + if sender =/= s then failwith("Unauthorized sender") else skip; + var message : pass_message_pt := param + } with (param (unit), s) -function main(const param : entry_point_t; const s : storage_t) : contract_return_t is -block {skip} with +function main (const param : entry_point_t; const s : storage_t) : + contract_return_t is case param of - | Change_address (p) -> change_address(p,s) - | Pass_message (p) -> pass_message(p,s) -end \ No newline at end of file + Change_address (p) -> change_address (p,s) + | Pass_message (p) -> pass_message (p,s) + end diff --git a/src/test/contracts/self_address.ligo b/src/test/contracts/self_address.ligo index 72872ce0f..5dd4aebe0 100644 --- a/src/test/contracts/self_address.ligo +++ b/src/test/contracts/self_address.ligo @@ -1 +1 @@ -function main (const p: unit) : address is self_address +function main (const p : unit) : address is Tezos.self_address diff --git a/src/test/contracts/self_address.mligo b/src/test/contracts/self_address.mligo index ade0926ee..bd33b92a6 100644 --- a/src/test/contracts/self_address.mligo +++ b/src/test/contracts/self_address.mligo @@ -1 +1 @@ -let main (p: unit) : address = Current.self_address +let main (p : unit) : address = Tezos.self_address diff --git a/src/test/contracts/self_address.religo b/src/test/contracts/self_address.religo index e072bc56f..a2dd5a652 100644 --- a/src/test/contracts/self_address.religo +++ b/src/test/contracts/self_address.religo @@ -1 +1 @@ -let main = (p: unit): address => Current.self_address; +let main = (p: unit) : address => Tezos.self_address; diff --git a/src/test/contracts/set_arithmetic-1.ligo b/src/test/contracts/set_arithmetic-1.ligo index 87e2621b2..4ad3b13cf 100644 --- a/src/test/contracts/set_arithmetic-1.ligo +++ b/src/test/contracts/set_arithmetic-1.ligo @@ -1,17 +1,17 @@ // Test set iteration in PascaLIGO -function iter_op (const s : set(int)) : int is - begin - var r : int := 0 ; - function aggregate (const i : int) : unit is - begin - r := r + i ; - end with unit ; - set_iter(aggregate, s) ; - end with r - -function fold_op (const s : set(int)) : int is +function iter_op (const s : set (int)) : int is block { - function aggregate (const i : int ; const j : int) : int is + var r : int := 0; + function aggregate (const i : int) : unit is + block { + r := r + i + } with unit; + set_iter (aggregate, s) + } with r // ALWAYS RETURNS 0 + +function fold_op (const s : set (int)) : int is + block { + function aggregate (const i : int; const j : int) : int is i + j - } with set_fold(aggregate, s , 15) + } with set_fold (aggregate, s, 15) diff --git a/src/test/contracts/set_arithmetic-1.mligo b/src/test/contracts/set_arithmetic-1.mligo index 6c31953b4..634c18cc6 100644 --- a/src/test/contracts/set_arithmetic-1.mligo +++ b/src/test/contracts/set_arithmetic-1.mligo @@ -2,5 +2,4 @@ let aggregate (i : int) (j : int) : int = i + j -let fold_op (s : int set) : int = - Set.fold aggregate s 15 +let fold_op (s : int set) : int = Set.fold aggregate s 15 diff --git a/src/test/contracts/set_arithmetic.ligo b/src/test/contracts/set_arithmetic.ligo index eb0f8cf9e..2c801abbe 100644 --- a/src/test/contracts/set_arithmetic.ligo +++ b/src/test/contracts/set_arithmetic.ligo @@ -1,30 +1,27 @@ // Test set type and basic operations in PascaLIGO -const s_e : set(string) = (set_empty : set(string)) +const s_e : set (string) = set_empty -const s_fb : set(string) = set [ - "foo" ; - "bar" ; -] +const s_fb : set (string) = set ["foo"; "bar"] -function add_op (const s : set(string)) : set(string) is - begin skip end with set_add("foobar" , s) +function add_op (const s : set (string)) : set (string) is + set_add ("foobar", s) -function remove_op (const s : set(string)) : set(string) is - begin skip end with set_remove("foobar" , s) +function remove_op (const s : set (string)) : set (string) is + set_remove ("foobar", s) // Test the PascaLIGO syntactic sugar for set removal vs. the function call -function remove_syntax (var s : set(string)) : set(string) is - begin remove "foobar" from set s; end with s +function remove_syntax (var s : set (string)) : set (string) is + block {remove "foobar" from set s} with s -function remove_deep (var s : set(string) * nat) : set(string) * nat is - begin remove "foobar" from set s.0; end with s +function remove_deep (var s : set (string) * nat) : set (string) * nat is + block {remove "foobar" from set s.0} with s -function patch_op (var s: set(string)) : set(string) is - begin patch s with set ["foobar"]; end with s +function patch_op (var s : set (string)) : set (string) is + block {patch s with set ["foobar"]} with s -function patch_op_deep (var s: set(string)*nat) : set(string)*nat is - begin patch s.0 with set ["foobar"]; end with s +function patch_op_deep (var s : set (string) * nat) : set (string) * nat is + block {patch s.0 with set ["foobar"]} with s -function mem_op (const s : set(string)) : bool is - begin skip end with set_mem("foobar" , s) +function mem_op (const s : set (string)) : bool is + set_mem ("foobar", s) diff --git a/src/test/contracts/set_arithmetic.mligo b/src/test/contracts/set_arithmetic.mligo index 0eff261f7..3ff55333e 100644 --- a/src/test/contracts/set_arithmetic.mligo +++ b/src/test/contracts/set_arithmetic.mligo @@ -20,8 +20,6 @@ let patch_op_deep (s: string set * nat) : string set * nat = begin patch s.0 with set ["foobar"]; end with s *) -let mem_op (s : string set) : bool = - Set.mem "foobar" s +let mem_op (s : string set) : bool = Set.mem "foobar" s -let size_op (s: string set) : nat = - Set.size s +let size_op (s: string set) : nat = Set.cardinal s diff --git a/src/test/contracts/set_arithmetic.religo b/src/test/contracts/set_arithmetic.religo index 5aa634333..a219fba9b 100644 --- a/src/test/contracts/set_arithmetic.religo +++ b/src/test/contracts/set_arithmetic.religo @@ -1,22 +1,19 @@ /* Test set operations in ReasonLIGO */ -let literal_op = (p: unit) : set(string) => Set.literal(["foo", "bar", "foobar"]); +let literal_op = (p: unit) : set (string) => + Set.literal (["foo", "bar", "foobar"]); -let add_op = (s: set(string)): set(string) => Set.add("foobar", s); +let add_op = (s: set (string)) : set (string) => + Set.add ("foobar", s); -let remove_op = (s: set(string)): set(string) => Set.remove("foobar", s); +let remove_op = (s: set (string)) : set(string) => + Set.remove ("foobar", s); -let remove_deep = (s: (set(string), nat)): (set(string), nat) => - Set.remove("foobar", s[0]); +let remove_deep = (s: (set (string), nat)): (set (string), nat) => + Set.remove ("foobar", s[0]); -/* - let patch_op (s: string set) : string set = - begin patch s with set ["foobar"]; end with s +let mem_op = (s: set (string)) : bool => + Set.mem ("foobar", s); - let patch_op_deep (s: string set * nat) : string set * nat = - begin patch s[0] with set ["foobar"]; end with s - */ - -let mem_op = (s: set(string)): bool => Set.mem("foobar", s); - -let size_op = (s: set(string)): nat => Set.size(s); +let size_op = (s: set (string)): nat => + Set.cardinal (s); diff --git a/src/test/contracts/set_delegate.ligo b/src/test/contracts/set_delegate.ligo index 32f571741..dfdc7a0ef 100644 --- a/src/test/contracts/set_delegate.ligo +++ b/src/test/contracts/set_delegate.ligo @@ -1,6 +1,5 @@ -function main (const p: key_hash) : list(operation) is - begin - const unused: operation = set_delegate(Some(p)) ; - const dummy: list(operation) = nil; - end with dummy - +function main (const p : key_hash) : list (operation) is + block { + const unused : operation = set_delegate (Some (p)); + const dummy : list (operation) = nil + } with dummy diff --git a/src/test/contracts/set_delegate.mligo b/src/test/contracts/set_delegate.mligo index 9b3629f5d..66346cef6 100644 --- a/src/test/contracts/set_delegate.mligo +++ b/src/test/contracts/set_delegate.mligo @@ -1,3 +1,3 @@ -let main (p: key_hash) : operation list = - let unused: operation = (Operation.set_delegate (Some p)) in ([]: operation list) - +let main (p : key_hash) : operation list = + let useless : operation = Tezos.set_delegate (Some p) + in ([] : operation list) diff --git a/src/test/contracts/set_delegate.religo b/src/test/contracts/set_delegate.religo index bae3a38fb..90d3d0c12 100644 --- a/src/test/contracts/set_delegate.religo +++ b/src/test/contracts/set_delegate.religo @@ -1,4 +1,4 @@ -let main = (p: key_hash) : list(operation) => { - let unused: operation = (Operation.set_delegate(Some(p))); - ([]: list(operation)); +let main = (p: key_hash) : list (operation) => { + let unused : operation = (Tezos.set_delegate (Some (p))); + ([] : list (operation)); } ; diff --git a/src/test/contracts/shadow.ligo b/src/test/contracts/shadow.ligo index a1891c651..a170b6d43 100644 --- a/src/test/contracts/shadow.ligo +++ b/src/test/contracts/shadow.ligo @@ -1,5 +1,4 @@ function foo (const i : int) : int is block { - function bar (const i : int) : int is - i ; + function bar (const i : int) : int is i } with bar (0) diff --git a/src/test/contracts/simple_access.ligo b/src/test/contracts/simple_access.ligo index e26e23bc7..9a5c585a3 100644 --- a/src/test/contracts/simple_access.ligo +++ b/src/test/contracts/simple_access.ligo @@ -1,21 +1,21 @@ -//Test simple_access in PascalLigo -type tpi is (int*int) -type rpi is record -x : int; -y : int; -end -type mpi is map(string,int) +//Test simple_access in PascaLIGO + +type tpi is int * int + +type rpi is record [x : int; y : int] + +type mpi is map (string, int) function main (const toto : tpi) : int is - begin + block { var a : tpi := toto; - var b : rpi := record x = 0; y=1 ; end; - var m : mpi := map "y" -> 1; end; + var b : rpi := record [x=0; y=1]; + var m : mpi := map ["y" -> 1]; a.0 := 2; b.x := a.0; - m["x"] := b.x; - end with - case m["x"] of - | Some (s) -> s - | None -> 42 - end + m["x"] := b.x + } with + case m["x"] of + Some (s) -> s + | None -> 42 + end diff --git a/src/test/contracts/string.ligo b/src/test/contracts/string.ligo index 846daf7e5..c563cd16c 100644 --- a/src/test/contracts/string.ligo +++ b/src/test/contracts/string.ligo @@ -1,3 +1,3 @@ const s : string = "toto" -const x : string = s^"bar" -const y : string = "foo"^x +const x : string = s ^ "bar" +const y : string = "foo" ^ x diff --git a/src/test/contracts/string_arithmetic.ligo b/src/test/contracts/string_arithmetic.ligo index c8ceacb01..d76fd041d 100644 --- a/src/test/contracts/string_arithmetic.ligo +++ b/src/test/contracts/string_arithmetic.ligo @@ -1,5 +1,5 @@ function concat_op (const s : string) : string is - begin skip end with string_concat(s , "toto") + string_concat (s, "toto") function slice_op (const s : string) : string is - begin skip end with string_slice(1n , 2n , s) + string_slice (1n, 2n, s) diff --git a/src/test/contracts/string_arithmetic.mligo b/src/test/contracts/string_arithmetic.mligo index a17e8bd47..97d74d5e3 100644 --- a/src/test/contracts/string_arithmetic.mligo +++ b/src/test/contracts/string_arithmetic.mligo @@ -1,7 +1,5 @@ (* Test that the string concatenation syntax in CameLIGO works *) -let size_op (s: string) : nat = String.size s - -let slice_op (s: string) : string = String.slice 1n 2n s - -let concat_syntax (s: string) = s ^ "test_literal" +let size_op (s : string) : nat = String.length s +let slice_op (s : string) : string = String.sub 1n 2n s +let concat_syntax (s : string) = s ^ "test_literal" diff --git a/src/test/contracts/string_arithmetic.religo b/src/test/contracts/string_arithmetic.religo index ba3949f08..cd3a785cb 100644 --- a/src/test/contracts/string_arithmetic.religo +++ b/src/test/contracts/string_arithmetic.religo @@ -1,7 +1,5 @@ /* Test that the string concatenation syntax in ReasonLIGO works */ -let size_op = (s: string): nat => String.size(s); - -let slice_op = (s: string): string => String.slice(1n, 2n, s); - +let size_op = (s: string) : nat => String.length (s); +let slice_op = (s: string) : string => String.sub (1n, 2n, s); let concat_syntax = (s: string) => s ++ "test_literal"; diff --git a/src/test/contracts/subtle_nontail_fail.mligo b/src/test/contracts/subtle_nontail_fail.mligo index 107dbdb1e..6b3c52b9b 100644 --- a/src/test/contracts/subtle_nontail_fail.mligo +++ b/src/test/contracts/subtle_nontail_fail.mligo @@ -1,4 +1,4 @@ -let main (ps : unit * unit) = +let main (_ : unit * unit) = if true then failwith "This contract always fails" else failwith "This contract still always fails" diff --git a/src/test/contracts/super-counter.ligo b/src/test/contracts/super-counter.ligo index fcfa8422e..5bdde86d0 100644 --- a/src/test/contracts/super-counter.ligo +++ b/src/test/contracts/super-counter.ligo @@ -1,10 +1,14 @@ type action is -| Increment of int + Increment of int | Decrement of int -function main (const p : action ; const s : int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), - case p of - | Increment (n) -> s + n - | Decrement (n) -> s - n - end) +type storage is int + +type return is list (operation) * storage + +function main (const p : action; const s : int) : return is + ((nil : list (operation)), + case p of + Increment (n) -> s + n + | Decrement (n) -> s - n + end) diff --git a/src/test/contracts/super-counter.mligo b/src/test/contracts/super-counter.mligo index dc00c9567..2090a5732 100644 --- a/src/test/contracts/super-counter.mligo +++ b/src/test/contracts/super-counter.mligo @@ -1,13 +1,17 @@ -type action = -| Increment of int +type parameter = + Increment of int | Decrement of int -let test_param = Increment(1) +type storage = int + +type return = operation list * storage + +let test_param = Increment 1 let test_storage = 2 -let main (ps : action * int) : (operation list * int) = - let storage = - match ps.0 with - | Increment n -> ps.1 + n - | Decrement n -> ps.1 - n in - (([] : operation list) , storage) +let main (action, store : parameter * storage) : return = + let store = + match action with + | Increment n -> store + n + | Decrement n -> store - n + in ([] : operation list), store diff --git a/src/test/contracts/super-counter.religo b/src/test/contracts/super-counter.religo index 3e64f3152..53eba61af 100644 --- a/src/test/contracts/super-counter.religo +++ b/src/test/contracts/super-counter.religo @@ -1,12 +1,16 @@ -type action = - | Increment(int) - | Decrement(int); +type parameter = + Increment (int) +| Decrement (int); -let main = (p: action, s: int): (list(operation), int) => { - let storage = - switch (p) { - | Increment(n) => s + n - | Decrement(n) => s - n +type storage = int; + +type return = (list (operation), storage); + +let main = ((action, store): (parameter, storage) : return => { + let store = + switch (action) { + | Increment (n) => store + n + | Decrement (n) => store - n }; - ([]: list(operation), storage); + ([] : list (operation), store); }; diff --git a/src/test/contracts/tez.ligo b/src/test/contracts/tez.ligo index 31d5915cf..d39524d2b 100644 --- a/src/test/contracts/tez.ligo +++ b/src/test/contracts/tez.ligo @@ -1,16 +1,18 @@ -const add_tez : tez = 21mutez + 0.000021tz; -const sub_tez : tez = 21mutez - 20mutez; +const add_tez : tez = 21mutez + 0.000_021tez + +const sub_tez : tez = 21mutez - 20mutez + (* This is not enough. *) -const not_enough_tez : tez = 4611686018427387903mutez; +const not_enough_tez : tez = 461_168_601_842_738_7903mutez -const nat_mul_tez : tez = 1n * 100mutez; -const tez_mul_nat : tez = 100mutez * 10n; +const nat_mul_tez : tez = 1n * 100mutez +const tez_mul_nat : tez = 100mutez * 10n -const tez_div_tez1 : nat = 100mutez / 1mutez; -const tez_div_tez2 : nat = 100mutez / 90mutez; -const tez_div_tez3 : nat = 100mutez / 110mutez; +const tez_div_tez1 : nat = 100mutez / 1mutez +const tez_div_tez2 : nat = 100mutez / 90mutez +const tez_div_tez3 : nat = 100mutez / 110mutez -const tez_mod_tez1 : tez = 100mutez mod 1mutez; -const tez_mod_tez2 : tez = 100mutez mod 90mutez; -const tez_mod_tez3 : tez = 100mutez mod 110mutez; +const tez_mod_tez1 : tez = 100mutez mod 1mutez +const tez_mod_tez2 : tez = 100mutez mod 90mutez +const tez_mod_tez3 : tez = 100mutez mod 110mutez diff --git a/src/test/contracts/tez.mligo b/src/test/contracts/tez.mligo index 557de9e2d..f03821ec8 100644 --- a/src/test/contracts/tez.mligo +++ b/src/test/contracts/tez.mligo @@ -1,5 +1,6 @@ -let add_tez : tez = 21mutez + 0.000021tz -let sub_tez : tez = 0.000021tz - 0.000020tz -let not_enough_tez : tez = 4611686018427.387903tz +let add_tez : tez = 21mutez + 0.000_021tez +let sub_tez : tez = 0.000021tez - 0.000_020tez +let not_enough_tez : tez = 461_168_601_842_738_7903mutez -let add_more_tez : tez = 100tz + 10tz + 1tz + 0.1tz + 0.01tz + 0.001tz +let add_more_tez : tez = + 100tez + 10tez + 1tez + 0.1tez + 0.01tez + 0.001tez diff --git a/src/test/contracts/time-lock.ligo b/src/test/contracts/time-lock.ligo index c45f40a23..24065e25a 100644 --- a/src/test/contracts/time-lock.ligo +++ b/src/test/contracts/time-lock.ligo @@ -1,25 +1,28 @@ type storage_t is timestamp -type message_t is (unit -> list(operation)) +type message_t is unit -> list (operation) type default_pt is unit type call_pt is message_t -type contract_return_t is (list(operation) * storage_t) +type contract_return_t is list (operation) * storage_t type entry_point_t is | Call of call_pt | Default of default_pt -function call (const p : call_pt; const s : storage_t) : contract_return_t is block { - if s >= now then failwith("Contract is still time locked") else skip ; - const message : message_t = p ; - const ret_ops : list(operation) = message(unit) ; -} with (ret_ops,s) +function call (const p : call_pt; const s : storage_t) : contract_return_t is + block { + if s >= now then failwith ("Contract is still time locked") else skip; + const message : message_t = p; + const ret_ops : list (operation) = message (unit) + } with (ret_ops, s) -function default (const p : default_pt; const s : storage_t) : contract_return_t is - ((nil: list(operation)) , s) +function default (const p : default_pt; const s : storage_t) : + contract_return_t is + ((nil : list (operation)), s) -function main(const param : entry_point_t; const s : storage_t) : contract_return_t is +function main(const param : entry_point_t; const s : storage_t) : + contract_return_t is case param of - | Call (p) -> call(p,s) - | Default (p) -> default(p,s) -end \ No newline at end of file + Call (p) -> call (p,s) + | Default (p) -> default (p,s) + end diff --git a/src/test/contracts/timelock_repeat.mligo b/src/test/contracts/timelock_repeat.mligo index 5efff81a9..e2d4edd05 100644 --- a/src/test/contracts/timelock_repeat.mligo +++ b/src/test/contracts/timelock_repeat.mligo @@ -1,22 +1,22 @@ +type parameter = unit + type storage = { - next_use: timestamp; - interval: int; - execute: unit -> operation list; + next_use : timestamp; + interval : int; + execute : unit -> operation list } -let main (p,s: unit * storage) : operation list * storage = - (* Multiple calls to Current.time give different values *) - let now: timestamp = Current.time in - if now > s.next_use +type return = operation list * storage + +let main (action, store : parameter * storage) : return = + (* Multiple evaluations of Tezos.now give different values *) + let my_now : timestamp = Tezos.now in + if my_now > store.next_use then - let s: storage = { - next_use = now + s.interval; - interval = s.interval; - execute = s.execute; - } - in - (s.execute (), s) + let store : storage = + {store with next_use = my_now + store.interval} + in store.execute (), store else (* TODO: Add the time until next use to this message *) - (failwith "You have to wait before you can execute this contract again.": - operation list * storage) + (failwith "You have to wait before you can execute this contract again." + : return) diff --git a/src/test/contracts/timestamp.ligo b/src/test/contracts/timestamp.ligo index 4e105c45f..7d176cda8 100644 --- a/src/test/contracts/timestamp.ligo +++ b/src/test/contracts/timestamp.ligo @@ -1,3 +1,4 @@ type storage_ is timestamp -function main(const p : unit; const s : storage_) : list(operation) * storage_ is ((nil: list(operation)), now) \ No newline at end of file +function main (const p : unit; const s : storage_) : + list (operation) * storage_ is ((nil: list (operation)), now) diff --git a/src/test/contracts/toto.ligo b/src/test/contracts/toto.ligo index 785655b4a..6fd888e1c 100644 --- a/src/test/contracts/toto.ligo +++ b/src/test/contracts/toto.ligo @@ -1,6 +1,3 @@ -type toto is record - a : nat ; - b : nat -end +type toto is record [a : nat; b : nat] const foo : int = 3 diff --git a/src/test/contracts/tuple.ligo b/src/test/contracts/tuple.ligo index 9a39cde03..afe953345 100644 --- a/src/test/contracts/tuple.ligo +++ b/src/test/contracts/tuple.ligo @@ -1,22 +1,18 @@ -type abc is (int * int * int) +type abc is int * int * int -function projection_abc (const tpl : abc) : int is - block { skip } with tpl.1 +function projection_abc (const tpl : abc) : int is tpl.1 function modify_abc (const tpl : abc) : abc is block { - tpl.1 := 2048 ; + tpl.1 := 2048 } with tpl -type foobar is (int * int) +type foobar is int * int -const fb : foobar = (0, 0) +const fb : foobar = (0,0) -function projection (const tpl : foobar) : int is - begin - skip - end with tpl.0 + tpl.1 +function projection (const tpl : foobar) : int is tpl.0 + tpl.1 -type big_tuple is (int * int * int * int * int) +type big_tuple is int * int * int * int * int const br : big_tuple = (23, 23, 23, 23, 23) diff --git a/src/test/contracts/tuple.mligo b/src/test/contracts/tuple.mligo index 11726bf18..5dd1c4c2e 100644 --- a/src/test/contracts/tuple.mligo +++ b/src/test/contracts/tuple.mligo @@ -4,7 +4,7 @@ let projection_abc (tpl : abc) : int = tpl.1 type foobar = int * int -let fb : foobar = (0, 0) +let fb : foobar = (0,0) let projection (tpl : foobar) : int = tpl.0 + tpl.1 diff --git a/src/test/contracts/tuple_type.mligo b/src/test/contracts/tuple_type.mligo index d9cdb62b5..98e85209f 100644 --- a/src/test/contracts/tuple_type.mligo +++ b/src/test/contracts/tuple_type.mligo @@ -1,14 +1,13 @@ -let g (b: int) = b + 3 +let g (b : int) = b + 3 -let f (b: int * int) : int -> int = g +let f (b : int * int) : int -> int = g -let a (b: int * int -> int -> int) : int = (b (5,3)) 5 +let a (b : int * int -> int -> int) : int = (b (5,3)) 5 -let test1 (_: int) = - a f +let test1 (_: int) = a f -let n (a, b: int * int): int = a + b +let n (a, b : int * int) : int = a + b -let o (p: int * int -> int): int = p((3, 9)) +let o (p : int * int -> int) : int = p (3, 9) -let test2 (ignore: int) = o(n) +let test2 (ignore : int) = o (n) diff --git a/src/test/contracts/tuple_type.religo b/src/test/contracts/tuple_type.religo index 6148840c0..e17fbc9fb 100644 --- a/src/test/contracts/tuple_type.religo +++ b/src/test/contracts/tuple_type.religo @@ -1,49 +1,43 @@ -/* - The difference between tuples and arguments is subtle in ReasonLIGO. - - `f(a, b);` +/* + The difference between tuples and arguments is subtle in ReasonLIGO. + + `f(a, b);` f is called with two arguments - `f((a, b));` + `f((a, b));` f is called with a tuple. - + */ type fun_type = (int, int) => int; -let arguments = (b: int, c: int) => { - b + c; -}; +let arguments = (b: int, c: int) => { b + c; }; -let arguments_type_def = (b: fun_type) => b(5, 3); +let arguments_type_def = (b: fun_type) => b (5, 3); -let arguments_test = (ignore: int) => arguments_type_def(arguments); +let arguments_test = (ignore: int) => arguments_type_def (arguments); type tuple_type = ((int, int)) => int; -let tuple = ((a, b): (int, int)) => { - a + b; -}; +let tuple = ((a, b): (int, int)) => { a + b; }; -let tuple_type_def = (b: tuple_type) => b((5, 3)); +let tuple_type_def = (b: tuple_type) => b ((5, 3)); -let tuple_test = (ignore: int) => tuple_type_def(tuple); +let tuple_test = (ignore: int) => tuple_type_def (tuple); /* inline */ -let arguments_inline = (b: int, c: int) => { - b + c; -}; +let arguments_inline = (b: int, c: int) => { b + c; }; -let arguments_type_def_inline = (b: (int, int) => int) => b(5, 3); +let arguments_type_def_inline = (b: (int, int) => int) => b (5, 3); -let arguments_test_inline = (ignore: int) => arguments_type_def_inline(arguments_inline); +let arguments_test_inline = (ignore: int) => + arguments_type_def_inline (arguments_inline); -let tuple_inline = ((a, b): (int, int)) => { - a + b; -}; +let tuple_inline = ((a, b): (int, int)) => { a + b; }; -let tuple_type_def_inline = (b: ((int, int)) => int) => b((5, 3)); +let tuple_type_def_inline = (b: ((int, int)) => int) => b ((5, 3)); -let tuple_test_inline = (ignore: int) => tuple_type_def_inline(tuple_inline); +let tuple_test_inline = (ignore: int) => + tuple_type_def_inline(tuple_inline); diff --git a/src/test/contracts/tuples_sequences_functions.religo b/src/test/contracts/tuples_sequences_functions.religo index bffd78faf..38107dd54 100644 --- a/src/test/contracts/tuples_sequences_functions.religo +++ b/src/test/contracts/tuples_sequences_functions.religo @@ -34,12 +34,12 @@ let q = { }, }; -/* +/* Not supported yet by parser: let r = { a: 1 -}; +}; */ let s = { diff --git a/src/test/contracts/type_tuple_destruct.mligo b/src/test/contracts/type_tuple_destruct.mligo index 05bcaea59..b9b9afcaa 100644 --- a/src/test/contracts/type_tuple_destruct.mligo +++ b/src/test/contracts/type_tuple_destruct.mligo @@ -1,11 +1,11 @@ type foobar = int * int -let test_t: foobar = 10, 25 +let test_t : foobar = 10, 25 let foo, bar = test_t -let type_tuple_d (p: unit) = foo + bar +let type_tuple_d (p : unit) = foo + bar type complex = string * int * string * nat let test_t_2 = "hello", 10, "world", 50n let hello, ten, world, fifty_n = test_t_2 -let type_tuple_d_2 (p: unit) = hello ^ world +let type_tuple_d_2 (p : unit) = hello ^ world diff --git a/src/test/contracts/variant-matching.ligo b/src/test/contracts/variant-matching.ligo index 5c13a5053..b19303da3 100644 --- a/src/test/contracts/variant-matching.ligo +++ b/src/test/contracts/variant-matching.ligo @@ -1,11 +1,11 @@ type foobar is -| Foo of int + Foo of int | Bar of bool | Kee of nat -function fb(const p : foobar) : int is - block { skip } with (case p of - | Foo (n) -> n +function fb (const p : foobar) : int is + case p of + Foo (n) -> n | Bar (t) -> 42 | Kee (n) -> 23 - end) + end diff --git a/src/test/contracts/variant.ligo b/src/test/contracts/variant.ligo index b98001a02..af84d1731 100644 --- a/src/test/contracts/variant.ligo +++ b/src/test/contracts/variant.ligo @@ -1,5 +1,5 @@ type foobar is -| Foo of int + Foo of int | Bar of bool | Kee of nat diff --git a/src/test/contracts/variant.mligo b/src/test/contracts/variant.mligo index ee56b808d..874ab75be 100644 --- a/src/test/contracts/variant.mligo +++ b/src/test/contracts/variant.mligo @@ -4,7 +4,5 @@ type foobar = | Kee of nat let foo : foobar = Foo 42 - let bar : foobar = Bar true - let kee : foobar = Kee 23n diff --git a/src/test/contracts/variant.religo b/src/test/contracts/variant.religo index 99b69e94f..a408a3900 100644 --- a/src/test/contracts/variant.religo +++ b/src/test/contracts/variant.religo @@ -1,10 +1,8 @@ type foobar = - | Foo(int) - | Bar(bool) - | Kee(nat); + Foo (int) +| Bar (bool) +| Kee (nat); -let foo: foobar = Foo(42); - -let bar: foobar = Bar(true); - -let kee: foobar = Kee(23n); +let foo: foobar = Foo (42); +let bar: foobar = Bar (true); +let kee: foobar = Kee (23n); diff --git a/src/test/contracts/vote.mligo b/src/test/contracts/vote.mligo index a32f54fa4..aefc8e4a0 100644 --- a/src/test/contracts/vote.mligo +++ b/src/test/contracts/vote.mligo @@ -1,56 +1,49 @@ type storage = { - title : string ; - candidates : (string , int) map ; - voters : address set ; - beginning_time : timestamp ; - finish_time : timestamp ; + title : string; + yea : nat; + nay : nat; + voters : address set; + start_time : timestamp; + finish_time : timestamp } -type init_action = { - title : string ; - beginning_time : timestamp ; - finish_time : timestamp ; +type return = operation list * storage + +type vote = Yea | Nay + +type reset = { + title : string; + start_time : timestamp; + finish_time : timestamp } -type action = - | Vote of string - | Init of init_action +type parameter = +| Vote of vote +| Reset of reset -let init (init_params_s : init_action * storage) = - let candidates = Map.literal [ - ("Yes" , 0) ; - ("No" , 0) - ] in - ( - ([] : operation list), - { - title = init_params_s.0.title ; - candidates = candidates ; - voters = (Set.empty : address set) ; - beginning_time = init_params_s.0.beginning_time ; - finish_time = init_params_s.0.finish_time ; - } - ) +let reset (reset, _ : reset * storage) : return = + ([] : operation list), + {title = reset.title; + yea = 0n; + nay = 0n; + voters = (Set.empty : address set); + start_time = reset.start_time; + finish_time = reset.finish_time} -let vote (ps : string * storage) = - let now = Current.time in - (* let _ = assert (now >= ps.1.beginning_time && ps.1.finish_time > now) in *) - let addr = Current.sender in - (* let _ = assert (not Set.mem addr ps.1.voters) in *) - let x = Map.find ps.0 ps.1.candidates in - ( - ([] : operation list), - { - title = ps.1.title ; - candidates = Map.update ps.0 (Some (x + 1)) ps.1.candidates ; - voters = Set.add addr ps.1.voters ; - beginning_time = ps.1.beginning_time ; - finish_time = ps.1.finish_time ; - } - ) - -let main (a_s : action * storage) = - match a_s.0 with - | Vote p -> vote (p, a_s.1) - | Init ps -> init (ps, a_s.1) +let vote (vote, store : vote * storage) : return = + let now = Tezos.now in + (* let _ = + assert (now >= store.start_time && store.finish_time > now) in *) + let addr = Tezos.sender in + (* let _ = assert (not Set.mem addr store.voters) in *) + let store = + match vote with + Yea -> {store with yea = store.yea + 1n} + | Nay -> {store with nay = store.nay + 1n} + in ([] : operation list), + {store with voters = Set.add addr store.voters} +let main (action, store : parameter * storage) : return = + match action with + | Vote v -> vote (v, store) + | Reset r -> reset (r, store) diff --git a/src/test/contracts/website1.ligo b/src/test/contracts/website1.ligo index 4c8272d64..38ea61b8f 100644 --- a/src/test/contracts/website1.ligo +++ b/src/test/contracts/website1.ligo @@ -1,2 +1,2 @@ -function main (const p : int ; const s : int) : (list(operation) * int) is - block {skip} with ((nil : list(operation)), s + 1) +function main (const p : int; const s : int) : list (operation) * int is + ((nil : list (operation)), s + 1) diff --git a/src/test/contracts/website2.ligo b/src/test/contracts/website2.ligo index ac13b7c6f..7d326e407 100644 --- a/src/test/contracts/website2.ligo +++ b/src/test/contracts/website2.ligo @@ -1,16 +1,20 @@ -// variant defining pseudo multi-entrypoint actions +// variant defining entrypoints + type action is -| Increment of int + Increment of int | Decrement of int -function add (const a : int ; const b : int) : int is a + b +type return is list (operation) * int -function subtract (const a : int ; const b : int) : int is a - b +function add (const a : int; const b : int) : int is a + b -// real entrypoint that re-routes the flow based on the action provided -function main (const p : action ; const s : int) : (list(operation) * int) is - ((nil : list(operation)), +function subtract (const a : int; const b : int) : int is a - b + +// main function routing the flow based on the action provided + +function main (const p : action; const s : int) : return is + ((nil : list (operation)), case p of - | Increment (n) -> add (s, n) + Increment (n) -> add (s, n) | Decrement (n) -> subtract (s, n) end) diff --git a/src/test/contracts/website2.mligo b/src/test/contracts/website2.mligo index 73c04cbd5..cc6d85ff5 100644 --- a/src/test/contracts/website2.mligo +++ b/src/test/contracts/website2.mligo @@ -4,16 +4,16 @@ type storage = int (* variant defining pseudo multi-entrypoint actions *) -type action = +type parameter = | Increment of int | Decrement of int let add (a,b: int * int) : int = a + b let sub (a,b: int * int) : int = a - b -(* real entrypoint that re-routes the flow based on the action provided *) +(* real entrypoint that re-routes the flow based on the parameter provided *) -let main (p,s: action * storage) = +let main (p,s: parameter * storage) = let storage = match p with | Increment n -> add (s, n) diff --git a/src/test/contracts/website2.religo b/src/test/contracts/website2.religo index ffed8cd90..f9b936047 100644 --- a/src/test/contracts/website2.religo +++ b/src/test/contracts/website2.religo @@ -4,22 +4,22 @@ type storage = int; /* variant defining pseudo multi-entrypoint actions */ -type action = - | Increment(int) - | Decrement(int); +type parameter = +| Increment (int) +| Decrement (int); let add = ((a,b): (int, int)): int => a + b; let sub = ((a,b): (int, int)): int => a - b; -/* real entrypoint that re-routes the flow based on the action provided */ +/* real entrypoint that re-routes the flow based on the parameter provided */ -let main = ((p,storage): (action, storage)) => { +let main = ((p,storage): (parameter, storage)) => { let storage = switch (p) { - | Increment(n) => add((storage, n)) - | Decrement(n) => sub((storage, n)) + | Increment(n) => add ((storage, n)) + | Decrement(n) => sub ((storage, n)) }; - ([]: list(operation), storage); + ([]: list (operation), storage); }; (* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *) diff --git a/src/test/hash_lock_tests.ml b/src/test/hash_lock_tests.ml index 7bfe77c88..7da1882ab 100644 --- a/src/test/hash_lock_tests.ml +++ b/src/test/hash_lock_tests.ml @@ -61,7 +61,7 @@ let commit () = let salted_hash = e_bytes_raw (sha_256_hash (Bytes.concat Bytes.empty [test_hash_raw; packed_sender])) - + in let pre_commits = e_typed_big_map [] t_address (t_record_ez [("date", t_timestamp); ("salted_hash", t_bytes)]) @@ -99,7 +99,7 @@ let reveal_no_commit () = let init_storage = storage test_hash true pre_commits in expect_string_failwith program "reveal" (e_pair reveal init_storage) - "You haven't made a commitment to hash against yet." + "You have not made a commitment to hash against yet." (* Test that the contract fails if our commit isn't 24 hours old yet *) let reveal_young_commit () = @@ -132,7 +132,7 @@ let reveal_young_commit () = in expect_string_failwith ~options program "reveal" (e_pair reveal init_storage) - "It hasn't been 24 hours since your commit yet." + "It has not been 24 hours since your commit yet." (* Test that the contract fails if our reveal doesn't meet our commitment *) let reveal_breaks_commit () = @@ -164,7 +164,7 @@ let reveal_breaks_commit () = in expect_string_failwith ~options program "reveal" (e_pair reveal init_storage) - "This reveal doesn't match your commitment." + "This reveal does not match your commitment." (* Test that the contract fails if we reveal the wrong bytes for the stored hash *) let reveal_wrong_commit () = @@ -199,7 +199,7 @@ let reveal_wrong_commit () = "Your commitment did not match the storage hash." (* Test that the contract fails if we try to reuse it after unused flag changed *) -let reveal_no_reuse () = +let reveal_no_reuse () = let%bind program,_ = get_program () in let empty_message = empty_message in let reveal = e_record_ez [("hashable", e_bytes_string "hello"); diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index b8270e005..2ad0dfc8f 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1019,21 +1019,11 @@ let map_ type_f path : unit result = let make_expected = e_nat in expect_eq_n_strict_pos_small program "size_" make_input make_expected in - let%bind () = - let make_input = fun n -> ez [(23, n) ; (42, 4)] in - let make_expected = e_int in - expect_eq_n program "gf" make_input make_expected - in let%bind () = let make_input = fun n -> ez [(23, n) ; (42, 4)] in let make_expected = fun _ -> e_some @@ e_int 4 in expect_eq_n program "get" make_input make_expected in - let%bind () = - let make_input = fun n -> ez [(23, n) ; (42, 4)] in - let make_expected = fun _ -> e_some @@ e_int 4 in - expect_eq_n program "get_" make_input make_expected - in let%bind () = let input_map = ez [(23, 10) ; (42, 4)] in expect_eq program "mem" (e_tuple [(e_int 23) ; input_map]) (e_bool true) @@ -1081,11 +1071,6 @@ let big_map_ type_f path : unit result = let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in (e_typed_big_map lst' t_int t_int) in - let%bind () = - let make_input = fun n -> ez [(23, n) ; (42, 4)] in - let make_expected = e_int in - expect_eq_n program "gf" make_input make_expected - in let%bind () = let make_input = fun n -> let m = ez [(23 , 0) ; (42 , 0)] in @@ -2241,51 +2226,51 @@ let empty_case_religo () : unit result = in ok () -let tuple_type_mligo () : unit result = +let tuple_type_mligo () : unit result = let%bind program = mtype_file "./contracts/tuple_type.mligo" in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "test1" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 12 in expect_eq_n program "test2" input expected in ok () -let tuple_type_religo () : unit result = +let tuple_type_religo () : unit result = let%bind program = retype_file "./contracts/tuple_type.religo" in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "arguments_test" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "tuple_test" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "arguments_test_inline" input expected in - let%bind () = - let input _ = e_int 0 in + let%bind () = + let input _ = e_int 0 in let expected _ = e_int 8 in expect_eq_n program "tuple_test_inline" input expected in ok () -let no_semicolon_religo () : unit result = +let no_semicolon_religo () : unit result = let%bind program = retype_file "./contracts/no_semicolon.religo" in - let%bind () = - let input _ = e_int 2 in + let%bind () = + let input _ = e_int 2 in let expected _ = e_int 3 in expect_eq_n program "a" input expected - in + in ok () let loop_bugs_ligo () : unit result = diff --git a/src/test/time_lock_repeat_tests.ml b/src/test/time_lock_repeat_tests.ml index aa7b8b01b..4405948bf 100644 --- a/src/test/time_lock_repeat_tests.ml +++ b/src/test/time_lock_repeat_tests.ml @@ -17,7 +17,7 @@ let get_program = ok program ) -let compile_main () = +let compile_main () = let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/timelock_repeat.mligo" (Syntax_name "cameligo") in let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in @@ -63,7 +63,7 @@ let interval_advance () = let%bind predecessor_timestamp = mk_time "2000-01-01T10:10:10Z" in let%bind lock_time = mk_time "2000-01-01T00:10:10Z" in let init_storage = storage lock_time 86400 empty_message in - (* It takes a second for Current.now to be called, awful hack *) + (* It takes a second for Tezos.now to be called, awful hack *) let%bind new_timestamp = mk_time "2000-01-02T10:10:11Z" in let new_storage_fake = storage new_timestamp 86400 fake_uncompiled_empty_message in let options = diff --git a/src/test/vote_tests.ml b/src/test/vote_tests.ml index 6817b9d6d..3a0a95021 100644 --- a/src/test/vote_tests.ml +++ b/src/test/vote_tests.ml @@ -20,38 +20,33 @@ open Ast_simplified let init_storage name = e_record_ez [ ("title" , e_string name) ; - ("candidates" , e_map [ - (e_string "Yes" , e_int 0) ; - (e_string "No" , e_int 0) ; - ]) ; + ("yea", e_nat 0) ; + ("nay", e_nat 0) ; ("voters" , e_typed_set [] t_address) ; - ("beginning_time" , e_timestamp 0) ; + ("start_time" , e_timestamp 0) ; ("finish_time" , e_timestamp 1000000000) ; ] -let init title beginning_time finish_time = - let init_action = e_record_ez [ +let reset title start_time finish_time = + let reset_action = e_record_ez [ ("title" , e_string title) ; - ("beginning_time" , e_timestamp beginning_time) ; - ("finish_time" , e_timestamp finish_time) ; - ] in - e_constructor "Init" init_action + ("start_time" , e_timestamp start_time) ; + ("finish_time" , e_timestamp finish_time)] + in e_constructor "Reset" reset_action -let vote str = - let vote = e_string str in - e_constructor "Vote" vote +let yea = e_constructor "Vote" (e_constructor "Yea" (e_unit ())) let init_vote () = let%bind (program , _) = get_program () in - let%bind result = Test_helpers.run_typed_program_with_simplified_input program "main" (e_pair (vote "Yes") (init_storage "basic")) in - let%bind (_ , storage) = extract_pair result in + let%bind result = + Test_helpers.run_typed_program_with_simplified_input + program "main" (e_pair yea (init_storage "basic")) in + let%bind (_, storage) = extract_pair result in let%bind storage' = extract_record storage in - let votes = List.assoc (Label "candidates") storage' in - let%bind votes' = extract_map votes in - let%bind (_ , yess) = - trace_option (simple_error "") @@ - List.find_opt (fun (k , _) -> Ast_simplified.Misc.is_value_eq (k , e_string "Yes")) votes' in - let%bind () = Ast_simplified.Misc.assert_value_eq (yess , e_int 1) in +(* let votes = List.assoc (Label "voters") storage' in + let%bind votes' = extract_map votes in *) + let yea = List.assoc (Label "yea") storage' in + let%bind () = Ast_simplified.Misc.assert_value_eq (yea, e_nat 1) in ok () let main = test_suite "Vote" [