Add tests for CameLIGO.
This commit is contained in:
parent
54cefddd51
commit
623e6f1251
File diff suppressed because it is too large
Load Diff
136
src/test/contracts/expected/FA1.2.mligo
Normal file
136
src/test/contracts/expected/FA1.2.mligo
Normal file
@ -0,0 +1,136 @@
|
||||
type tokens = (address, nat) big_map
|
||||
|
||||
type allowances = (address * address, nat) big_map
|
||||
|
||||
type storage =
|
||||
{tokens : tokens;
|
||||
allowances : allowances;
|
||||
total_amount : nat}
|
||||
|
||||
type transfer =
|
||||
{address_from : address;
|
||||
address_to : address;
|
||||
value : nat}
|
||||
|
||||
type approve = {spender : address; value : nat}
|
||||
|
||||
type getAllowance =
|
||||
{owner : address;
|
||||
spender : address;
|
||||
callback : nat contract}
|
||||
|
||||
type getBalance = {owner : address; callback : nat contract}
|
||||
|
||||
type getTotalSupply = {callback : nat contract}
|
||||
|
||||
type action =
|
||||
Transfer of transfer
|
||||
| Approve of approve
|
||||
| GetAllowance of getAllowance
|
||||
| GetBalance of getBalance
|
||||
| GetTotalSupply of getTotalSupply
|
||||
|
||||
let transfer (p, s : transfer * storage)
|
||||
: operation list * storage =
|
||||
let new_allowances =
|
||||
if Tezos.sender = p.address_from
|
||||
then s.allowances
|
||||
else
|
||||
let authorized_value =
|
||||
match Big_map.find_opt
|
||||
(Tezos.sender, p.address_from)
|
||||
s.allowances
|
||||
with
|
||||
Some value -> value
|
||||
| None -> 0n
|
||||
in if (authorized_value < p.value)
|
||||
then (failwith "Not Enough Allowance" : allowances)
|
||||
else
|
||||
Big_map.update
|
||||
(Tezos.sender, p.address_from)
|
||||
(Some (abs (authorized_value - p.value)))
|
||||
s.allowances
|
||||
in let sender_balance =
|
||||
match Big_map.find_opt p.address_from s.tokens with
|
||||
Some value -> value
|
||||
| None -> 0n
|
||||
in if (sender_balance < p.value)
|
||||
then
|
||||
(failwith "Not Enough Balance"
|
||||
: operation list * storage)
|
||||
else
|
||||
let new_tokens =
|
||||
Big_map.update
|
||||
p.address_from
|
||||
(Some (abs (sender_balance - p.value)))
|
||||
s.tokens
|
||||
in let receiver_balance =
|
||||
match Big_map.find_opt p.address_to s.tokens
|
||||
with
|
||||
Some value -> value
|
||||
| None -> 0n
|
||||
in let new_tokens =
|
||||
Big_map.update
|
||||
p.address_to
|
||||
(Some (receiver_balance + p.value))
|
||||
new_tokens
|
||||
in ([] : operation list),
|
||||
{s with
|
||||
tokens = new_tokens;
|
||||
allowances = new_allowances}
|
||||
|
||||
let approve (p, s : approve * storage)
|
||||
: operation list * storage =
|
||||
let previous_value =
|
||||
match Big_map.find_opt
|
||||
(p.spender, Tezos.sender)
|
||||
s.allowances
|
||||
with
|
||||
Some value -> value
|
||||
| None -> 0n
|
||||
in if previous_value > 0n && p.value > 0n
|
||||
then
|
||||
(failwith "Unsafe Allowance Change"
|
||||
: operation list * storage)
|
||||
else
|
||||
let new_allowances =
|
||||
Big_map.update
|
||||
(p.spender, Tezos.sender)
|
||||
(Some (p.value))
|
||||
s.allowances
|
||||
in ([] : operation list),
|
||||
{s with
|
||||
allowances = new_allowances}
|
||||
|
||||
let getAllowance (p, s : getAllowance * storage)
|
||||
: operation list * storage =
|
||||
let value =
|
||||
match Big_map.find_opt (p.owner, p.spender) s.allowances
|
||||
with
|
||||
Some value -> value
|
||||
| None -> 0n
|
||||
in let op = Tezos.transaction value 0mutez p.callback
|
||||
in ([op], s)
|
||||
|
||||
let getBalance (p, s : getBalance * storage)
|
||||
: operation list * storage =
|
||||
let value =
|
||||
match Big_map.find_opt p.owner s.tokens with
|
||||
Some value -> value
|
||||
| None -> 0n
|
||||
in let op = Tezos.transaction value 0mutez p.callback
|
||||
in ([op], s)
|
||||
|
||||
let getTotalSupply (p, s : getTotalSupply * storage)
|
||||
: operation list * storage =
|
||||
let total = s.total_amount
|
||||
in let op = Tezos.transaction total 0mutez p.callback
|
||||
in ([op], s)
|
||||
|
||||
let main (a, s : action * storage) =
|
||||
match a with
|
||||
Transfer p -> transfer (p, s)
|
||||
| Approve p -> approve (p, s)
|
||||
| GetAllowance p -> getAllowance (p, s)
|
||||
| GetBalance p -> getBalance (p, s)
|
||||
| GetTotalSupply p -> getTotalSupply (p, s)
|
3
src/test/contracts/expected/address.mligo
Normal file
3
src/test/contracts/expected/address.mligo
Normal file
@ -0,0 +1,3 @@
|
||||
let main (p : key_hash) =
|
||||
let c : unit contract = Tezos.implicit_account p
|
||||
in Tezos.address c
|
2
src/test/contracts/expected/amount.mligo
Normal file
2
src/test/contracts/expected/amount.mligo
Normal file
@ -0,0 +1,2 @@
|
||||
let check_ (p : unit) : int =
|
||||
if Tezos.amount = 100000000mutez then 42 else 0
|
10
src/test/contracts/expected/amount_lambda.mligo
Normal file
10
src/test/contracts/expected/amount_lambda.mligo
Normal file
@ -0,0 +1,10 @@
|
||||
let f1 (x : unit) : unit -> tez =
|
||||
let amt : tez = Current.amount
|
||||
in fun (x : unit) -> amt
|
||||
|
||||
let f2 (x : unit) : unit -> tez =
|
||||
fun (x : unit) -> Current.amount
|
||||
|
||||
let main (b, s : bool * (unit -> tez))
|
||||
: operation list * (unit -> tez) =
|
||||
(([] : operation list), (if b then f1 () else f2 ()))
|
17
src/test/contracts/expected/arithmetic.mligo
Normal file
17
src/test/contracts/expected/arithmetic.mligo
Normal file
@ -0,0 +1,17 @@
|
||||
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)
|
||||
|
||||
let ediv_op (n : int) : (int * nat) option = ediv n 2
|
3
src/test/contracts/expected/assert.mligo
Normal file
3
src/test/contracts/expected/assert.mligo
Normal file
@ -0,0 +1,3 @@
|
||||
let main (p, s : bool * unit) =
|
||||
let u : unit = assert p
|
||||
in ([] : operation list), s
|
14
src/test/contracts/expected/attributes.mligo
Normal file
14
src/test/contracts/expected/attributes.mligo
Normal file
@ -0,0 +1,14 @@
|
||||
let x = 1 [@@inline]
|
||||
|
||||
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]
|
||||
in test b
|
8
src/test/contracts/expected/balance_constant.mligo
Normal file
8
src/test/contracts/expected/balance_constant.mligo
Normal file
@ -0,0 +1,8 @@
|
||||
type parameter = unit
|
||||
|
||||
type storage = tez
|
||||
|
||||
type return = operation list * storage
|
||||
|
||||
let main (p, s : parameter * storage) : return =
|
||||
([] : operation list), Tezos.balance
|
3
src/test/contracts/expected/basic.mligo
Normal file
3
src/test/contracts/expected/basic.mligo
Normal file
@ -0,0 +1,3 @@
|
||||
type toto = int
|
||||
|
||||
let foo : toto = 42 + 127
|
22
src/test/contracts/expected/big_map.mligo
Normal file
22
src/test/contracts/expected/big_map.mligo
Normal file
@ -0,0 +1,22 @@
|
||||
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 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 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 mutimaps (m : foo) (n : foo) : foo =
|
||||
let bar : foo = Big_map.update 42 (Some 0) m
|
||||
in Big_map.update 42 (get bar) n
|
9
src/test/contracts/expected/bitwise_arithmetic.mligo
Normal file
9
src/test/contracts/expected/bitwise_arithmetic.mligo
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
9
src/test/contracts/expected/boolean_operators.mligo
Normal file
9
src/test/contracts/expected/boolean_operators.mligo
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
5
src/test/contracts/expected/bytes_arithmetic.mligo
Normal file
5
src/test/contracts/expected/bytes_arithmetic.mligo
Normal file
@ -0,0 +1,5 @@
|
||||
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
|
11
src/test/contracts/expected/bytes_unpack.mligo
Normal file
11
src/test/contracts/expected/bytes_unpack.mligo
Normal file
@ -0,0 +1,11 @@
|
||||
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_address (p : address) : address option =
|
||||
let packed : bytes = Bytes.pack p
|
||||
in (Bytes.unpack packed : address option)
|
11
src/test/contracts/expected/check_signature.mligo
Normal file
11
src/test/contracts/expected/check_signature.mligo
Normal file
@ -0,0 +1,11 @@
|
||||
let check_signature
|
||||
(pk, signed, msg : key * signature * bytes) : bool =
|
||||
Crypto.check pk signed msg
|
||||
|
||||
let example : bool =
|
||||
Crypto.check
|
||||
("edpktz4xg6csJnJ5vcmMb2H37sWXyBDcoAp3XrBvjRaTSQ1zmZTeRQ"
|
||||
: key)
|
||||
("edsigtnzKd51CDomKVMFBoU8SzFZgNqRkYUaQH4DLUg8Lsimz98DFB82uiHAkdvx29DDqHxPf1noQ8noWpKMZoxTCsfprrbs4Xo"
|
||||
: signature)
|
||||
0x05010000000568656c6c6f
|
5
src/test/contracts/expected/closure.mligo
Normal file
5
src/test/contracts/expected/closure.mligo
Normal file
@ -0,0 +1,5 @@
|
||||
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 close 20
|
28
src/test/contracts/expected/comparable.mligo
Normal file
28
src/test/contracts/expected/comparable.mligo
Normal file
@ -0,0 +1,28 @@
|
||||
let int_ (a : int) = a < a
|
||||
|
||||
let nat_ (a : nat) = a < a
|
||||
|
||||
let bool_ (a : bool) = a < a
|
||||
|
||||
let mutez_ (a : tez) = a < a
|
||||
|
||||
let string_ (a : string) = a < a
|
||||
|
||||
let bytes_ (a : bytes) = a < a
|
||||
|
||||
let address_ (a : address) = a < a
|
||||
|
||||
let timestamp_ (a : timestamp) = a < a
|
||||
|
||||
let key_hash_ (a : key_hash) = a < a
|
||||
|
||||
type comp_pair = int * int
|
||||
|
||||
let comp_pair (a : comp_pair) = a < a
|
||||
|
||||
type inner_record = (int, "one", nat, "two") michelson_pair
|
||||
|
||||
type comb_record =
|
||||
(int, "three", inner_record, "four") michelson_pair
|
||||
|
||||
let comb_record (a : comb_record) = a < a
|
4
src/test/contracts/expected/condition-annot.mligo
Normal file
4
src/test/contracts/expected/condition-annot.mligo
Normal file
@ -0,0 +1,4 @@
|
||||
type integer = int
|
||||
|
||||
let main (i : int) =
|
||||
if (i = 2 : bool) then (42 : int) else (0 : integer)
|
9
src/test/contracts/expected/condition-shadowing.mligo
Normal file
9
src/test/contracts/expected/condition-shadowing.mligo
Normal file
@ -0,0 +1,9 @@
|
||||
let main (i : int) =
|
||||
let result = 0
|
||||
in if i = 2
|
||||
then
|
||||
let result = 42
|
||||
in result
|
||||
else
|
||||
let result = 0
|
||||
in result
|
1
src/test/contracts/expected/condition.mligo
Normal file
1
src/test/contracts/expected/condition.mligo
Normal file
@ -0,0 +1 @@
|
||||
let main (i : int) = if i = 2 then 42 else 0
|
4
src/test/contracts/expected/counter.mligo
Normal file
4
src/test/contracts/expected/counter.mligo
Normal file
@ -0,0 +1,4 @@
|
||||
type storage = int
|
||||
|
||||
let main (p, s : int * storage) =
|
||||
([] : operation list), p + s
|
11
src/test/contracts/expected/create_contract.mligo
Normal file
11
src/test/contracts/expected/create_contract.mligo
Normal file
@ -0,0 +1,11 @@
|
||||
type return = operation list * string
|
||||
|
||||
let main (action, store : string * string) : return =
|
||||
let toto : operation * address =
|
||||
Tezos.create_contract
|
||||
(fun (p, s : nat * string) ->
|
||||
(([] : operation list), "one"))
|
||||
(None : key_hash option)
|
||||
300000000mutez
|
||||
"un"
|
||||
in ([toto.0], store)
|
3
src/test/contracts/expected/crypto.mligo
Normal file
3
src/test/contracts/expected/crypto.mligo
Normal file
@ -0,0 +1,3 @@
|
||||
let hasherman512 (s : bytes) : bytes = Crypto.sha512 s
|
||||
|
||||
let hasherman_blake (s : bytes) : bytes = Crypto.blake2b s
|
9
src/test/contracts/expected/curry.mligo
Normal file
9
src/test/contracts/expected/curry.mligo
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
10
src/test/contracts/expected/double_michelson_or.mligo
Normal file
10
src/test/contracts/expected/double_michelson_or.mligo
Normal file
@ -0,0 +1,10 @@
|
||||
type storage = (int, "foo", string, "bar") michelson_or
|
||||
|
||||
type foobar = (int, "baz", int, "fooo") michelson_or
|
||||
|
||||
type return = operation list * storage
|
||||
|
||||
let main (action, store : unit * storage) : return =
|
||||
let foo = (M_right ("one") : storage)
|
||||
in let bar = (M_right 1 : foobar)
|
||||
in (([] : operation list), (foo : storage))
|
6
src/test/contracts/expected/empty_case.mligo
Normal file
6
src/test/contracts/expected/empty_case.mligo
Normal file
@ -0,0 +1,6 @@
|
||||
type foo = Bar of int | Baz
|
||||
|
||||
let main (f : foo) : int =
|
||||
match f with
|
||||
Bar i -> i
|
||||
| Baz -> -1
|
1
src/test/contracts/expected/eq_bool.mligo
Normal file
1
src/test/contracts/expected/eq_bool.mligo
Normal file
@ -0,0 +1 @@
|
||||
let main (a, b : bool * bool) = if a = b then 999 else 1
|
6
src/test/contracts/expected/failwith.mligo
Normal file
6
src/test/contracts/expected/failwith.mligo
Normal file
@ -0,0 +1,6 @@
|
||||
type storage = unit
|
||||
|
||||
let main (p, store : unit * storage)
|
||||
: operation list * storage =
|
||||
(failwith "This contract always fails"
|
||||
: operation list * storage)
|
13
src/test/contracts/expected/fibo.mligo
Normal file
13
src/test/contracts/expected/fibo.mligo
Normal file
@ -0,0 +1,13 @@
|
||||
type storage = unit
|
||||
|
||||
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
|
10
src/test/contracts/expected/fibo2.mligo
Normal file
10
src/test/contracts/expected/fibo2.mligo
Normal file
@ -0,0 +1,10 @@
|
||||
type storage = unit
|
||||
|
||||
let main (p, store : unit * 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
|
12
src/test/contracts/expected/fibo3.mligo
Normal file
12
src/test/contracts/expected/fibo3.mligo
Normal file
@ -0,0 +1,12 @@
|
||||
type storage = unit
|
||||
|
||||
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
|
6
src/test/contracts/expected/fibo4.mligo
Normal file
6
src/test/contracts/expected/fibo4.mligo
Normal file
@ -0,0 +1,6 @@
|
||||
type storage = unit
|
||||
|
||||
let main (p, s : unit * storage) =
|
||||
(fun (f : int -> int) (x : int) -> f x)
|
||||
(fun (x : int) -> x)
|
||||
1
|
5
src/test/contracts/expected/function-shared.mligo
Normal file
5
src/test/contracts/expected/function-shared.mligo
Normal file
@ -0,0 +1,5 @@
|
||||
let foo (i : int) : int = i + 20
|
||||
|
||||
let bar (i : int) : int = i + 50
|
||||
|
||||
let foobar (i : int) : int = foo i + bar i
|
17
src/test/contracts/expected/guess_string.mligo
Normal file
17
src/test/contracts/expected/guess_string.mligo
Normal file
@ -0,0 +1,17 @@
|
||||
type storage = {challenge : string}
|
||||
|
||||
type param = {new_challenge : string; attempt : string}
|
||||
|
||||
type return = operation list * storage
|
||||
|
||||
let attempt (p, store : param * storage) : return =
|
||||
let contract : unit contract =
|
||||
match (Tezos.get_contract_opt Tezos.sender
|
||||
: unit contract option)
|
||||
with
|
||||
Some contract -> contract
|
||||
| None -> (failwith "No contract" : unit contract)
|
||||
in let transfer : operation =
|
||||
Tezos.transaction (unit, contract, 10000000mutez)
|
||||
in let store : storage = {challenge = p.new_challenge}
|
||||
in ([] : operation list), store
|
Loading…
Reference in New Issue
Block a user