Updating contracts.

This commit is contained in:
Christian Rinderknecht 2020-02-27 17:51:29 +01:00
parent 4d61c2285c
commit 93682629b4
53 changed files with 288 additions and 366 deletions

View File

@ -1,3 +1,3 @@
let main (p : key_hash) =
let c : unit contract = Current.implicit_account p in
Current.address c
let c : unit contract = Current.implicit_account p
in Current.address c

View File

@ -1,8 +1,8 @@
function check (const p : unit) : int is
begin
block {
var result : int := 0;
if amount = 100tz then
if Tezos.amount = 100tz then
result := 42
else
result := 0
end with result
} with result

View File

@ -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

View File

@ -1,29 +1,16 @@
// 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

View File

@ -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

View File

@ -12,12 +12,10 @@ 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

View File

@ -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 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

View File

@ -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

View File

@ -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

View File

@ -1,11 +1,11 @@
let id_string (p : string) : string option =
let packed : bytes = Bytes.pack p in
((Bytes.unpack packed): string option)
(Bytes.unpack packed : string option)
let id_int (p : int) : int option =
let packed : bytes = Bytes.pack p in
((Bytes.unpack packed): int option)
(Bytes.unpack packed : int option)
let id_address (p : address) : address option =
let packed : bytes = Bytes.pack p in
((Bytes.unpack packed): address option)
(Bytes.unpack packed : address option)

View File

@ -2,8 +2,6 @@
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 close : int -> int = fun (i : int) -> i + j in
let j : int = 20 (* Shadow original variable *)
in close 20

View File

@ -1,2 +1,4 @@
type integer is int
let main (i : int) =
if (i=2 : bool) then (42: int) else (0: int)
if (i = 2 : bool) then (42 : int) else (0 : integer)

View File

@ -1,4 +1,4 @@
type storage = int
let main (ps : int * storage) =
(([] : operation list) , ps.0 + ps.1)
([] : operation list), ps.0 + ps.1

View File

@ -4,6 +4,6 @@ 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 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

View File

@ -1,8 +1,8 @@
type foo =
| Bar of int
Bar of int
| Baz
let main (f : foo) : int =
match f with
| Bar i -> i
Bar i -> i
| Baz -> -1

View File

@ -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"

View File

@ -1,7 +1,9 @@
type storage = unit
let main (p: unit) storage =
(fun (f: (int * int) -> int) (x: int) (y: int) -> f (y,x))
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

View File

@ -1,7 +1,9 @@
type storage = unit
let main (p: unit) storage =
(fun (f: int -> int) (_: int) (y: int) -> f y)
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

View File

@ -1,7 +1,9 @@
type storage = unit
let main (p: unit) storage =
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

View File

@ -4,4 +4,4 @@ let foo (i: int) : int = i + 20
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

View File

@ -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

View File

@ -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".

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -1,6 +1,6 @@
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))
((nil : list (operation)), foo (unit))
function foo (const p : unit) : int is 1

View File

@ -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
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
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
block {
if sender =/= s then failwith("Unauthorized sender") else skip;
var message : pass_message_pt := param ;
end with (param(unit),s)
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)
Change_address (p) -> change_address (p,s)
| Pass_message (p) -> pass_message (p,s)
end

View File

@ -1,14 +1,14 @@
// Test set iteration in PascaLIGO
function iter_op (const s : set (int)) : int is
begin
block {
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
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 {

View File

@ -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)
set_add ("foobar", s)
function remove_op (const s : set (string)) : set (string) is
begin skip end with set_remove("foobar" , s)
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
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
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
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
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)
set_mem ("foobar", s)

View File

@ -1,6 +1,5 @@
function main (const p : key_hash) : list (operation) is
begin
block {
const unused : operation = set_delegate (Some (p));
const dummy: list(operation) = nil;
end with dummy
const dummy : list (operation) = nil
} with dummy

View File

@ -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)

View File

@ -1,21 +1,21 @@
//Test simple_access in PascalLigo
type tpi is (int*int)
type rpi is record
x : int;
y : int;
end
//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
m["x"] := b.x
} with
case m["x"] of
| Some (s) -> s
Some (s) -> s
| None -> 42
end

View File

@ -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)

View File

@ -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)),
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
Increment (n) -> s + n
| Decrement (n) -> s - n
end)

View File

@ -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

View File

@ -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 {
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) ;
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
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)
Call (p) -> call (p,s)
| Default (p) -> default (p,s)
end

View File

@ -1,3 +1,4 @@
type storage_ is timestamp
function main(const p : unit; const s : storage_) : list(operation) * storage_ is ((nil: list(operation)), now)
function main (const p : unit; const s : storage_) :
list (operation) * storage_ is ((nil: list (operation)), now)

View File

@ -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

View File

@ -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)
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)

View File

@ -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
case p of
Foo (n) -> n
| Bar (t) -> 42
| Kee (n) -> 23
end)
end

View File

@ -1,5 +1,5 @@
type foobar is
| Foo of int
Foo of int
| Bar of bool
| Kee of nat

View File

@ -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)

View File

@ -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
type return is list (operation) * int
function add (const a : int; const b : int) : int is a + b
function subtract (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
// 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)