From 93682629b4b3dc94974e9ca0c95aae184ce043ce Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Thu, 27 Feb 2020 17:51:29 +0100 Subject: [PATCH] Updating contracts. --- src/test/contracts/address.mligo | 4 +- src/test/contracts/amount.ligo | 8 +-- src/test/contracts/amount.mligo | 2 +- src/test/contracts/arithmetic.mligo | 27 +++----- src/test/contracts/assert.mligo | 2 +- src/test/contracts/attributes.mligo | 6 +- src/test/contracts/balance_constant.mligo | 11 ++-- src/test/contracts/big_map.mligo | 14 ++--- src/test/contracts/bitwise_arithmetic.mligo | 10 +-- src/test/contracts/boolean_operators.mligo | 15 ++--- src/test/contracts/bytes_arithmetic.mligo | 9 +-- src/test/contracts/bytes_unpack.mligo | 18 +++--- src/test/contracts/check_signature.mligo | 2 +- src/test/contracts/closure.mligo | 12 ++-- src/test/contracts/condition-annot.mligo | 6 +- src/test/contracts/condition-shadowing.mligo | 2 +- src/test/contracts/counter.mligo | 4 +- src/test/contracts/crypto.mligo | 4 +- src/test/contracts/curry.mligo | 10 +-- src/test/contracts/empty_case.mligo | 12 ++-- src/test/contracts/eq_bool.mligo | 2 +- src/test/contracts/failwith.mligo | 4 +- src/test/contracts/fibo.mligo | 12 ++-- src/test/contracts/fibo2.mligo | 12 ++-- src/test/contracts/fibo3.mligo | 12 ++-- src/test/contracts/function-shared.mligo | 6 +- src/test/contracts/guess_string.mligo | 22 +++---- src/test/contracts/option.ligo | 6 +- .../contracts/parser-bad-reported-term.ligo | 6 -- src/test/contracts/procedure.ligo | 11 ---- src/test/contracts/quote-declaration.ligo | 9 +-- src/test/contracts/quote-declarations.ligo | 14 +---- src/test/contracts/record.ligo | 62 +++++-------------- src/test/contracts/redeclaration.ligo | 8 +-- src/test/contracts/replaceable_id.ligo | 40 ++++++------ src/test/contracts/self_address.ligo | 2 +- src/test/contracts/set_arithmetic-1.ligo | 26 ++++---- src/test/contracts/set_arithmetic.ligo | 35 +++++------ src/test/contracts/set_delegate.ligo | 11 ++-- src/test/contracts/shadow.ligo | 3 +- src/test/contracts/simple_access.ligo | 32 +++++----- src/test/contracts/string.ligo | 4 +- src/test/contracts/string_arithmetic.ligo | 4 +- src/test/contracts/super-counter.ligo | 18 +++--- src/test/contracts/tez.ligo | 24 +++---- src/test/contracts/time-lock.ligo | 29 +++++---- src/test/contracts/timestamp.ligo | 3 +- src/test/contracts/toto.ligo | 5 +- src/test/contracts/tuple.ligo | 18 +++--- src/test/contracts/variant-matching.ligo | 10 +-- src/test/contracts/variant.ligo | 2 +- src/test/contracts/website1.ligo | 4 +- src/test/contracts/website2.ligo | 20 +++--- 53 files changed, 288 insertions(+), 366 deletions(-) delete mode 100644 src/test/contracts/parser-bad-reported-term.ligo delete mode 100644 src/test/contracts/procedure.ligo diff --git a/src/test/contracts/address.mligo b/src/test/contracts/address.mligo index 3651ea223..2b24b7d08 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 = Current.implicit_account p + in Current.address c diff --git a/src/test/contracts/amount.ligo b/src/test/contracts/amount.ligo index 8d4961be8..9c0263635 100644 --- a/src/test/contracts/amount.ligo +++ b/src/test/contracts/amount.ligo @@ -1,8 +1,8 @@ -function check (const p: unit) : int is - begin +function check (const p : unit) : int is + block { var result : int := 0; - if amount = 100tz then + if Tezos.amount = 100tz then result := 42 else result := 0 - end with result + } with result diff --git a/src/test/contracts/amount.mligo b/src/test/contracts/amount.mligo index 8e31e2d0c..a2db44946 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 = if Tezos.amount > 100tez then 42 else 0 diff --git a/src/test/contracts/arithmetic.mligo b/src/test/contracts/arithmetic.mligo index e3bb8ba07..66c241f86 100644 --- a/src/test/contracts/arithmetic.mligo +++ b/src/test/contracts/arithmetic.mligo @@ -1,30 +1,17 @@ // Test CameLIGO arithmetic operators -let mod_op (n : int) : nat = - n mod 42 +let mod_op (n : int) : nat = n mod 42 -let plus_op (n : int) : int = - n + 42 +let plus_op (n : int) : int = n + 42 -let minus_op (n : int) : int = - n - 42 +let minus_op (n : int) : int = n - 42 -let times_op (n : int) : int = - n * 42 +let times_op (n : int) : int = n * 42 -let div_op (n : int) : int = - n / 2 +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 neg_op (n : int) : int = -n let foo (n : int) : int = n + 10 -let neg_op_2 (b: int) : int = -(foo b) +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/attributes.mligo b/src/test/contracts/attributes.mligo index 8f582a725..a96d63710 100644 --- a/src/test/contracts/attributes.mligo +++ b/src/test/contracts/attributes.mligo @@ -1,10 +1,10 @@ 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/balance_constant.mligo b/src/test/contracts/balance_constant.mligo index c364d2bce..b73319f8f 100644 --- a/src/test/contracts/balance_constant.mligo +++ b/src/test/contracts/balance_constant.mligo @@ -1,17 +1,16 @@ -(** - +(* 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 storage = tez let main (p, s : unit * storage) = ([] : operation list), balance - diff --git a/src/test/contracts/big_map.mligo b/src/test/contracts/big_map.mligo index 35a173f82..434878013 100644 --- a/src/test/contracts/big_map.mligo +++ b/src/test/contracts/big_map.mligo @@ -2,22 +2,20 @@ 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/bitwise_arithmetic.mligo b/src/test/contracts/bitwise_arithmetic.mligo index d79cbe348..5675df1b8 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.lor n 4n +let and_op (n : nat) : nat = Bitwise.land n 7n +let xor_op (n : nat) : nat = Bitwise.lxor 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.mligo b/src/test/contracts/boolean_operators.mligo index 7eb3cfd69..63091dbf8 100644 --- a/src/test/contracts/boolean_operators.mligo +++ b/src/test/contracts/boolean_operators.mligo @@ -1,16 +1,11 @@ // Test CameLIGO boolean operators -let or_true (b : bool) : bool = - b || true +let or_true (b : bool) : bool = b || true -let or_false (b : bool) : bool = - b || false +let or_false (b : bool) : bool = b || false -let and_true (b : bool) : bool = - b && true +let and_true (b : bool) : bool = b && true -let and_false (b : bool) : bool = - b && false +let and_false (b : bool) : bool = b && false -let not_bool (b: bool) : bool = - not b +let not_bool (b : bool) : bool = not b diff --git a/src/test/contracts/bytes_arithmetic.mligo b/src/test/contracts/bytes_arithmetic.mligo index 4d71994a2..44d89cb36 100644 --- a/src/test/contracts/bytes_arithmetic.mligo +++ b/src/test/contracts/bytes_arithmetic.mligo @@ -1,8 +1,5 @@ -let concat_op (s : bytes) : bytes = - Bytes.concat s 0x7070 +let concat_op (s : bytes) : bytes = Bytes.concat s 0x7070 -let slice_op (s : bytes) : bytes = - Bytes.slice 1n 2n s +let slice_op (s : bytes) : bytes = Bytes.slice 1n 2n s -let hasherman (s : bytes) : bytes = - Crypto.sha256 s +let hasherman (s : bytes) : bytes = Crypto.sha256 s 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/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/closure.mligo b/src/test/contracts/closure.mligo index ee5f616ae..ddd866df7 100644 --- a/src/test/contracts/closure.mligo +++ b/src/test/contracts/closure.mligo @@ -1,9 +1,7 @@ (* Test whether closures retain values 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/condition-annot.mligo b/src/test/contracts/condition-annot.mligo index 697329fcb..93aece587 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 is int + +let main (i : int) = + if (i = 2 : bool) then (42 : int) else (0 : integer) diff --git a/src/test/contracts/condition-shadowing.mligo b/src/test/contracts/condition-shadowing.mligo index c4dbbbb7b..97ee6eb51 100644 --- a/src/test/contracts/condition-shadowing.mligo +++ b/src/test/contracts/condition-shadowing.mligo @@ -1,6 +1,6 @@ (* 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 diff --git a/src/test/contracts/counter.mligo b/src/test/contracts/counter.mligo index 615dfa62a..548a1e07e 100644 --- a/src/test/contracts/counter.mligo +++ b/src/test/contracts/counter.mligo @@ -1,4 +1,4 @@ type storage = int -let main (ps: int * storage) = - (([] : operation list) , ps.0 + ps.1) +let main (ps : int * storage) = + ([] : operation list), ps.0 + ps.1 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/curry.mligo b/src/test/contracts/curry.mligo index eee47985a..ffcaafe15 100644 --- a/src/test/contracts/curry.mligo +++ b/src/test/contracts/curry.mligo @@ -1,9 +1,9 @@ -let conv_test (j: int) (k: int) = j + k +let conv_test (j : int) (k : int) = j + k -let main (i: int) : int = conv_test i 10 +let main (i : int) : int = conv_test i 10 -let partial (a: int) (b: int) : int = a + b +let partial (a : int) (b : int) : int = a + b -let mk_partial (j: int) : (int -> int) = partial j +let mk_partial (j : int) : int -> int = partial j -let partial_apply (i: int) : int = (mk_partial 10) i +let partial_apply (i : int) : int = mk_partial 10 i 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/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/failwith.mligo b/src/test/contracts/failwith.mligo index fbc5976bd..2938a703d 100644 --- a/src/test/contracts/failwith.mligo +++ b/src/test/contracts/failwith.mligo @@ -1,4 +1,4 @@ type storage = unit -let main (p: unit) storage = - if true then failwith "This contract always fails" else () +let main (p : unit; store : storage) : operation list * storage = + if true then failwith "This contract always fails" diff --git a/src/test/contracts/fibo.mligo b/src/test/contracts/fibo.mligo index fa345f653..3d2e3a687 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 : unit; store : 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..836f24517 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 : unit; store : 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/function-shared.mligo b/src/test/contracts/function-shared.mligo index 3568f0b3a..e8f70f6bd 100644 --- a/src/test/contracts/function-shared.mligo +++ b/src/test/contracts/function-shared.mligo @@ -1,7 +1,7 @@ (* Test use of multiple subroutines in a CameLIGO function *) -let foo (i: int) : int = i + 20 +let foo (i : int) : int = i + 20 -let bar (i: int) : int = i + 50 +let bar (i : int) : int = i + 50 -let foobar (i: int) : int = (foo i) + (bar i) +let foobar (i : int) : int = foo i + bar i diff --git a/src/test/contracts/guess_string.mligo b/src/test/contracts/guess_string.mligo index 3921d4108..adde5b642 100644 --- a/src/test/contracts/guess_string.mligo +++ b/src/test/contracts/guess_string.mligo @@ -1,20 +1,18 @@ 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 *) - let contract : unit contract = - Operation.get_contract sender in +type return = operation list * storage + +let attempt (p: param; store : storage) : return = + (* if p.attempt <> store.challenge then failwith "Failed challenge" else *) + let contract : unit contract = Operation.get_contract sender 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 + Operation.transaction (unit, contract, 10.00tez) in + let store : storage = {challenge = p.new_challenge} + in ([] : operation list), store 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/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/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..e6f440a7e 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 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.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_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/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/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/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/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/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/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/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)